-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbme280.xlua
More file actions
37 lines (31 loc) · 1.35 KB
/
bme280.xlua
File metadata and controls
37 lines (31 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
-- BME280 documentation:
-- A basic example designed to test your BME280 wiring.
-- To run this code: https://realtimelogic.com/ba/ESP32/source/BME280.html
-- Wire up a BME280 via I2C:
-- https://learn.sparkfun.com/tutorials/sparkfun-bme280-breakout-hookup-guide/all
-- 1: Upload the bme280.lua module to the .lua directory i.e. to
-- http://esp32-ip/fs/.lua/ (ESP32 web-file-manager and WebDAV address)
-- 2: Create an app using Xedge and add this file to the app
-- 3: Set your I2C GPIO settings below
-- 4: Save and run
-- Check out the MQTT Sparkplug-Enabled Weather Station after testing
-- this example: http://bit.ly/3DwZYZY
local SDA_GPIO <const> = 21 -- the GPIO number; if you connect SDA to GPIO8, then set this to 8
local SCL_GPIO <const> = 22 -- the GPIO number; if you connect SCL to GPIO9, then set this to 9
local BME280_I2C_ADDR <const> = 0x76 -- Default BME280 I2C address
local settings={
tStandby=1,
filter=4,
pressOverSample=5,
humidOverSample=1,
tempOverSample=2
}
bme,err = require"bme280".create(0, BME280_I2C_ADDR, SDA_GPIO, SCL_GPIO, settings)
if bme then
local temperature, humidity, pressure = bme:read()
print(string.format("Temperature: %0.2f, Humidity: %0.2f, Pressure: %0.2f",
temperature,humidity,pressure/100))
bme:close()
else
print("Cannot create bme280 instance:", err)
end