Skip to content

Commit 76c49f0

Browse files
committed
Update nano-rp2040-connect.md
1 parent cf3a453 commit 76c49f0

File tree

1 file changed

+170
-1
lines changed

1 file changed

+170
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,173 @@
11
---
22
title: Nano RP2040 Connect
33
description: Learn how to use specific features on the Nano RP2040 Connect using MicroPython
4-
---
4+
---
5+
6+
![Nano RP2040 Connect]()
7+
8+
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.
9+
10+
For installation instructions, please visit the link below.
11+
- [Installing MicroPython]()
12+
13+
## Pinout
14+
15+
The pinout for the Nano RP2040 Connect can be found in the image below.
16+
17+
![Nano RP2040 Connect Pinout]()
18+
19+
***For more details on this product, visit the [hardware product page](/hardware/nano-rp2040-connect/).***
20+
21+
## Board Specific Features
22+
23+
The Nano RP2040 Connect has a number of board-specific features that can be accessed through MicroPython:
24+
25+
- **RGB LED** - a simple RGB pixel that can be controlled by setting `r`, `g` and `b` values.
26+
- **Microphone (MP34DT05)** - a microphone for recording audio samples.
27+
- **IMU (LSM6DSOX)** - for sampling gyroscope and accelerometer data.
28+
29+
### RGB LED
30+
31+
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:
32+
33+
```python
34+
# code example RGB
35+
```
36+
37+
### Microphone (MP34DT05)
38+
39+
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.
40+
41+
```python
42+
import image, audio, time
43+
from ulab import numpy as np
44+
from ulab import scipy as sp
45+
46+
CHANNELS = 1
47+
FREQUENCY = 32000
48+
N_SAMPLES = 32 if FREQUENCY == 16000 else 64
49+
SCALE = 2
50+
SIZE = (N_SAMPLES * SCALE) // CHANNELS
51+
52+
raw_buf = None
53+
fb = image.Image(SIZE+(50*SCALE), SIZE, image.RGB565, copy_to_fb=True)
54+
audio.init(channels=CHANNELS, frequency=FREQUENCY, gain_db=16)
55+
56+
def audio_callback(buf):
57+
# NOTE: do Not call any function that allocates memory.
58+
global raw_buf
59+
if (raw_buf == None):
60+
raw_buf = buf
61+
62+
# Start audio streaming
63+
audio.start_streaming(audio_callback)
64+
65+
def draw_fft(img, fft_buf):
66+
fft_buf = (fft_buf / max(fft_buf)) * SIZE
67+
fft_buf = np.log10(fft_buf + 1) * 20
68+
color = (0xFF, 0x0F, 0x00)
69+
for i in range(0, len(fft_buf)):
70+
img.draw_line(i*SCALE, SIZE, i*SCALE, SIZE-int(fft_buf[i]) * SCALE, color, SCALE)
71+
72+
def draw_audio_bar(img, level, offset):
73+
blk_size = (SIZE//10)
74+
color = (0xFF, 0x00, 0xF0)
75+
blk_space = (blk_size//4)
76+
for i in range(0, int(round(level/10))):
77+
fb.draw_rectangle(SIZE+offset, SIZE - ((i+1)*blk_size) + blk_space, 20 * SCALE, blk_size - blk_space, color, 1, True)
78+
79+
while (True):
80+
if (raw_buf != None):
81+
pcm_buf = np.frombuffer(raw_buf, dtype=np.int16)
82+
raw_buf = None
83+
84+
if CHANNELS == 1:
85+
fft_buf = sp.signal.spectrogram(pcm_buf)
86+
l_lvl = int((np.mean(abs(pcm_buf[1::2])) / 32768)*100)
87+
else:
88+
fft_buf = sp.signal.spectrogram(pcm_buf[0::2])
89+
l_lvl = int((np.mean(abs(pcm_buf[1::2])) / 32768)*100)
90+
r_lvl = int((np.mean(abs(pcm_buf[0::2])) / 32768)*100)
91+
92+
fb.clear()
93+
draw_fft(fb, fft_buf)
94+
draw_audio_bar(fb, l_lvl, 0)
95+
draw_audio_bar(fb, l_lvl, 25*SCALE)
96+
if CHANNELS == 2:
97+
draw_audio_bar(fb, r_lvl, 25 * SCALE)
98+
fb.flush()
99+
100+
# Stop streaming
101+
audio.stop_streaming()
102+
```
103+
104+
## IMU (LSM6DSOX)
105+
106+
The Nano RP2040 Connect has a built-in inertial measure unit (IMU). With the following script, you can retrieve the accelerometer and gyroscope data and print it in the REPL.
107+
108+
```python
109+
import time
110+
from lsm6dsox import LSM6DSOX
111+
from machine import Pin, I2C
112+
113+
# Initialize the LSM6DSOX sensor with I2C interface
114+
lsm = LSM6DSOX(I2C(0, scl=Pin(13), sda=Pin(12)))
115+
116+
while True:
117+
# Read accelerometer values
118+
accel_values = lsm.accel()
119+
print('Accelerometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*accel_values))
120+
121+
# Read gyroscope values
122+
gyro_values = lsm.gyro()
123+
print('Gyroscope: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*gyro_values))
124+
125+
print("")
126+
time.sleep_ms(100)
127+
```
128+
129+
## Communication
130+
131+
The Nano RP2040 Connect supports **I2C**, **UART** and **SPI**. Below you will find examples on how to use them.
132+
133+
### I2C
134+
135+
The I2C bus on the Nano RP2040 Connect is available through the **A4/A5** pins. Below is an example for how to use it:
136+
137+
```python
138+
139+
```
140+
141+
***Read more about I2C in [this article]().***
142+
143+
### UART
144+
145+
The Nano RP2040 Connect supports **UART** through the **D0/D1** pins. Below is an example for how to use it:
146+
147+
```python
148+
149+
```
150+
151+
***Read more about SPI in [this article]().***
152+
153+
### SPI
154+
155+
The Nano RP2040 Connect supports **SPI** through the following pins:
156+
- **(CIPO)** - D12
157+
- **(COPI)** - D11
158+
- **(SCK)** - D13
159+
- **(CS)** - Any GPIO (except for A6/A7)
160+
161+
Below is an example for how to use it:
162+
163+
```python
164+
165+
```
166+
167+
***Read more about UART in [this article]().***
168+
169+
## Wireless
170+
171+
The Nano RP2040 Connect has a radio module that supports Wi-Fi® and Bluetooth®. To find examples, please visit the links below:
172+
- [MicroPython - Bluetooth® documentation]()
173+
- [MicroPython - Wi-Fi® documentation]()

0 commit comments

Comments
 (0)