BME680 and i2c communication

Hey,
Have anyone managed to connect bme680 or similar i2c sensor in Nodered using i2c contrib node?
Can you share the sample flow? I read the sensor datasheet, but looks like my knowledge is limited.
I know the i2c adress and sensor is working in python, so wiring is good. I tried various numbers for command and bytes, but the values recieved are not good. Maybe I need to send specific command first, before sensor returns data?
I also tried to use exec node, to run the python code directly, but I get IO errors like I2c communication is not working, which is strange as sensor works normally in python.

Looking for advice from more expirienced user

2019-09-13%20163622

Connecting the sensor using I2C should be relatively easy if you have the datasheet. The problem after you do connect is that you need to do a LOT of maths to get results as the sensor delivers raw data only. It might be easier to grab the results of the python script with an exec node (once you get it working). If you do decide to do the maths yourself you do have the results of the python script to check your results. The datasheet has all the algorithms:

I know my coding knowledge, so the only solution is to use the exec node.
This is the command I use in exec node and the error I get :
python3 /home/pi/Pimoroni/bme680/examples/read-all.py


If I run the code from the terminal directly, I get the correct values from the sensor

EDIT: I mean, I could calculate the values using the algoritms too, but usign exec node seems better for my case.

Any ideas how to make it work?
Thansk for your time!

Can you post your flow?

Sure, many thanks for help!
I found the flow on the web, as I didnt use the exec node before.

[
    {
        "id": "ddf1664c.ea95a8",
        "type": "tab",
        "label": "MQTT Humdity Flow",
        "disabled": false,
        "info": ""
    },
    {
        "id": "a938202d.205da8",
        "type": "exec",
        "z": "ddf1664c.ea95a8",
        "command": "python3 /home/pi/Pimoroni/bme680/examples/read-all.py",
        "addpay": false,
        "append": "",
        "useSpawn": "false",
        "timer": "",
        "oldrc": false,
        "name": "Sensor Script",
        "x": 323.0000305175781,
        "y": 87.99999237060547,
        "wires": [
            [
                "22433620.cb3822",
                "3c24d2a7.a12a86"
            ],
            [],
            []
        ]
    },
    {
        "id": "d4fe4f85.abf38",
        "type": "inject",
        "z": "ddf1664c.ea95a8",
        "name": "Repeater",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": "",
        "x": 91.5,
        "y": 94.99999237060547,
        "wires": [
            [
                "a938202d.205da8",
                "2a2501dd.4dc7de"
            ]
        ]
    },
    {
        "id": "22433620.cb3822",
        "type": "function",
        "z": "ddf1664c.ea95a8",
        "name": "test",
        "func": "var hum = {payload: {humidity: msg.payload}};\nreturn hum;",
        "outputs": 1,
        "noerr": 0,
        "x": 512,
        "y": 87.99999237060547,
        "wires": [
            [
                "66851d0b.05ae74"
            ]
        ]
    },
    {
        "id": "66851d0b.05ae74",
        "type": "json",
        "z": "ddf1664c.ea95a8",
        "name": "JSON Parser",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 689,
        "y": 85.99999237060547,
        "wires": [
            []
        ]
    },
    {
        "id": "3c24d2a7.a12a86",
        "type": "debug",
        "z": "ddf1664c.ea95a8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 490.6166076660156,
        "y": 158.95001220703125,
        "wires": []
    },
    {
        "id": "2a2501dd.4dc7de",
        "type": "debug",
        "z": "ddf1664c.ea95a8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 400.8500061035156,
        "y": 233.85000610351562,
        "wires": []
    }
]

This is why most of use use external microprocessors to do things like this. For example, there are several BME680 libraries for the Arduino IDE so it would be trivial to wire up a cheap Arduino Nano clone or, perhaps better still, use an ESP8266 which lets you put the sensor anywhere as long as you have WiFi (and there are now ways around that as well).

As these things only cost a couple of US Dollars a piece from your favourite Chinese Amazon clone, it adds very little to the project cost but saves you a lot of time and effort.

1 Like

@TotallyInformation's advice is indeed what most people, myself included, do.

In the exec node try putting just python3 in the command line and the path to the script as an append.

As per the info panel you may need to add -u to python to not buffer any output

Thanks for advice, I have some d1 minis lying around so it shouldnt be a problem
I actually went for direct direct Pi connection, so I dont need to power another module.

I have tried all suggestions, but still got the same error in node red.

Just as a wild stab - try changing the node to use python instead of python3

For future reference, that might work now, but if that’s actually the difference it should be filed as an issue to the creator/manufacturer for support. Python 2 has just over 3 months left before reaching End Of Life. In my (personal) opinion, it is not wise to write (new) code that depends on it now. Better to migrate everything to py3 directly, for future support and being able to keep your sensor readings/flow future proof, running on top of supported software.

With some care, you may be able to power it from the Pi if your Pi power supply is good enough and you don't have much connected to the D1m.

Thats true, and I already have T cobbler connected on a breadboard, so distributing power to vin, shouldnt be a problem.
I tried using this code to run the sensor, but I dont recive any debug info, although i deleted the // from the debug part of code: https://github.com/wtremmel/MQTTClient
AlsoI havent got succes with flashing tasmota, with Arduino IDE or Platformio..

Have you done a basic blink sketch?

Personally I would stick with the Arduino IDE since that has the most support and examples. It is also the simplest to use.

I tried changing the command for the exec node and come to the point, I dont get any error messeges, just 0 as a result.
Im not sure if this is step forward, as I expected straightfoward sensor values as a result.
Any ideas?

That won't work! The command should be python3 -u and the append should be the full path to the script.

1 Like

Thanks for help everyone!
I got it working by using the github link I posted above, d1 mini and mqtt to get values in node red.
Also like adviced, I used the 3v3 rail from Raspberry to power d1.
Its working great!

3 Likes

The read-all.py that comes with the BME680 library points to address 0x76 but I found that my adafruit and most other boards are addressed to 0x77. Change the address in your script and try again.

1 Like

Do you realize you just replied to a two year old thread? It’s good information you provided, but I’m going to close this thread.