Pololu DRV8835 2ch PWM DC Motor Controller (Raspberry Pi)

Flow to allow control of a pair of DC motors connected to Pololu DRV8835 (https://www.pololu.com/product/2753) on Raspberry Pi via node-red-contrib-ui / node-red-dashboard

Requires wiring-pi to be installed as a node_module within node-red folder and added to global context via settings.js (see “wiring-pi module” section at http://nodered.org/docs/hardware/raspberrypi)

[
    {
        "id": "79ea8e00.7cd484",
        "type": "ui_slider",
        "z": "a7216b4a.a1fcd",
        "tab": "9cfc2f36.2694a8",
        "name": "Speed",
        "topic": "m1",
        "group": "Motor 1",
        "order": 1,
        "min": 0,
        "max": "480",
        "x": 810,
        "y": 260,
        "wires": [
            [
                "b481c365.4a42f",
                "3dc20b3e.fe5d14"
            ]
        ]
    },
    {
        "id": "f889fc69.10b538",
        "type": "ui_slider",
        "z": "a7216b4a.a1fcd",
        "tab": "9cfc2f36.2694a8",
        "name": "Speed",
        "topic": "m2",
        "group": "Motor 2",
        "order": 1,
        "min": 0,
        "max": "480",
        "x": 810,
        "y": 400,
        "wires": [
            [
                "a03df7dc.38827",
                "dde030f6.7ad65"
            ]
        ]
    },
    {
        "id": "647df633.d2cba",
        "type": "ui_switch",
        "z": "a7216b4a.a1fcd",
        "tab": "9cfc2f36.2694a8",
        "name": "Direction",
        "topic": "",
        "group": "Motor 1",
        "order": 1,
        "onvalue": "1",
        "offvalue": "0",
        "x": 280,
        "y": 300,
        "wires": [
            [
                "2edc04b.5fa487c"
            ]
        ]
    },
    {
        "id": "45b2b096.767608",
        "type": "ui_switch",
        "z": "a7216b4a.a1fcd",
        "tab": "9cfc2f36.2694a8",
        "name": "Direction",
        "topic": "",
        "group": "Motor 2",
        "order": 1,
        "onvalue": "1",
        "offvalue": "0",
        "x": 280,
        "y": 440,
        "wires": [
            [
                "ef9e9962.a8354"
            ]
        ]
    },
    {
        "id": "2edc04b.5fa487c",
        "type": "rpi-gpio out",
        "z": "a7216b4a.a1fcd",
        "name": "Motor 1 Direction",
        "pin": "29",
        "set": true,
        "level": "1",
        "out": "out",
        "x": 1090,
        "y": 300,
        "wires": []
    },
    {
        "id": "ef9e9962.a8354",
        "type": "rpi-gpio out",
        "z": "a7216b4a.a1fcd",
        "name": "Motor 2 Direction",
        "pin": "31",
        "set": true,
        "level": "1",
        "out": "out",
        "x": 1090,
        "y": 440,
        "wires": []
    },
    {
        "id": "c4ce2cdb.917fa",
        "type": "inject",
        "z": "a7216b4a.a1fcd",
        "name": "Init 1",
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "repeat": "",
        "crontab": "",
        "once": true,
        "x": 90,
        "y": 380,
        "wires": [
            [
                "45b2b096.767608",
                "647df633.d2cba",
                "fb5ed58c.1458d8",
                "f800ca94.eb7e"
            ]
        ]
    },
    {
        "id": "b481c365.4a42f",
        "type": "function",
        "z": "a7216b4a.a1fcd",
        "name": "Motor 1 Speed",
        "func": "var pin = 26;\nvar wpi = context.global.wpi;\nwpi.wiringPiSetup();\nwpi.pinMode(pin, wpi.PWM_OUTPUT);\nwpi.pwmSetMode(wpi.PWM_MODE_MS);\nwpi.pwmSetRange(480);\nwpi.pwmSetClock(2);\nif(msg.payload){\n    wpi.pwmWrite(pin, parseInt(msg.payload));\n} else {\n    wpi.pwmWrite(pin, 0);\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 1080,
        "y": 260,
        "wires": [
            []
        ]
    },
    {
        "id": "a03df7dc.38827",
        "type": "function",
        "z": "a7216b4a.a1fcd",
        "name": "Motor 2 Speed",
        "func": "var pin2 = 23;\nvar wpi = context.global.wpi;\nwpi.wiringPiSetup();\nwpi.pinMode(pin2, wpi.PWM_OUTPUT);\nwpi.pwmSetMode(wpi.PWM_MODE_MS);\nwpi.pwmSetRange(480);\nwpi.pwmSetClock(2);\nif(msg.payload){\n    wpi.pwmWrite(pin2, parseInt(msg.payload));\n} else {\n    wpi.pwmWrite(pin2, 0);\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 1080,
        "y": 400,
        "wires": [
            []
        ]
    },
    {
        "id": "dde030f6.7ad65",
        "type": "ui_chart",
        "z": "a7216b4a.a1fcd",
        "tab": "9cfc2f36.2694a8",
        "name": "Motor 2 (Y / Alt / DEC)",
        "group": "History",
        "order": 1,
        "interpolate": "basis",
        "nodata": "No Data",
        "removeOlder": 1,
        "removeOlderUnit": "60",
        "x": 1100,
        "y": 360,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "3dc20b3e.fe5d14",
        "type": "ui_chart",
        "z": "a7216b4a.a1fcd",
        "tab": "9cfc2f36.2694a8",
        "name": "Motor 1 (X / Az / RA)",
        "group": "History",
        "order": 1,
        "interpolate": "basis",
        "nodata": "No Data",
        "removeOlder": 1,
        "removeOlderUnit": "60",
        "x": 1100,
        "y": 220,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "9cfc2f36.2694a8",
        "type": "ui_tab",
        "z": "",
        "name": "Home",
        "icon": "dashboard",
        "order": "1"
    }
]
PatchworkBoy

Flow Info

created 11 months, 1 week ago

Node Types

Core
  • function (x2)
  • inject (x1)
  • rpi-gpio out (x2)
Other
  • ui_chart (x2)
  • ui_slider (x2)
  • ui_switch (x2)
  • ui_tab (x1)

Tags

  • pololu
  • motor
  • drv8835
  • raspberry
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option