Skip to content

Commit

Permalink
Fix things up after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBell committed May 10, 2024
1 parent 19fa8a7 commit 6e0eb26
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 33 deletions.
34 changes: 9 additions & 25 deletions documentation/developer-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,6 @@ del reading["temperature"] # remove the temperature data
reading["custom"] = my_reading() # add my custom reading value
```

#### Custom data points (BME688 example)
Add simple built in module calls in main.py after the reading dictionary is populated and modify the reading dictionary as required

Add your code after the line:
```
reading = enviro.get_sensor_readings()
```

A simple BME688 module example:
```
reading = enviro.get_sensor_readings()
from breakout_bme68x import BreakoutBME68X
bme = BreakoutBME68X(enviro.i2c)
temperature, pressure, humidity, gas_resistance, status, gas_index, meas_index = bme.read()
reading["temperature2"] = temperature
```
Credit: @hfg-gmuend in [#178](https://github.com/pimoroni/enviro/issues/178)

The above code will overwrite the returned data if you use the same key name e.g. "temperature", ensure this is what you want to do, or otherwise pick a unique name for your new data point e.g. "temperature2"

#### Adding a QW/ST globally supported module
You can add one or more module boards connected over the QW/ST connector and provide a global configuration for collecting and returning the data to the readings alongside the enviro board specific items.

Expand Down Expand Up @@ -68,6 +47,8 @@ def add_missing_config_settings():
config.bme688_address = DEFAULT_BME688_ADDRESS
```

Alternatively, if the module can only use a single address, you can simply add the address to constants.py

Create a new python module in the enviro/qwst_modules/ directory that defines how your custom board should collect and return data to the reading dictionary. The readings must be performed in a function called get_readings that takes positional arguments i2c and address. The return of this function must be an OrderedDict{} and should contain key value pairs of reading names to values, with reading names that are likely to be unique to this board to ensure they do not overwrite other readings on upload.

Example:
Expand All @@ -78,7 +59,7 @@ from breakout_bme68x import BreakoutBME68X
from ucollections import OrderedDict
from phew import logging
def get_readings(i2c, address):
def get_readings(i2c, address, seconds_since_last):
bme688 = BreakoutBME68X(i2c)
bme688_data = bme688.read()
Expand All @@ -96,7 +77,7 @@ def get_readings(i2c, address):
return readings
```

Modify the function get_qwst_modules() in enviro/\_\_init\_\_.py to include an entry for your new board. This should use an if statement to check the address from the config file is visible on the I2C bus, reference your new module file path from the section above in the import statement and append a dictionary that has keys for "name", "include" and "address" to the modules list. The include key has a value of your imported module and the address is the I2C address from the config file.
Modify the function get_qwst_modules() in enviro/\_\_init\_\_.py to include an entry for your new board. This should use an if statement to check the address from the config file is visible on the I2C bus, reference your new module file path from the section above in the import statement and yield a dictionary that has keys for "name", "include" and "address" to the caller. The include key has a value of your imported module and the address is the I2C address from the config file.

Example:
```
Expand All @@ -105,8 +86,11 @@ def get_qwst_modules():
# <...existing module configurations...>
if config.bme688_address in i2c_devices:
import enviro.qwst_modules.bme688 as bme688
modules.append({"name": "BME688", "include": bme688, "address": config.bme688_address})
try:
import enviro.qwst_modules.bme688 as bme688
yield {"name": "BME688", "include": bme688, "address": config.bme688_address}
except RuntimeError:
pass
return modules
```
Expand Down
4 changes: 2 additions & 2 deletions enviro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_board():
def get_qwst_modules():
if I2C_ADDR_SCD41 in i2c_devices:
try:
import enviro.sensors.scd41 as scd41
import enviro.qwst_modules.scd41 as scd41
yield {"name": "SCD41", "include": scd41, "address": I2C_ADDR_SCD41}
except RuntimeError:
# Likely another device present on the SCD41 address
Expand Down Expand Up @@ -437,7 +437,7 @@ def get_sensor_readings():

return readings

def get_qwst_modules_readings():
def get_qwst_modules_readings(seconds_since_last):
module_readings = {}
for module in get_qwst_modules():
logging.info(f" - getting readings from module: {module['name']}")
Expand Down
2 changes: 1 addition & 1 deletion enviro/qwst_modules/bme688.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from ucollections import OrderedDict
from phew import logging

def get_readings(i2c, address):
def get_readings(i2c, address, seconds_since_last):
bme688 = BreakoutBME68X(i2c)
bme688_data = bme688.read()

Expand Down
8 changes: 3 additions & 5 deletions enviro/sensors/scd41.py → enviro/qwst_modules/scd41.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import breakout_scd41

from enviro import i2c
def get_readings(i2c, address, seconds_since_last):
breakout_scd41.init(i2c)
breakout_scd41.start()

breakout_scd41.init(i2c)
breakout_scd41.start()

def get_sensor_readings(seconds_since_last):
retries = 25
while retries > 0 and not breakout_scd41.ready():
time.sleep(0.2)
Expand Down

0 comments on commit 6e0eb26

Please sign in to comment.