www.joy
-
it.net
Pascalstr. 8 47506 Neukirchen
-
Vluyn
3. Code example
Now test your BMP280 with the following sample code.
First you create a file with :
sudo nano bmp280.py
An empty window will now open in which you can enter the following
sample code.
import
board
import
busio
import
adafruit_bmp280
# Create sensor as an object depending on I2C
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
# This value must be changed to the current air pressure at your location
# Otherwise inaccuracies will occur
# Weather services can give you information
# 1013.25 hPa is the average air pressure at the sea level
sensor.sea_level_pressure =
1013.25
# Output of the measured values
(
"\nTemperatur: %0.1f *C"
% sensor.temperature)
(
"Luftdruck: %0.1f hPa"
% sensor.pressure)
(
"Höhe: %0.2f m"
% sensor.altitude)
Save the code example with the key combination
CTRL + O
and confirm
with
Enter
. Exit the editor with
CTRL + X
.
You run this program with the following command:
sudo python3 bmp280.py
3. USAGE WITH THE ARDUINO
1. Connection
Arduino
KY052
5V
VCC, SDO, CSB
GND
GND
A4
SCL
A5
SDA