Simple test
Ensure your device works with this simple test.
examples/bmp3xx_simpletest.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import time
5
6import board
7
8import adafruit_bmp3xx
9
10# I2C setup
11i2c = board.I2C() # uses board.SCL and board.SDA
12# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
13bmp = adafruit_bmp3xx.BMP3XX_I2C(i2c)
14
15# SPI setup
16# from digitalio import DigitalInOut, Direction
17# spi = board.SPI()
18# cs = DigitalInOut(board.D5)
19# bmp = adafruit_bmp3xx.BMP3XX_SPI(spi, cs)
20
21bmp.pressure_oversampling = 8
22bmp.temperature_oversampling = 2
23
24while True:
25 print(f"Pressure: {bmp.pressure:6.4f} Temperature: {bmp.temperature:5.2f}")
26 time.sleep(1)
DisplayIO Simpletest
This is a simple test for boards with built-in display.
examples/bmp3xx_displayio_simpletest.py
1# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
2# SPDX-FileCopyrightText: 2024 Jose D. Montoya
3#
4# SPDX-License-Identifier: MIT
5
6# Simple demo of the BMP3XX pressure sensor using a built-in display.
7import time
8
9import board
10from adafruit_display_text.bitmap_label import Label
11from displayio import Group
12from terminalio import FONT
13
14import adafruit_bmp3xx
15
16# create a main_group to hold anything we want to show on the display.
17main_group = Group()
18# Initialize I2C bus and sensor.
19i2c = board.I2C() # uses board.SCL and board.SDA
20bmp = adafruit_bmp3xx.BMP3XX_I2C(i2c)
21
22bmp.pressure_oversampling = 8
23bmp.temperature_oversampling = 2
24
25# Create a Label to show the readings. If you have a very small
26# display you may need to change to scale=1.
27display_output_label = Label(FONT, text="", scale=2)
28
29# place the label in the middle of the screen with anchored positioning
30display_output_label.anchor_point = (0, 0)
31display_output_label.anchored_position = (4, board.DISPLAY.height // 2)
32
33# add the label to the main_group
34main_group.append(display_output_label)
35
36# set the main_group as the root_group of the built-in DISPLAY
37board.DISPLAY.root_group = main_group
38
39# begin main loop
40while True:
41 # Update the label.text property to change the text on the display
42 display_output_label.text = (
43 f"Pressure: {bmp.pressure:6.4f} Temperature: {bmp.temperature:5.2f}"
44 )
45 # wait for a bit
46 time.sleep(1)