In a previous guide I showed how to activate the 5V output and connect a fan Module to the CoreMP135. In this guide I will show you how to control the CoreMP135 using Python.
Installing Python on the CoreMP135The CoreMP135 should have Python install by default in the OS but may need updating. First run the following to update the Debian OS used on the CoreMP135.
apt-get update
followed by:
apt-get upgrade
or
apt-get dist-upgrade
Once finished you need to check the python version with:
python3 --version
or
python3 --V
REPLThe REPL is available in the Command line and not just the GUI version. To access the REPL Shell from the command line type:
python3
At the command prompt and python REPL will launch.
To exit out of REPL just press CTRL-D.
SHT30 Temperature and Humidity SensorReopen the REPL and type:
import smbus
REPL should throw up an error saying that sambas is not installed meaning we need to install it. CTRL-D out of REPL back to the command line and type:
sudo apt-get install python3-smbus
Please note that you must type python3 not python.Once installed, reopen REPL again and type the following to import the libraries needed to get the SHT30 part of the ENVIII unit running.
import smbus
import time
bus = smbus.SMBus(1)
bus.write_i2c_block_data(0x44, 0x2C, [0x06])
time.sleep(0.5)
data = bus.read_i2c_block_data(0x44, 0x00, 6)
cTemp = ((((data[0] * 256.0) + data[1]) * 175) / 65535.0) - 45
fTemp = cTemp * 1.8 + 32
humidity = 100 * (data[3] * 256 + data[4]) / 65535.0
print("Relative Humidity : %.2f %%RH" %humidity)
print("Temperature in Celsius : %.2f C" %cTemp)
print("Temperature in Freedom Heat : %.2f F" %fTemp)
This is a slightly modded version ryker1990's code found here: https://github.com/ControlEverythingCommunity/SHT30/tree/master
The results after the last three lines should look like the following screen grab.
Now that we have the temperature and humidity readings working, it time to move on to the QMP6988 pressor sensor in the ENVIII unit.
Unfortunately, just like with one of my other guides, Accessing the QMP6988 is proving to be a challenge and not going to be solved anytime soon.
If you dear reader have the solution to getting the QMP6988 working on the CoreMP135 then let me know and I can update this guide.
Contact Me.Due to Issues with code and researching functions, this part has taken a lot longer than the other parts. If you find this useful then there is more crossover guides coming. You can drop a Message in Hackster.io message box below of find me via the following links:
https://twitter.com/Cpt_J_Purcell
https://bsky.app/profile/jamespurcell.bsky.social
On Discord (if I ever work out how to share the profile!)https://mastodonapp.uk/@AdamBryant
And on the M5Stack Facebook group and community forum.
If you have some spare change you can now buy me a tea @ https://bmc.link/ajb2k35
Comments