diff --git a/content/micropython/03.micropython/00.first-steps/00.intro-micropython/assets/micropython-arduino.png b/content/micropython/00.first-steps/00.intro-micropython/assets/micropython-arduino.png similarity index 100% rename from content/micropython/03.micropython/00.first-steps/00.intro-micropython/assets/micropython-arduino.png rename to content/micropython/00.first-steps/00.intro-micropython/assets/micropython-arduino.png diff --git a/content/micropython/03.micropython/00.first-steps/00.intro-micropython/assets/run-script.gif b/content/micropython/00.first-steps/00.intro-micropython/assets/run-script.gif similarity index 100% rename from content/micropython/03.micropython/00.first-steps/00.intro-micropython/assets/run-script.gif rename to content/micropython/00.first-steps/00.intro-micropython/assets/run-script.gif diff --git a/content/micropython/03.micropython/00.first-steps/00.intro-micropython/intro-micropython.md b/content/micropython/00.first-steps/00.intro-micropython/intro-micropython.md similarity index 100% rename from content/micropython/03.micropython/00.first-steps/00.intro-micropython/intro-micropython.md rename to content/micropython/00.first-steps/00.intro-micropython/intro-micropython.md diff --git a/content/micropython/03.micropython/00.first-steps/01.install-guide/assets/installation-success.png b/content/micropython/00.first-steps/01.install-guide/assets/installation-success.png similarity index 100% rename from content/micropython/03.micropython/00.first-steps/01.install-guide/assets/installation-success.png rename to content/micropython/00.first-steps/01.install-guide/assets/installation-success.png diff --git a/content/micropython/03.micropython/00.first-steps/01.install-guide/assets/repl-print.png b/content/micropython/00.first-steps/01.install-guide/assets/repl-print.png similarity index 100% rename from content/micropython/03.micropython/00.first-steps/01.install-guide/assets/repl-print.png rename to content/micropython/00.first-steps/01.install-guide/assets/repl-print.png diff --git a/content/micropython/03.micropython/00.first-steps/01.install-guide/assets/select-board-ide.png b/content/micropython/00.first-steps/01.install-guide/assets/select-board-ide.png similarity index 100% rename from content/micropython/03.micropython/00.first-steps/01.install-guide/assets/select-board-ide.png rename to content/micropython/00.first-steps/01.install-guide/assets/select-board-ide.png diff --git a/content/micropython/03.micropython/00.first-steps/01.install-guide/assets/select-board.png b/content/micropython/00.first-steps/01.install-guide/assets/select-board.png similarity index 100% rename from content/micropython/03.micropython/00.first-steps/01.install-guide/assets/select-board.png rename to content/micropython/00.first-steps/01.install-guide/assets/select-board.png diff --git a/content/micropython/03.micropython/00.first-steps/01.install-guide/assets/usb-comp.png b/content/micropython/00.first-steps/01.install-guide/assets/usb-comp.png similarity index 100% rename from content/micropython/03.micropython/00.first-steps/01.install-guide/assets/usb-comp.png rename to content/micropython/00.first-steps/01.install-guide/assets/usb-comp.png diff --git a/content/micropython/03.micropython/00.first-steps/01.install-guide/assets/write-code-run.png b/content/micropython/00.first-steps/01.install-guide/assets/write-code-run.png similarity index 100% rename from content/micropython/03.micropython/00.first-steps/01.install-guide/assets/write-code-run.png rename to content/micropython/00.first-steps/01.install-guide/assets/write-code-run.png diff --git a/content/micropython/03.micropython/00.first-steps/01.install-guide/installing-micropython.md b/content/micropython/00.first-steps/01.install-guide/installing-micropython.md similarity index 100% rename from content/micropython/03.micropython/00.first-steps/01.install-guide/installing-micropython.md rename to content/micropython/00.first-steps/01.install-guide/installing-micropython.md diff --git a/content/micropython/03.micropython/00.first-steps/02.first-script/assets/blink.gif b/content/micropython/00.first-steps/02.first-script/assets/blink.gif similarity index 100% rename from content/micropython/03.micropython/00.first-steps/02.first-script/assets/blink.gif rename to content/micropython/00.first-steps/02.first-script/assets/blink.gif diff --git a/content/micropython/03.micropython/00.first-steps/02.first-script/assets/open-files.png b/content/micropython/00.first-steps/02.first-script/assets/open-files.png similarity index 100% rename from content/micropython/03.micropython/00.first-steps/02.first-script/assets/open-files.png rename to content/micropython/00.first-steps/02.first-script/assets/open-files.png diff --git a/content/micropython/03.micropython/00.first-steps/02.first-script/assets/run-script.png b/content/micropython/00.first-steps/02.first-script/assets/run-script.png similarity index 100% rename from content/micropython/03.micropython/00.first-steps/02.first-script/assets/run-script.png rename to content/micropython/00.first-steps/02.first-script/assets/run-script.png diff --git a/content/micropython/03.micropython/00.first-steps/02.first-script/assets/select-board-ide.png b/content/micropython/00.first-steps/02.first-script/assets/select-board-ide.png similarity index 100% rename from content/micropython/03.micropython/00.first-steps/02.first-script/assets/select-board-ide.png rename to content/micropython/00.first-steps/02.first-script/assets/select-board-ide.png diff --git a/content/micropython/03.micropython/00.first-steps/02.first-script/assets/usb-comp.png b/content/micropython/00.first-steps/02.first-script/assets/usb-comp.png similarity index 100% rename from content/micropython/03.micropython/00.first-steps/02.first-script/assets/usb-comp.png rename to content/micropython/00.first-steps/02.first-script/assets/usb-comp.png diff --git a/content/micropython/03.micropython/00.first-steps/02.first-script/first-script.md b/content/micropython/00.first-steps/02.first-script/first-script.md similarity index 100% rename from content/micropython/03.micropython/00.first-steps/02.first-script/first-script.md rename to content/micropython/00.first-steps/02.first-script/first-script.md diff --git a/content/micropython/00.first-steps/first-steps.md b/content/micropython/00.first-steps/first-steps.md new file mode 100644 index 0000000000..a58504c5c1 --- /dev/null +++ b/content/micropython/00.first-steps/first-steps.md @@ -0,0 +1,4 @@ +--- +title: First Steps +description: Get started with MicroPython +--- \ No newline at end of file diff --git a/content/micropython/03.micropython/01.basics/00.digital-io/assets/LED.png b/content/micropython/01.basics/00.digital-io/assets/LED.png similarity index 100% rename from content/micropython/03.micropython/01.basics/00.digital-io/assets/LED.png rename to content/micropython/01.basics/00.digital-io/assets/LED.png diff --git a/content/micropython/03.micropython/01.basics/00.digital-io/assets/pull-down.png b/content/micropython/01.basics/00.digital-io/assets/pull-down.png similarity index 100% rename from content/micropython/03.micropython/01.basics/00.digital-io/assets/pull-down.png rename to content/micropython/01.basics/00.digital-io/assets/pull-down.png diff --git a/content/micropython/03.micropython/01.basics/00.digital-io/assets/pull-up.png b/content/micropython/01.basics/00.digital-io/assets/pull-up.png similarity index 100% rename from content/micropython/03.micropython/01.basics/00.digital-io/assets/pull-up.png rename to content/micropython/01.basics/00.digital-io/assets/pull-up.png diff --git a/content/micropython/03.micropython/01.basics/00.digital-io/assets/select-board-ide.png b/content/micropython/01.basics/00.digital-io/assets/select-board-ide.png similarity index 100% rename from content/micropython/03.micropython/01.basics/00.digital-io/assets/select-board-ide.png rename to content/micropython/01.basics/00.digital-io/assets/select-board-ide.png diff --git a/content/micropython/03.micropython/01.basics/00.digital-io/assets/usb-comp.png b/content/micropython/01.basics/00.digital-io/assets/usb-comp.png similarity index 100% rename from content/micropython/03.micropython/01.basics/00.digital-io/assets/usb-comp.png rename to content/micropython/01.basics/00.digital-io/assets/usb-comp.png diff --git a/content/micropython/03.micropython/01.basics/00.digital-io/digital-io.md b/content/micropython/01.basics/00.digital-io/digital-io.md similarity index 99% rename from content/micropython/03.micropython/01.basics/00.digital-io/digital-io.md rename to content/micropython/01.basics/00.digital-io/digital-io.md index b8a41c53b0..d95558e848 100644 --- a/content/micropython/03.micropython/01.basics/00.digital-io/digital-io.md +++ b/content/micropython/01.basics/00.digital-io/digital-io.md @@ -3,6 +3,7 @@ title: 'Digital I/O' description: 'A guide to digital inputs and outputs using MicroPython.' author: 'Pedro Lima' tags: [MicroPython, Digital I/O] +micropython_type: basics --- Digital pins are fundamental for interacting with the physical world using your Arduino board. With them, you can: diff --git a/content/micropython/03.micropython/01.basics/01.analog-io/analog-io.md b/content/micropython/01.basics/01.analog-io/analog-io.md similarity index 100% rename from content/micropython/03.micropython/01.basics/01.analog-io/analog-io.md rename to content/micropython/01.basics/01.analog-io/analog-io.md diff --git a/content/micropython/03.micropython/01.basics/01.analog-io/assets/LED.png b/content/micropython/01.basics/01.analog-io/assets/LED.png similarity index 100% rename from content/micropython/03.micropython/01.basics/01.analog-io/assets/LED.png rename to content/micropython/01.basics/01.analog-io/assets/LED.png diff --git a/content/micropython/03.micropython/01.basics/01.analog-io/assets/photoresistor.png b/content/micropython/01.basics/01.analog-io/assets/photoresistor.png similarity index 100% rename from content/micropython/03.micropython/01.basics/01.analog-io/assets/photoresistor.png rename to content/micropython/01.basics/01.analog-io/assets/photoresistor.png diff --git a/content/micropython/03.micropython/01.basics/01.analog-io/assets/pwm.gif b/content/micropython/01.basics/01.analog-io/assets/pwm.gif similarity index 100% rename from content/micropython/03.micropython/01.basics/01.analog-io/assets/pwm.gif rename to content/micropython/01.basics/01.analog-io/assets/pwm.gif diff --git a/content/micropython/03.micropython/01.basics/01.analog-io/assets/select-board-ide.png b/content/micropython/01.basics/01.analog-io/assets/select-board-ide.png similarity index 100% rename from content/micropython/03.micropython/01.basics/01.analog-io/assets/select-board-ide.png rename to content/micropython/01.basics/01.analog-io/assets/select-board-ide.png diff --git a/content/micropython/03.micropython/01.basics/01.analog-io/assets/usb-comp.png b/content/micropython/01.basics/01.analog-io/assets/usb-comp.png similarity index 100% rename from content/micropython/03.micropython/01.basics/01.analog-io/assets/usb-comp.png rename to content/micropython/01.basics/01.analog-io/assets/usb-comp.png diff --git a/content/micropython/01.basics/01.overview/overview.md b/content/micropython/01.basics/01.overview/overview.md deleted file mode 100644 index be1db2d232..0000000000 --- a/content/micropython/01.basics/01.overview/overview.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: Overview -description: An introduction to Arduino and MicroPython -author: Francesca Sanfilippo -micropython_type: basics ---- - -MicroPython is an implementation of the Python programming language, and includes some of the standard Python libraries. It is designed to run on microcontrollers with constrained environments. - -In this sequence of guides, you will among other things, learn how to: -- Install MicroPython on your Arduino board, -- Install an editor with support for MicroPython, -- How to make basic scripts that can for example blink an LED, read an analog pin and print things to the terminal (REPL). - -You do not need any prior knowledge in either programming with Arduino or MicroPython, but it is recommended to know the basics of Python. - -What you need to do it is have a Compatible Board and a Code Editor. You can choose between two alternatives: -- **Arduino Lab for MicroPython:** an experimental editor from Arduino, designed for simpler projects. -- **OpenMV:** an editor for more complex projects, such as computer vision. - -## Python vs C/C++. - -If you are experienced with Arduino programming in C and C++ a lot of the presented topics will look familiar to you. -There's a big difference between how we program an Arduino board with the Arduino IDE, using the Arduino programming language (based on C++), and how we program it using MicroPython. -- The “Arduino way” requires compiling the sketch before uploading it to your board. The previous code running is replaced by the new one. -- The “MicroPython way” does not require compiling, as you will have MicroPython installed on the actual board. Code is instead run through an interpreter, line by line. - -## Python vs MicroPython - -MicroPython was created to work under constrained conditions, like a small environment. The main difference between Python and MicroPython is that MicroPython does not have the full standard Python language, it is only a subset of it. \ No newline at end of file diff --git a/content/micropython/01.basics/01.overview/py-hero-banner.png b/content/micropython/01.basics/01.overview/py-hero-banner.png deleted file mode 100644 index 35dc29dfde..0000000000 Binary files a/content/micropython/01.basics/01.overview/py-hero-banner.png and /dev/null differ diff --git a/content/micropython/01.basics/02.board-installation/assets/ble-sense.png b/content/micropython/01.basics/02.board-installation/assets/ble-sense.png deleted file mode 100644 index 52908dbc5e..0000000000 Binary files a/content/micropython/01.basics/02.board-installation/assets/ble-sense.png and /dev/null differ diff --git a/content/micropython/01.basics/02.board-installation/assets/ble.png b/content/micropython/01.basics/02.board-installation/assets/ble.png deleted file mode 100644 index e63994064d..0000000000 Binary files a/content/micropython/01.basics/02.board-installation/assets/ble.png and /dev/null differ diff --git a/content/micropython/01.basics/02.board-installation/assets/board-selected.png b/content/micropython/01.basics/02.board-installation/assets/board-selected.png deleted file mode 100644 index 96ca301d46..0000000000 Binary files a/content/micropython/01.basics/02.board-installation/assets/board-selected.png and /dev/null differ diff --git a/content/micropython/01.basics/02.board-installation/assets/boardmanager-portenta.png b/content/micropython/01.basics/02.board-installation/assets/boardmanager-portenta.png deleted file mode 100644 index 8611774cc0..0000000000 Binary files a/content/micropython/01.basics/02.board-installation/assets/boardmanager-portenta.png and /dev/null differ diff --git a/content/micropython/01.basics/02.board-installation/assets/boardmanager.png b/content/micropython/01.basics/02.board-installation/assets/boardmanager.png deleted file mode 100644 index c6045bb130..0000000000 Binary files a/content/micropython/01.basics/02.board-installation/assets/boardmanager.png and /dev/null differ diff --git a/content/micropython/01.basics/02.board-installation/assets/examplesketch.png b/content/micropython/01.basics/02.board-installation/assets/examplesketch.png deleted file mode 100644 index 4de4d978ac..0000000000 Binary files a/content/micropython/01.basics/02.board-installation/assets/examplesketch.png and /dev/null differ diff --git a/content/micropython/01.basics/02.board-installation/assets/flashed.png b/content/micropython/01.basics/02.board-installation/assets/flashed.png deleted file mode 100644 index 5e81087c88..0000000000 Binary files a/content/micropython/01.basics/02.board-installation/assets/flashed.png and /dev/null differ diff --git a/content/micropython/01.basics/02.board-installation/assets/giga-r1-wifi.png b/content/micropython/01.basics/02.board-installation/assets/giga-r1-wifi.png deleted file mode 100644 index 45c29be8a9..0000000000 Binary files a/content/micropython/01.basics/02.board-installation/assets/giga-r1-wifi.png and /dev/null differ diff --git a/content/micropython/01.basics/02.board-installation/assets/nano-rp2040.png b/content/micropython/01.basics/02.board-installation/assets/nano-rp2040.png deleted file mode 100644 index d38a07ea22..0000000000 Binary files a/content/micropython/01.basics/02.board-installation/assets/nano-rp2040.png and /dev/null differ diff --git a/content/micropython/01.basics/02.board-installation/assets/portenta-c33-1.png b/content/micropython/01.basics/02.board-installation/assets/portenta-c33-1.png deleted file mode 100644 index 87ce87533d..0000000000 Binary files a/content/micropython/01.basics/02.board-installation/assets/portenta-c33-1.png and /dev/null differ diff --git a/content/micropython/01.basics/02.board-installation/assets/portenta-c33-2.png b/content/micropython/01.basics/02.board-installation/assets/portenta-c33-2.png deleted file mode 100644 index c6e2846adf..0000000000 Binary files a/content/micropython/01.basics/02.board-installation/assets/portenta-c33-2.png and /dev/null differ diff --git a/content/micropython/01.basics/02.board-installation/assets/portenta-c33-3.png b/content/micropython/01.basics/02.board-installation/assets/portenta-c33-3.png deleted file mode 100644 index fe48fda770..0000000000 Binary files a/content/micropython/01.basics/02.board-installation/assets/portenta-c33-3.png and /dev/null differ diff --git a/content/micropython/01.basics/02.board-installation/assets/portenta.png b/content/micropython/01.basics/02.board-installation/assets/portenta.png deleted file mode 100644 index b696c79a88..0000000000 Binary files a/content/micropython/01.basics/02.board-installation/assets/portenta.png and /dev/null differ diff --git a/content/micropython/01.basics/02.board-installation/board-installation.md b/content/micropython/01.basics/02.board-installation/board-installation.md deleted file mode 100644 index 56e80d6c52..0000000000 --- a/content/micropython/01.basics/02.board-installation/board-installation.md +++ /dev/null @@ -1,305 +0,0 @@ ---- -title: Board Installation -description: A list of Arduino boards compatible with MicroPython and how to install them. -author: Francesca Sanfilippo, Karl Söderby & Jacob Hylén -micropython_type: basics -featured: micropython -hero_image: "./hero-banner.png" -hero_position: 1 ---- - -So what do you need to start your first project with MicroPython and Arduino? First, you will need a compatible board. In this page, you will find the compatible boards, with instructions on how to install them. - -In order to understand which board is more suitable to your project, you can visit the documentation of each board. - -## Supported Boards - -The following boards support MicroPython: -- [Nano BLE](https://store.arduino.cc/products/arduino-nano-33-ble) / [Nano BLE Sense](https://store.arduino.cc/products/arduino-nano-33-ble-sense) / [Nano BLE Sense Rev2](https://store.arduino.cc/products/nano-33-ble-sense-rev2) -- [Nano RP2040 Connect](https://store.arduino.cc/products/arduino-nano-rp2040-connect) -- [Nano ESP32](https://store.arduino.cc/products/nano-esp32) -- [Nicla Vision](https://store.arduino.cc/products/nicla-vision) -- [GIGA R1 WiFi](https://store.arduino.cc/products/giga-r1-wifi) -- [Portenta H7](https://store.arduino.cc/collections/portenta-family/products/portenta-h7) -- [Portenta C33](https://store.arduino.cc/collections/portenta-family/products/portenta-c33) - - -## Arduino MicroPython Installer - -We have developed a tool for installing the MicroPython firmware to your Arduino boards with a simple click. This tool lets you plug in the board, select it from a menu, and automatically flash the latest firmware, or a custom one of your choice to the board. - -Download [Arduino MicroPython Installer here](https://labs.arduino.cc/en/labs/micropython-installer). - -Arduino MicroPython Installer is part of [Arduino Labs](https://labs.arduino.cc), and is therefore considered experimental software. - -To get started, open the app and plug in your board to the computer. You should now see it pop up ready to be selected in the list. If it doesn't, try putting it in bootloader mode by double tapping the reset button. - -![Arduino Nano ESP32 detected!](./assets/board-selected.png) - -Now, uploading the MicroPython firmware is as easy as pressing **"install MicroPython"** and waiting for a couple of seconds while the installer tool takes care of everything else. - -![Firmware Successfully Uploaded!](./assets/flashed.png) - - -If you don't want to use the Arduino MicroPython Installer tool, these are the per-board steps for manual installation: - -## Nano ESP32 - -Software required: -- MicroPython Firmware -- [esptool.py](https://github.com/espressif/esptool) installed -- [Python](https://www.python.org) installed on your computer -​ -First prepare the board for a new firmware upload by shorting the B1 pin to GND and pressing the reset button. - -Then run the following esptool command to erase the flash, replace `{port-name}` with the name of the port your board is connected to: - -​ -``` -esptool.py --chip esp32s3 --port {port-name} erase_flash -``` -​ -Then run this command to upload the new firmware, replace `{firmware.bin}` with the name of your firmware binary file, and `{port-name}` with the name of the port your board is connected to: - - -​ -``` -esptool.py --chip esp32s3 --port {port-name} write_flash -z 0 {firmware.bin} - -``` -​ -Now your board should be prepared to be programmed with MicroPython! - -## Nano 33 BLE & Nano 33 BLE Sense - -- [Nano 33 BLE documentation](/hardware/nano-33-ble). -- [Nano 33 BLE Rev2 documentation.](/hardware/nano-33-ble-rev2) -- [Nano 33 BLE Sense documentation.](/hardware/nano-33-ble-sense) -- [Nano 33 BLE Sense Rev2 documentation.](/hardware/nano-33-ble-sense-rev2) - -![Nano 33 BLE.](assets/ble.png) - -The process for flashing the firmware on the Nano 33 BLE requires to first update the bootloader and SoftDevice. Once this is done you can flash the MicroPython firmware to your board. - -This process requires a version of the [Arduino IDE](https://www.arduino.cc/en/main/software) installed, which is explained in the next step. - -**Step 1: Installing the Core** - -Start by making sure that you have the respective core installed. Open the **Arduino IDE** (not Arduino Lab for MicroPython) and navigate to the boards manager. Search for your board (Nano 33 BLE), and make sure you have the latest version of the core installed. More detailed information about this step can be found [here](/software/ide-v2/tutorials/ide-v2-board-manager). - -![Board manager](assets/boardmanager.png) - -This is not only needed to upload the next sketch, but you're also going to dive into the core files themselves to find a specific tool in an upcoming step. - -**Step 2: Update Bootloader** - -In the Nano 33 BLE core is an example sketch that you will use to update the bootloader and SoftDevice of your board. Go back to the Arduino IDE and navigate to `File > Examples > Nano33BLE_System > Nano33_updateBLandSoftDevice` and open the sketch. - -![Example sketch](assets/examplesketch.png) - -Upload the sketch to your board. Beware! the bootloader is not updated just yet! Once the sketch is uploaded, you can interface with your board through the serial monitor to actually update the bootloader. - -In the Serial monitor, you are asked to confirm that you want to update the bootloader. In the message text box in the top of the serial monitor, write a **"y"** and press enter to send it to your board. - -You can now watch as the bootloader update process progresses, **do not disconnect or reset your board during this process** or you could brick your board. - -Once this bar completes, you will be prompted with another choice. This time it asks if you want to update the SoftDevice on your board. Repeat the process of sending a **"y"** to the board, and watch the progress of this too. - -When this bar fills and the SoftDevice update completes, the board will restart, and you've successfully made it through the procedure. - -***Note: An important thing to do at this point which is easily forgotten is to close the serial monitor, we will need to use the serial port for other things very soon and if you leave the monitor open it will be busy and won't be able to receive any new interactions.*** - -**Step 3: Download Firmware** - -Now you will need to find the specific firmware that you need to flash to your board. You can find the available firmware on the [MicroPython](/micropython) Documentation site. - -Download the `.bin` file that corresponds to the board you have. - -Now you will need to dive into the core files you downloaded in the first step to find a command line tool that is included called BOSSAC. This process will be different for you depending on if you're on a Windows or MacOS computer. - - -**Step 4a: Flash Firmware (Windows)** - ->Instructions for MacOS are available just below this section. - -The file you will is named `bossac.exe` and can be found in the following directory: - -``` -C:\Users\[your-username]\AppData\Local\Arduino15\staging\packages\bossac-1.9.1-arduino2-windows.tar.gz\bossac-1.9.1-arduino2-windows.tar\bin\` -``` - -One you've found the file, extract it from the `.tar` archive and copy it somewhere else, your desktop for example. - -Open a command terminal and start typing in `start`, now drag and drop the bossac.exe file you've found into the terminal, and press enter. - -If successful, another command terminal window should open in which you are able to execute the command that will flash your board with the MicroPython firmware. - -Execute the following command, but replace the port with the name of the port where your board is connected, and the firmware file with the directory where you have placed the firmware you downloaded previously: - -``` -bossac -e -w --offset=0x16000 --port=[port] -i -d -U -R [firmware] -``` - -Don't disconnect or power off your board during this part of the process, watch the progress of flashing the firmware to your board. Once complete, you're all set and you're ready to start programming the board in MicroPython. - -Go to the Arduino Lab MicroPython IDE and press connect in the top left, choose the port, and you are now ready to program your Nano 33 BLE. - -**Step 4b: Flash Firmware (MacOS)** - -The file you will need to access is called `bossac` and can be found in the following directory: - -``` -Users/[your-user]/Library/Arduino15/packages/arduino/tools/bossac/1.9.1-arduino2 -``` - -***Note: The `"Library"` directory is hidden, press `Shift + Command + . ` to reveal hidden directories.*** - -Open a terminal window and drag and drop the `bossac` file into the terminal window. - -Now, you should be able to execute the command that will flash your board with the MicroPython firmware. - -Execute the following command, but replace the port with the name of the port where your board is connected, and the firmware file with the directory where you have placed the firmware you downloaded previously: - -``` -bossac -e -w --offset=0x16000 --port=[port] -i -d -U -R [firmware] -``` - -Again, don't disconnect or power off your board during this part of the process, watch the progress of flashing the firmware to your board. Once complete, you're all set and you're ready to start programming the board in MicroPython. - -Go to the Arduino Lab MicroPython IDE and press connect in the top left, choose the port, and you are now ready to program your Nano 33 BLE! - -## Nano RP2040 Connect - -- [Arduino Nano RP2040 Documentation](https://docs.arduino.cc/hardware/nano-rp2040-connect) - -![Nano RP2040 Connect.](assets/nano-rp2040.png) - -To program your Nano RP2040 Connect board with MicroPython, follow the instructions below. The installation for Nano RP2040 Connect requires no additional software tools for installation. - -Follow the steps below to install MicroPython on the Nano RP2040 Connect board. - -1. Download the `.uf2` firmware file from the [MicroPython](/micropython) page. -2. Connect the `REC` pin to `GND` (they are placed next to each other) and press the reset button. This exposes the board's file system to your computer. -3. Drag and drop the firmware file onto the boards flash storage which shows up as an external storage device on your computer -4. Go to the Arduino Lab MicroPython IDE and press connect in the top left, choose the port. - -Congratulations, you are now ready to program your Nano RP2040 Connect with MicroPython. - -## GIGA R1 WiFi - -- [Arduino GIGA R1 WiFi documentation](/hardware/giga-r1-wifi) - -![GIGA R1 WiFi.](assets/giga-r1-wifi.png) - -The installation instructions for the **GIGA R1 WiFi** is identical to the **Portenta H7** instructions found just below. - -You will however need a different firmware, which you can download from the link below: - -- [Download GIGA R1 WiFi MicroPython firmware (dfu)](/resources/firmware/GIGAR1_MP_FW.dfu) - -***The GIGA R1 WiFi and Portenta H7 boards are based on the same microcontroller, [STM32H747XI](static/resources/datasheets/stm32h747xi.pdf) and therefore share the same installation instructions.*** - -## Portenta H7 - -- [Arduino Portenta H7 Documentation](https://docs.arduino.cc/hardware/portenta-h7) - -![Portenta H7.](assets/portenta.png) - -To install MicroPython on the Portenta H7 you will first need to install the corresponding core which also installs the required command line tool, called `dfu-util`. - -This tool can be used to directly flash a binary to your board, in this case, a MicroPython build. - -***The instructions below uses the `dfu-util` that is bundled with the Arduino IDE. You can also obtain the `dfu-util` directly, through the [dfu-util home page](https://dfu-util.sourceforge.net/) or via package management systems such as [Homebrew](https://formulae.brew.sh/formula/dfu-util) (MacOS / Linux).*** - -**Step 1: Install Arduino IDE** - -First, download and install the [Arduino IDE](https://arduino.cc/en/software) for your operating system. - -Open the Arduino IDE (not Arduino Lab for MicroPython) and navigate to the boards manager. Search for "Portenta H7", and make sure you have the latest version of the core installed. - -![Installing the Portenta core](assets/boardmanager-portenta.png) - -**Step 2: Download Firmware** - -Now you will need to find the specific firmware that you need to flash to your board. You can find the available firmware on the [MicroPython with Arduino](https://docs.arduino.cc/micropython/) home page. The firmware is available as a `.dfu` file for the Portenta H7. - -In the next step you will be diving into the core files you downloaded in the first step to find a command line tool called **dfu-util**. This process is differs depending on if you're on a Windows or MacOS computer. MacOS instructions are available further below. - -**Step 3a: Install Firmware (Windows)** - -To flash your board, you will need a file named `dfu-util.exe`. This is found in your following directory: - -``` -C:\Users\\AppData\Local\Arduino15\staging\packages\dfu-util-0.10.0-arduino1-windows.tar.bz2\dfu-util-0.10.0-arduino1-windows.tar\windows\ -``` - -One you've found the file, extract it from the .tar archive and copy it somewhere else, your desktop for example. - -Open a command terminal and start typing in `start`, now drag and drop the dfu-util.exe file you've found into the terminal, and press enter. - -If successful, another command terminal window should open in which you are able to execute the command that will flash your board with the MicroPython firmware. - -Double tap the reset button on your board to put it in DFU mode, and execute the following command, but replace the path of the firmware file with the directory where you have placed the firmware you downloaded previously: - -``` -dfu-util -a 0 -d 0x2341:0x035b -D .dfu -``` - -Again, don't disconnect or power off your board during this part of the process, watch the progress of flashing the firmware to your board. - -You should now see **two** progress bars appear in one after the other. The first one is showing the progress of erasing the firmware that was previously on the board, and the second one is showing the progress of flashing the new firmware. - -Once complete, you're all set and you're ready to start programming the board in MicroPython. - -Go to the Arduino Lab MicroPython IDE and press connect in the top left, choose the port, and code away! - -**Step 3b: Install Firmware (MacOS)** - -The file you will need to access is named `dfu-util` and can be found in the following directory: - -``` -Users/[your-username]/Library/Arduino15/packages/arduino/tools/dfu-util/0.10.0-arduino1/dfu-util -``` - -***Note: The `"Library"` directory is hidden, press `Shift + Command + . ` to reveal hidden directories.*** - -Open a terminal window and drag and drop the dfu-util file into the terminal window. - -Now, you should be able to execute the command that will flash your board with the MicroPython firmware. - -Double tap the reset button on your board to put it in DFU mode, and execute the following command, but replace the path of the firmware file with the directory where you have placed the firmware you downloaded previously: - -``` -dfu-util -a 0 -d 0x2341:0x035b -D .dfu -``` - -Do not disconnect your board during this part of the process, watch the progress of flashing the firmware to your board. - -Once complete, you're all set and you're ready to start programming the board in MicroPython. - -Go to the Arduino Lab MicroPython IDE and press connect in the top left corner, choose the port and you are ready to load scripts to your board. - -## Portenta C33 - -To install the MicroPython firmware to the Portenta C33 board, you can use the **Arduino MicroPython Installer**. This tool lets you plug in the board, select it from a menu, and automatically flash the latest firmware or a custom one of your choice to the board. You can download the [Arduino MicroPython Installer here](https://labs.arduino.cc/en/labs/micropython-installer). - -***The Arduino MicroPython Installer is part of [Arduino Labs](https://labs.arduino.cc) and is considered experimental software.*** - -Before installing the MicroPython firmware, **ensure you have installed the latest Portenta Renesas board package**. To install the board package for the Portenta C33 board, navigate to **Tools > Board > Boards Manager** or click the Boards Manager icon in the left tab of the IDE. In the Boards Manager tab, search for `renesas` and install the latest `Arduino Renesas Portenta Boards` version. - - -![Installing the Arduino Renesas Portenta Board Package in the Arduino IDE](./assets/portenta-c33-1.png) - - -With the latest board package installed, open the Arduino MicroPython Installer and plug your board into your computer; your board should appear ready to be selected, as shown in the image below. If your board does not appear in the installer, try putting it in bootloader mode by double-tapping your board's reset button. - - - -![Portenta C33 board detected on the Arduino MicroPython Installer](./assets/portenta-c33-2.png) - -To install the MicroPython firmware, press the **INSTALL MICROPYTHON** button and wait a few seconds while the installer tool takes care of everything else. When finished, you should see a message in the image below. - -![Firmware successfully uploaded to the Portenta C33 board](./assets/portenta-c33-3.png) - - -Now you are ready to use MicroPython with your Portenta C33 board. \ No newline at end of file diff --git a/content/micropython/01.basics/02.board-installation/hero-banner.svg b/content/micropython/01.basics/02.board-installation/hero-banner.svg deleted file mode 100644 index 4d1f364db5..0000000000 --- a/content/micropython/01.basics/02.board-installation/hero-banner.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/content/micropython/01.basics/02.board-installation/py-hero-banner.png b/content/micropython/01.basics/02.board-installation/py-hero-banner.png deleted file mode 100644 index 2a33e91b55..0000000000 Binary files a/content/micropython/01.basics/02.board-installation/py-hero-banner.png and /dev/null differ diff --git a/content/micropython/03.micropython/01.basics/02.loops/assets/select-board-ide.png b/content/micropython/01.basics/02.loops/assets/select-board-ide.png similarity index 100% rename from content/micropython/03.micropython/01.basics/02.loops/assets/select-board-ide.png rename to content/micropython/01.basics/02.loops/assets/select-board-ide.png diff --git a/content/micropython/03.micropython/01.basics/02.loops/assets/usb-comp.png b/content/micropython/01.basics/02.loops/assets/usb-comp.png similarity index 100% rename from content/micropython/03.micropython/01.basics/02.loops/assets/usb-comp.png rename to content/micropython/01.basics/02.loops/assets/usb-comp.png diff --git a/content/micropython/03.micropython/01.basics/02.loops/loops.md b/content/micropython/01.basics/02.loops/loops.md similarity index 100% rename from content/micropython/03.micropython/01.basics/02.loops/loops.md rename to content/micropython/01.basics/02.loops/loops.md diff --git a/content/micropython/01.basics/03.code-editors/assets/mpylabs-ss.png b/content/micropython/01.basics/03.code-editors/assets/mpylabs-ss.png deleted file mode 100644 index b56c8a1a7e..0000000000 Binary files a/content/micropython/01.basics/03.code-editors/assets/mpylabs-ss.png and /dev/null differ diff --git a/content/micropython/01.basics/03.code-editors/assets/openmv-ss.png b/content/micropython/01.basics/03.code-editors/assets/openmv-ss.png deleted file mode 100644 index ede5900ed6..0000000000 Binary files a/content/micropython/01.basics/03.code-editors/assets/openmv-ss.png and /dev/null differ diff --git a/content/micropython/01.basics/03.code-editors/code-editors.md b/content/micropython/01.basics/03.code-editors/code-editors.md deleted file mode 100644 index 35d440d769..0000000000 --- a/content/micropython/01.basics/03.code-editors/code-editors.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: Code Editors -description: Explore the available code editors for programming your Arduino board with MicroPython -author: Francesca Sanfilippo & Karl Söderby -micropython_type: basics -featured: micropython -hero_image: "./hero-banner.png" ---- - -To write and load scripts to your board, you will also need a Code Editor. In this page, you will find two alternatives: -- **Arduino Lab for MicroPython:** an experimental editor from Arduino, designed for simpler projects. -- **OpenMV:** an editor for more complex projects, such as computer vision. - -## Arduino Lab for MicroPython - -Arduino Lab for MicroPython is a software that supports programming Arduino boards with MicroPython. Through the customized editor, we can install MicroPython, and upload scripts directly to the board. The editor is able to manage the files and you can see what is uploaded on the board and vice versa. - -![Arduino Lab for MicroPython](assets/mpylabs-ss.png) - -- [Download Arduino Lab for MicroPython](https://labs.arduino.cc/en/labs/micropython). - -## OpenMV Editor - -OpenMV is a platform that supports programming Arduino boards with MicroPython. Through the OpenMV editor, we can install MicroPython and upload scripts directly to the board. There's also a number of examples available directly in the editor. - -![OpenMV editor.](assets/openmv-ss.png) - -- [Download OpenMV](https://openmv.io/pages/download). - -***You can also check out the full list of examples in the [OpenMV's GitHub repository](https://github.com/openmv/openmv/tree/master/scripts/examples/50-Arduino-Boards).*** \ No newline at end of file diff --git a/content/micropython/01.basics/03.code-editors/py-hero-banner.png b/content/micropython/01.basics/03.code-editors/py-hero-banner.png deleted file mode 100644 index 00021c97cc..0000000000 Binary files a/content/micropython/01.basics/03.code-editors/py-hero-banner.png and /dev/null differ diff --git a/content/micropython/03.micropython/01.basics/03.data-logger/assets/data-csv.png b/content/micropython/01.basics/03.data-logger/assets/data-csv.png similarity index 100% rename from content/micropython/03.micropython/01.basics/03.data-logger/assets/data-csv.png rename to content/micropython/01.basics/03.data-logger/assets/data-csv.png diff --git a/content/micropython/03.micropython/01.basics/03.data-logger/assets/select-board-ide.png b/content/micropython/01.basics/03.data-logger/assets/select-board-ide.png similarity index 100% rename from content/micropython/03.micropython/01.basics/03.data-logger/assets/select-board-ide.png rename to content/micropython/01.basics/03.data-logger/assets/select-board-ide.png diff --git a/content/micropython/03.micropython/01.basics/03.data-logger/assets/usb-comp.png b/content/micropython/01.basics/03.data-logger/assets/usb-comp.png similarity index 100% rename from content/micropython/03.micropython/01.basics/03.data-logger/assets/usb-comp.png rename to content/micropython/01.basics/03.data-logger/assets/usb-comp.png diff --git a/content/micropython/03.micropython/01.basics/03.data-logger/data-logger.md b/content/micropython/01.basics/03.data-logger/data-logger.md similarity index 100% rename from content/micropython/03.micropython/01.basics/03.data-logger/data-logger.md rename to content/micropython/01.basics/03.data-logger/data-logger.md diff --git a/content/micropython/03.micropython/01.basics/04. essentials/essentials.md b/content/micropython/01.basics/04. essentials/essentials.md similarity index 100% rename from content/micropython/03.micropython/01.basics/04. essentials/essentials.md rename to content/micropython/01.basics/04. essentials/essentials.md diff --git a/content/micropython/01.basics/04.micropython-basics/assets/labs-connect.png b/content/micropython/01.basics/04.micropython-basics/assets/labs-connect.png deleted file mode 100644 index 53d4b1d934..0000000000 Binary files a/content/micropython/01.basics/04.micropython-basics/assets/labs-connect.png and /dev/null differ diff --git a/content/micropython/01.basics/04.micropython-basics/micropython-basics.md b/content/micropython/01.basics/04.micropython-basics/micropython-basics.md deleted file mode 100644 index af91c68cf9..0000000000 --- a/content/micropython/01.basics/04.micropython-basics/micropython-basics.md +++ /dev/null @@ -1,158 +0,0 @@ ---- -title: MicroPython Basics -description: An introduction to MicroPython -author: Francesca Sanfilippo & Karl Söderby -micropython_type: basics ---- - -As you read in the Overview, MicroPython is an implementation of Python. In this page, you will find some basic and intermediate MicroPython scripts that can be used by any Arduino board. This includes some very common concepts such as variables, loops, delays, how to print and more. - -***There are some differences between MicroPython and Python, which mostly concern standard library and types, but also some language-level features.*** - -After you download [Arduino Lab for MicroPython](https://labs.arduino.cc/en/labs/micropython), click the file for your system, extract and run the application. The interface is similar to Arduino IDE. - -First of all, we need to connect our board to the computer via USB. - -After connecting the board, click on the connect button, and select the port. - -![Connect and select the port.](assets/labs-connect.png) - -Now that you have connected your board, let’s create a file that will contain the script that will run on your board. Click on New button to create your file. The editor automatically creates the main file in the board. - -If you are not working with the editor, the file should be named main.py and should be saved to your board manually. The board will recognize this as the main program. - -## First MicroPython Script - -Our first example is a basic script that will print `Hello world!` every second in the terminal. Paste the below script in the editor, and press the **"Play"** button. - -```python -print('Hello world!') -``` - -## Program Constructs - -There are three basic programming constructs which are Sequential, Looping and Branching. -- Sequential: a sequence of instructions. -- Looping: the program is executed according to the condition being used. There are two functions: while loop and for loop. -- Branching: it is a programming construct where a section of code is run only if a condition is met. - -In this section we’ll see some of program constructs. - -## Variables, While Loop and Sleep - -In this second example we introduce the module time using import in order to pause the execution for a specific time. The module help us control the board with MicroPython. - -```python -import time -content = "Hello world!" - -while True: - print(content) - time.sleep(1) -``` - -By definition a variable is a string of characters and numbers associated with a piece of information. We define the variable content `Hello World!`. - -Then with the `while` loop we execute the statements as long as the condition is true. In the code we use the `sleep` function to pause the execution of the script for a second before it continues to print. This is imported from the `time` module. - -## Functions - -A function is a block of code, a sequence of instructions composed by several statements, which runs only when it is called. -You can pass the information as parameters into a function. A function can have input arguments, and can also have output parameters. - -We can define our own functions, the most common way can be specified using the def keyword, inside the parentheses you can find the arguments if there are. Take a look to the example below: - -```python -def my_function(): - print("Hello world!") -``` - -Then you can call your function using the function name followed by parentheses: - -```python -my_function() -``` - -The function need two components: the header, starting with keyword def, followed by parentheses with inside the arguments and ending by colon (:) and the indented body is composed by descriptive string, function statements, return statements. - -This script prints "Hello world!" every second. In addition, the function counter_function() increases the number every second and will be printed next to. - -```python -import time - -content = "Hello world!" -count = 0 - -def counter_function(): - global count - count = count + 1 - -while True: - counter_function() - print(content, count) - time.sleep(1) -``` - -## Conditionals and Loops - -MicroPython supports logical conditions from mathematics, that can be used in several ways, the most common is an "if conditional" and “for loop”. The if statements is written by if keyword and it needs the indentation, otherwise you will get an error. - -### If/Else Statement - -A if/else statement is used to handle conditions in your program. These statements guide the program while making decisions based on the conditions encountered by the program. - -You can try the code below: - -```python -a = 42 -b = 23 -if a > b : - print("a is greater than b") -else : - print("a is not greater than b") -``` - -The result in this case is always going to be: `a is greater than b`, because `42` is larger than `23`. - -### For Loop - -Simple use of a for loop and functions. This script counts to 10, and then back to 0. - -```python -import time - -count = 0 - -def function_increase(): - global count - count = count +1 - print(count) - -def function_decrease(): - global count - count = count -1 - print(count) - -while True: - for x in range(10): - function_increase() - time.sleep(1) - - for x in range(10): - function_decrease() - time.sleep(1) -``` - -## Arrays - -An array is one of the most known and used construct in programming. In MicroPython an array by definition is a collection of elements (values or variables), selected by one or more indices computed at run-time, you refer to an array element by referring to the index number. - -```python -myFruit = ['orange', 'persimon', 'apple', 'kiwi', 'lemon'] - -def printFruitNames(): - for fruit in myFruit: - print(fruit) - -printFruitNames() -``` \ No newline at end of file diff --git a/content/micropython/01.basics/04.micropython-basics/py-hero-banner.png b/content/micropython/01.basics/04.micropython-basics/py-hero-banner.png deleted file mode 100644 index 0aaf7ba007..0000000000 Binary files a/content/micropython/01.basics/04.micropython-basics/py-hero-banner.png and /dev/null differ diff --git a/content/micropython/01.basics/05.digital-analog-pins/digital-analog-pins.md b/content/micropython/01.basics/05.digital-analog-pins/digital-analog-pins.md deleted file mode 100644 index 5ba0ba6616..0000000000 --- a/content/micropython/01.basics/05.digital-analog-pins/digital-analog-pins.md +++ /dev/null @@ -1,171 +0,0 @@ ---- -title: Digital and Analog Pins -description: Learn how to use digital and analog Pins with Micropython -author: Francesca Sanfilippo & Karl Söderby -micropython_type: basics ---- - -In this chapter we will learn about managing digital and analog pins. - -All the compatible boards have a series of pins, most of these pins work as a general-purpose input/output (GPIO) pin. There are Digital Pins and Analog Pins depending on the signal. We will learn how to use the inputs and outputs. - -There are essentially two types of pins, analog and digital pins. Digital pins can be set to either HIGH (usually 5V or 3.3V) or LOW (0V). You can use that to e.g. read a button state or toggle an LED. - -***Important: unfortunately, the MicroPython implementation does not match the regular pinout of your board. This means, that if you want to use for example, digital pin (5), it might be digital pin (27) on one board, or digital pin (14) on another. Please visit the [Board API article](/micropython/basics/board-examples) to see what the pin map for your board is.*** - -## Digital Pins - -Digital signals have two distinct values: HIGH (1) or LOW (0). You use digital signals in situations where the input or output will have one of those two values. For example, you can use a digital signal to turn an LED on or off. - -### Digital Write - -In this section we will introduce the `machine` module to control the state of a pin. In this example, we will name the pin `myLED`. - -In MicroPython we can declare a `Pin` with two arguments: Pin number, such as `25`, which defines the number of the pin that you would like to control, and `Pin.OUT`, to declare a pin as output. - -Finally, to turn the pin to a high or low state, we set the `value` to either `1` or `0`. - -```python -from machine import Pin #import pin function - -myLED = Pin(25, Pin.OUT) #declare pin 25 as an output - -myLED.value(1) #set pin to a high state (1) / ON -myLED.value(0) #set pin to a low state (0) / OFF -``` - -To create the classic "blink" example, we can also import the `time` module, and create a `while` loop. - -The following example blinks the onboard LED every second. - -```python -from machine import Pin -import time - -myLED = Pin(25, Pin.OUT) #Nano RP2040 Connect -#myLED = Pin(10, Pin.OUT) #Nano 33 BLE / Nano 33 BLE Sense -#myLED = Pin(2, Pin.OUT) #Portenta H7 - - -while True: - myLED.value(0) - time.sleep(1) - myLED.value(1) - time.sleep(1) -``` - -### Digital Read (Pull Up) - -In this example we read a digital value from a digital pin, using the `PULL_UP` mode. Here, we declare the pin an input through the `Pin.IN` command. - -Then, we use `p2.value()` to read the state, which returns either 0 (low) or 1 (high). - -```python -from machine import Pin -import utime - -p2 = Pin(25, Pin.IN, Pin.PULL_UP) - -while True: - print(p2.value()) - utime.sleep(1) -``` - -### Digital Read (Pull Down) - -In this example we read a digital value from a digital pin, using the `PULL_DOWN` mode. Here, we declare the pin an input through the `Pin.IN` command. - -Then, we use `p2.value()` to read the state, which returns either 0 (low) or 1 (high). - -```python -from machine import Pin -import utime - -p2 = Pin(25, Pin.IN, Pin.PULL_DOWN) - -while True: - print(p2.value()) - utime.sleep(1) -``` - -## Analog Pins - -An example of the analog pin is the ADC class, which supplies an interface to analog-to-digital converters, and figures a single endpoint that can sample a continuous voltage and convert it to a discretized value. - -There are four methods to use inside the ADC class: `ADC.init`, `ADC.block()`, `ADC.read_16()` and `ADC.read_uv()`. - -### Analog Read - -To read an analog pin, we can use the `ADC.read_u16` command. This reads the specified analog pin and returns an integer in the range 0 - 65535. For this, we need to import `ADC` and `Pin` from the `machine` module. - -```python -import machine -import time - -# Make sure to follow the GPIO map for the board you are using. -# Pin 29 in this case is the "A3" pin on the Nano 33 BLE / BLE Sense -adc_pin = machine.Pin(29) -adc = machine.ADC(adc_pin) - -while True: - reading = adc.read_u16() - print("ADC: ",reading) - time.sleep_ms(500) -``` - -***If you are using an [Arduino Nano RP2040 Connect](https://store.arduino.cc/products/arduino-nano-rp2040-connect), you can also do the following: `adc = ADC("A4")`. For more information check out the example [here](http://docs.arduino.cc/micropython/basics/board-examples/#analog-read).*** - -## PWM (Pulse Width Modulation) - -[PWM](/learn/microcontrollers/analog-output) is used to produce analog results with digital means, by switching ON/OFF a signal rapidly. - -As a result, you can simulate a specific voltage written to a pin. In the example below, we write `30000` in a range between 0 - 65535 (16 bits), which if you connect an LED to the pin, will be on at about "half" capacity. - -For this, we need to import `PWM` and `Pin` from the `machine` module. - -### Coding with PWM - -```python -from machine import Pin, PWM, ADC - -pwm = PWM(Pin(15)) -duty = 30000 #between 0-65000 - -pwm.freq(1000) - -while True: - pwm.duty_u16(duty) -``` -In this example: - -- `Pin(15)` is attached to PWM -- `duty` is set at 3000 -- `freq` is set at 1 Hz - -### PWM on the GIGA R1 - -On STM32 boards like the [Arduino GIGA R1 WiFi](https://store.arduino.cc/products/giga-r1-wifi), PWM is handled differently. You need to use the `Timer` class along with the `Pin` class from the `pyb` module. - -Here's the correct code that works on these boards: - -```python -from pyb import Pin, Timer - -p = Pin('A13') # Replace 'A13' with your desired PWM-capable pin -tim = Timer(2, freq=1000) -ch = tim.channel(1, Timer.PWM, pin=p) -ch.pulse_width_percent(25) -``` - -In this example: - -- `p` is a `Pin` object initialized on pin `'A13'`. This pin is set up for PWM output. -- `tim` is a `Timer` object initialized with timer number 2 and a frequency of 1000 Hz. -- `ch` is a PWM channel created on timer 2, channel 1, and is associated with pin `p`. -- `ch.pulse_width_percent(25)` sets the duty cycle of the PWM signal to 25%. -- `'A13'` is marked as **DAC1** on the GIGA R1 WiFi - - - -- Pin names and timer configurations, may vary between different STM32 boards. For more information, check out the [GIGA R1 MicroPython Guide](https://docs.arduino.cc/tutorials/giga-r1-wifi/giga-micropython/). - diff --git a/content/micropython/01.basics/05.digital-analog-pins/py-hero-banner.png b/content/micropython/01.basics/05.digital-analog-pins/py-hero-banner.png deleted file mode 100644 index f0680b9243..0000000000 Binary files a/content/micropython/01.basics/05.digital-analog-pins/py-hero-banner.png and /dev/null differ diff --git a/content/micropython/01.basics/06.board-examples/assets/ble-sense.png b/content/micropython/01.basics/06.board-examples/assets/ble-sense.png deleted file mode 100644 index 52908dbc5e..0000000000 Binary files a/content/micropython/01.basics/06.board-examples/assets/ble-sense.png and /dev/null differ diff --git a/content/micropython/01.basics/06.board-examples/assets/ble.png b/content/micropython/01.basics/06.board-examples/assets/ble.png deleted file mode 100644 index e63994064d..0000000000 Binary files a/content/micropython/01.basics/06.board-examples/assets/ble.png and /dev/null differ diff --git a/content/micropython/01.basics/06.board-examples/assets/nano-rp2040.png b/content/micropython/01.basics/06.board-examples/assets/nano-rp2040.png deleted file mode 100644 index d38a07ea22..0000000000 Binary files a/content/micropython/01.basics/06.board-examples/assets/nano-rp2040.png and /dev/null differ diff --git a/content/micropython/01.basics/06.board-examples/assets/portenta.png b/content/micropython/01.basics/06.board-examples/assets/portenta.png deleted file mode 100644 index b696c79a88..0000000000 Binary files a/content/micropython/01.basics/06.board-examples/assets/portenta.png and /dev/null differ diff --git a/content/micropython/01.basics/06.board-examples/assets/portenta33_MKR_pinout.png b/content/micropython/01.basics/06.board-examples/assets/portenta33_MKR_pinout.png deleted file mode 100644 index 6767c082b1..0000000000 Binary files a/content/micropython/01.basics/06.board-examples/assets/portenta33_MKR_pinout.png and /dev/null differ diff --git a/content/micropython/01.basics/06.board-examples/board-examples.md b/content/micropython/01.basics/06.board-examples/board-examples.md deleted file mode 100644 index 16535998d2..0000000000 --- a/content/micropython/01.basics/06.board-examples/board-examples.md +++ /dev/null @@ -1,1895 +0,0 @@ ---- -title: Examples by Board -description: Find examples that work only with specific boards, such as reading built-in sensors. -author: Karl Söderby -micropython_type: basics -featured: micropython -hero_image: "./hero-banner.png" ---- - -In this article, you will find examples that works only with specific boards. Each board also has a GPIO map that explains how each pin can be addressed. - -## Nano RP2040 Connect - -![Nano RP2040 Connect.](assets/nano-rp2040.png) - -### GPIO Map - -The pinout for the **Nano RP2040 Connect** and the **RP2040 microcontroller** varies greatly. For example, if we are to use `D2` according to the Arduino pinout, we would actually need to use **pin 25**. - -```python -# Defining "D2" on the Arduino Nano RP2040 Connect -p0 = Pin(25, Pin.OUT) -``` - -Before you start using the board's pins, it might be a good idea to check out the table below to understand the relationship between Arduino's pinout and the RP2040's pinout. - -| Arduino | RP2040 | Usage | -| ------- | ------ | ------------- | -| TX | GPIO0 | UART/TX | -| RX | GPIO1 | UART/RX | -| D2 | GPIO25 | GPIO | -| D3 | GPIO15 | GPIO | -| D4 | GPIO16 | GPIO | -| D5 | GPIO17 | GPIO | -| D6 | GPIO18 | GPIO | -| D7 | GPIO19 | GPIO | -| D8 | GPIO20 | GPIO | -| D9 | GPIO21 | GPIO | -| D10 | GPIO5 | GPIO | -| D11 | GPIO7 | SPI/COPI | -| D12 | GPIO4 | SPI/CIPO | -| D13 | GPIO6 | SPI/SCK | -| D14/A0 | GPIO26 | ADC/RP2040 | -| D15/A1 | GPIO27 | ADC/RP2040 | -| D16/A2 | GPIO28 | ADC/RP2040 | -| D17/A3 | GPIO29 | ADC/RP2040 | -| D18/A4 | GPIO12 | I2C | -| D19/A5 | GPIO13 | I2C | -| D20/A6 | GPIO36 | ADC/NINA-W102 | -| D21/A7 | GPIO35 | ADC/NINA-W102 | - -### Analog Read - -***Note: This is currently only available on the nightly build. Follow [this link](https://docs.arduino.cc/micropython/#firmware) to download it.*** - -To read an analog pin, we can use the `ADC.read_u16` command. This reads the specified analog pin and returns an integer in the range 0 - 65535. For this, we need to import `ADC` from the `machine` module. - -```python -from machine import ADC - -while True: - adc = ADC("A4") - adc.read_u16() -``` - -### Sensors - -#### IMU (LSM6DSOX) - -Prints the accelerometer and gyroscope values in the Serial Monitor. - -```python -import time -from lsm6dsox import LSM6DSOX -from machine import Pin, I2C - -# Initialize the LSM6DSOX sensor with I2C interface -lsm = LSM6DSOX(I2C(0, scl=Pin(13), sda=Pin(12))) - -while True: - # Read accelerometer values - accel_values = lsm.accel() - print('Accelerometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*accel_values)) - - # Read gyroscope values - gyro_values = lsm.gyro() - print('Gyroscope: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*gyro_values)) - - print("") - time.sleep_ms(100) -``` - -### Microphone (MP34DT05) - -Below example can be used with OpenMV's frame buffer window (top right corner). - -```python -import image, audio, time -from ulab import numpy as np -from ulab import scipy as sp - -CHANNELS = 1 -FREQUENCY = 32000 -N_SAMPLES = 32 if FREQUENCY == 16000 else 64 -SCALE = 2 -SIZE = (N_SAMPLES * SCALE) // CHANNELS - -raw_buf = None -fb = image.Image(SIZE+(50*SCALE), SIZE, image.RGB565, copy_to_fb=True) -audio.init(channels=CHANNELS, frequency=FREQUENCY, gain_db=16) - -def audio_callback(buf): - # NOTE: do Not call any function that allocates memory. - global raw_buf - if (raw_buf == None): - raw_buf = buf - -# Start audio streaming -audio.start_streaming(audio_callback) - -def draw_fft(img, fft_buf): - fft_buf = (fft_buf / max(fft_buf)) * SIZE - fft_buf = np.log10(fft_buf + 1) * 20 - color = (0xFF, 0x0F, 0x00) - for i in range(0, len(fft_buf)): - img.draw_line(i*SCALE, SIZE, i*SCALE, SIZE-int(fft_buf[i]) * SCALE, color, SCALE) - -def draw_audio_bar(img, level, offset): - blk_size = (SIZE//10) - color = (0xFF, 0x00, 0xF0) - blk_space = (blk_size//4) - for i in range(0, int(round(level/10))): - fb.draw_rectangle(SIZE+offset, SIZE - ((i+1)*blk_size) + blk_space, 20 * SCALE, blk_size - blk_space, color, 1, True) - -while (True): - if (raw_buf != None): - pcm_buf = np.frombuffer(raw_buf, dtype=np.int16) - raw_buf = None - - if CHANNELS == 1: - fft_buf = sp.signal.spectrogram(pcm_buf) - l_lvl = int((np.mean(abs(pcm_buf[1::2])) / 32768)*100) - else: - fft_buf = sp.signal.spectrogram(pcm_buf[0::2]) - l_lvl = int((np.mean(abs(pcm_buf[1::2])) / 32768)*100) - r_lvl = int((np.mean(abs(pcm_buf[0::2])) / 32768)*100) - - fb.clear() - draw_fft(fb, fft_buf) - draw_audio_bar(fb, l_lvl, 0) - draw_audio_bar(fb, l_lvl, 25*SCALE) - if CHANNELS == 2: - draw_audio_bar(fb, r_lvl, 25 * SCALE) - fb.flush() - -# Stop streaming -audio.stop_streaming() -``` - -### Communication - -#### I2C - -Scans for devices connected to the I2C buses: - -```python -import time -from machine import Pin, I2C - -i2c_list = [None, None] -i2c_list[0] = I2C(0, scl=Pin(13), sda=Pin(12), freq=100_000) -i2c_list[1] = I2C(1, scl=Pin(7), sda=Pin(6), freq=100_000) - -for bus in range(0, 2): - print("\nScanning bus %d..."%(bus)) - for addr in i2c_list[bus].scan(): - print("Found device at address %d:0x%x" %(bus, addr)) -``` - -#### UART - -To read data and write data through TX and RX pins, you can use `uart.write()` and `uart.read()`. - -```python -from machine import UART, Pin -import time - -uart = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1)) - -while True: - uart.write('hello') # writes 5 bytes - val = uart.read(5) # reads up to 5 bytes - print(val) # prints data - time.sleep(1) -``` - -### Wireless - -Below are examples on wireless connectivity, using the NINA-W102 module onboard the Nano RP2040 Connect. - -***In order to use these examples, you may have to upgrade your firmware. You can find instructions on how to in [Upgrading Nano RP2040 Connect NINA firmware](/tutorials/nano-rp2040-connect/rp2040-upgrading-nina-firmware).*** - -#### Wi-Fi AP Mode - -Turn your board into an access point: - -```python -# Wi-Fi AP Mode Example -# -# This example shows how to use Wi-Fi in Access Point mode. -import network, socket, sys, time, gc - -SSID ='My_Nano_RP2040_Connect' # Network SSID -KEY ='1234567890' # Network key (must be 10 chars) -HOST = '' # Use first available interface -PORT = 8080 # Arbitrary non-privileged port - -# Init wlan module and connect to network -wlan = network.WLAN(network.AP_IF) -wlan.active(True) -wlan.config(essid=SSID, key=KEY, security=wlan.WEP, channel=2) -print("AP mode started. SSID: {} IP: {}".format(SSID, wlan.ifconfig()[0])) - -def recvall(sock, n): - # Helper function to recv n bytes or return None if EOF is hit - data = bytearray() - while len(data) < n: - packet = sock.recv(n - len(data)) - if not packet: - raise OSError("Timeout") - data.extend(packet) - return data - -def start_streaming(server): - print ('Waiting for connections..') - client, addr = server.accept() - - # set client socket timeout to 5s - client.settimeout(5.0) - print ('Connected to ' + addr[0] + ':' + str(addr[1])) - - # FPS clock - clock = time.clock() - while (True): - try: - # Read data from client - data = recvall(client, 1024) - # Send it back - client.send(data) - except OSError as e: - print("start_streaming(): socket error: ", e) - client.close() - break - -while (True): - try: - server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - # Bind and listen - server.bind([HOST, PORT]) - server.listen(1) - - # Set server socket to blocking - server.setblocking(True) - while (True): - start_streaming(server) - except OSError as e: - server.close() - print("Server socket error: ", e) -``` - -#### Wi-Fi® Scan - -To scan available networks: - -```python -# Scan Example - -# This example shows how to scan for Wi-Fi networks. - -import time, network - -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -print("Scanning...") -while (True): - scan_result = wlan.scan() - for ap in scan_result: - print("Channel:%d RSSI:%d Auth:%d BSSID:%s SSID:%s"%(ap)) - print() - time.sleep_ms(1000) -``` - -#### HTTP Request - -Making an HTTP request (in this case to google): - -***Remember to enter your network name and password inside the SSID and KEY variables.*** - -```python -import network, socket - -# AP info -SSID='' # Network SSID -KEY='' # Network key - -PORT = 80 -HOST = "www.google.com" - -# Init wlan module and connect to network -print("Trying to connect. Note this may take a while...") - -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -wlan.connect(SSID, KEY) - -# We should have a valid IP now via DHCP -print("Wi-Fi Connected ", wlan.ifconfig()) - -# Get addr info via DNS -addr = socket.getaddrinfo(HOST, PORT)[0][4] -print(addr) - -# Create a new socket and connect to addr -client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -client.connect(addr) - -# Set timeout -client.settimeout(3.0) - -# Send HTTP request and recv response -client.send("GET / HTTP/1.1\r\nHost: %s\r\n\r\n"%(HOST)) -print(client.recv(1024)) - -# Close socket -client.close() -``` - -#### NTP (Network Time Protocol) - -***Remember to enter your network name and password inside the SSID and KEY variables.*** - -Obtain accurate time and date from the Internet: - -```python -# NTP Example -# -# This example shows how to get the current time using NTP - -import network, usocket, ustruct, utime - -# AP info -SSID='' # Network SSID -KEY='' # Network key - -TIMESTAMP = 2208988800 - -# Init wlan module and connect to network -print("Trying to connect... (may take a while)...") - -wlan = network.WLAN() -wlan.active(True) -wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK) - -# We should have a valid IP now via DHCP -print(wlan.ifconfig()) - -# Create new socket -client = usocket.socket(usocket.AF_INET, usocket.SOCK_DGRAM) -client.bind(("", 8080)) -#client.settimeout(3.0) - -# Get addr info via DNS -addr = usocket.getaddrinfo("pool.ntp.org", 123)[0][4] - -# Send query -client.sendto('\x1b' + 47 * '\0', addr) -data, address = client.recvfrom(1024) - -# Print time -t = ustruct.unpack(">IIIIIIIIIIII", data)[10] - TIMESTAMP -print ("Year:%d Month:%d Day:%d Time: %d:%d:%d" % (utime.localtime(t)[0:6])) -``` - -In the terminal, we should see it in this format: - -``` -Year:2021 Month:8 Day:10 Time: 7:56:30 -``` - -#### Bluetooth® Low Energy - -This example allows us to connect to our board via our phone, and control the built-in LED. We recommend using the **nRF Connect** applications. - -- [nRF desktop](https://www.nordicsemi.com/Products/Development-tools/nrf-connect-for-desktop) -- [nRF mobile](https://www.nordicsemi.com/Products/Development-tools/nrf-connect-for-mobile) - -***After loading the script below, your board should be listed as "Nano RP2040 Connect" in the list of available devices. You need to pair in order to control the built-in LED.*** - -```python -import bluetooth -import random -import struct -import time -from ble_advertising import advertising_payload -from machine import Pin -from micropython import const - -LED_PIN = 6 - -_IRQ_CENTRAL_CONNECT = const(1) -_IRQ_CENTRAL_DISCONNECT = const(2) -_IRQ_GATTS_WRITE = const(3) - -_FLAG_READ = const(0x0002) -_FLAG_WRITE = const(0x0008) -_FLAG_NOTIFY = const(0x0010) -_FLAG_INDICATE = const(0x0020) - -_SERVICE_UUID = bluetooth.UUID(0x1523) -_LED_CHAR_UUID = (bluetooth.UUID(0x1525), _FLAG_WRITE) -_LED_SERVICE = (_SERVICE_UUID, (_LED_CHAR_UUID,),) - -class BLETemperature: - def __init__(self, ble, name="NANO RP2040"): - self._ble = ble - self._ble.active(True) - self._ble.irq(self._irq) - ((self._handle,),) = self._ble.gatts_register_services((_LED_SERVICE,)) - self._connections = set() - self._payload = advertising_payload(name=name, services=[_SERVICE_UUID]) - self._advertise() - - def _irq(self, event, data): - # Track connections so we can send notifications. - if event == _IRQ_CENTRAL_CONNECT: - conn_handle, _, _ = data - self._connections.add(conn_handle) - elif event == _IRQ_CENTRAL_DISCONNECT: - conn_handle, _, _ = data - self._connections.remove(conn_handle) - # Start advertising again to allow a new connection. - self._advertise() - elif event == _IRQ_GATTS_WRITE: - Pin(LED_PIN, Pin.OUT).value(int(self._ble.gatts_read(data[-1])[0])) - - def _advertise(self, interval_us=500000): - self._ble.gap_advertise(interval_us, adv_data=self._payload) - -if __name__ == "__main__": - ble = bluetooth.BLE() - temp = BLETemperature(ble) - - while True: - time.sleep_ms(1000) -``` - -## Nano 33 BLE - -![Nano 33 BLE.](assets/ble.png) - -### GPIO Map - -The pinout for the **Nano 33 BLE** and the **NRF52840 microcontroller** varies greatly. For example, if we are to use `D2` according to the Arduino pinout, we would actually need to use **pin 43**. - -```python -# Defining "D2" on the Nano 33 BLE -p0 = Pin(43, Pin.OUT) -``` - -In the MicroPython port of the Nano 33 BLE board, the pinout is the same as the Nordic NRF52840 (the microcontroller). You will find a GPIO Map below that explains how to address the different pins. - -| Arduino | nRF52840 | -| ------- | -------- | -| TX | 35 | -| RX | 42 | -| D2 | 43 | -| D3 | 44 | -| D4 | 47 | -| D5 | 45 | -| D6 | 46 | -| D7 | 23 | -| D8 | 21 | -| D9 | 27 | -| D10 | 34 | -| D11 | 33 | -| D12 | 40 | -| D13 | 13 | -| D14/A0 | 4 | -| D15/A1 | 5 | -| D16/A2 | 30 | -| D17/A3 | 29 | -| D18/A4 | 31 | -| D19/A5 | 2 | -| D20/A6 | 28 | -| D21/A7 | 3 | - -### Analog Read - -***The following example is currently only possible with the nightly build*** - -### LED Control - -There are 3 different LEDs that can be accessed on the Nano 33 BLE: **RGB, the built-in LED** and the **power LED**. - -They can be accessed by importing the `LED` module, where the RGB and built-in LED can be accessed. - -```python -from board import LED - -led_red = LED(1) # red LED -led_green = LED(2) # green LED -led_blue = LED(3) # blue LED -led_builtin = LED(4) # classic built-in LED (also accessible through pin 13) -``` - -To access the **power LED** we need to import the `Pin` module. - -```python -from machine import Pin - -led_pwr = Pin(41, Pin.OUT) -``` - -#### RGB - -Blink all RGB lights every 0.25 seconds. - -```python -from board import LED -import time - -led_red = LED(1) -led_green = LED(2) -led_blue = LED(3) - -while (True): - - # Turn on LEDs - led_red.on() - led_green.on() - led_blue.on() - - # Wait 0.25 seconds - time.sleep_ms(250) - - # Turn off LEDs - led_red.off() - led_green.off() - led_blue.off() - - # Wait 0.25 seconds - time.sleep_ms(250) -``` - -#### Built-in LED - -The classic blink example! Blink the built-in LED every 0.25 seconds. - -```python -from board import LED -import time - -led_builtin = LED(4) - -while (True): - - # Turn on LED - led_builtin.on() - - # Wait 0.25 seconds - time.sleep_ms(250) - - # Turn off LED - led_builtin.off() - - # Wait 0.25 seconds - time.sleep_ms(250) - -``` - -### Sensors - -#### IMU (LSM9DS1, BMI270 + BMM150) - -Access the `accelerometer`, `magnetometer`, and `gyroscope` data from the IMU module. - -```python -import time -import imu -from machine import Pin, I2C - -bus = I2C(1, scl=Pin(15), sda=Pin(14)) -imu = imu.IMU(bus) - -while (True): - print('Accelerometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.accel())) - print('Gyroscope: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.gyro())) - print('Magnetometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.magnet())) - print("") - time.sleep_ms(100) -``` - -### Wireless - -#### Bluetooth® Low Energy - -This example allows us to connect to our board via our phone, and control the built-in LED. We recommend using the **nRF Connect** applications. - -- [nRF desktop](https://www.nordicsemi.com/Products/Development-tools/nrf-connect-for-desktop) -- [nRF mobile](https://www.nordicsemi.com/Products/Development-tools/nrf-connect-for-mobile) - -***After loading the script below, your board should be listed as "Nano 33 BLE" in the list of available devices. You need to pair in order to control the built-in LED.*** - -```python -# Use nRF Connect from App store, connect to the Nano and write 1/0 to control the LED. - -import time -from board import LED -from ubluepy import Service, Characteristic, UUID, Peripheral, constants - -def event_handler(id, handle, data): - global periph - global service - if id == constants.EVT_GAP_CONNECTED: - pass - elif id == constants.EVT_GAP_DISCONNECTED: - # restart advertisement - periph.advertise(device_name="Nano 33 BLE", services=[service]) - elif id == constants.EVT_GATTS_WRITE: - LED(1).on() if int(data[0]) else LED(1).off() - -# start off with LED(1) off -LED(1).off() - -notif_enabled = False -uuid_service = UUID("0x1523") -uuid_led = UUID("0x1525") - -service = Service(uuid_service) -char_led = Characteristic(uuid_led, props=Characteristic.PROP_WRITE) -service.addCharacteristic(char_led) - -periph = Peripheral() -periph.addService(service) -periph.setConnectionHandler(event_handler) -periph.advertise(device_name="Nano 33 BLE", services=[service]) - -while (True): - time.sleep_ms(500) -``` - -## Nano 33 BLE Sense - -![Nano 33 BLE Sense.](assets/ble-sense.png) - -### Pin Map - -The pinout for the **Nano 33 BLE Sense** and the **NRF52840 microcontroller** varies greatly. For example, if we are to use `D2` according to the Arduino pinout, we would actually need to use **pin 43**. - -```python -# Defining "D2" on the Nano 33 BLE Sense -p0 = Pin(43, Pin.OUT) -``` - -In the MicroPython port of the Nano 33 BLE Sense board, the pinout is the same as the Nordic NRF52840 (the microcontroller). You will find a pin map below this section that explains how to address the different pins. - -| Arduino | nRF52840 | -| ------- | -------- | -| TX | 35 | -| RX | 42 | -| D2 | 43 | -| D3 | 44 | -| D4 | 47 | -| D5 | 45 | -| D6 | 46 | -| D7 | 23 | -| D8 | 21 | -| D9 | 27 | -| D10 | 34 | -| D11 | 33 | -| D12 | 40 | -| D13 | 13 | -| D14/A0 | 4 | -| D15/A1 | 5 | -| D16/A2 | 30 | -| D17/A3 | 29 | -| D18/A4 | 31 | -| D19/A5 | 2 | -| D20/A6 | 28 | -| D21/A7 | 3 | - - -### LED Control - -There are 3 different LEDs that can be accessed on the Nano 33 BLE Sense: **RGB, the built-in LED** and the **power LED**. - -They can be accessed by importing the `LED` module, where the RGB and built-in LED can be accessed. - -```python -from board import LED - -led_red = LED(1) # red LED -led_green = LED(2) # green LED -led_blue = LED(3) # blue LED -led_builtin = LED(4) # classic built-in LED (also accessible through pin 13) -``` - -To access the **power LED** we need to import the `Pin` module. - -```python -from machine import Pin - -led_pwr = Pin(41, Pin.OUT) -``` - -#### RGB - -Blink all RGB lights every 0.25 seconds. - -```python -from board import LED -import time - -led_red = LED(1) -led_green = LED(2) -led_blue = LED(3) - -while (True): - - # Turn on LEDs - led_red.on() - led_green.on() - led_blue.on() - - # Wait 0.25 seconds - time.sleep_ms(250) - - # Turn off LEDs - led_red.off() - led_green.off() - led_blue.off() - - # Wait 0.25 seconds - time.sleep_ms(250) -``` - -#### Built-in LED - -The classic blink example! Blink the built-in LED every 0.25 seconds. - -```python -from board import LED -import time - -led_builtin = LED(4) - -while (True): - - # Turn on LED - led_builtin.on() - - # Wait 0.25 seconds - time.sleep_ms(250) - - # Turn off LED - led_builtin.off() - - # Wait 0.25 seconds - time.sleep_ms(250) - -``` - -### Sensors - -There are several sensors onboard the Nano 33 BLE Sense. The scripts below can be used to access the data from each of them. - -#### IMU (LSM9DS1, BMI270 + BMM150) - -Access the `accelerometer`, `magnetometer`, and `gyroscope` data from the IMU module. - -```python -import time -import imu -from machine import Pin, I2C - -bus = I2C(1, scl=Pin(15), sda=Pin(14)) -imu = imu.IMU(bus) - -while (True): - print('Accelerometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.accel())) - print('Gyroscope: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.gyro())) - print('Magnetometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.magnet())) - print("") - time.sleep_ms(100) -``` - - -#### Temperature & Humidity (HTS221) - -Access the `temperature` & `humidity` values from the HTS221 sensor (Nano 33 BLE Sense). - -```python -import time -import hts221 -from machine import Pin, I2C - -bus = I2C(1, scl=Pin(15), sda=Pin(14)) -hts = hts221.HTS221(bus) - -while (True): - rH = hts.humidity() - temp = hts.temperature() - print ("rH: %.2f%% T: %.2fC" %(rH, temp)) - time.sleep_ms(100) -``` - -#### Temperature & Humidity (HS3003) - -Access the `temperature` & `humidity` values from the HTS221 sensor (Nano 33 BLE Sense Rev2). - -```python -import time -from hs3003 import HS3003 -from machine import Pin, I2C - -bus = I2C(1, scl=Pin(15), sda=Pin(14)) -hts = HS3003(bus) - -while True: - rH = hts.humidity() - temp = hts.temperature() - print ("rH: %.2f%% T: %.2fC" %(rH, temp)) - time.sleep_ms(100) -``` - -#### Pressure (LPS22) - -Access the `pressure` values from the LPS22 sensor. - -```python -import time -import lps22h -from machine import Pin, I2C - -bus = I2C(1, scl=Pin(15), sda=Pin(14)) -lps = lps22h.LPS22H(bus) - -while (True): - pressure = lps.pressure() - temperature = lps.temperature() - print("Pressure: %.2f hPa Temperature: %.2f C"%(pressure, temperature)) - time.sleep_ms(100) -``` - -#### Ambient Light (APDS9960) - -Access the `Ambient Light` values from the APDS9960 sensor. - -```python -from time import sleep_ms -from machine import Pin, I2C -from apds9960.const import * -from apds9960 import uAPDS9960 as APDS9960 - -bus = I2C(1, sda=Pin(13), scl=Pin(14)) -apds = APDS9960(bus) - -print("Light Sensor Test") -print("=================") -apds.enableLightSensor() - -while True: - sleep_ms(250) - val = apds.readAmbientLight() - print("AmbientLight={}".format(val)) -``` - -#### Proximity (APDS9960) - -Access the `Proximity values` from the APDS9960 sensor. - -```python -from time import sleep_ms -from machine import Pin, I2C - -from apds9960.const import * -from apds9960 import uAPDS9960 as APDS9960 - -bus = I2C(1, sda=Pin(13), scl=Pin(14)) -apds = APDS9960(bus) - -apds.setProximityIntLowThreshold(50) - -print("Proximity Sensor Test") -print("=====================") -apds.enableProximitySensor() - -while True: - sleep_ms(250) - val = apds.readProximity() - print("proximity={}".format(val)) -``` - -#### Microphone (MP34DT05) - -Below example can be used with OpenMV's frame buffer window (top right corner). - -```python -import image, audio, time -from ulab import numpy as np -from ulab import scipy as sp - -CHANNELS = 1 -SIZE = 256//(2*CHANNELS) - -raw_buf = None -fb = image.Image(SIZE+50, SIZE, image.RGB565, copy_to_fb=True) -audio.init(channels=CHANNELS, frequency=16000, gain_db=80, highpass=0.9883) - -def audio_callback(buf): - # NOTE: do Not call any function that allocates memory. - global raw_buf - if (raw_buf == None): - raw_buf = buf - -# Start audio streaming -audio.start_streaming(audio_callback) - -def draw_fft(img, fft_buf): - fft_buf = (fft_buf / max(fft_buf)) * SIZE - fft_buf = np.log10(fft_buf + 1) * 20 - color = (0xFF, 0x0F, 0x00) - for i in range(0, SIZE): - img.draw_line(i, SIZE, i, SIZE-int(fft_buf[i]), color, 1) - -def draw_audio_bar(img, level, offset): - blk_size = SIZE//10 - color = (0xFF, 0x00, 0xF0) - blk_space = (blk_size//4) - for i in range(0, int(round(level/10))): - fb.draw_rectangle(SIZE+offset, SIZE - ((i+1)*blk_size) + blk_space, 20, blk_size - blk_space, color, 1, True) - -while (True): - if (raw_buf != None): - pcm_buf = np.frombuffer(raw_buf, dtype=np.int16) - raw_buf = None - - if CHANNELS == 1: - fft_buf = sp.signal.spectrogram(pcm_buf) - l_lvl = int((np.mean(abs(pcm_buf[1::2])) / 32768)*100) - else: - fft_buf = sp.signal.spectrogram(pcm_buf[0::2]) - l_lvl = int((np.mean(abs(pcm_buf[1::2])) / 32768)*100) - r_lvl = int((np.mean(abs(pcm_buf[0::2])) / 32768)*100) - - fb.clear() - draw_fft(fb, fft_buf) - draw_audio_bar(fb, l_lvl, 0) - if CHANNELS == 2: - draw_audio_bar(fb, r_lvl, 25) - fb.flush() - -# Stop streaming -audio.stop_streaming() -``` - -### Wireless - -#### Bluetooth® Low Energy - -This example allows us to connect to our board via our phone, and control the built-in LED. We recommend using the **nRF Connect** applications. - -- [nRF desktop](https://www.nordicsemi.com/Products/Development-tools/nrf-connect-for-desktop) -- [nRF mobile](https://www.nordicsemi.com/Products/Development-tools/nrf-connect-for-mobile) - -***After loading the script below, your board should be listed as "Nano 33 BLE Sense" in the list of available devices. You need to pair in order to control the built-in LED.*** - -```python -# Use nRF Connect from App store, connect to the Nano and write 1/0 to control the LED. - -import time -from board import LED -from ubluepy import Service, Characteristic, UUID, Peripheral, constants - -def event_handler(id, handle, data): - global periph - global service - if id == constants.EVT_GAP_CONNECTED: - pass - elif id == constants.EVT_GAP_DISCONNECTED: - # restart advertisement - periph.advertise(device_name="Nano 33 BLE Sense", services=[service]) - elif id == constants.EVT_GATTS_WRITE: - LED(1).on() if int(data[0]) else LED(1).off() - -# start off with LED(1) off -LED(1).off() - -notif_enabled = False -uuid_service = UUID("0x1523") -uuid_led = UUID("0x1525") - -service = Service(uuid_service) -char_led = Characteristic(uuid_led, props=Characteristic.PROP_WRITE) -service.addCharacteristic(char_led) - -periph = Peripheral() -periph.addService(service) -periph.setConnectionHandler(event_handler) -periph.advertise(device_name="Nano 33 BLE Sense", services=[service]) - -while (True): - time.sleep_ms(500) -``` - -## Portenta H7 - -![Portenta H7.](assets/portenta.png) - -***Note that the [Portenta H7 Lite](/hardware/portenta-h7-lite) and [Portenta H7 Lite Connected](/hardware/portenta-h7-lite-connected) boards are compatible with most examples listed here, as they are variations of the Portenta H7.*** - -### GPIO Map - -Most of the pins are referred to via their port name or their function. Please refer to the list below to see which function corresponds to which port on the Portenta H7. - -| Arduino | STM32H747 | -| ---------------- | --------- | -| PA0 | PA0 | -| PA1 | PA1 | -| PA2 | PA2 | -| PA3 | PA3 | -| PA4 | PA4 | -| PA5 | PA5 | -| PA6 | PA6 | -| PA7 | PA7 | -| PA8 | PA8 | -| PA9 | PA9 | -| PA10 | PA10 | -| PA11 | PA11 | -| PA12 | PA12 | -| PA13 | PA13 | -| PA14 | PA14 | -| PA15 | PA15 | -| PB0 | PB0 | -| PB1 | PB1 | -| PB2 | PB2 | -| PB3 | PB3 | -| PB4 | PB4 | -| PB5 | PB5 | -| PB6 | PB6 | -| PB7 | PB7 | -| PB8 | PB8 | -| PB9 | PB9 | -| PB10 | PB10 | -| PB11 | PB11 | -| PB12 | PB12 | -| PB13 | PB13 | -| PB14 | PB14 | -| PB15 | PB15 | -| PC0 | PC0 | -| PC1 | PC1 | -| PC2 | PC2 | -| PC3 | PC3 | -| PC4 | PC4 | -| PC5 | PC5 | -| PC6 | PC6 | -| PC7 | PC7 | -| PC8 | PC8 | -| PC9 | PC9 | -| PC10 | PC10 | -| PC11 | PC11 | -| PC12 | PC12 | -| PC13 | PC13 | -| PC14 | PC14 | -| PC15 | PC15 | -| PD0 | PD0 | -| PD1 | PD1 | -| PD2 | PD2 | -| PD3 | PD3 | -| PD4 | PD4 | -| PD5 | PD5 | -| PD6 | PD6 | -| PD7 | PD7 | -| PD8 | PD8 | -| PD9 | PD9 | -| PD10 | PD10 | -| PD11 | PD11 | -| PD12 | PD12 | -| PD13 | PD13 | -| PD14 | PD14 | -| PD15 | PD15 | -| PE0 | PE0 | -| PE1 | PE1 | -| PE2 | PE2 | -| PE3 | PE3 | -| PE4 | PE4 | -| PE5 | PE5 | -| PE6 | PE6 | -| PE7 | PE7 | -| PE8 | PE8 | -| PE9 | PE9 | -| PE10 | PE10 | -| PE11 | PE11 | -| PE12 | PE12 | -| PE13 | PE13 | -| PE14 | PE14 | -| PE15 | PE15 | -| PF0 | PF0 | -| PF1 | PF1 | -| PF2 | PF2 | -| PF3 | PF3 | -| PF4 | PF4 | -| PF5 | PF5 | -| PF6 | PF6 | -| PF7 | PF7 | -| PF8 | PF8 | -| PF9 | PF9 | -| PF10 | PF10 | -| PF11 | PF11 | -| PF12 | PF12 | -| PF13 | PF13 | -| PF14 | PF14 | -| PF15 | PF15 | -| PG0 | PG0 | -| PG1 | PG1 | -| PG2 | PG2 | -| PG3 | PG3 | -| PG4 | PG4 | -| PG5 | PG5 | -| PG6 | PG6 | -| PG7 | PG7 | -| PG8 | PG8 | -| PG9 | PG9 | -| PG10 | PG10 | -| PG11 | PG11 | -| PG12 | PG12 | -| PG13 | PG13 | -| PG14 | PG14 | -| PG15 | PG15 | -| PH0 | PH0 | -| PH1 | PH1 | -| PH2 | PH2 | -| PH3 | PH3 | -| PH4 | PH4 | -| PH5 | PH5 | -| PH6 | PH6 | -| PH7 | PH7 | -| PH8 | PH8 | -| PH9 | PH9 | -| PH10 | PH10 | -| PH11 | PH11 | -| PH12 | PH12 | -| PH13 | PH13 | -| PH14 | PH14 | -| PH15 | PH15 | -| PI0 | PI0 | -| PI1 | PI1 | -| PI2 | PI2 | -| PI3 | PI3 | -| PI4 | PI4 | -| PI5 | PI5 | -| PI6 | PI6 | -| PI7 | PI7 | -| PI8 | PI8 | -| PI9 | PI9 | -| PI10 | PI10 | -| PI11 | PI11 | -| PI12 | PI12 | -| PI13 | PI13 | -| PI14 | PI14 | -| PI15 | PI15 | -| PJ0 | PJ0 | -| PJ1 | PJ1 | -| PJ2 | PJ2 | -| PJ3 | PJ3 | -| PJ4 | PJ4 | -| PJ5 | PJ5 | -| PJ6 | PJ6 | -| PJ7 | PJ7 | -| PJ8 | PJ8 | -| PJ9 | PJ9 | -| PJ10 | PJ10 | -| PJ11 | PJ11 | -| PJ12 | PJ12 | -| PJ13 | PJ13 | -| PJ14 | PJ14 | -| PJ15 | PJ15 | -| PK0 | PK0 | -| PK1 | PK1 | -| PK2 | PK2 | -| PK3 | PK3 | -| PK4 | PK4 | -| PK5 | PK5 | -| PK6 | PK6 | -| PK7 | PK7 | -| UART1_TX | PA9 | -| UART1_RX | PA10 | -| UART4_TX | PA0 | -| UART4_RX | PI9 | -| UART6_TX | PG14 | -| UART6_RX | PG9 | -| UART8_TX | PJ8 | -| UART8_RX | PJ9 | -| ETH_RMII_REF_CLK | PA1 | -| ETH_MDIO | PA2 | -| ETH_RMII_CRS_DV | PA7 | -| ETH_MDC | PC1 | -| ETH_RMII_RXD0 | PC4 | -| ETH_RMII_RXD1 | PC5 | -| ETH_RMII_TX_EN | PG11 | -| ETH_RMII_TXD0 | PG13 | -| ETH_RMII_TXD1 | PG12 | -| USB_HS_CLK | PA5 | -| USB_HS_STP | PC0 | -| USB_HS_NXT | PH4 | -| USB_HS_DIR | PI11 | -| USB_HS_D0 | PA3 | -| USB_HS_D1 | PB0 | -| USB_HS_D2 | PB1 | -| USB_HS_D3 | PB10 | -| USB_HS_D4 | PB11 | -| USB_HS_D5 | PB12 | -| USB_HS_D6 | PB13 | -| USB_HS_D7 | PB5 | -| USB_HS_RST | PJ4 | -| USB_DM | PA11 | -| USB_DP | PA12 | -| BOOT0 | BOOT0 | -| DAC1 | PA4 | -| DAC2 | PA5 | -| LEDR | PK5 | -| LEDG | PK6 | -| LEDB | PK7 | -| I2C1_SDA | PB7 | -| I2C1_SCL | PB6 | -| I2C3_SDA | PH8 | -| I2C3_SCL | PH7 | -| -WL_REG_ON | PJ1 | -| -WL_HOST_WAKE | PJ5 | -| -WL_SDIO_0 | PC8 | -| -WL_SDIO_1 | PC9 | -| -WL_SDIO_2 | PC10 | -| -WL_SDIO_3 | PC11 | -| -WL_SDIO_CMD | PD2 | -| -WL_SDIO_CLK | PC12 | -| -BT_RXD | PF6 | -| -BT_TXD | PA15 | -| -BT_CTS | PF9 | -| -BT_RTS | PF8 | -| -BT_REG_ON | PJ12 | -| -BT_HOST_WAKE | PJ13 | -| -BT_DEV_WAKE | PJ14 | -| -QSPI2_CS | PG6 | -| -QSPI2_CLK | PF10 | -| -QSPI2_D0 | PD11 | -| -QSPI2_D1 | PD12 | -| -QSPI2_D2 | PF7 | -| -QSPI2_D3 | PD13 | - - -### I/O Pins - -To access the I/O pins, you can use the `Pin` module from the `pyb` library. - -```python -from pyb import Pin -``` - -To reference a pin on the Portenta, you can use the `Pin()` constructor. The first argument you have to provide is the pin you want to use. The second parameter, `mode`, can be set as: `Pin.IN`, `Pin.OUT_PP`, `Pin.OUT_OD`, `Pin.AF_PP`, `Pin.AF_OD` or `Pin.ANALOG`. An explanation of the pin modes can be found [here](https://docs.openmv.io/library/pyb.Pin.html#methods). The third parameter, `pull`, represents the pull mode. It can be set to: `Pin.PULL_NONE`, `Pin.PULL_UP` or `Pin.PULL_DOWN`. E.g.: - -```python -pin0 = Pin('P0', mode, pull) -``` - -To get the logic level of a pin, call `.value()`. It will return a 0 or a 1. This corresponds to `LOW` and `HIGH` in Arduino terminology. - -```python -pin0.value() -``` - -### PWM - -To use PWM, you import the `pyb`, `time`, `Pin`, `Timer` modules. - -```python -import pyb -import time -from pyb import Pin, Timer -``` - -First you need to choose the pin you want to use PWM with. - -```python -pin1 = Pin("PC6", Pin.OUT_PP, Pin.PULL_NONE) -``` - -Create a timer for the PWM, where you set the ID and the frequency. - -```python -timer1 = Timer(3, freq=1000) -``` - -Then you need to start a PWM channel with the timer object. - -```python -channel1 = timer1.channel(1, Timer.PWM, pin=pin1, pulse_width=0) -``` - -Get or set the pulse width value on a channel. To get, pass no arguments. To set, give a value as an argument. - -```python -channel1.pulse_width(Width) -``` - -### RGB LED - -The Portenta H7 has built-in RGB that can be used as feedback for applications. Using the `pyb` library, you can easily define the different LED colors on the Portenta. - -For this you will use the `pyb` library. - -```python -import pyb -``` - -Now you can easily define the different colors of the built in LED. - -```python -redLED = pyb.LED(1) -greenLED = pyb.LED(2) -blueLED = pyb.LED(3) -``` - -And then control them in our script. - -```python -redLED.on() -redLED.off() - -greenLED.on() -greenLED.off() - -blueLED.on() -blueLED.off() -``` - -You could also set a custom intensity for our LED lights. This ranges between the values 0 (off) and 255 (full on). Below you can see an example of how to set the intensity on our different LED lights. - -```python -redLED.intensity(128) -greenLED.intensity(64) -blueLED.intensity(50) -``` - -If no argument is given in the `.intensity()` function, it will return the LED intensity. - -### Communication - -Like other Arduino® products, the Portenta H7 features dedicated pins for different protocols. - -#### SPI - -The pins used for SPI on the Portenta H7 are the following: - - -| Pin | Function | -| :---: | :------: | -| PI0 | CS | -| PC3 | COPI | -| PI1 | CK | -| PC2 | CIPO | - -You can refer to the [pinout](#gpio-map-2) above to find them on the board. - -First, you have to import the relevant module from `pyb`. - -```python -from pyb import SPI -``` - -When you initialize SPI, the only thing you need to state is the bus, which will always be `2` on the Portenta H7; this is the only available bus. The rest of the arguments are optional. But if it is needed, you can state the mode of the SPI device as either `SPI.MASTER` or `SPI.SLAVE`, you can also manually set the `baudrate` of the device. `Polarity` can be set to 0 or 1, and is the logic level the idle clock line sits at (HIGH or LOW). `Phase` can be 0 or 1 to sample data on the first (0) or second (1) clock edge. - -```python -spi = SPI(2, SPI.MASTER, baudrate=100000, polarity=0, phase=0) -``` - -Now, if you want to send data over SPI, you simply call `.send()` inside the arguments you want to send. `data` is the data to send, which could be an integer (dataInt) or a buffer object (dataBuffer). It is optional to set the `timeout`, it indicates the timeout in milliseconds to wait for the send. - -```python -dataInt = 21 -dataBuffer = bytearray(4) -spi.send(data, timeout=5000) -``` - -Similarly, if you want to receive data over SPI, you call `.recv()`. `data` indicates the number of bytes to receive, this can be an integer (dataInt) or a buffer (dataBuffer), which will be filled with received bytes. It is optional to set the `timeout`, which is the time in milliseconds to wait for the receive. - -```python -dataInt = 0 -dataBuffer = bytearray(4) -SPI.recv(data, timeout=5000) -``` - -#### I2C - -The pins used for I2C (Inter-Integrated Circuit) on the Portenta H7 are the following: - -| Pin | Function | -| :---: | :------: | -| PH8 | SDA | -| PH7 | SCL | - -You can refer to the [pinout](##gpio-map-2) above to find them on the board. - -To use the I2C, you import the relevant module. - -```python -from pyb import I2C -``` - -You can now create the I2C object. To create an I2C object you need to state the bus, this indicates what pins you will use for I2C. Giving bus a value of `3` starts I2C on the SCL and SDA pins on the Portenta H7. There are 4 I2C buses on the Portenta H7. - -```python -i2c = I2C(3) -``` - -Now that the object is created, you can initialize it. You need to decide if your device is going to be a controller (I2C.MASTER) or a reader (I2C.SLAVE). If it is a reader device, you also need to set the `address`. You can then set a baudrate if you need to. - -```python -i2c.init(I2C.MASTER, addr=address, baudrate=100000) -``` - -To receive data on the bus, you call the `.recv()` function. In the functions arguments `data` is the number of bytes to receive, it can be an integer (dataInt) or a buffer (dataBuffer), which will be filled with received bytes. `addr` is the address to receive from, this is only required in controller mode. `timeout` indicates how many milliseconds to wait for the receive. The code below shows how to receive and print your data in the OpenMV serial terminal. - -```python -dataInt = 0 -dataBuffer = bytearray(4) -receivedData = i2c.recv(data, addr=0, timeout=5000) -Print(receivedData) -``` - -To send data on the bus, you can call the `.send()` function. In the functions arguments `data` is the data to send, an integer (dataInt) or a buffer object (dataBuffer). `addr` is the address to send to, this is only required in controller mode. `timeout` indicates how many milliseconds to wait for the send. - -```python -dataInt = 412 -dataBuffer = bytearray(4) -i2c.send(data, addr=0, timeout=5000) -``` - -If you need to make sure that devices are connected to the I2C bus, you can use the `.scan()` function. It will scan all I2C addresses from 0x01 to 0x7f and return a list of those that respond. It only works when in controller mode. - -```python -i2c.scan() -``` - -#### UART - -The pins used for UART on the Portenta H7 are the following: - -| Pin | Function | -| :---: | :------: | -| PA10 | RX | -| PA9 | TX | - -You can refer to the [pinout](#gpio-map-2) above to find them on the board. - -To use the UART, you need to import the relevant module. - -```python -from pyb import UART -``` - -To create the UART object, you need to indicate the UART bus, the Portenta has 3 UART buses, but there is only on UART bus available to use with OpenMV through the boards pins. - -```python -uart = UART(1) -``` - -With the object created, you can initialize it with `init`. When initilazing, you can set the `baudrate`. `bits` is the number of bits per character (7, 8 or 9). `parity` can be set to `None`, `0` (even) or `1` (odd). `stop` is the number of stop bits, 1 or 2. `flow` sets the flow control type, can be 0, UART.RTS, UART.CTS or UART.RTS | UART.CTS. More information on this can be found [here](https://docs.openmv.io/library/pyb.UART.html#flow-control). `timeout` is the time in milliseconds to wait for writing/reading the first character. `timeout_char` is the timeout in milliseconds to wait between characters while writing or reading. `read_buf_len` is the character length of the read buffer (0 to disable). - -```python -uart.init(baudrate, bits=8, parity=None, stop=1, timeout=0, flow=0, timeout_char=0, read_buf_len=64) -``` - -To read from UART, you can call `.read()`. If `bytes` is specified then read at most that many bytes. If `bytes` is not given then the method reads as much data as possible. It returns after the timeout has elapsed. The example code below will read bytes received through uart into an array and then print it in the serial terminal. - -```python -array = bytearray(5) -uart.read(array) -print(array) -``` - -If you intend to write over UART, you can call `.write()`. The function writes `buffer` of bytes to the bus. If characters are 7 or 8 bits wide then each byte is one character. If characters are 9 bits wide then two bytes are used for each character and `buffer` must contain an even number of bytes. - -```python -uart.write(buffer) -``` - -#### Wi-Fi® - -To use Wi-Fi® you first need to import the relevant library. - -```python -import network -``` - -Then you need to define the Wi-Fi® networks SSID and put that in a variable. You must do the same for the networks password. - -```python -SSID='' -PASSWORD='' -``` - -Next, you can create a WLAN network interface object. In the argument you can enter `network.STA_IF`, which indicates that your device will be a client and connect to a Wi-Fi® access point. - -```python -wlan = network.WLAN(network.STA_IF) -``` - -To activate the network interface, you can simply call `.activate` with the argument `True`. - -```python -wlan.active(True) -``` - -Now you can decide which network to connect to. Here it is where the `SSID` and `PASSWORD` variables come in handy. - -```python -wlan.connect(SSID, PASSWORD, timeout=30000) -``` - -If you need to troubleshoot, the connection `.status()` can be used. This function will return a value that describes the connection status. It will also let you know what went wrong with the connection in case it failed. - -```python -wlan.status() -``` - -### Audio - -If you want to use audio with the Portenta H7, you first need to include the `audio` module. Another helpful module is `micro_speech`, this runs Google's TensorFlow Lite for Microcontrollers Micro Speech framework for voice recognition. - -```python -import audio, micro_speech -``` - -Next you need to initialize the audio object. In the initialization you can decide how many `channels` to use, it is possible to use either 1 or 2 channels. Frequency decides the sample frequency. Using a higher sample frequency results in a higher noise flow, meaning less effective bits per sample. By default audio samples are 8-bits with 7-bits of effective dynamic range. `gain_db` sets the microphone gain to use. `highpass` is the high pass filter cut off given the target sample frequency. - -```python -audio.init(channels=2, frequency=16000, gain_db=24, highpass=0.9883) -``` - -If you need to deinitialize the audio object, you can simply call `deint()`. - -```python -audio.deint() -``` - -To use micro_speech, you first need to create a micro_speech object. You can create this object in the variable `speech`. - -```python -speech = micro_speech.MicroSpeech() -``` - -Next you can start streaming audio into the `micro_speech` object, to do this you can call `audio.start_streaming()`. Here you can pass the `micro_speech` object as the argument, this will fill the object with audio samples. The MicroSpeech module will compute the FFT of the audio samples and keep a sliding window internally of the FFT the last 100ms or so of audio samples received as features for voice recognition. - -```python -audio.start_streaming(speech.audio_callback) -``` - -If you need to stop the audio streaming, you can call `.stop_streaming()`. - -```python -audio.stop_streaming() -``` - -## Portenta C33 - -### Pinout Mapping - -The Portenta C33 has two ways its pins are physically available: through its MKR-styled connectors and its High-Density connectors. Most pins are referred to via their port name or function. In the image below, the Portenta C33 MKR-styled connectors pinout is shown. - -![Portenta C33 MKR-styled connectors pinout](assets/portenta33_MKR_pinout.png) - -The MKR-styled connectors pinout is mapped in MicroPython as follows: - -| **Arduino Pin Mapping** | **MicroPython Pin Mapping** | -|:-----------------------:|:---------------------------:| -| `P006`/`A0` | `P006` | -| `P005`/`A1` | `P005` | -| `P004`/`A2` | `P004` | -| `P002`/`A3` | `P002` | -| `P001`/`A4` | `P001` | -| `P015`/`A5` | `P015` | -| `P014`/`A6` | `P014` | -| `P105`/`D0` | `P105` | -| `P106`/`D1` | `P106` | -| `P111`/`D2` | `P111` | -| `P303`/`D3` | `P303` | -| `P401`/`D4` | `P401` | -| `P210`/`D5` | `P210` | -| `P602` | `P602` | -| `P110` | `P110` | -| `P408` | `P408` | -| `P407` | `P407` | -| `P315` | `P315` | -| `P204` | `P204` | -| `P900` | `P900` | -| `P402` | `P402` | -| `P601` | `P601` | - -The complete MicroPython pinout is available [here](https://github.com/micropython/micropython/blob/master/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/pins.csv). - -### Input/Output Pins - -The `Pin` class in the `machine` module is essential for controlling Input/Output (I/O) pins of the Portenta C33 board. These pins are crucial for a wide range of applications, including reading sensor data, controlling actuators, and interfacing with other hardware components. - -#### Pin Initialization - -To begin using an I/O pin of the Portenta C33 board with MicroPython, you need to initialize it using the `Pin` class from the `machine` module. This involves specifying the pin identifier and its mode (input, output, etc.). - -```python -from machine import Pin - -# Initializing pin P107 as an output -p107 = Pin('P107', Pin.OUT) -``` - -#### Configuring Pin Modes - -You can configure a pin as an input or output. For input pins, it's often useful to activate an internal pull-up or pull-down resistor. This helps to stabilize the input signal, especially in cases where the pin is reading a mechanical switch or a button. - -```python -# Configuring pin P105 as an input with its pull-up resistor enabled -p105 = Pin('P105', Pin.IN, Pin.PULL_UP) -``` - -#### Reading from and Writing to Pins - -To read a digital value from a pin, use the `.value()` method without any arguments. This is particularly useful for input pins. Conversely, to write a digital value, use the `.value()` method with an argument. Passing `1` sets the pin to `HIGH`, while `0` sets it to `LOW`. This is applicable to output pins. - -```python -# Reading from P105 -pin_value = p105.value() - -# Writing to P107 -p107.value(1) # Set p2 to high -``` - -#### Advanced Pin Configuration - -The Pin class allows dynamic reconfiguration of pins and setting up interrupt callbacks. This feature is essential for creating responsive and interactive applications. - -```python -# Reconfiguring P105 as an input with a pull-down resistor -p105.init(Pin.IN, Pin.PULL_DOWN) - -# Setting up an interrupt on P105 -p105.irq(lambda p: print("- IRQ triggered!", p)) -``` - -#### Practical Example - -In this example, we will configure one pin as an input to read the state of a button and another pin as an output to control an LED. The LED will turn on when the button is pressed and off when it's released. - -```python -from machine import Pin -import time - -# Configure pin P107 as an output (for the LED) -led = Pin('P107', Pin.OUT_PP) - -# Configure pin P105 as input with pull-up resistor enabled (for the button) -button = Pin('P105', Pin.IN, Pin.PULL_UP) - -while True: - # Read the state of the button - button_state = button.value() - if button_state == 0: - # Turn on LED if button is pressed (button_state is LOW) - led.value(1) - else: - # Turn off LED if button is not pressed (button_state is HIGH) - led.value(0) - - # Short delay to debounce the button - time.sleep(0.1) -``` - -This practical example demonstrates controlling an LED based on a button's state. The LED, connected to pin `P107` (configured as an output), is turned on or off depending on the button's input read from pin `P105` (set as an input with a pull-up resistor). The main loop continually checks the button's state; pressing the button fixes the LED on while releasing it turns the LED off. A brief delay is included for debouncing, ensuring stable operation without false triggers from the button. - -### Analog to Digital Converter - -The `ADC` class in MicroPython provides an interface for the Analog-to-Digital (ADC) converter of the Portenta C33 board, enabling the measurement of continuous voltages and their conversion into discrete digital values. This functionality is crucial for applications that, for example, require reading from analog sensors. The `ADC` class represents a single endpoint for sampling voltage from an analog pin and converting it to a digital value. - -The available ADC pins of the Portenta C33 board in MicroPython are the following: - -| **Available ADC Pins** | -|:----------------------:| -| `P006` | -| `P005` | -| `P004` | -| `P002` | -| `P001` | -| `P015` | -| `P014` | -| `P000` | - -#### Initializing the ADC - -First, to use an ADC of the Portenta C33 board, create an ADC object associated with a specific pin. This pin will be used to read analog values. - -```python -from machine import ADC - -# Create an ADC object on a specific pin -adc = ADC(pin) -``` - -#### Reading Analog Values - -You can read analog values as raw values using the `read_u16()` method. This method returns a raw integer from 0-65535, representing the analog reading. - -```python -# Reading a raw analog value -val = adc.read_u16() -``` - -#### Practical Example - -This example demonstrates the use of the `ADC` class to read values from a potentiometer on the Portenta C33 board. First, connect your potentiometer to the Portenta C33 board. One outer pin goes to `GND`, the other to `3V3`, and the middle pin to an analog-capable I/O pin, such as `P006`. This setup creates a variable voltage divider, with the voltage at the center pin changing as you adjust the potentiometer. - -```python -from machine import ADC, Pin -import time - -# Initialize the ADC on the potentiometer-connected pin -pot_pin = Pin('P006') -pot_adc = ADC(pot_pin) - -while True: - # Read the raw analog value - raw_value = pot_adc.read_u16() - print("- Potentiometer raw value:", raw_value) - - # Delay for readability - time.sleep(0.1) -``` -The example starts by importing the necessary modules and setting up the ADC on a pin connected to a potentiometer (`P006`). The ADC object (`pot_adc`) is used to interface with the potentiometer. Inside the loop, the analog value from the potentiometer is continuously read using the `read_u16()` method that provides a raw integer value scaled between `0` and `65535`, reflecting the potentiometer's position. The analog value value is printed to the console, and a short delay is included in the loop to ensure the output is readable. - -### Pulse Width Modulation - -Pulse Width Modulation (PWM) is a method to emulate an analog output using a digital pin. It does this by rapidly toggling the pin between low and high states. Two primary aspects define PWM behavior: - -- **Frequency**: This is the speed at which the pin toggles between low and high states. A higher frequency means the pin toggles faster. -- **Duty cycle**: This refers to the ratio of the high state duration to the total cycle duration. A 100% duty cycle means the pin remains high all the time, while a 0% duty cycle means it stays low. - -The available PWM pins of the Portenta C33 board in MicroPython are the following: - -| **Available PWM Pins** | -|:----------------------:| -| `P105` | -| `P106` | -| `P111` | -| `P303` | -| `P401` | -| `P601` | - -#### Setting Up PWM - -To use PWM, start by initializing a pin and then creating a PWM object associated with that pin. - -```python -import machine - -# Initialize a pin for PWM (e.g., pin P105) -p105 = machine.Pin('P105') -pwm1 = machine.PWM(p105) -``` - -#### Configuring PWM Parameters - -The frequency and duty cycle of the PWM signal are set based on the specific needs of your application: - -```python -# Set the frequency to 500 Hz -pwm1.freq(500) - -# Adjusting the duty cycle to 50 for 50% duty -pwm1.duty(50) -``` - -#### Checking PWM Configuration - -You can check the current configuration of the PWM object by printing it: - -```python -# Will show the current frequency and duty cycle -print(pwm1) -``` - -Retrieve the frequency and duty cycle values: - -```python -current_freq = pwm1.freq() -current_duty = pwm1.duty() -``` - -#### Deinitializing PWM - -When PWM is no longer needed, the pin can be deinitialized: - -```python -pwm1.deinit() -``` - -#### Practical Example - -In this example, we will use PWM to control the brightness of an LED connected to pin `P105` of the Portenta C33 board. - -```python -import machine -import time - -# Configure the LED pin and PWM -led_pin = machine.Pin('P105') -led_pwm = machine.PWM(led_pin) -led_pwm.freq(500) - -# Loop to vary brightness -while True: - # Increase brightness - for duty in range(100): - led_pwm.duty(duty) - time.sleep(0.001) - - # Decrease brightness - for duty in range(100, -1, -1): - led_pwm.duty(duty) - time.sleep(0.001) -``` - -### Real-Time Clock - -The `RTC` class in MicroPython provides a way to manage and utilize the Real-Time Clock (RTC) of the Portenta C33 board. This feature is essential for applications that require accurate timekeeping, even when the main processor is not active. The RTC maintains accurate time and date, functioning independently from the main system. It continues to keep track of the time even when the board is powered off, as long as it's connected to a power source like a battery. - -#### Initializing the RTC - -To use the RTC, first create an RTC object. This object is then used to set or read the current date and time. - - -```python -import machine - -# Create an RTC object -rtc = machine.RTC() -``` - -#### Setting and Getting Date and Time - -The RTC allows you to set and retrieve the current date and time. The date and time are represented as an 8-tuple format. - -```python -# Setting the RTC date and time -rtc.datetime((2024, 1, 4, 4, 20, 0, 0, 0)) - -# Getting the current date and time -current_datetime = rtc.datetime() -print("- Current date and time:", current_datetime) -``` - -The 8-tuple for the date and time follows the format `(year, month, day, weekday, hours, minutes, seconds, subseconds)`. - -#### Practical Example - -A practical use case for the RTC is to add timestamps to sensor data readings. By setting the current time on the RTC, you can then append an accurate timestamp each time a sensor value is logged. - -```python -import machine - -# Initialize the RTC and set the current datetime -rtc.datetime((2024, 1, 4, 4, 20, 0, 0, 0)) - -# Function to read a sensor value (placeholder) -def read_sensor(): - # Replace with actual sensor reading logic - return 42 - -# Read sensor value and get the current time -sensor_value = read_sensor() -timestamp = rtc.datetime() - -# Output the sensor value with its timestamp -print("- Sensor value at ", timestamp, ":", sensor_value) -``` - -In this example, every sensor reading is accompanied by a timestamp, which can be crucial for data analysis or logging purposes. The RTC's ability to maintain time independently of the main system's power status makes it reliable for time-sensitive applications. diff --git a/content/micropython/01.basics/06.board-examples/py-hero-banner.png b/content/micropython/01.basics/06.board-examples/py-hero-banner.png deleted file mode 100644 index d597d5b64e..0000000000 Binary files a/content/micropython/01.basics/06.board-examples/py-hero-banner.png and /dev/null differ diff --git a/content/micropython/01.basics/07.installing-modules/assets/delete-file.png b/content/micropython/01.basics/07.installing-modules/assets/delete-file.png deleted file mode 100644 index e80cc59480..0000000000 Binary files a/content/micropython/01.basics/07.installing-modules/assets/delete-file.png and /dev/null differ diff --git a/content/micropython/01.basics/07.installing-modules/assets/install-cert.png b/content/micropython/01.basics/07.installing-modules/assets/install-cert.png deleted file mode 100644 index 42169ed361..0000000000 Binary files a/content/micropython/01.basics/07.installing-modules/assets/install-cert.png and /dev/null differ diff --git a/content/micropython/01.basics/07.installing-modules/installing-modules.md b/content/micropython/01.basics/07.installing-modules/installing-modules.md deleted file mode 100644 index 3fc3715447..0000000000 --- a/content/micropython/01.basics/07.installing-modules/installing-modules.md +++ /dev/null @@ -1,146 +0,0 @@ ---- -title: Installing Modules -description: Learn how to install and remove external modules on your Arduino board. -author: Karl Söderby -micropython_type: basics -hero_image: "./hero-banner.png" ---- - -Your MicroPython installation comes with a set of modules built-in to the firmware. If you are using any external components such as sensors, displays or neopixels, you will need to install these manually. - -There are currently two methods available when installing a module on your board running MicroPython: -- Using the `mip` module on your **board**, (download and install via Wi-Fi® connection), -- using `mpremote` on your **computer** (download and install through a USB connection), - -In this article, we will cover these two methods, as well as how to remove them from your board. - -***Please note: installing packages that contain 2-byte characters (such as emojis, Chinese symbols), is currently not supported in the [Arduino Lab for MicroPython editor](https://labs.arduino.cc/en/labs/micropython). You will however receive a "successful installation" response, which is a bug being investigated.*** - -## Hardware & Software Needed - -- [A MicroPython compatible board](/micropython/basics/board-installation#supported-boards), - -- [Arduino Lab for MicroPython editor](https://labs.arduino.cc/en/labs/micropython), -- [mpremote](https://pypi.org/project/mpremote/) (optional). - -## Option 1: MIP - -***Please note that the `mip` module requires a stable Internet connection via Wi-Fi. Installation may fail if connection is unstable.*** - -[mip](https://docs.micropython.org/en/latest/reference/packages.html#installing-packages-with-mip) is a module that allows you to install external packages/libraries/modules remotely. This module is built in to your MicroPython firmware. - -To use the `mip` module, you will however need to connect to Internet via a Wi-Fi network first. To do so, open the **Arduino Lab for MicroPython editor**, and run the following code: - -***Note: Replace "YOUR_NETWORK_NAME" and "" YOUR_NETWORK_PASSWORD" with the SSID and password for your Wi-Fi® network.*** - - -```python -import network - -WIFI_NETWORK='YOUR_NETWORK_NAME' -WIFI_PASSWORD='YOUR_NETWORK_PASSWORD' - -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -wlan.connect(WIFI_NETWORK, WIFI_PASSWORD) - -print() -print("Connected to ",WIFI_NETWORK) -``` - -Once you are connected, you can use the `mip` module to install external modules. - -You can install by specifying the **organisation** and **repository**: - -```python -import mip -mip.install(github:org/repo) -``` - -Or you can specify the url to the file you want to install: - -``` -mip.install("https://raw.githubusercontent.com/tinypico/tinypico-micropython/master/lis3dh%20library/lis3dh.py") - -``` - -Files are added to a folder named `lib` on your board. - -***There are a number of ways you can use the `install()` method, read more about this in the [MIP documentation](https://docs.micropython.org/en/latest/reference/packages.html#installing-packages-with-mip).*** - -### Complete Example - -In this example, we first connect to Wi-Fi®, and then proceed to install the `[arduino-iot-cloud-py](https://github.com/arduino/arduino-iot-cloud-py) module. - -```python -import network -import mip - -# enter wi-fi creds -WIFI_NETWORK='YOUR_NETWORK_NAME' -WIFI_PASSWORD='YOUR_NETWORK_PASSWORD' - -# connect to wi-fi -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -wlan.connect(WIFI_NETWORK, WIFI_PASSWORD) - -print() -print("Connected to ",WIFI_NETWORK) - -# install the arduino-iot-cloud module -mip.install("github:arduino/arduino-iot-cloud-py") -``` - -***Running this example twice will result in a `202` error, as you have already connected to Wi-Fi. Once you have connected once to Wi-Fi, you only need to use the `mip.install()` method.*** - -### Failed Installation - -Installation via `mip` may fail due to an unstable Internet connection. If you have installed a module but you are receiving errors, make sure your Internet connection is good (your board is within reach of your router), and run the installation again. - -This is typically not an issue with smaller installations (like single files), but when installing larger packages it is increased. - -You can install the same module again, it will only overwrite the existing version. - -## Option 2: Mpremote - -To install a MicroPython module on your board, you can use the Python based tool `mpremote`. This requires Python to be installed. On macOS and Linux Python usually comes pre-installed. If it's not installed on your system you may download it from [here](https://www.python.org/downloads/). Then, to install `mpremote` you can use pip: - -```bash -$ pip install mpremote -``` - -Run `mpremote connect list` to retrieve the serial number of your device. The output will look similar to this: - -``` -/dev/cu.usbmodem3871345733302 335B34603532 2341:055b Arduino Portenta Virtual Comm Port in HS Mode -``` - -Pass this serial number (the second value) to the install command: - -```bash -$ mpremote connect id:335B34603532 mip install github:arduino/arduino-iot-cloud-py -``` - -This will install the library and all required dependencies on the board. - -### Error: Certificate Verify Fail (MacOS) - -On some computers, you may receive error: - -``` -[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: -unable to get local issuer certificate (_ssl.c:1002) -``` - -This indicates a problem with the Python version installed, and that it is unable to locate the SSL certificate. To work around this, navigate to your Python installation (typically **Applications > Python 3.X**), and run the `Install Certificates.command` script. - -![Install Certificate.](assets/install-cert.png) - -## Delete Files - -To delete a file from your board, open the **Arduino Lab for MicroPython** editor, connect to your board, and click the **"File"** button. This will open your local files as well as your board's files. - -If you want to remove a file, simply mark it and click on the trashcan icon in the top right of the file window, as the image below shows: - -![Removing files.](assets/delete-file.png) \ No newline at end of file diff --git a/content/micropython/01.basics/07.installing-modules/py-hero-banner.png b/content/micropython/01.basics/07.installing-modules/py-hero-banner.png deleted file mode 100644 index d9a2f1d9dc..0000000000 Binary files a/content/micropython/01.basics/07.installing-modules/py-hero-banner.png and /dev/null differ diff --git a/content/micropython/01.basics/08.reference/py-hero-banner.png b/content/micropython/01.basics/08.reference/py-hero-banner.png deleted file mode 100644 index f0680b9243..0000000000 Binary files a/content/micropython/01.basics/08.reference/py-hero-banner.png and /dev/null differ diff --git a/content/micropython/01.basics/basics.md b/content/micropython/01.basics/basics.md index abf7073e1a..759ad01c12 100644 --- a/content/micropython/01.basics/basics.md +++ b/content/micropython/01.basics/basics.md @@ -1,4 +1,4 @@ --- title: Basics -description: Basics Description +description: Learn about the basics of MicroPython --- \ No newline at end of file diff --git a/content/micropython/03.micropython/02.environment/00.online-editor/assets/connect-board.png b/content/micropython/02.environment/00.online-editor/assets/connect-board.png similarity index 100% rename from content/micropython/03.micropython/02.environment/00.online-editor/assets/connect-board.png rename to content/micropython/02.environment/00.online-editor/assets/connect-board.png diff --git a/content/micropython/03.micropython/02.environment/00.online-editor/assets/online-editor-access.png b/content/micropython/02.environment/00.online-editor/assets/online-editor-access.png similarity index 100% rename from content/micropython/03.micropython/02.environment/00.online-editor/assets/online-editor-access.png rename to content/micropython/02.environment/00.online-editor/assets/online-editor-access.png diff --git a/content/micropython/03.micropython/02.environment/00.online-editor/online-editor.md b/content/micropython/02.environment/00.online-editor/online-editor.md similarity index 100% rename from content/micropython/03.micropython/02.environment/00.online-editor/online-editor.md rename to content/micropython/02.environment/00.online-editor/online-editor.md diff --git a/content/micropython/03.micropython/02.environment/01.code-editor/assets/IDEFileManager.png b/content/micropython/02.environment/01.code-editor/assets/IDEFileManager.png similarity index 100% rename from content/micropython/03.micropython/02.environment/01.code-editor/assets/IDEFileManager.png rename to content/micropython/02.environment/01.code-editor/assets/IDEFileManager.png diff --git a/content/micropython/03.micropython/02.environment/01.code-editor/assets/IDEOverview.png b/content/micropython/02.environment/01.code-editor/assets/IDEOverview.png similarity index 100% rename from content/micropython/03.micropython/02.environment/01.code-editor/assets/IDEOverview.png rename to content/micropython/02.environment/01.code-editor/assets/IDEOverview.png diff --git a/content/micropython/03.micropython/02.environment/01.code-editor/assets/consoleTerminal.png b/content/micropython/02.environment/01.code-editor/assets/consoleTerminal.png similarity index 100% rename from content/micropython/03.micropython/02.environment/01.code-editor/assets/consoleTerminal.png rename to content/micropython/02.environment/01.code-editor/assets/consoleTerminal.png diff --git a/content/micropython/03.micropython/02.environment/01.code-editor/code-editor.md b/content/micropython/02.environment/01.code-editor/code-editor.md similarity index 100% rename from content/micropython/03.micropython/02.environment/01.code-editor/code-editor.md rename to content/micropython/02.environment/01.code-editor/code-editor.md diff --git a/content/micropython/03.micropython/02.environment/01.repl/repl.md b/content/micropython/02.environment/01.repl/repl.md similarity index 100% rename from content/micropython/03.micropython/02.environment/01.repl/repl.md rename to content/micropython/02.environment/01.repl/repl.md diff --git a/content/micropython/03.micropython/02.environment/02.file-system/file-system.md b/content/micropython/02.environment/02.file-system/file-system.md similarity index 100% rename from content/micropython/03.micropython/02.environment/02.file-system/file-system.md rename to content/micropython/02.environment/02.file-system/file-system.md diff --git a/content/micropython/03.micropython/02.environment/03.modules/assets/microPythonLabsFiles.png b/content/micropython/02.environment/03.modules/assets/microPythonLabsFiles.png similarity index 100% rename from content/micropython/03.micropython/02.environment/03.modules/assets/microPythonLabsFiles.png rename to content/micropython/02.environment/03.modules/assets/microPythonLabsFiles.png diff --git a/content/micropython/03.micropython/02.environment/03.modules/modules.md b/content/micropython/02.environment/03.modules/modules.md similarity index 100% rename from content/micropython/03.micropython/02.environment/03.modules/modules.md rename to content/micropython/02.environment/03.modules/modules.md diff --git a/content/micropython/03.micropython/02.environment/04.runtime/runtime.md b/content/micropython/02.environment/04.runtime/runtime.md similarity index 100% rename from content/micropython/03.micropython/02.environment/04.runtime/runtime.md rename to content/micropython/02.environment/04.runtime/runtime.md diff --git a/content/micropython/02.environment/environment.md b/content/micropython/02.environment/environment.md new file mode 100644 index 0000000000..6fd45bfda8 --- /dev/null +++ b/content/micropython/02.environment/environment.md @@ -0,0 +1,4 @@ +--- +title: Environment +description: Learn about code editor and other tools in the MicroPython environment +--- \ No newline at end of file diff --git a/content/micropython/01.basics/08.reference/reference.md b/content/micropython/03.language/01.reference/reference.md similarity index 100% rename from content/micropython/01.basics/08.reference/reference.md rename to content/micropython/03.language/01.reference/reference.md diff --git a/content/micropython/03.language/language.md b/content/micropython/03.language/language.md new file mode 100644 index 0000000000..c91ef4ee37 --- /dev/null +++ b/content/micropython/03.language/language.md @@ -0,0 +1,4 @@ +--- +title: Language +description: A reference to the Arduino MicroPython API +--- \ No newline at end of file diff --git a/content/micropython/03.micropython/00.first-steps/first-steps.md b/content/micropython/03.micropython/00.first-steps/first-steps.md deleted file mode 100644 index ef0430aa15..0000000000 --- a/content/micropython/03.micropython/00.first-steps/first-steps.md +++ /dev/null @@ -1,3 +0,0 @@ ---- -title: First Steps ---- \ No newline at end of file diff --git a/content/micropython/03.micropython/01.basics/basics.md b/content/micropython/03.micropython/01.basics/basics.md deleted file mode 100644 index c2556bad89..0000000000 --- a/content/micropython/03.micropython/01.basics/basics.md +++ /dev/null @@ -1,3 +0,0 @@ ---- -title: Basics ---- \ No newline at end of file diff --git a/content/micropython/03.micropython/02.environment/environment.md b/content/micropython/03.micropython/02.environment/environment.md deleted file mode 100644 index c2556bad89..0000000000 --- a/content/micropython/03.micropython/02.environment/environment.md +++ /dev/null @@ -1,3 +0,0 @@ ---- -title: Basics ---- \ No newline at end of file diff --git a/content/micropython/03.micropython/03.language/01.reference/reference.md b/content/micropython/03.micropython/03.language/01.reference/reference.md deleted file mode 100644 index 3c6e92eed1..0000000000 --- a/content/micropython/03.micropython/03.language/01.reference/reference.md +++ /dev/null @@ -1,1838 +0,0 @@ ---- -title: MicroPython Reference -description: A single document reference of the MicroPython API. -authors: Karl Söderby -micropython_type: basics ---- - -***Please note that some part of this reference is still in progress and will be updated over time. The article is subject to minor changes.*** - -This reference serves as a "translation" between what is known as the **Arduino API**, which is documented in the [Arduino Language Reference](https://www.arduino.cc/reference/en/), and the **MicroPython API**. - -The main goal with this reference is to provide an understanding of how to e.g. use common Arduino concepts such as `digitalWrite()` in a MicroPython script. - -For example: -- `digitalWrite(pin, HIGH)` (Arduino/C++) -- `pin.value(1)` (MicroPython) - -The entries are named exactly the same as in the language reference, with the MicroPython syntax, description and code example provided for each entry. It is however important to understand that any given board may not be fully compatible with this reference, as some implementations vary between board/architecture. For example, using PWM on a STM32 board will differ from using it on an ESP32 board. - -***Note that several entries in the original [Language Reference](https://www.arduino.cc/reference/en/) are directly taken from the C++ reference. In the same fashion, many functions located in this reference are taken from the Python reference, and are not MicroPython specific.*** - -## Digital I/O - -To access digital GPIOs using MicroPython, we use the `Pin` module. To define a pin, we use `Pin(pin,type)`. - -### pinMode() - -- `output_pin = Pin(pin, Pin.OUT)` (define as output) -- `input = Pin(pin, Pin.IN)` -- `input_pullup = Pin(pin, Pin.IN, Pin.PULL_UP` (define as input pull up) -- `input_pulldown = Pin(pin, Pin.IN, Pin.PULL_DOWN` (define as input pull down) - -**Parameters:** -- `pin` - pin we want to set -- `type` - define as input or output -- `pullmode` - define as pull up or pull down mode (optional). - -**Example:** - -```python -from machine import Pin - -output_pin = Pin(5, Pin.OUT) #define pin -input_pin = Pin(6, Pin.IN, Pin.PULL_UP) #define pin as an input pullup -``` - -### digitalRead() - -`pin.value()` - -Reads the state of a digital pin defined as input. -- **Parameters:** none. -- **Returns:** the value of the digital pin (0 or 1). - -```python -from machine import Pin - -pin = Pin(5, Pin.PULL_UP) #define pin -reading = pin.value() #read pin - -print(reading) #print state of pin to REPL -``` - -### digitalWrite() - -`pin.value(state)` - -Writes a state to a digital pin defined as an output. -- **Parameters:** none. -- **Returns:** the value of the digital pin (0 or 1). - - -```python -from machine import Pin - -pin = Pin(5, Pin.PULL_UP) #define pin -pin.value(1) #set pin to high state -``` - -## Analog I/O - -### Configure Input (ADC) - -To read an analog input pin, we need to attach a pin to the ADC. - -- `adc_pin = machine.Pin(pin)` - create the pin. -- `adc = machine.ADC(adc_pin)` - attach it to the ADC. - -### Configure Output (PWM) - -To write analog values using PWM, we need to define the pin and set the frequency. - -- `pwm = PWM(Pin(15))` -- `pwm.freq(1000)` - -On STM32 boards (GIGA R1, Portenta H7 etc.), we need to define at as follows: - -- `pin1 = Pin("PC6", Pin.OUT_PP, Pin.PULL_NONE)` -- `timer1 = Timer(3, freq=1000)` -- `channel1 = timer1.channel(1, Timer.PWM, pin=pin1, pulse_width=0)` - -### analogRead() - -`adc.read_u16()` - -Attach a pin to an ADC, and read the raw value. - -- **Returns:** - the raw analog value in a 16-bit format (0-65535). -- **Parameters:** none. - -**Example:** - -```python -import machine -import time - -adc_pin = machine.Pin("PC4") -adc = machine.ADC(adc_pin) - -while True: - reading = adc.read_u16() - print("ADC: ",reading) - - time.sleep_ms(1000) -``` - -**Note:** to convert the 16-bit value to a 10-bit value, you can use the following formula: - -```python -# right-shifts the bits and discards the 6 most significant bits -# effectively changing the value range from 0-65535 to 0-1023 -result = (reading >> 6) & 0x3FF -``` - -### analogWrite() - -`pwm.duty_u16(duty)` - -Writes the duty cycle (0-65535) to a PWM pin. - -- **Parameters:** duty cycle (0-65535). -- **Returns:** None. - -**Example:** - -```python -from machine import Pin, PWM, ADC - -pwm = PWM(Pin(15)) -duty = 30000 #between 0-65535 - -pwm.freq(1000) - -while True: - pwm.duty_u16(duty) -``` - -### analogWrite() (STM32) - -`channel1.pulse_width(duty)` - -Writes the duty cycle in percentage (0-100) to a PWM pin. - -- **Parameters:** duty cycle in percentage (0-100). -- **Returns:** None. - -**Example:** - -```python -import pyb -import time -from pyb import Pin, Timer - -pin1 = Pin("PC6", Pin.OUT_PP, Pin.PULL_NONE) -timer1 = Timer(3, freq=1000) -channel1 = timer1.channel(1, Timer.PWM, pin=pin1, pulse_width=0) - -channel1.pulse_width(50) #duty cycle at 50% -``` - -## Time - -To introduce timings & delays, use the `time` module. - -### delay() - -`time.sleep(seconds)` - -Creates a delay for the number of specified seconds. - -- **Parameters:** seconds. -- **Returns:** nothing. - -**Example:** -```python -import time - -time.sleep(1) #freeze program for 1 seconds -``` - -### millis() - -`time.time()` - -Returns the number of seconds elapsed since the start of the script. - -- **Returns:** seconds (float). -- **Parameters:** none. - -**Example:** - -```python -''' -"Blink Without Delay" script. -Blinks an LED attached to pin 5 every second, -without freezing the program. -''' - -import time -from machine import Pin - -ledPin = Pin(5, Pin.OUT) - -interval = 1 -previousTime = 0 -switch = False - -while True: - currentTime = time.time() - - if currentTime - previousTime >= interval: - previousTime = currentTime - - switch = not switch - ledPin.value(switch) -``` - -## Bits and Bytes - -### bitRead() - -`bit_value = (variable >> bit_index) & 1` - -Reads a specific bit of an integer variable. - -**Parameters:** -- `variable` - an integer variable with numeric value, e.g. `12345` -- `bit_index` - the specific bit we want to read (e.g. `5`) - -**Returns:** -- The value of the specific bit. - -**Example:** - -```python -''' -This example prints out each bit of an 8-bit variable -It stops after 255 (the max value an 8-bit variable can hold) -''' -import time -counter = 0 - -bit_length = 8 # 8 bits -while True: - bits = [] - for bit_index in range(bit_length - 1, -1, -1): - bit_value = (counter >> bit_index) & 1 - bits.append(bit_value) - print("Binary: ", bits, " DEC: ", counter) - - counter += 1 - time.sleep(0.01) - if counter > 255: - break -``` - -### bitSet() - -`variable = variable | (1 << bit_index)` - -Sets a specific bit of an integer variable. - -**Parameters:** -- `variable` - an integer variable with numeric value, e.g. `12345` -- `bit_index` - the specific bit we want to read (e.g. `5`) - -**Returns:** -- Nothing. - -**Example:** - -```python -# Example variable -variable = 12345 - -# Set the third bit -bit_index = 2 - -print() -print("Before setting a bit: ",bin(variable)) -print("Before setting a bit: ",variable) -variable = variable | (1 << bit_index) - -# Print the result -print("After setting a bit: ",bin(variable)) -print("After setting a bit: ",variable) -``` - -### highByte() - -`leftmost_bit = (variable >> leftmost_bit_index) & 1` - -Reads the high-order (leftmost) bit of a variable. - -**Parameters** -- `variable` - an integer variable with numeric value, e.g. `255` -- `leftmost_bit_index` - the leftmost bit, e.g. `7` in an 8-bit variable. - -**Returns** -- `leftmost_bit` - the value of the leftmost bit. - -**Example:** - -```python -# Example variable -variable = 255 - -bit_length = 8 -# Extract the leftmost bit -leftmost_bit_index = bit_length - 1 -leftmost_bit = (variable >> leftmost_bit_index) & 1 - -# Print the result -print("Leftmost bit: ", leftmost_bit) -``` - -### lowByte() - -`rightmost_bit = variable & 1` - -Reads the low-order (rightmost) bit of a variable. - -**Parameters** -- `variable` - an integer variable with numeric value, e.g. `255` -- `rightmost_bit` - the rightmost bit, `0` in an 8-bit variable. - -**Returns** -- `rightmost_bit` - the value of the rightmost bit, e.g. `1` if `variable` is 255 (255 is 11111111 in binary). - -**Example:** - -```python -# Example variable -variable = 255 - -# Extract the rightmost bit -rightmost_bit = variable & 1 - -# Print the result -print("Rigthmost bit: ", rightmost_bit) -``` - - -## Advanced I/O - -### tone() / noTone() - -- `tone(pin,frequency,volume,duration)` -- `noTone(pin,duration)` - -To use the popular `tone()` and `noTone()` functions, we need to define them as functions as they currently are not implemented. - -**Example:** - -```python -from machine import Pin, PWM -import time - -def tone(pin,frequency,volume,duration=None): - speaker = PWM(Pin(pin)) - speaker.freq(frequency) - speaker.duty_u16(volume) - if duration is not None: - time.sleep(duration) - -def noTone(pin,duration=None): - speaker = PWM(Pin(pin)) - speaker.deinit() - if duration is not None: - time.sleep(duration) - -while True: - tone(5,500,1000,1) - noTone(5,1) -``` - -## Math - -### abs() - -`abs(value)` - -Returns the absolute value of a number. - -**Example:** - -```python -result = abs(-5) -print(result) -``` - -### constrain() - -`constrain(value, min, max)` - -Constrains the value to be within a specific range. - -**Example:** - -```python -def constrain(value, lower, upper): - return max(min(value, upper), lower) - -result = constrain(10, 0, 5) # Result will be 5 -print(result) -``` - - -### map() - -`map(value, in_min, in_max, out_min, out_max)` - -Maps a value from one range to another. - -**Example:** - -```python -def map(value, in_min, in_max, out_min, out_max): - return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min - -result = map(50, 0, 100, 0, 255) # Result is 127.5 -print(result) -``` - - -### max() - -`max(value1, value2, value3, valueX)` - -Returns the highest value among the given parameters. Accepts many arguments separated by comma. - -**Example:** - -```python -result = max(5, 10, 3) # Result will be 10 -print(result) -``` - -### min() - -`min(value1, value2, value3, valueX)` - -Returns the lowest value among the given parameters. Accepts many arguments separated by comma. - -**Example:** - -```python -result = min(5, 10, 3) # Result will be 3 -print(result) -``` - -### pow() - -`pow(base, exponent)` - -Raises a number to the power of another. - -**Example:** - -```python -result = pow(2, 3) # Result will be 8 -print(result) -``` - -### sq() - -`sq(value)` - -Returns the square of a number. - -**Example:** - -```python -result = sq(4) # Result will be 16 -print(result) -``` - -### sqrt() - -`math.sqrt(value)` - -This function returns the square root of a number. - -**Example:** - -```python -import math - -result = math.sqrt(16) # Result will be 4.0 -print(result) -``` - -## Trigonometry - -### cos() - -`math.cos(angle_in_radians)` - -Calculates the cosine of an angle (in radians). The result will be between -1 and 1. - -**Example:** - -```python -import math - -# Specify the angle in radians -angle_in_radians = math.radians(45) - -# Calculate the cosine of the angle -cos_value = math.cos(angle_in_radians) - -# Print the result -print(f"The cosine of {angle_in_radians} radians is: {cosine_value}") -``` - -### sin() - -`math.sin(angle_in_radians)` - -Calculates the sine of an angle (in radians). The result will be between -1 and 1. - -**Example:** - -```python -import math - -# Specify the angle in radians -angle_in_radians = math.radians(30) - -# Calculate the sine of the angle -sine_value = math.sin(angle_in_radians) - -# Print the result -print(f"The sine of {angle_in_radians} radians is: {sine_value}") - -``` - -### tan() - -`math.tan(angle_in_radians)` - -Calculates the tangent of an angle (in radians). The result will be between negative infinity and infinity. - -**Example:** - -```python -import math - -# Specify the angle in radians -angle_in_radians = math.radians(60) - -# Calculate the tangent of the angle -tangent_value = math.tan(angle_in_radians) - -# Print the result -print(f"The tangent of {angle_in_radians} radians is: {tangent_value}") -``` - -## Characters - -### isAlpha() - -`char.isalpha()` - -Analyse if a single character is alphabetic. - -```python -char = 'a' -if char.isalpha(): - print(f"{char} is alphabetic.") -else: - print(f"{char} is not alphabetic.") -``` - -### isAlphaNumeric() - -`char.isDigit()` and `char.isAlpha()` - -Checks if char is a number **or** an alphabetic character. - -**Example:** - -```python -# Function to check if a character is alphanumeric -def is_alphanumeric(char): - return char.isalpha() or char.isdigit() - -# Example usage -test_char = 'a' - -if is_alphanumeric(test_char): - print(f"{test_char} is alphanumeric.") -else: - print(f"{test_char} is not alphanumeric.") - -``` - -### isAscii() - -`ord(char) < 128` - -Checks if character is an ASCII character by checking if the decimal number of the character presented is over 128. If it is over, it is not an ASCII character. - -```python -char = 'Ö' - -if 0 <= ord(char) < 128: - print(f"{char} is an ASCII character.") -else: - print(f"{char} is not an ASCII character.") -``` - -### isControl() - -`ord(char) < 32 or ord(char) == 127` - -Checks whether character presented is less than 32 or 127, which represents control characters. - -```python -char = '\t' # Example: Tab character - -if 0 <= ord(char) < 32 or ord(char) == 127: - print(f"{char} is a control character.") -else: - print(f"{char} is not a control character.") -``` - -### isDigit() - -`char.isDigit()` - - -```python -char = '5' -if char.isdigit(): - print(f"{char} is a digit.") -else: - print(f"{char} is not a digit.") -``` - -### isGraph() - -**Example:** - -```python -char = 'A' - -if char.isprintable() and not char.isspace(): - print(f"{char} is a graph character.") -else: - print(f"{char} is not a graph character.") -``` - -### isLowerCase() - -**Example:** - -`islower()` - -```python -char = 'a' - -if char.islower(): - print("Is lower case.") -else: - print("Is not lower case.") -``` - -### isPrintable() - -`isprintable()` - -Checks if a character is printable, e.g. any character, including blank space, but not control characters. - -**Example:** - -```python -char = '\t' - -if char.isprintable(): - print("Is printable.") -else: - print("Is not printable.") -``` - -### isPunct() - -There is no built-in function for checking punctuation in Python. Instead, we can define a variable containing all punctioation characters, and a function that compares the provided value with it. - -**Example:** - -```python -def isPunct(char): - punctuation_chars = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" - return char in punctuation_chars - -print(isPunct(".")) -``` - -### isSpace() - -`char.isspace()` - -**Example:** - -```python -char = ' ' - -if char.isspace(): - print(f"{char} is a space character.") -else: - print(f"{char} is not a space character.") -``` - -### isUpperCase() - -`char.isupper()` - -**Example:** - -```python -char = 'A' - -if char.isupper(): - print(f"{char} is an uppercase letter.") -else: - print(f"{char} is not an uppercase letter.") -``` - - -## Random Numbers - - -### random() - -`random.random()` - -Produces a random number within the range provided. - -**Example:** - -```python -import random - -random_integer = random.randint(1, 10) -print("Random integer between 1 and 10:", random_integer) -``` - -### randomSeed() - -`seed_value = int(time.time())` and `random.seed()` - -To generate a random seed value, we first use the `time()` module to generate a unique value, and feed it to the `random.seed()` generator. The result is that you will always get a unique random number. - -**Example:** - -```python -import random -import time - -# Seed the random number generator with the current time -seed_value = int(time.time()) -random.seed(seed_value) - -# Generate random numbers using the seeded generator -random_number = random.randint(1,100) -print(random_number) -``` - -***Note that `time.time()` generates a new value every second. E.g. running `random.seed()` twice within a second will generate the same value. `random.seed()` should not be used repetitively.*** - -## External Interrupts - -### attachInterrupt() - -`interrupt_pin.irq(trigger=mode, handler=function)` - -Attaches an interrupt to a pin with specified mode. - -```python -from machine import Pin -import time - -# Define a callback function to be called when the interrupt occurs -def interrupt_callback(pin): - print("Interrupt occurred on pin", pin_name) - -# Pin name -pin_name = "PA3" - -# Define the pin to which you want to attach the interrupt -interrupt_pin = Pin(pin_name, Pin.IN, Pin.PULL_UP) # Replace 2 with the actual pin number you are using - -# Attach the interrupt to the pin, specifying the callback function and trigger type -interrupt_pin.irq(trigger=Pin.IRQ_FALLING, handler=interrupt_callback) - -while True: - print("hello world") - time.sleep(1) -``` - -### detachInterrupt() - -`interrupt_pin.irq(handler=None)` - -Detaches the active interrupt from specified pin. - -**Example:** - -```python -from machine import Pin -import time - -# Define a callback function to be called when the interrupt occurs -def interrupt_callback(pin): - print("Interrupt occurred on pin", pin_name) - # Detaches the interrupt from the pin - interrupt_pin.irq(handler=None) - -# Pin name -pin_name = "PA3" - -# Define the pin to which you want to attach the interrupt -interrupt_pin = Pin(pin_name, Pin.IN, Pin.PULL_UP) # Replace 2 with the actual pin number you are using - -# Attach the interrupt to the pin, specifying the callback function and trigger type -interrupt_pin.irq(trigger=Pin.IRQ_FALLING, handler=interrupt_callback) - -while True: - print("hello world") - time.sleep(1) -``` - -## Serial (USB) - -In the Arduino API, we are accustomed to using `Serial.begin()` and `Serial.print()` to send data from a board to a computer. - -The same API is used for sending and receiving data over UART, using `Serial1`. For UART, see the [Serial (UART)](#serial-uart) section. - -In MicroPython, to send data over USB, we can use the `print()` function, which prints the content to the REPL. As MicroPython is implemented a bit differently, the REPL also allows you to write commands inside it. The REPL is therefore in many ways, different from the Serial Monitor we are used to in the Arduino IDE. - - -### Serial.print() - -`print(content)` - -This function prints the content to the REPL. - -**Example:** - -```python -variable = 5 - -print("I am a string!") # prints a string -print(variable) # prints value of variable -print(58) # prints a numeric value -print(f"The value is {variable}") # prints a string with a value inserted -``` - -## Serial1 (UART) - -UART communication is initialized using the `UART` object from the `machine` module. - -***When sending & receiving data on a hardware UART port on an Arduino board, we use the `Serial1` class.*** - -### Serial1.begin() - -`machine.UART(port, baudrate=baud)` - -Initialize UART communication on specified port (default is `1`), and specified baud rate. - -**Example:** - -```python -import machine -import time - -uart = machine.UART(1, baudrate=57600) -``` - -***Baud rate `57600` is used as using the common `115200` and `9600` interfered with the Arduino IDE's Serial Monitor.*** - -### Serial1.available() - -`uart.any()` - -Checks if there's any data available on the UART port. - -**Example:** - -```python -import machine -import time - -uart = machine.UART(1, baudrate=57600) - -while True: - if uart.any(): - print("data available") -``` - - -### Serial1.read() - -`uart.read(1)` - -Reads one byte from the buffer. - -**Example:** - -This example reads the first byte of data from the buffer, stores it into the `received_data` string. When a new line character (`\n`) is detected, the received message is printed to the REPL. - -```python -import machine -import time - - -uart = machine.UART(1, baudrate=57600) -received_data = "" - -while True: - if uart.any(): - data = uart.read(1) - received_data += data - - if received_data and received_data[-1] == '\n': - print("Received:", received_data[:-1]) # Print the accumulated data (excluding the newline character) - received_data = "" # Reset the string after printing - - time.sleep(0.1) -``` - -### Serial1.write() - -`uart.write(message)` - -Writes / sends data over UART. - -**Example:** - -```python -import machine -import time - - -uart = machine.UART(1, baudrate=57600) - -while True: - data_to_send = "Hello World!\n" - uart.write(data_to_send) - - time.sleep(1) -``` - -## SPI - -SPI communication is initialized using the `SPI` object from the `machine` module. - -### SPI.begin() - -`spi = machine.SPI(port, baudrate, polarity, phase)` - -SPI is initialized by importing the `machine` module and specifying a number of parameters, such as baudrate and polarity. - -**Example:** - -```python -import machine - -spi = machine.SPI(0, baudrate=1000000, polarity=0, phase=0) -``` - -### SPI.read() - -***Note that `SPI.read()` is not in the Arduino API, as the `SPI.transfer()` handles both outgoing and incoming data.*** - -`spi.readinto(data_in)` - -Reads incoming data and stores it in an array. The size of the array needs to be adjusted to match the size of the incoming data size. - -**Example:** - -```python -import machine -import time - -spi = machine.SPI(0, baudrate=1000000, polarity=0, phase=0) -data_in = bytearray(3) - -spi.readinto(data_in) - -print("Received Data:", data_in) -``` - -### SPI.write() - -***Note that `SPI.write()` is not in the Arduino API, as the `SPI.transfer()` handles both outgoing and incoming data.*** - -`spi.write(data_out)` - -Writes data to the SPI bus. - -**Example:** - -```python -import machine -import time - -spi = machine.SPI(0, baudrate=1000000, polarity=0, phase=0) -data_out = b'\x01\x02\x03' - -spi.write(data_out) -``` - -### SPI.transfer() - -`spi.write_readinto(data_out, data_in)` - -Reads & writes data simultaneously, where incoming data is stored in a buffer. - -**Example:** - -```python -import machine -import time - -spi = machine.SPI(0, baudrate=1000000, polarity=0, phase=0) - -data_to_send = b'\x01\x02\x03' - -data_received = bytearray(len(data_to_send)) - -spi.write_readinto(data_to_send, data_received) - -print("Received Data:", data_received) - -spi.deinit() -``` - -### Bit Size - -`spi.bits = 8` - -Sets the number of bits per word. - -**Example:** - -```python -spi.bits = 8 -``` - -## Wire / I2C - -### Wire.begin() - -`i2c = I2C(port, scl, sda, freq)` - -Initializes I2C communication on specified port and pins. The `port` and `freq` are optional parameters, if left unspecified, default values will be set. -```python -from machine import I2C - -i2c = I2C(0, scl=Pin(SCL_PIN), sda=Pin(SDA_PIN), freq=100000) -``` - -### Wire.available() - -`i2c.in_waiting()` - -Checks the number of available bytes to read. - -```python -available_bytes = i2c.in_waiting() - -print("Available bytes to read: ", available_bytes) -``` - -### Wire.read() - -`i2c.readfrom(address, num_bytes)` - -Reads data in specified number of bytes from a device with the specified address. - -```python -data_in = i2c.readfrom(address, num_bytes) - -print("I2C data: ", data_in) -``` - -### Wire.write() - -`i2c.writeto(address, data_out)` - -Writes data to specified address. - -**Example:** - -```python -from machine import I2C, Pin - -# Initialize I2C anc configure device & reg addresses -i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=100000) # Adjust pins and frequency as needed -device_address = 0x68 -register_address = 0x00 - -# The array of bytes to be send out -# This buffer simply stores 1,2,3,4 -data_out = bytearray([0x01, 0x02, 0x03, 0x04]) - -# Send the device address with the write bit to indicate a write operation -i2c.writeto(device_address, bytearray([register_address])) - -# Finally, send data to the device -i2c.writeto(device_address, data_out) -``` - -### Wire.setClock() - -The frequency for the clock is set during initialization. See [begin()](#wirebegin) for more info. - -### SoftI2C - -MicroPython has a built in class called `SoftI2C` (as in software I2C). Software I2C does not use a dedicated hardware I2C peripheral, but instead relies on the CPU to handle the clock signal, communication protocol etc. - -`SoftI2C` is available through the `machine` module, and uses the same API as hardware I2C, with a few additional methods. - -- `softi2c = machine.SoftI2C(scl,sda,freq,timeout)` - creates the `softi2c` object with specified pins, frequency and timeout. -- `softi2c.start()` - create the start condition for initializing communication over I2C (SDA goes to **LOW** while SCL is **HIGH**). -- `softi2c.stop()` - create the stop condition for ending communication over I2C (SDA goes to **HIGH** while SCL is **HIGH**). - -## USB HID - -Human Interface Device (HID) is currently **not supported** on any of the Arduino boards. - -To use HID functions on Arduino boards that support it (most modern boards), please refer to the Arduino / C++ reference: -- [Mouse](https://www.arduino.cc/reference/en/language/functions/usb/mouse/) -- [Keyboard](https://www.arduino.cc/reference/en/language/functions/usb/keyboard/) - -## Data Types - -When declaring variables in MicroPython / Python, you do not need to specify the data type, this is done automatically. - -Examples for variable declaration can be seen in the snippet below: - -```python -var_array = [1, 2, 3] -var_bool = True/False -var_unsigned_byte = 255 -var_signed_byte = -128 -var_char = 'A' -var_double = 3.14 -var_float = 29.231232 -var_int = 2147483647 -var_long = 2147483647 -var_short = 32767 -var_string = "This is a string" -var_unsigned_int = 4294967295 -var_unsigned_long = 4294967295 -``` - -### size_t - -`len(my_array)` - -There is no direct equivalent to `size_t`, but using the `len()` function, you can return the size of an object. - -**Example:** - -```python -my_array = [1,2,3,4,5] - -array_size = len(my_array) - -print("Size of array is: ", array_size) -``` - -### void - -`def my_func():` - -There is no direct equivalent to `void`, but when defining a function without a return statement, the function is of a "void" type. - -**Example:** - -```python -def my_function(): - print("Function executed, nothing returned though!") -``` - -## Conversion - -### byte() - -`bytes(value)` - -Converts a value to a byte. - -**Example:** - -```python -my_byte = bytes([255]) -print(my_byte) # prints \xff which in hex is 255 -``` - -### char() - -`chr(value)` - -Converts a value to a char - - -**Example:** - -```python -value = 65 # 65 is "A" in ASCII code -char_value = chr(value) # converts a value to char (65 to "A") -print("Char value:", char_value) # prints "A" -``` - -### float() - -`float(value)` - -**Example 1:** - -Converts an integer to float. - -```python -value = 25 -float_value = float(value) -print("Float value:", float_value) # prints 25.0 -``` - -**Example 2:** - -Converts a string to float. - -```python -value = "3.14" -float_value = float(value) -print("Float value:", float_value) #prints 3.14 -``` - -### int() - -`int(value)` - -Converts a value - -**Example 1:** - -Converts a float to int. Rounds the number up/down, e.g. `42.232` = `42`. - -```python -value = 42.232 -int_value = int(value) -print("Int value:", int_value) -``` - -**Example 2:** - -Converts a string to int. - -```python -value = "42" -int_value = int(value) -print("Int value:", int_value) -``` - -## Local / Global Variables - -Variables can either be globally or locally declared: - -- Global variables can be accessed anywhere in the program. -- Local variables can only be accessed within the function it is declared. - -When creating a program, you can decide whether you want certain variables accessible from anywhere, or just within the function. - -The benefit of declaring a local variable is that it uses less memory space (as it is only assigned within the function). - -The con of declaring a local variable is that it is not accessible anywhere else in the program. - -```python -global_var = 0 #initial value - -def my_function(): - local_var = 10 # declare local variable - print() - print("(inside function) local_var is: ", local_var) - - global_var = local_var + 25 - print("(inside function) global_var is updated to: ", global_var) - - return global_var - -global_var = my_function() + 25 -print("(outside function) global_var is finally: ", global_var) - -''' -The line below will cause the script to fail -because it is not declared globally. -''' -#print(local_var) -``` - -## Sketch - -MicroPython uses scripts as opposed to traditional sketches that require the `void loop()` and `void setup()` functions. - -A script can be as simple as a single line that prints "Hello World!" - -```python -print("Hello World!") -``` - -### loop() - -`while True:` - -A loop is not required in a MicroPython script, but is required in order to run a script continuously on the board. To have a loop in a program, we need to use a [while loop](). - -**Example:** - -The example below runs a loop that increases the `value` variable by `1` each time the loop is run. It then prints the value to the REPL, and waits for a second. - -```python -import time -value = 0 - -while True: - value += 1 - print(value) - time.sleep(1) -``` - -### setup() - -In MicroPython, there's no equalivent of the `setup()` function. Configurations that are traditionally done in this function can simply be declared at the top of the program. - -**Example:** - -This script simply declares a pin's pin mode (see [pinMode()](#pinmode)). - -```python -from machine import Pin - -output_pin = Pin(5, Pin.OUT) - -while True: - #loops forever -``` - -## Control Structure - -Control structures are used to control the flow of a program, i.e. what code will and won't execute. When a condition is met, the specified code block executes. - -### if - -The `if` statement checks *if* a condition is met, and executes the following block of code. - -**Example:** - -```python -x = 10 -if x > 5: - print("x is greater than 5") -``` - -### else - -The `else` statement can be used after e.g. an `if` statement. If the previous condition is not met, then it will the block of code following the `else` statement - -**Example:** - -```python -x = 5 -y = 10 - -if x > y: - print("x is greater") -else: - print("y is greater") -``` - -### for - -The `for` loop is used to iterate through a sequence, e.g. a range of numbers, a list, or a string. - -**Example 1: Number Range** - -```python -for number in range(5): - print(number) -``` - -**Example 2: List** - -```python -my_list = [10, 20, 30, 40, 50] -for item in my_list: - print(item) -``` - -**Example 3: String** - -```python -my_string = "Hello World!" -for char in my_string: - print(char) -``` - -### while - -The while loop is used to repeatedly execute a block of code as long as the specified condition is `True`. - -**Example 1:** - -```python -i = 0 -while i < 5: - print(i) - i += 1 -``` - -**Example 2: Infinity Loop** - -The while loop is critical to MicroPython as it is needed to create the "infinity" loop, i.e. a loop that runs whenever the board is powered. - -```python -while True: - # your program -``` - - - -### break - -The `break` statement is used to break out of loops before it ends. - -**Example:** - -```python -for i in range(5): - if i == 3: - break - print(i) - -``` - -### continue - -The `continue` statement is used to skip to the end of the code block, effectively moving on to the next iteration. This is useful to e.g. filter out specific data points. - -**Example:** - -This example iterates through a list of numbers. If the number is less than `0` (negative), it will skip it. - -```python -my_list = [0, -5, -3, 8, 9 , 11] -for num in my_list: - if num < 0: - continue - print(num) -``` - -### return - -Terminates a function and `return` a value from a function to the calling function. - -**Example:** - -In this example, we call a function named `add_numbers()`, which takes two parameters. It then returns the processed value, using the `return` statement. - -```python -def add_numbers(a, b): - result = a + b - return result - -print(add_numbers(5,5)) -``` - -## Operators - -### Arithmetic Operators - -Arithmetic operators are symbols used in programming and mathematics to perform basic arithmetic operations on numerical values. - -To assign a new value to any variable, use an assignment operator (single equal sign `=`). - -```python -my_variable = 5 # the value of my_variable is now 5 -``` - -The following arithmetic operators can be used: - -- `%` (remainder) -- `*` (multiplication) -- `+` (addition) -- `-` (subtraction) -- `/` (division) -- `**` (exponentiation) - - -**Example:** - -The script below demonstrates - -```python -remainder = 5 % 10 # remainder is 5 -multiplication = 10 * 5 # result of multiplication is 50 -addition = 10 + 5 # result of addition is 15 -subtraction = 10 - 5 # result of subtraction is 5 -division = 10 / 5 # result of division is 2 -exponentiation = 10 ** 5 # result of exponentiation is 10000 (10*10*10*10*10) - -print("remainder:", remainder) -print("multiplication:", multiplication) -print("addition:", addition) -print("subtraction:", subtraction) -print("division:", division) -print("exponentiation:", exponentiation) -``` - -### Comparison Operators - -Comparison operators are used to compare two values or expressions, and returns a boolean result (`True` or `False`) - -- `==` (equal to) -- `!=` (not equal to) -- `<` (less than) -- `<=` (less than or equal to) -- `>` (greater than) -- `>=` (greater than or equal to) - -The following scripts will compare the `x` with `y` variables and print the result in the REPL. - -**Equal to `==`** - -```python -x = 10 -y = 5 - -if x == y: - print("x is equal to y") -else: - print("x is not equal to y") -``` - -**Not equal to `!=`** - -```python -x = 10 -y = 5 - -if x != y: - print("x is not equal to y") -else: - print("x is equal to y") -``` - -**Less than `<`** - -```python -x = 10 -y = 5 - -if x < y: - print("x is smaller than x") -else: - print("x is not smaller than y") -``` - -**Less or equal to `<=`** - -```python -x = 10 -y = 5 - -if x <= y: - print("x is smaller or equal to y") -else: - print("x is not smaller or equal to y") - -``` - -**Greater than `>`** - -```python -x = 10 -y = 5 - -if x > y: - print("x is greater than y") -else: - print("x is not greater than y") -``` - -**Greater than or equal to `>=`** - -```python -x = 10 -y = 5 - -if x >= y: - print("x is greater than or equal to y") -else: - print("x is not greater than or equal to y") - -``` - -### Boolean Operators - -Boolean operators are used to perform logical operations between Boolean values (`True` or `False`). - -Boolean operators are expressed in written format, and not with symbols ( `!`, `&&`, `||`) like other programming frameworks such as Arduino / C++ use. - -- `not` (logical not) -- `and` (logical and) -- `or` (logical or) - -The following scripts demonstrates how to use the boolean operators: - -**Logical `not`:** - -```python -x = True - -if not x: - print("False") -else: - print("True") -``` - -**Logical `and`:** - -```python -x = 7 - -if x > 5 and x < 10: - print("x is greater than 5 AND smaller than 10") -``` - -**Logical `or`:** - -```python -x = 5 -y = 10 - -if x == 3 or y == 10: - print("One condition matched!") -``` - - -### Bitwise Operators - -Bitwise operators are used to manipulate individual bits at a binary level. For example, an integer variable that holds the value of `15` is in binary `1111`. With bitwise operators, you can for example change `1111` (15) to `1011` (11). - -The following bitwise operators are available: - -- `&` (bitwise and) -- `<<` (bitshift left) -- `>>` (bitshift right) -- `^` (bitwise xor) -- `|` (bitwise or) -- `~` (bitwise not) - -Below are a set of scripts that explains the usage of bitwise operators: - -**Bitwise and `&`:** - -```python -a = 5 # 101 in binary -b = 3 # 011 in binary - -result = a & b -print(result) # Output: 1 (001 in binary) -``` - -**Bitshift left `<<`:** - -```python -x = 3 # 11 in binary - -result = x << 2 -print(result) # Output: 12 (1100 in binary) -``` - -**Bitshift right `>>`:** - -```python -y = 16 # 10000 in binary - -result = y >> 2 -print(result) # Output: 4 (100 in binary) -``` - -**Bitwise xor `^`:** - -```python -p = 12 # 1100 in binary -q = 7 # 0111 in binary - -result = p ^ q -print(result) # Output: 11 (1011 in binary) -``` - -**Bitwise or `|`:** - -```python -m = 10 # 1010 in binary -n = 5 # 0101 in binary - -result = m | n -print(result) # Output: 15 (1111 in binary) -``` - -**Bitwise not `~`:** - -```python -z = 7 # 0111 in binary - -result = ~z -print(result) # Output: -8 (1000 in two's complement binary) -``` - -### Compound Operators - -A compound operator combines an arithmetic or bitwise operation with an assignment. For example, instead of writing `x = x +3`, you can write `x += 3`, using the compound addition (+) operator. - -The following compound operators are available: - -- `%=` (compound remainder) -- `&=` (compound bitwise and) -- `*=` (compound multiplication) -- `+=` (compound addition) -- `-=` (compound subtraction) -- `/=` (compound division) -- `^=` (compound bitwise xor) -- `|=` (compound bitwise or) - -***Please note that increment `++` and decrement `--` are not available in the Python language. The equalivent is `x +=1` and `x -=1`.** - -Below are a set of scripts that explains the usage of compound operators: - -**Compound remainder `%=`:** - -```python -a = 15 -b = 7 - -a %= b -print(a) # Output: 1 (15 % 7) -``` - -**Compound bitwise and `&=`:** - -```python -x = 5 -y = 3 - -x &= y -print(x) # Output: 1 (5 & 3) -``` - -**Compound multiplication `*=`:** - -```python -num = 8 - -num *= 3 -print(num) # Output: 24 (8 * 3) -``` - -**Compound addition `+=`:** - -```python -total = 10 - -total += 5 -print(total) # Output: 15 (10 + 5) -``` - -**Compound subtraction `-=`:** - -```python -result = 20 - -result -= 8 -print(result) # Output: 12 (20 - 8) -``` - -**Compound division `/=`:** - -```python -value = 30 - -value /= 6 -print(value) # Output: 5.0 (30 / 6) -``` - -**Compound bitwise xor `^=`:** - -```python -m = 12 -n = 7 - -m ^= n -print(m) # Output: 11 (12 ^ 7) -``` - -**Compound bitwise or `|=`:** - -```python -p = 10 -q = 5 - -p |= q -print(p) # Output: 15 (10 | 5) -``` diff --git a/content/micropython/03.micropython/micropython.md b/content/micropython/03.micropython/micropython.md deleted file mode 100644 index 9e9aae8bda..0000000000 --- a/content/micropython/03.micropython/micropython.md +++ /dev/null @@ -1,4 +0,0 @@ ---- -title: Test -description: Test ---- \ No newline at end of file diff --git a/content/micropython/04.board-examples/board-examples.md b/content/micropython/04.board-examples/board-examples.md new file mode 100644 index 0000000000..7658b8f1f5 --- /dev/null +++ b/content/micropython/04.board-examples/board-examples.md @@ -0,0 +1,4 @@ +--- +title: Board Examples +description: Learn how to use board-specific features +--- \ No newline at end of file diff --git a/content/micropython/03.micropython/04.board-examples/giga-r1-wifi/assets/ABX00063-pinout.png b/content/micropython/04.board-examples/giga-r1-wifi/assets/ABX00063-pinout.png similarity index 100% rename from content/micropython/03.micropython/04.board-examples/giga-r1-wifi/assets/ABX00063-pinout.png rename to content/micropython/04.board-examples/giga-r1-wifi/assets/ABX00063-pinout.png diff --git a/content/micropython/03.micropython/04.board-examples/giga-r1-wifi/assets/giga-r1.png b/content/micropython/04.board-examples/giga-r1-wifi/assets/giga-r1.png similarity index 100% rename from content/micropython/03.micropython/04.board-examples/giga-r1-wifi/assets/giga-r1.png rename to content/micropython/04.board-examples/giga-r1-wifi/assets/giga-r1.png diff --git a/content/micropython/03.micropython/04.board-examples/giga-r1-wifi/giga-r1-wifi.md b/content/micropython/04.board-examples/giga-r1-wifi/giga-r1-wifi.md similarity index 100% rename from content/micropython/03.micropython/04.board-examples/giga-r1-wifi/giga-r1-wifi.md rename to content/micropython/04.board-examples/giga-r1-wifi/giga-r1-wifi.md diff --git a/content/micropython/03.micropython/04.board-examples/nano-ble-sense/assets/ABX00031-pinout.png b/content/micropython/04.board-examples/nano-ble-sense/assets/ABX00031-pinout.png similarity index 100% rename from content/micropython/03.micropython/04.board-examples/nano-ble-sense/assets/ABX00031-pinout.png rename to content/micropython/04.board-examples/nano-ble-sense/assets/ABX00031-pinout.png diff --git a/content/micropython/03.micropython/04.board-examples/nano-ble-sense/assets/ble-sense.png b/content/micropython/04.board-examples/nano-ble-sense/assets/ble-sense.png similarity index 100% rename from content/micropython/03.micropython/04.board-examples/nano-ble-sense/assets/ble-sense.png rename to content/micropython/04.board-examples/nano-ble-sense/assets/ble-sense.png diff --git a/content/micropython/03.micropython/04.board-examples/nano-ble-sense/nano-ble-sense.md b/content/micropython/04.board-examples/nano-ble-sense/nano-ble-sense.md similarity index 100% rename from content/micropython/03.micropython/04.board-examples/nano-ble-sense/nano-ble-sense.md rename to content/micropython/04.board-examples/nano-ble-sense/nano-ble-sense.md diff --git a/content/micropython/03.micropython/04.board-examples/nano-esp32/assets/ABX00083-pinout.png b/content/micropython/04.board-examples/nano-esp32/assets/ABX00083-pinout.png similarity index 100% rename from content/micropython/03.micropython/04.board-examples/nano-esp32/assets/ABX00083-pinout.png rename to content/micropython/04.board-examples/nano-esp32/assets/ABX00083-pinout.png diff --git a/content/micropython/03.micropython/04.board-examples/nano-esp32/assets/esp32.png b/content/micropython/04.board-examples/nano-esp32/assets/esp32.png similarity index 100% rename from content/micropython/03.micropython/04.board-examples/nano-esp32/assets/esp32.png rename to content/micropython/04.board-examples/nano-esp32/assets/esp32.png diff --git a/content/micropython/03.micropython/04.board-examples/nano-esp32/nano-esp32.md b/content/micropython/04.board-examples/nano-esp32/nano-esp32.md similarity index 100% rename from content/micropython/03.micropython/04.board-examples/nano-esp32/nano-esp32.md rename to content/micropython/04.board-examples/nano-esp32/nano-esp32.md diff --git a/content/micropython/03.micropython/04.board-examples/nano-rp2040-connect/assets/ABX00053-pinout.png b/content/micropython/04.board-examples/nano-rp2040-connect/assets/ABX00053-pinout.png similarity index 100% rename from content/micropython/03.micropython/04.board-examples/nano-rp2040-connect/assets/ABX00053-pinout.png rename to content/micropython/04.board-examples/nano-rp2040-connect/assets/ABX00053-pinout.png diff --git a/content/micropython/03.micropython/04.board-examples/nano-rp2040-connect/assets/rp-2040.png b/content/micropython/04.board-examples/nano-rp2040-connect/assets/rp-2040.png similarity index 100% rename from content/micropython/03.micropython/04.board-examples/nano-rp2040-connect/assets/rp-2040.png rename to content/micropython/04.board-examples/nano-rp2040-connect/assets/rp-2040.png diff --git a/content/micropython/03.micropython/04.board-examples/nano-rp2040-connect/nano-rp2040-connect.md b/content/micropython/04.board-examples/nano-rp2040-connect/nano-rp2040-connect.md similarity index 100% rename from content/micropython/03.micropython/04.board-examples/nano-rp2040-connect/nano-rp2040-connect.md rename to content/micropython/04.board-examples/nano-rp2040-connect/nano-rp2040-connect.md diff --git a/content/micropython/03.micropython/modulinos/01.installation/assets/MicroPythonPackageInstallationDone.png b/content/micropython/05.modulinos/01.installation/assets/MicroPythonPackageInstallationDone.png similarity index 100% rename from content/micropython/03.micropython/modulinos/01.installation/assets/MicroPythonPackageInstallationDone.png rename to content/micropython/05.modulinos/01.installation/assets/MicroPythonPackageInstallationDone.png diff --git a/content/micropython/03.micropython/modulinos/01.installation/assets/microPythonInstaller.png b/content/micropython/05.modulinos/01.installation/assets/microPythonInstaller.png similarity index 100% rename from content/micropython/03.micropython/modulinos/01.installation/assets/microPythonInstaller.png rename to content/micropython/05.modulinos/01.installation/assets/microPythonInstaller.png diff --git a/content/micropython/03.micropython/modulinos/01.installation/assets/microPythonLabs.png b/content/micropython/05.modulinos/01.installation/assets/microPythonLabs.png similarity index 100% rename from content/micropython/03.micropython/modulinos/01.installation/assets/microPythonLabs.png rename to content/micropython/05.modulinos/01.installation/assets/microPythonLabs.png diff --git a/content/micropython/03.micropython/modulinos/01.installation/assets/microPythonLabsFiles.png b/content/micropython/05.modulinos/01.installation/assets/microPythonLabsFiles.png similarity index 100% rename from content/micropython/03.micropython/modulinos/01.installation/assets/microPythonLabsFiles.png rename to content/micropython/05.modulinos/01.installation/assets/microPythonLabsFiles.png diff --git a/content/micropython/03.micropython/modulinos/01.installation/assets/microPythonLabsSelectPort.png b/content/micropython/05.modulinos/01.installation/assets/microPythonLabsSelectPort.png similarity index 100% rename from content/micropython/03.micropython/modulinos/01.installation/assets/microPythonLabsSelectPort.png rename to content/micropython/05.modulinos/01.installation/assets/microPythonLabsSelectPort.png diff --git a/content/micropython/03.micropython/modulinos/01.installation/assets/package-installed.png b/content/micropython/05.modulinos/01.installation/assets/package-installed.png similarity index 100% rename from content/micropython/03.micropython/modulinos/01.installation/assets/package-installed.png rename to content/micropython/05.modulinos/01.installation/assets/package-installed.png diff --git a/content/micropython/03.micropython/modulinos/01.installation/installation.md b/content/micropython/05.modulinos/01.installation/installation.md similarity index 100% rename from content/micropython/03.micropython/modulinos/01.installation/installation.md rename to content/micropython/05.modulinos/01.installation/installation.md diff --git a/content/micropython/03.micropython/modulinos/02.modulino-distance/assets/CIRCUIT-BREAKOUT.png b/content/micropython/05.modulinos/02.modulino-distance/assets/CIRCUIT-BREAKOUT.png similarity index 100% rename from content/micropython/03.micropython/modulinos/02.modulino-distance/assets/CIRCUIT-BREAKOUT.png rename to content/micropython/05.modulinos/02.modulino-distance/assets/CIRCUIT-BREAKOUT.png diff --git a/content/micropython/03.micropython/modulinos/02.modulino-distance/assets/how-it-works.gif b/content/micropython/05.modulinos/02.modulino-distance/assets/how-it-works.gif similarity index 100% rename from content/micropython/03.micropython/modulinos/02.modulino-distance/assets/how-it-works.gif rename to content/micropython/05.modulinos/02.modulino-distance/assets/how-it-works.gif diff --git a/content/micropython/03.micropython/modulinos/02.modulino-distance/modulino-distance.md b/content/micropython/05.modulinos/02.modulino-distance/modulino-distance.md similarity index 100% rename from content/micropython/03.micropython/modulinos/02.modulino-distance/modulino-distance.md rename to content/micropython/05.modulinos/02.modulino-distance/modulino-distance.md diff --git a/content/micropython/03.micropython/modulinos/03.modulino-pixels/assets/CIRCUIT-BREAKOUT.png b/content/micropython/05.modulinos/03.modulino-pixels/assets/CIRCUIT-BREAKOUT.png similarity index 100% rename from content/micropython/03.micropython/modulinos/03.modulino-pixels/assets/CIRCUIT-BREAKOUT.png rename to content/micropython/05.modulinos/03.modulino-pixels/assets/CIRCUIT-BREAKOUT.png diff --git a/content/micropython/03.micropython/modulinos/03.modulino-pixels/assets/how-it-works.gif b/content/micropython/05.modulinos/03.modulino-pixels/assets/how-it-works.gif similarity index 100% rename from content/micropython/03.micropython/modulinos/03.modulino-pixels/assets/how-it-works.gif rename to content/micropython/05.modulinos/03.modulino-pixels/assets/how-it-works.gif diff --git a/content/micropython/03.micropython/modulinos/03.modulino-pixels/modulino-pixels.md b/content/micropython/05.modulinos/03.modulino-pixels/modulino-pixels.md similarity index 100% rename from content/micropython/03.micropython/modulinos/03.modulino-pixels/modulino-pixels.md rename to content/micropython/05.modulinos/03.modulino-pixels/modulino-pixels.md diff --git a/content/micropython/03.micropython/modulinos/04.modulino-buzzer/assets/CIRCUIT-BREAKOUT.png b/content/micropython/05.modulinos/04.modulino-buzzer/assets/CIRCUIT-BREAKOUT.png similarity index 100% rename from content/micropython/03.micropython/modulinos/04.modulino-buzzer/assets/CIRCUIT-BREAKOUT.png rename to content/micropython/05.modulinos/04.modulino-buzzer/assets/CIRCUIT-BREAKOUT.png diff --git a/content/micropython/03.micropython/modulinos/04.modulino-buzzer/assets/how-it-works.gif b/content/micropython/05.modulinos/04.modulino-buzzer/assets/how-it-works.gif similarity index 100% rename from content/micropython/03.micropython/modulinos/04.modulino-buzzer/assets/how-it-works.gif rename to content/micropython/05.modulinos/04.modulino-buzzer/assets/how-it-works.gif diff --git a/content/micropython/03.micropython/modulinos/04.modulino-buzzer/modulino-buzzer.md b/content/micropython/05.modulinos/04.modulino-buzzer/modulino-buzzer.md similarity index 100% rename from content/micropython/03.micropython/modulinos/04.modulino-buzzer/modulino-buzzer.md rename to content/micropython/05.modulinos/04.modulino-buzzer/modulino-buzzer.md diff --git a/content/micropython/03.micropython/modulinos/05.modulino-buttons/assets/CIRCUIT-BREAKOUT.png b/content/micropython/05.modulinos/05.modulino-buttons/assets/CIRCUIT-BREAKOUT.png similarity index 100% rename from content/micropython/03.micropython/modulinos/05.modulino-buttons/assets/CIRCUIT-BREAKOUT.png rename to content/micropython/05.modulinos/05.modulino-buttons/assets/CIRCUIT-BREAKOUT.png diff --git a/content/micropython/03.micropython/modulinos/05.modulino-buttons/assets/how-it-works.gif b/content/micropython/05.modulinos/05.modulino-buttons/assets/how-it-works.gif similarity index 100% rename from content/micropython/03.micropython/modulinos/05.modulino-buttons/assets/how-it-works.gif rename to content/micropython/05.modulinos/05.modulino-buttons/assets/how-it-works.gif diff --git a/content/micropython/03.micropython/modulinos/05.modulino-buttons/modulino-buttons.md b/content/micropython/05.modulinos/05.modulino-buttons/modulino-buttons.md similarity index 100% rename from content/micropython/03.micropython/modulinos/05.modulino-buttons/modulino-buttons.md rename to content/micropython/05.modulinos/05.modulino-buttons/modulino-buttons.md diff --git a/content/micropython/03.micropython/modulinos/06.modulino-knob/assets/CIRCUIT-BREAKOUT.png b/content/micropython/05.modulinos/06.modulino-knob/assets/CIRCUIT-BREAKOUT.png similarity index 100% rename from content/micropython/03.micropython/modulinos/06.modulino-knob/assets/CIRCUIT-BREAKOUT.png rename to content/micropython/05.modulinos/06.modulino-knob/assets/CIRCUIT-BREAKOUT.png diff --git a/content/micropython/03.micropython/modulinos/06.modulino-knob/assets/how-it-works.gif b/content/micropython/05.modulinos/06.modulino-knob/assets/how-it-works.gif similarity index 100% rename from content/micropython/03.micropython/modulinos/06.modulino-knob/assets/how-it-works.gif rename to content/micropython/05.modulinos/06.modulino-knob/assets/how-it-works.gif diff --git a/content/micropython/03.micropython/modulinos/06.modulino-knob/modulino-knob.md b/content/micropython/05.modulinos/06.modulino-knob/modulino-knob.md similarity index 100% rename from content/micropython/03.micropython/modulinos/06.modulino-knob/modulino-knob.md rename to content/micropython/05.modulinos/06.modulino-knob/modulino-knob.md diff --git a/content/micropython/03.micropython/modulinos/07.modulino-movement/assets/CIRCUIT-BREAKOUT.png b/content/micropython/05.modulinos/07.modulino-movement/assets/CIRCUIT-BREAKOUT.png similarity index 100% rename from content/micropython/03.micropython/modulinos/07.modulino-movement/assets/CIRCUIT-BREAKOUT.png rename to content/micropython/05.modulinos/07.modulino-movement/assets/CIRCUIT-BREAKOUT.png diff --git a/content/micropython/03.micropython/modulinos/07.modulino-movement/assets/how-it-works.gif b/content/micropython/05.modulinos/07.modulino-movement/assets/how-it-works.gif similarity index 100% rename from content/micropython/03.micropython/modulinos/07.modulino-movement/assets/how-it-works.gif rename to content/micropython/05.modulinos/07.modulino-movement/assets/how-it-works.gif diff --git a/content/micropython/03.micropython/modulinos/07.modulino-movement/modulino-movement.md b/content/micropython/05.modulinos/07.modulino-movement/modulino-movement.md similarity index 100% rename from content/micropython/03.micropython/modulinos/07.modulino-movement/modulino-movement.md rename to content/micropython/05.modulinos/07.modulino-movement/modulino-movement.md diff --git a/content/micropython/03.micropython/modulinos/08.modulino-thermo/assets/CIRCUIT-BREAKOUT.png b/content/micropython/05.modulinos/08.modulino-thermo/assets/CIRCUIT-BREAKOUT.png similarity index 100% rename from content/micropython/03.micropython/modulinos/08.modulino-thermo/assets/CIRCUIT-BREAKOUT.png rename to content/micropython/05.modulinos/08.modulino-thermo/assets/CIRCUIT-BREAKOUT.png diff --git a/content/micropython/03.micropython/modulinos/08.modulino-thermo/assets/how-it-works.gif b/content/micropython/05.modulinos/08.modulino-thermo/assets/how-it-works.gif similarity index 100% rename from content/micropython/03.micropython/modulinos/08.modulino-thermo/assets/how-it-works.gif rename to content/micropython/05.modulinos/08.modulino-thermo/assets/how-it-works.gif diff --git a/content/micropython/03.micropython/modulinos/08.modulino-thermo/modulino-thermo.md b/content/micropython/05.modulinos/08.modulino-thermo/modulino-thermo.md similarity index 100% rename from content/micropython/03.micropython/modulinos/08.modulino-thermo/modulino-thermo.md rename to content/micropython/05.modulinos/08.modulino-thermo/modulino-thermo.md diff --git a/content/micropython/05.modulinos/modulinos.md b/content/micropython/05.modulinos/modulinos.md new file mode 100644 index 0000000000..4ccf84e2e9 --- /dev/null +++ b/content/micropython/05.modulinos/modulinos.md @@ -0,0 +1,4 @@ +--- +title: Modulinos +description: Learn how to control and read Modulino nodes +--- \ No newline at end of file