Skip to content

Commit 85e5a9d

Browse files
committed
add pinout and fix article
1 parent fa82087 commit 85e5a9d

File tree

2 files changed

+322
-1
lines changed

2 files changed

+322
-1
lines changed
257 KB
Loading
Lines changed: 322 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,325 @@
11
---
22
title: Nano BLE Sense
33
description: Learn how to use specific features on the Nano BLE Sense using MicroPython
4-
---
4+
---
5+
6+
![Nano BLE Sense]()
7+
8+
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.
9+
10+
For installation instructions, please visit the link below.
11+
- [Installing MicroPython]()
12+
13+
## Pinout
14+
15+
The pinout for the Nano BLE Sense can be found in the image below.
16+
17+
![Nano BLE Sense Pinout](assets/ABX00031-pinout.png)
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 BLE Sense has a number of board-specific features that can be accessed through MicroPython:
24+
25+
- **Built-in LED** - a small single pixel LED on the board.
26+
- **RGB LED** - a simple RGB pixel that can be controlled by setting `r`, `g` and `b` values.
27+
- **Microphone (MP34DT05)** - a microphone for recording audio samples.
28+
- **Gesture Sensor (APDS9960)** - measure ambient light and proximity.
29+
- **Pressure Sensor (LPS22)** - measure air pressure for weather applications.
30+
- **Temperature and Humidity (HTS221 & HS3003)** - record temperature and relative humidity.
31+
- **IMU (LSM9DS1, BMI270 + BMM150)** - read gyroscope and accelerometer data.
32+
33+
***Note that there are multiple revisions of the Nano BLE Sense (Rev1 and Rev2), where different sensors are used.***
34+
35+
## RGB LED
36+
37+
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:
38+
39+
```python
40+
from board import LED
41+
import time
42+
43+
led_red = LED(1)
44+
led_green = LED(2)
45+
led_blue = LED(3)
46+
47+
while (True):
48+
49+
# Turn on LEDs
50+
led_red.on()
51+
led_green.on()
52+
led_blue.on()
53+
54+
# Wait 0.25 seconds
55+
time.sleep_ms(250)
56+
57+
# Turn off LEDs
58+
led_red.off()
59+
led_green.off()
60+
led_blue.off()
61+
62+
# Wait 0.25 seconds
63+
time.sleep_ms(250)
64+
```
65+
66+
## Built-in LED
67+
68+
The classic blink example! Blink the built-in LED every 0.25 seconds.
69+
70+
```python
71+
from board import LED
72+
import time
73+
74+
led_builtin = LED(4)
75+
76+
while (True):
77+
78+
# Turn on LED
79+
led_builtin.on()
80+
81+
# Wait 0.25 seconds
82+
time.sleep_ms(250)
83+
84+
# Turn off LED
85+
led_builtin.off()
86+
87+
# Wait 0.25 seconds
88+
time.sleep_ms(250)
89+
90+
```
91+
92+
## IMU (LSM9DS1, BMI270 + BMM150)
93+
94+
Access the `accelerometer`, `magnetometer`, and `gyroscope` data from the IMU module.
95+
96+
```python
97+
import time
98+
import imu
99+
from machine import Pin, I2C
100+
101+
bus = I2C(1, scl=Pin(15), sda=Pin(14))
102+
imu = imu.IMU(bus)
103+
104+
while (True):
105+
print('Accelerometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.accel()))
106+
print('Gyroscope: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.gyro()))
107+
print('Magnetometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.magnet()))
108+
print("")
109+
time.sleep_ms(100)
110+
```
111+
112+
## Temperature & Humidity (HTS221)
113+
114+
Access the `temperature` & `humidity` values from the HTS221 sensor (Nano 33 BLE Sense).
115+
116+
```python
117+
import time
118+
import hts221
119+
from machine import Pin, I2C
120+
121+
bus = I2C(1, scl=Pin(15), sda=Pin(14))
122+
hts = hts221.HTS221(bus)
123+
124+
while (True):
125+
rH = hts.humidity()
126+
temp = hts.temperature()
127+
print ("rH: %.2f%% T: %.2fC" %(rH, temp))
128+
time.sleep_ms(100)
129+
```
130+
131+
## Temperature & Humidity (HS3003)
132+
133+
Access the `temperature` & `humidity` values from the HTS221 sensor (Nano 33 BLE Sense Rev2).
134+
135+
```python
136+
import time
137+
from hs3003 import HS3003
138+
from machine import Pin, I2C
139+
140+
bus = I2C(1, scl=Pin(15), sda=Pin(14))
141+
hts = HS3003(bus)
142+
143+
while True:
144+
rH = hts.humidity()
145+
temp = hts.temperature()
146+
print ("rH: %.2f%% T: %.2fC" %(rH, temp))
147+
time.sleep_ms(100)
148+
```
149+
150+
## Pressure (LPS22)
151+
152+
Access the `pressure` values from the LPS22 sensor.
153+
154+
```python
155+
import time
156+
import lps22h
157+
from machine import Pin, I2C
158+
159+
bus = I2C(1, scl=Pin(15), sda=Pin(14))
160+
lps = lps22h.LPS22H(bus)
161+
162+
while (True):
163+
pressure = lps.pressure()
164+
temperature = lps.temperature()
165+
print("Pressure: %.2f hPa Temperature: %.2f C"%(pressure, temperature))
166+
time.sleep_ms(100)
167+
```
168+
169+
## Ambient Light (APDS9960)
170+
171+
Access the `Ambient Light` values from the APDS9960 sensor.
172+
173+
```python
174+
from time import sleep_ms
175+
from machine import Pin, I2C
176+
from apds9960.const import *
177+
from apds9960 import uAPDS9960 as APDS9960
178+
179+
bus = I2C(1, sda=Pin(13), scl=Pin(14))
180+
apds = APDS9960(bus)
181+
182+
print("Light Sensor Test")
183+
print("=================")
184+
apds.enableLightSensor()
185+
186+
while True:
187+
sleep_ms(250)
188+
val = apds.readAmbientLight()
189+
print("AmbientLight={}".format(val))
190+
```
191+
192+
## Proximity (APDS9960)
193+
194+
Access the `Proximity values` from the APDS9960 sensor.
195+
196+
```python
197+
from time import sleep_ms
198+
from machine import Pin, I2C
199+
200+
from apds9960.const import *
201+
from apds9960 import uAPDS9960 as APDS9960
202+
203+
bus = I2C(1, sda=Pin(13), scl=Pin(14))
204+
apds = APDS9960(bus)
205+
206+
apds.setProximityIntLowThreshold(50)
207+
208+
print("Proximity Sensor Test")
209+
print("=====================")
210+
apds.enableProximitySensor()
211+
212+
while True:
213+
sleep_ms(250)
214+
val = apds.readProximity()
215+
print("proximity={}".format(val))
216+
```
217+
218+
## Microphone (MP34DT05)
219+
220+
Below example can be used with OpenMV's frame buffer window (top right corner).
221+
222+
```python
223+
import image, audio, time
224+
from ulab import numpy as np
225+
from ulab import scipy as sp
226+
227+
CHANNELS = 1
228+
SIZE = 256//(2*CHANNELS)
229+
230+
raw_buf = None
231+
fb = image.Image(SIZE+50, SIZE, image.RGB565, copy_to_fb=True)
232+
audio.init(channels=CHANNELS, frequency=16000, gain_db=80, highpass=0.9883)
233+
234+
def audio_callback(buf):
235+
# NOTE: do Not call any function that allocates memory.
236+
global raw_buf
237+
if (raw_buf == None):
238+
raw_buf = buf
239+
240+
# Start audio streaming
241+
audio.start_streaming(audio_callback)
242+
243+
def draw_fft(img, fft_buf):
244+
fft_buf = (fft_buf / max(fft_buf)) * SIZE
245+
fft_buf = np.log10(fft_buf + 1) * 20
246+
color = (0xFF, 0x0F, 0x00)
247+
for i in range(0, SIZE):
248+
img.draw_line(i, SIZE, i, SIZE-int(fft_buf[i]), color, 1)
249+
250+
def draw_audio_bar(img, level, offset):
251+
blk_size = SIZE//10
252+
color = (0xFF, 0x00, 0xF0)
253+
blk_space = (blk_size//4)
254+
for i in range(0, int(round(level/10))):
255+
fb.draw_rectangle(SIZE+offset, SIZE - ((i+1)*blk_size) + blk_space, 20, blk_size - blk_space, color, 1, True)
256+
257+
while (True):
258+
if (raw_buf != None):
259+
pcm_buf = np.frombuffer(raw_buf, dtype=np.int16)
260+
raw_buf = None
261+
262+
if CHANNELS == 1:
263+
fft_buf = sp.signal.spectrogram(pcm_buf)
264+
l_lvl = int((np.mean(abs(pcm_buf[1::2])) / 32768)*100)
265+
else:
266+
fft_buf = sp.signal.spectrogram(pcm_buf[0::2])
267+
l_lvl = int((np.mean(abs(pcm_buf[1::2])) / 32768)*100)
268+
r_lvl = int((np.mean(abs(pcm_buf[0::2])) / 32768)*100)
269+
270+
fb.clear()
271+
draw_fft(fb, fft_buf)
272+
draw_audio_bar(fb, l_lvl, 0)
273+
if CHANNELS == 2:
274+
draw_audio_bar(fb, r_lvl, 25)
275+
fb.flush()
276+
277+
# Stop streaming
278+
audio.stop_streaming()
279+
```
280+
281+
## Communication
282+
283+
The Nano BLE Sense supports **I2C**, **UART** and **SPI**. Below you will find examples on how to use them.
284+
285+
### I2C
286+
287+
The I2C bus on the Nano BLE Sense is available through the **A4/A5** pins. Below is an example for how to use it:
288+
289+
```python
290+
291+
```
292+
293+
***Read more about I2C in [this article]().***
294+
295+
### UART
296+
297+
The Nano BLE Sense supports **UART** through the **D0/D1** pins. Below is an example for how to use it:
298+
299+
```python
300+
301+
```
302+
303+
***Read more about SPI in [this article]().***
304+
305+
### SPI
306+
307+
The Nano BLE Sense supports **SPI** through the following pins:
308+
- **(CIPO)** - D12
309+
- **(COPI)** - D11
310+
- **(SCK)** - D13
311+
- **(CS)** - Any GPIO (except for A6/A7)
312+
313+
Below is an example for how to use it:
314+
315+
```python
316+
317+
```
318+
319+
***Read more about UART in [this article]().***
320+
321+
## Wireless
322+
323+
The Nano BLE Sense has a radio module that supports Wi-Fi® and Bluetooth®. To find examples, please visit the links below:
324+
- [MicroPython - Bluetooth® documentation]()
325+
- [MicroPython - Wi-Fi® documentation]()

0 commit comments

Comments
 (0)