Customer:
I’m having trouble understanding how to get data from the MQ137 sensor using the easyC system. I have some questions:
-
Do I need to do any setup to start getting data from the sensor, such as warming it up for a specific time programmatically?
-
How do I programmatically get the ppm from the sensor? Are there any examples?
Originally submitted via email support on 8 January 2024. Migrated to the forum for community visibility.
Soldered Support:
The sensor is connected to your Raspberry Pi board via easyC. An easyC library was written for Arduino but not Python. EasyC devices have a microcontroller on-board which handles reading the data and communicating back to the main board (in your case, a Raspberry Pi).
The Arduino library source code for working with MQ sensors is here: Soldered-MQ-Gas-Sensor-Arduino-Library/src/libs/MQUnifiedsensor/src/MQUnifiedsensor.cpp at main · SolderedElectronics/Soldered-MQ-Gas-Sensor-Arduino-Library · GitHub
You’ll see checks for if(native), which in this context means connecting the sensor directly to the Raspberry Pi. In your case it’s connected via I2C (easyC), so it’s not ‘native’.
To use the sensor with a Raspberry Pi, you’ll need to translate the Arduino code to Python. Here’s some code to help you get started: import smbusclass MQUnifiedsensor: def __init__(self, ...): # other ini - Pastebin.com
The ‘update’ function is the most important - it’s how you get the voltage from the sensor using easyC by requesting two bytes from 0x30 (the default I2C address of easyC devices). Once you have that working, you can implement the rest of the library with configurations, though you may only need the simplest functionality.