How to use GY-521 MPU-6050 with Node-RED?

Hi,
I'm new in this forum. I use Node-Red v 1.3.4 and I'm trying to extract data from a MPU-6050 sensor. I don't know exactly how a I2C bus works, so I downloaded the package node-red-contrib-i2c but it seems doesn't work. This is the flow that I'm using.

[
    {
        "id": "e17abc1d.5dd908",
        "type": "tab",
        "label": "LB_MPU-6050_v01",
        "disabled": false,
        "info": ""
    },
    {
        "id": "c3fac518.cac9f8",
        "type": "inject",
        "z": "e17abc1d.5dd908",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 320,
        "y": 220,
        "wires": [
            [
                "450151ff.9292b"
            ]
        ]
    },
    {
        "id": "2b9c0dca.903ba2",
        "type": "debug",
        "z": "e17abc1d.5dd908",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 790,
        "y": 220,
        "wires": []
    },
    {
        "id": "450151ff.9292b",
        "type": "i2c in",
        "z": "e17abc1d.5dd908",
        "name": "",
        "busno": "1",
        "address": "104",
        "command": "59",
        "count": "14",
        "x": 470,
        "y": 220,
        "wires": [
            [
                "4b112863.d064d8"
            ]
        ]
    },
    {
        "id": "4b112863.d064d8",
        "type": "function",
        "z": "e17abc1d.5dd908",
        "name": "process i2c",
        "func": "var data = msg.payload;\nvar int16 = function(high, low) {\n  var result = (high << 8) | low;\n  // if highest bit is on, it is negative\n  return result >> 15 ? ((result ^ 0xFFFF) + 1) * -1 : result;\n};\n\n\nmsg.payload = {\n    accelerometer : {\n        x: int16(data[0], data[1]),\n        y: int16(data[2], data[3]),\n        z: int16(data[4], data[5])\n    },\n    temperature : int16(data[6], data[7]),\n    gyro : {\n        x: int16(data[8], data[9]),\n        y: int16(data[10], data[11]),\n        z: int16(data[12], data[13])\n    }\n};\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 630,
        "y": 220,
        "wires": [
            [
                "2b9c0dca.903ba2"
            ]
        ]
    }
]

Thanks for your support

Welcome to the forum!

This may help:
https://flows.nodered.org/flow/f8c7a94454f79d3cfdc5

Be aware that this is an old posting.

What hardware are you running node-red on? Also, that is a very old version, you might have more success if you can update to the current version.

Thanks, I'm using a Raspberry Pi Zero 2W. Now I'll try to update my Node Red.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.