Skip to content

Commit

Permalink
Fixes and notes for QMP6988 sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
vickash committed Oct 8, 2023
1 parent 89ede47 commit a8ef1c7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
6 changes: 5 additions & 1 deletion examples/advanced/m5_env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
qmp.pressure_samples = 16
qmp.iir_coefficient = 2

# Buggy on ESP32-S3 in forced mode. Data registers return zeroes on all but first read.
# Can't recreate on ESP32 V1, AVR or SAMD21. Put it in contiuous mode just in case.
qmp.continuous_mode

# Get the shared #print_tph_reading method to print readings neatly.
require_relative 'neat_tph_readings'
require_relative '../sensor/neat_tph_readings'

# How many degrees C the two temperature values can differ by before a warning.
TOLERANCE = 0.50
Expand Down
6 changes: 5 additions & 1 deletion examples/sensor/qmp6988.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@
sensor.pressure_samples = 16
sensor.iir_coefficient = 2

#
# Change mode (default: forced_mode)
#
# Buggy on ESP32S3 in forced mode. Data registers return zeroes on all but first read.
# Can't recreate on ESP32 V1, AVR or SAMD21. Put it in contiuous mode just in case.
sensor.continuous_mode
# sensor.forced_mode
# sensor.continuous_mode

#
# Set standby time (between measurements) for continuous mode only:
Expand Down
15 changes: 8 additions & 7 deletions lib/denko/sensor/qmp6988.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ def reset
sleep UPDATE_TIME
end

def get_config_registers
i2c_read(IIR_REGISTER, 5)
sleep 0.001 while !@registers
@registers
end

def iir_coefficient=(coeff)
raise ArgumentError, "invalid IIR coefficient: #{coeff}" unless IIR_COEFFICIENTS.keys.include? coeff
i2c_write [IIR_REGISTER, IIR_COEFFICIENTS[coeff]]
Expand Down Expand Up @@ -160,7 +154,7 @@ def forced_mode
end

def continuous_mode
@ctrl_meas_register = (@ctrl_meas_register & 0b11111100) | NORMAL_MDOE
@ctrl_meas_register = (@ctrl_meas_register & 0b11111100) | NORMAL_MODE
i2c_write [CTRL_MEAS_REGISTER, @ctrl_meas_register]
@forced_mode = false
sleep UPDATE_TIME
Expand Down Expand Up @@ -233,6 +227,13 @@ def update_state(reading)
end
end

def get_config_registers
@registers = {}
i2c_read(IIR_REGISTER, CONFIG_LENGTH)
sleep 0.001 while @registers.empty?
@registers
end

def process_config(bytes)
@registers = { f1: bytes[0], f2: bytes[1], f3: bytes[2], f4: bytes[3], f5: bytes[4] }
end
Expand Down

0 comments on commit a8ef1c7

Please sign in to comment.