diff --git a/content/micropython/03.micropython/04.board-examples/giga-r1-wifi/assets/ABX00063-pinout.png b/content/micropython/03.micropython/04.board-examples/giga-r1-wifi/assets/ABX00063-pinout.png new file mode 100644 index 0000000000..5fc3571cd4 Binary files /dev/null and b/content/micropython/03.micropython/04.board-examples/giga-r1-wifi/assets/ABX00063-pinout.png differ diff --git a/content/micropython/03.micropython/04.board-examples/giga-r1-wifi/assets/giga-r1.png b/content/micropython/03.micropython/04.board-examples/giga-r1-wifi/assets/giga-r1.png new file mode 100644 index 0000000000..4b0ac70349 Binary files /dev/null and b/content/micropython/03.micropython/04.board-examples/giga-r1-wifi/assets/giga-r1.png differ diff --git a/content/micropython/03.micropython/04.board-examples/giga-r1-wifi/giga-r1-wifi.md b/content/micropython/03.micropython/04.board-examples/giga-r1-wifi/giga-r1-wifi.md index 22772682b3..35e94cf7f7 100644 --- a/content/micropython/03.micropython/04.board-examples/giga-r1-wifi/giga-r1-wifi.md +++ b/content/micropython/03.micropython/04.board-examples/giga-r1-wifi/giga-r1-wifi.md @@ -2,7 +2,7 @@ title: GIGA R1 WiFi description: Learn how to use specific features on the GIGA R1 WiFi using MicroPython --- -![GIGA R1 WiFi](./assets/giga-r1-wifi.png) +![GIGA R1 WiFi](./assets/giga-r1.png) In this guide, you will find information specific to the [GIGA R1 WiFi board](https://store.arduino.cc/products/giga-r1-wifi), such as supported serial protocols, built-in peripherals, and how to access the wireless features. @@ -13,7 +13,7 @@ For installation instructions, please visit the link below: The pinout for the GIGA R1 WiFi can be found in the image below. -![GIGA R1 WiFi Pinout](./assets/giga-r1-wifi-pinout.png) +![GIGA R1 WiFi Pinout](./assets/ABX00063-pinout.png) ***For more details on this product, visit the [hardware product page](/hardware/giga-r1-wifi/).*** @@ -36,7 +36,7 @@ The GIGA R1 WiFi features a Murata 1DX module that provides both **Wi-Fi®** and -### Dual-Core Programming +## Dual-Core Programming The GIGA R1 WiFi supports dual-core programming, where the Cortex-M7 and Cortex-M4 cores can execute separate tasks simultaneously. Below is an example of how to run MicroPython on one core while offloading specific tasks to the other: @@ -64,7 +64,7 @@ main_task() -### RGB LED +## RGB LED The GIGA R1 WiFi has a built-in RGB LED that can be easily controlled to turn on each color individually. The following example shows how to cycle through red, green, and blue, waiting a second between each, and then turning off all colors before looping back. @@ -101,7 +101,7 @@ while True: ``` -### PWM on the GIGA R1 WiFi +## PWM on the GIGA R1 WiFi On STM32 boards like the Arduino GIGA R1 WiFi, PWM is handled differently than on typical MicroPython boards. Instead of directly using the `PWM` class, you need to use the `Timer` class in combination with the `Pin` class from the `pyb` module. @@ -136,7 +136,7 @@ ch.pulse_width_percent(25) # 25% duty cycle `ch.pulse_width_percent(25)` sets the duty cycle of the PWM signal to 25%. You can adjust this value between `0` and `100` to control the signal's ON time. -### Using the RPC Library with MicroPython +## RPC The **msgpackrpc** library provides the same functionality as the Arduino RPC library for MicroPython, allowing seamless communication between the two cores (M7 and M4) on the GIGA R1 WiFi. This library enables binding of local functions or objects, starting the M4 core, and invoking remote calls from Python scripts. @@ -153,7 +153,6 @@ While powerful, the **msgpackrpc** library has some limitations: 3. **Flash-based firmware** must use a 1.5MB M7 + 0.5MB M4 flash partitioning scheme. - #### Example Here’s how to bind a function on the M7 core and call it from the M4 core: @@ -191,9 +190,6 @@ print(result) # Outputs: Hello from M7! For a detailed explanation of the RPC library, including advanced use cases and configuration, visit the [RPC Library with MicroPython guide](https://docs.arduino.cc/tutorials/giga-r1-wifi/giga-dual-core/#using-the-rpc-library-with-micropython). - -!Needs testing for CANBUS! - ## Additional Features The GIGA R1 WiFi includes other features that can be explored: diff --git a/content/micropython/03.micropython/04.board-examples/nano-ble-sense/assets/ABX00031-pinout.png b/content/micropython/03.micropython/04.board-examples/nano-ble-sense/assets/ABX00031-pinout.png new file mode 100644 index 0000000000..1e4a42f20e Binary files /dev/null and b/content/micropython/03.micropython/04.board-examples/nano-ble-sense/assets/ABX00031-pinout.png differ diff --git a/content/micropython/03.micropython/04.board-examples/nano-ble-sense/assets/ble-sense.png b/content/micropython/03.micropython/04.board-examples/nano-ble-sense/assets/ble-sense.png new file mode 100644 index 0000000000..6771ea143a Binary files /dev/null and b/content/micropython/03.micropython/04.board-examples/nano-ble-sense/assets/ble-sense.png differ diff --git a/content/micropython/03.micropython/04.board-examples/nano-ble-sense/nano-ble-sense.md b/content/micropython/03.micropython/04.board-examples/nano-ble-sense/nano-ble-sense.md index a9b652628e..0df1a3fbc0 100644 --- a/content/micropython/03.micropython/04.board-examples/nano-ble-sense/nano-ble-sense.md +++ b/content/micropython/03.micropython/04.board-examples/nano-ble-sense/nano-ble-sense.md @@ -1,4 +1,339 @@ --- title: Nano BLE Sense description: Learn how to use specific features on the Nano BLE Sense using MicroPython ---- \ No newline at end of file +author: Karl Söderby +--- + +![Nano BLE Sense](assets/ble-sense.png) + +In this guide, you will find information specific to the [Nano BLE Sense board](), such as supported serial protocols and built-in sensors that can be accessed. + +For installation instructions, please visit the link below. +- [Installing MicroPython]() + +## Pinout + +The pinout for the Nano BLE Sense can be found in the image below. + +![Nano BLE Sense Pinout](assets/ABX00031-pinout.png) + +***For more details on this product, visit the [hardware product page](/hardware/nano-rp2040-connect/).*** + +## Board Specific Features + +The Nano BLE Sense has a number of board-specific features that can be accessed through MicroPython: + +- **Built-in LED** - a small single pixel LED on the board. +- **RGB LED** - a simple RGB pixel that can be controlled by setting `r`, `g` and `b` values. +- **Microphone (MP34DT05)** - a microphone for recording audio samples. +- **Gesture Sensor (APDS9960)** - measure ambient light and proximity. +- **Pressure Sensor (LPS22)** - measure air pressure for weather applications. +- **Temperature and Humidity (HTS221 & HS3003)** - record temperature and relative humidity. +- **IMU (LSM9DS1, BMI270 + BMM150)** - read gyroscope and accelerometer data. + +***Note that there are multiple revisions of the Nano BLE Sense (Rev1 and Rev2), where different sensors are used.*** + +## RGB LED + +To use the RGB pixel, we can control it by using the `1`, `2` and `3` pins. Below is an example that will blink the main colors in sequence: + +```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) + +``` + +## 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() +``` + +## Communication + +The Nano BLE Sense supports **I2C**, **UART** and **SPI**. Below you will find examples on how to use them. + +### I2C + +The I2C bus on the Nano BLE Sense is available through the **A4/A5** pins. Below is an example for how to use it: + +```python +from machine import Pin, I2C + +# Initialize I2C with SCL on A5 and SDA on A4 +i2c = I2C(0, scl=Pin(5), sda=Pin(4)) +devices = i2c.scan() + +print("I2C devices found:", devices) +``` + +***Read more about I2C in [this article]().*** + +### UART + +The Nano BLE Sense supports **UART** through the **D0/D1** pins. Below is an example for how to use it: + +```python +from machine import UART + +# Initialize UART on pins 16 (TX) and 17 (RX) +uart = UART(1, baudrate=9600, tx=16, rx=17) + +# Send and receive data +uart.write("Hello from Nano BLE Sense!") +data = uart.read() +print("Received:", data) +``` + +***Read more about SPI in [this article]().*** + +### SPI + +The Nano BLE Sense supports **SPI** through the following pins: +- **(CIPO)** - D12 +- **(COPI)** - D11 +- **(SCK)** - D13 +- **(CS)** - Any GPIO (except for A6/A7) + +Below is an example for how to use it: + +```python +from machine import Pin, SPI + +# Initialize SPI with SCK on pin 18, MOSI on pin 23, and MISO on pin 19 +spi = SPI(1, baudrate=1000000, polarity=0, phase=0, sck=Pin(18), mosi=Pin(23), miso=Pin(19)) + +print("SPI initialized") +``` + +***Read more about UART in [this article]().*** \ No newline at end of file diff --git a/content/micropython/03.micropython/04.board-examples/nano-esp32/assets/ABX00083-pinout.png b/content/micropython/03.micropython/04.board-examples/nano-esp32/assets/ABX00083-pinout.png new file mode 100644 index 0000000000..255dfaa818 Binary files /dev/null and b/content/micropython/03.micropython/04.board-examples/nano-esp32/assets/ABX00083-pinout.png differ diff --git a/content/micropython/03.micropython/04.board-examples/nano-esp32/assets/esp32.png b/content/micropython/03.micropython/04.board-examples/nano-esp32/assets/esp32.png new file mode 100644 index 0000000000..eafe5ff42a Binary files /dev/null and b/content/micropython/03.micropython/04.board-examples/nano-esp32/assets/esp32.png differ diff --git a/content/micropython/03.micropython/04.board-examples/nano-esp32/nano-esp32.md b/content/micropython/03.micropython/04.board-examples/nano-esp32/nano-esp32.md index c1f7a1c39e..6ce3701015 100644 --- a/content/micropython/03.micropython/04.board-examples/nano-esp32/nano-esp32.md +++ b/content/micropython/03.micropython/04.board-examples/nano-esp32/nano-esp32.md @@ -1,9 +1,10 @@ --- title: Nano ESP32 -description: Learn how to use specific features on the Nano ESP32 using MicroPython +description: Learn how to use specific features on the Nano ESP32 using MicroPython +author: Pedro Lima --- -![Nano ESP32](./assets/nano-esp32.png) +![Nano ESP32](./assets/esp32.png) In this guide, you will find information specific to the [Nano ESP32 board](https://store.arduino.cc/products/nano-esp32), such as supported serial protocols, built-in sensors, and how to access the wireless features. @@ -14,7 +15,7 @@ For installation instructions, please visit the link below: The pinout for the Nano ESP32 can be found in the image below. -![Nano ESP32 Pinout](./assets/nano-esp32-pinout.png) +![Nano ESP32 Pinout](./assets/ABX00083-pinout.png) ***For more details on this product, visit the [hardware product page](/hardware/nano-esp32/).*** diff --git a/content/micropython/03.micropython/04.board-examples/nano-rp2040-connect/assets/ABX00053-pinout.png b/content/micropython/03.micropython/04.board-examples/nano-rp2040-connect/assets/ABX00053-pinout.png new file mode 100644 index 0000000000..e9f998cb1e Binary files /dev/null and b/content/micropython/03.micropython/04.board-examples/nano-rp2040-connect/assets/ABX00053-pinout.png differ diff --git a/content/micropython/03.micropython/04.board-examples/nano-rp2040-connect/assets/rp-2040.png b/content/micropython/03.micropython/04.board-examples/nano-rp2040-connect/assets/rp-2040.png new file mode 100644 index 0000000000..e20ea6dde1 Binary files /dev/null and b/content/micropython/03.micropython/04.board-examples/nano-rp2040-connect/assets/rp-2040.png differ diff --git a/content/micropython/03.micropython/04.board-examples/nano-rp2040-connect/nano-rp2040-connect.md b/content/micropython/03.micropython/04.board-examples/nano-rp2040-connect/nano-rp2040-connect.md index 42f5e8108d..ccf0cae18a 100644 --- a/content/micropython/03.micropython/04.board-examples/nano-rp2040-connect/nano-rp2040-connect.md +++ b/content/micropython/03.micropython/04.board-examples/nano-rp2040-connect/nano-rp2040-connect.md @@ -1,9 +1,10 @@ --- title: Nano RP2040 Connect description: Learn how to use specific features on the Nano RP2040 Connect using MicroPython +author: Karl Söderby --- -![Nano RP2040 Connect]() +![Nano RP2040 Connect](assets/rp-2040.png) In this guide, you will find information specific to the [Nano RP2040 Connect board](), such as supported serial protocols and built-in sensors that can be accessed. @@ -14,7 +15,7 @@ For installation instructions, please visit the link below. The pinout for the Nano RP2040 Connect can be found in the image below. -![Nano RP2040 Connect Pinout]() +![Nano RP2040 Connect Pinout](assets/ABX00053-pinout.png) ***For more details on this product, visit the [hardware product page](/hardware/nano-rp2040-connect/).*** @@ -28,15 +29,38 @@ The Nano RP2040 Connect has a number of board-specific features that can be acce ### RGB LED -To use the RGB pixel, we can control it by using the `X`, `Y` and `Z` pins. Below is an example that will blink the main colors in sequence: +To use the RGB pixel, we can control it by using the `1`, `2` and `3` pins. Below is an example that will blink the main colors in sequence: ```python -# code example RGB +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) ``` ### Microphone (MP34DT05) -The Nano RP2040 Connect has a built-in microphone, that can be used through the OpenMV editor. To use it, you will need to install [OpenMV]() and run the following script. +The Nano RP2040 Connect has a built-in microphone, that can be used through the OpenMV editor. To use it, you will need to install [OpenMV](https://openmv.io/pages/download) and run the following script. ```python import image, audio, time @@ -135,7 +159,13 @@ The Nano RP2040 Connect supports **I2C**, **UART** and **SPI**. Below you will f The I2C bus on the Nano RP2040 Connect is available through the **A4/A5** pins. Below is an example for how to use it: ```python +from machine import Pin, I2C +# Initialize I2C with SCL on A5 and SDA on A4 +i2c = I2C(0, scl=Pin(5), sda=Pin(4)) +devices = i2c.scan() + +print("I2C devices found:", devices) ``` ***Read more about I2C in [this article]().*** @@ -145,7 +175,15 @@ The I2C bus on the Nano RP2040 Connect is available through the **A4/A5** pins. The Nano RP2040 Connect supports **UART** through the **D0/D1** pins. Below is an example for how to use it: ```python +from machine import UART + +# Initialize UART on pins 16 (TX) and 17 (RX) +uart = UART(1, baudrate=9600, tx=16, rx=17) +# Send and receive data +uart.write("Hello from Nano ESP32!") +data = uart.read() +print("Received:", data) ``` ***Read more about SPI in [this article]().*** @@ -161,13 +199,12 @@ The Nano RP2040 Connect supports **SPI** through the following pins: Below is an example for how to use it: ```python +from machine import Pin, SPI -``` +# Initialize SPI with SCK on pin 18, MOSI on pin 23, and MISO on pin 19 +spi = SPI(1, baudrate=1000000, polarity=0, phase=0, sck=Pin(18), mosi=Pin(23), miso=Pin(19)) -***Read more about UART in [this article]().*** - -## Wireless +print("SPI initialized") +``` -The Nano RP2040 Connect has a radio module that supports Wi-Fi® and Bluetooth®. To find examples, please visit the links below: -- [MicroPython - Bluetooth® documentation]() -- [MicroPython - Wi-Fi® documentation]() \ No newline at end of file +***Read more about UART in [this article]().*** \ No newline at end of file