MQ7 sensor with easyC: Python example and I2C interface documentation

Customer:

I bought the MQ7 sensor with easyC and want to use it with a Raspberry Pi. I can’t find example code snippets in Python. Are there any available? If not, where can I find documentation about the I2C interface of this module?

I also have some hardware questions:

  1. Does the module need to be powered with 5V, or is the 3.3V supply over the easyC connector enough?

  2. The board has jumpers for I2C pull-up resistors (JP1 5V I2C, JP2 3.3V I2C). Each jumper has three pins. Which pins should be connected to each other? (1-2, 2-3 or 1-2-3)

Originally submitted via email support on 5 February 2025. Migrated to the forum for community visibility.

Soldered Support:

There are currently only examples for Arduino. You can look at this Arduino sketch from the dev branch of the MQ library:

Note that this sketch includes an additional file which is also in the sketch folder on GitHub.

This is the firmware running on the on-board attiny chip. When data is requested via I2C, it performs an analogRead and packs it into a uint16_t to send over I2C, so it always sends 2 bytes. Here is how you can unpack the data.

Here is a link showing how the I2C data is requested by Arduino/Dasduino from the attiny:

You essentially just need a library for MQ sensors in Python and modify this part of the code. Since you aren’t measuring voltage directly but the attiny is doing that for you, you just need to ask for two bytes from it and then proceed to use them in the library.

Regarding your other questions:

The module has an on-board voltage regulator, so it can be connected via easyC to a 3.3V board or a 5V board and will work the same way. You do not need to change any jumper configuration for now - that’s only required if needed (for example, if you have many easyC modules connected to the same microcontroller, all the pull-ups could draw a lot of current). Let’s try getting a basic example working as a first step.