-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add specific example for M5Stack ENVIII unit
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# | ||
# This example combines the SHTX and QMP6988 examples. The M5Stack ENV III unit | ||
# contains both sensors, accessible over a single I2C connection. | ||
# | ||
require 'bundler/setup' | ||
require 'denko' | ||
|
||
board = Denko::Board.new(Denko::Connection::Serial.new) | ||
bus = Denko::I2C::Bus.new(board: board, pin: :SDA) | ||
sht = Denko::Sensor::SHT3X.new(bus: bus) # address: 0x44 default | ||
qmp = Denko::Sensor::QMP6988.new(bus: bus) # address: 0x70 default | ||
|
||
# Configure for higher accuracy. | ||
sht.repeatability = :high | ||
qmp.temperature_samples = 2 | ||
qmp.pressure_samples = 16 | ||
qmp.iir_coefficient = 2 | ||
|
||
# Get the shared #print_tph_reading method to print readings neatly. | ||
require_relative 'neat_tph_readings' | ||
|
||
# How many degrees C the two temperature values can differ by before a warning. | ||
TOLERANCE = 0.50 | ||
|
||
loop do | ||
# Read both sensors. | ||
qmp_reading = qmp.read | ||
sht_reading = sht.read | ||
|
||
# Warn if large gap between temperature readings. | ||
difference = (qmp_reading[:temperature] - sht_reading[:temperature]).abs | ||
if (difference > TOLERANCE) | ||
puts "WARNING: temperature values differed by more than #{TOLERANCE}\xC2\xB0C (#{difference.round(4)} \xC2\xB0C actual)" | ||
end | ||
|
||
# Combine values from both sensors, averaging their temperatures. | ||
average_temperature = (qmp_reading[:temperature] + sht_reading[:temperature]) / 2.0 | ||
print_tph_reading(temperature: average_temperature, humidity: sht_reading[:humidity], pressure: qmp_reading[:pressure]) | ||
|
||
sleep 5 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters