Motor Controller for Pi

A single motor controller using Simon Monk's RasPiRobot board and Raspberry Pi GPIO. Takes inputs to control direction, start stop and speed control.

[{"id":"6aec091d.ed76c8","type":"subflow","name":"Motor Controller","info":"Expects different messages\nAn \"On\" message and a \"Direction\" message","in":[{"x":25,"y":219,"wires":[{"id":"871d4b31.00f708"}]}],"out":[{"x":1050,"y":91,"wires":[{"id":"97e20750.1efbf","port":0},{"id":"96055f4a.b1fd9","port":0}]},{"x":1053,"y":164,"wires":[{"id":"97e20750.1efbf","port":0},{"id":"da799e81.3ed658","port":0}]},{"x":289,"y":67,"wires":[{"id":"871d4b31.00f708","port":0}]}]},{"id":"871d4b31.00f708","type":"switch","z":"6aec091d.ed76c8","name":"Split Messages","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"Speed","vt":"str"},{"t":"eq","v":"On","vt":"str"},{"t":"eq","v":"Direction","vt":"str"}],"checkall":"true","outputs":3,"x":165,"y":228,"wires":[["cc87f193.036b6"],["97e20750.1efbf","b941b823.3d9ad"],["15a636c8.5f73c1"]]},{"id":"97e20750.1efbf","type":"switch","z":"6aec091d.ed76c8","name":"Off","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"}],"checkall":"true","outputs":1,"x":494,"y":199,"wires":[["3625a995.7a0e8e","55fc649e.c8a8b4"]]},{"id":"3625a995.7a0e8e","type":"debug","z":"6aec091d.ed76c8","name":"Motor 1","active":true,"console":"false","complete":"payload","x":1099,"y":31.5,"wires":[]},{"id":"55fc649e.c8a8b4","type":"debug","z":"6aec091d.ed76c8","name":"Motor 2","active":true,"console":"false","complete":"payload","x":1095,"y":226.5,"wires":[]},{"id":"b941b823.3d9ad","type":"switch","z":"6aec091d.ed76c8","name":"On","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","outputs":1,"x":493,"y":263,"wires":[["96055f4a.b1fd9"]]},{"id":"1e5b325d.7cf07e","type":"change","z":"6aec091d.ed76c8","name":"Set Direction Clockwise","rules":[{"t":"set","p":"direction","pt":"flow","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":477,"y":358,"wires":[["96055f4a.b1fd9"]]},{"id":"c36344b4.96c548","type":"change","z":"6aec091d.ed76c8","name":"Set Direction Counter Clockwise","rules":[{"t":"set","p":"direction","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":417,"wires":[["96055f4a.b1fd9"]]},{"id":"96055f4a.b1fd9","type":"function","z":"6aec091d.ed76c8","name":"Get Direction","func":"var direction = flow.get('direction')||0;\nmsg.payload = direction;\nreturn msg;","outputs":1,"noerr":0,"x":713,"y":300,"wires":[["3625a995.7a0e8e","da799e81.3ed658"]]},{"id":"da799e81.3ed658","type":"function","z":"6aec091d.ed76c8","name":"Invert","func":"if (msg.payload == 1) {\n    msg.payload = 0;\n}\nelse\n{\n    msg.payload = 1;\n}\nreturn msg;","outputs":1,"noerr":0,"x":901,"y":303,"wires":[["55fc649e.c8a8b4"]]},{"id":"15a636c8.5f73c1","type":"switch","z":"6aec091d.ed76c8","name":"Direction","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","outputs":2,"x":253,"y":398,"wires":[["1e5b325d.7cf07e"],["c36344b4.96c548"]]},{"id":"cc87f193.036b6","type":"debug","z":"6aec091d.ed76c8","name":"Motor Speed","active":true,"console":"false","complete":"payload","x":353,"y":127.5,"wires":[]},{"id":"2a008f7a.796788","type":"rpi-gpio out","z":"bd4a7a6d.d56f2","name":"Right Motor Speed (PWM)","pin":"8","set":"","level":"0","out":"pwm","x":688,"y":373,"wires":[]},{"id":"45a30507.0c6a64","type":"inject","z":"bd4a7a6d.d56f2","name":"Slow","topic":"Speed","payload":"20","payloadType":"num","repeat":"","crontab":"","once":false,"x":108,"y":125,"wires":[["dca3df5f.d0d69"]]},{"id":"7515a9ee.212e8","type":"inject","z":"bd4a7a6d.d56f2","name":"Fast","topic":"Speed","payload":"45","payloadType":"num","repeat":"","crontab":"","once":false,"x":107,"y":180,"wires":[["dca3df5f.d0d69"]]},{"id":"b3fc58cf.e6a048","type":"rpi-gpio out","z":"bd4a7a6d.d56f2","name":"Right Motor Pin 1","pin":"19","set":true,"level":"0","out":"out","x":663,"y":222,"wires":[]},{"id":"b6f0d163.d874e8","type":"inject","z":"bd4a7a6d.d56f2","name":"Go","topic":"On","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"x":123,"y":240.5,"wires":[["dca3df5f.d0d69"]]},{"id":"9a7eb779.95d718","type":"inject","z":"bd4a7a6d.d56f2","name":"Stop","topic":"On","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"x":123,"y":289,"wires":[["dca3df5f.d0d69"]]},{"id":"b31c03ea.399288","type":"rpi-gpio out","z":"bd4a7a6d.d56f2","name":"Right Motor Pin 2","pin":"22","set":true,"level":"0","out":"out","x":664,"y":306,"wires":[]},{"id":"d47e48ce.b9b658","type":"inject","z":"bd4a7a6d.d56f2","name":"Forward","topic":"Direction","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"x":138,"y":344.5,"wires":[["dca3df5f.d0d69"]]},{"id":"19ee9b27.81631d","type":"inject","z":"bd4a7a6d.d56f2","name":"Backwards","topic":"Direction","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"x":138,"y":393,"wires":[["dca3df5f.d0d69"]]},{"id":"dca3df5f.d0d69","type":"subflow:6aec091d.ed76c8","z":"bd4a7a6d.d56f2","x":410,"y":252.5,"wires":[["b3fc58cf.e6a048"],["b31c03ea.399288"],["2a008f7a.796788"]]}]

Flow Info

Created 8 years, 9 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x2)
  • debug (x3)
  • function (x2)
  • inject (x6)
  • switch (x4)
Other
  • rpi-gpio out (x3)
  • subflow (x1)
  • subflow:6aec091d.ed76c8 (x1)

Tags

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