From e6f03d01c49f3ad890c8358745325b416ece3eba Mon Sep 17 00:00:00 2001 From: Hannes Siebeneicher Date: Fri, 14 Jun 2024 10:43:10 +0200 Subject: [PATCH] Update MicroPython examples --- .../06.board-examples/board-examples.md | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/content/micropython/01.basics/06.board-examples/board-examples.md b/content/micropython/01.basics/06.board-examples/board-examples.md index 6000d8efd9..16535998d2 100644 --- a/content/micropython/01.basics/06.board-examples/board-examples.md +++ b/content/micropython/01.basics/06.board-examples/board-examples.md @@ -72,13 +72,20 @@ 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): - print('Accelerometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*lsm.read_accel())) - print('Gyroscope: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*lsm.read_gyro())) +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) ``` @@ -791,7 +798,7 @@ while (True): #### Temperature & Humidity (HTS221) -Access the `temperature` & `humidity` values from the HTS221 sensor. +Access the `temperature` & `humidity` values from the HTS221 sensor (Nano 33 BLE Sense). ```python import time @@ -808,6 +815,25 @@ while (True): 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.