Using rotary encoder

So the GND Is conected to GND (pin 9)
The + is conected to 3.3V (Pin 1)
The DT is conected to GPIO17 (pin 11)
And the CLK Is conected to GPIO 18 (pin 12)

Do you have some software that allows you to determine the position, or some algorithm that has to be used to determine it? If it is designed for a pi it probably comes with some s/w.

No I dont have a software that allows that, and yes it comes with an SW but I didnt conect it to anything

I just connected the encoder to the pi, Im not using anything besides the pi, de encoder and of course the node red

This thread might help

1 Like

Just for as an exercise - I've come up with this flow - try connecting your DT/CLK signals to the two inputs and see if it give any sensible results at all.

Put CLK signal into top input

[{"id":"4cc4dd5a.e99f44","type":"switch","z":"dfaf687e.30fb88","name":"","property":"payload.DT","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":650,"y":360,"wires":[["a10eb221.01cba"],["b8eb77db.d1e298"]]}]

I don't have any encoders to check it with but it seems to work for slow moving test signals

1 Like

thank you, Ill try It when I have the time to

I found an encoder and it works - updated flow with Pi GPIO nodes added

[{"id":"403ca135.8773f","type":"debug","z":"dfaf687e.30fb88","name":"FINAL","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":990,"y":220,"wires":[]},{"id":"2ea6c228.7792fe","type":"join","z":"dfaf687e.30fb88","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":290,"y":320,"wires":[["c01e7353.5da95"]]},{"id":"384137a2.28f1d8","type":"change","z":"dfaf687e.30fb88","name":"","rules":[{"t":"set","p":"CLKedge","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"topic","pt":"msg","to":"CLK","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":220,"y":260,"wires":[["2ea6c228.7792fe","2b6b0070.b21a3"]]},{"id":"c01e7353.5da95","type":"switch","z":"dfaf687e.30fb88","name":"","property":"CLKedge","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":320,"wires":[["5a7e456.9ff69bc"]]},{"id":"4ef1f45d.febfec","type":"change","z":"dfaf687e.30fb88","name":"","rules":[{"t":"set","p":"CLKedge","pt":"msg","to":"false","tot":"bool"},{"t":"set","p":"topic","pt":"msg","to":"DT","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":380,"wires":[["2ea6c228.7792fe","c7fd0442.1b4e18"]]},{"id":"5a7e456.9ff69bc","type":"switch","z":"dfaf687e.30fb88","name":"","property":"payload.CLK","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":530,"y":320,"wires":[["c6969808.7e6a78"],["4cc4dd5a.e99f44"]]},{"id":"c6969808.7e6a78","type":"switch","z":"dfaf687e.30fb88","name":"","property":"payload.DT","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":650,"y":300,"wires":[["bdba459a.564768"],["dde61eeb.26b8f"]]},{"id":"4cc4dd5a.e99f44","type":"switch","z":"dfaf687e.30fb88","name":"","property":"payload.DT","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":650,"y":360,"wires":[["a10eb221.01cba"],["b8eb77db.d1e298"]]},{"id":"bdba459a.564768","type":"change","z":"dfaf687e.30fb88","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"clockwise","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":280,"wires":[["cc6d6356.1c6e9"]]},{"id":"dde61eeb.26b8f","type":"change","z":"dfaf687e.30fb88","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"anti-clockwise","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":320,"wires":[["cc6d6356.1c6e9"]]},{"id":"b8eb77db.d1e298","type":"change","z":"dfaf687e.30fb88","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"clockwise","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":400,"wires":[["cc6d6356.1c6e9"]]},{"id":"a10eb221.01cba","type":"change","z":"dfaf687e.30fb88","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"anti-clockwise","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":360,"wires":[["cc6d6356.1c6e9"]]},{"id":"2b6b0070.b21a3","type":"debug","z":"dfaf687e.30fb88","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":380,"y":260,"wires":[]},{"id":"c7fd0442.1b4e18","type":"debug","z":"dfaf687e.30fb88","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":400,"y":400,"wires":[]},{"id":"9d91be0c.c74c1","type":"rpi-gpio in","z":"dfaf687e.30fb88","name":"","pin":"8","intype":"tri","debounce":"0","read":true,"x":70,"y":260,"wires":[["384137a2.28f1d8"]]},{"id":"b58534f2.fb09e8","type":"rpi-gpio in","z":"dfaf687e.30fb88","name":"","pin":"10","intype":"tri","debounce":"0","read":true,"x":70,"y":380,"wires":[["4ef1f45d.febfec"]]},{"id":"bbd4af0c.aef2c","type":"debug","z":"dfaf687e.30fb88","name":"STATUS","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1020,"y":400,"wires":[]},{"id":"cc6d6356.1c6e9","type":"function","z":"dfaf687e.30fb88","name":"","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":975,"y":320,"wires":[["403ca135.8773f","bbd4af0c.aef2c"]],"l":false},{"id":"e5ecb697.26c048","type":"comment","z":"dfaf687e.30fb88","name":"CLK","info":"","x":190,"y":220,"wires":[]},{"id":"3cf589.899efa78","type":"comment","z":"dfaf687e.30fb88","name":"DT","info":"","x":190,"y":420,"wires":[]}]
1 Like

More compact version using a function node

[{"id":"2c40d42d.176cbc","type":"debug","z":"dfaf687e.30fb88","name":"STATUS_FUNCTION","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":680,"y":540,"wires":[]},{"id":"e2775f3d.af2bd","type":"change","z":"dfaf687e.30fb88","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"CLK","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":500,"wires":[["c4b142c4.477fe"]]},{"id":"27e7e692.0d532a","type":"change","z":"dfaf687e.30fb88","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"DT","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":580,"wires":[["c4b142c4.477fe"]]},{"id":"c4b142c4.477fe","type":"function","z":"dfaf687e.30fb88","name":"","func":"var CLK;\n\n\nif ((msg['topic']) == 'CLK') {\n  CLK = (msg['payload']);\n  if (context.keys().includes('DT')) {\n    if (CLK != (context.get('DT'))) {\n      msg['payload'] = 'clockwise';\n    } else {\n      msg['payload'] = 'anti-clockwise';\n    }\n    return msg;\n  }\n} else {\n  context.set('DT', (msg['payload']));\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":460,"y":540,"wires":[["2c40d42d.176cbc"]]},{"id":"1531b07b.ff934","type":"comment","z":"dfaf687e.30fb88","name":"CLK","info":"","x":270,"y":460,"wires":[]},{"id":"9aa49914.0e8cd8","type":"comment","z":"dfaf687e.30fb88","name":"DT","info":"","x":270,"y":620,"wires":[]},{"id":"a8fe264f.2d9368","type":"rpi-gpio in","z":"dfaf687e.30fb88","name":"","pin":"8","intype":"tri","debounce":"0","read":true,"x":90,"y":500,"wires":[["e2775f3d.af2bd"]]},{"id":"2a16462.f4e30ba","type":"rpi-gpio in","z":"dfaf687e.30fb88","name":"","pin":"10","intype":"tri","debounce":"0","read":true,"x":90,"y":580,"wires":[["27e7e692.0d532a"]]}]

If I apply that directly into the leds will It know the location? Or It's just going to turn every led on once a start rotating?

I was just supplying you with the info on how to read the encoder

I don't really understand what you want to do with the information

What exactly is your project about?

Using an encoder to be able to indicate the positions manually, whenever an input receives signal from the encoder, turn on the leds that represents the input. I want It to turn on my leds In order

You can't tell an absolute position with that sort of encoder. You would need to put it in a known position and then track the position from there. You have to track the sequence of inputs to know which direction it is turning and how much it has moved.

And how can I do that?

Actually, looking at the flow provided by @cymplecy it appears that it gives you a notification of each movement and in which direction it is. Have you got that bit going? That is the most complex bit, probably.
Then you would need to decide what you want to happen on the dashboard in order that you can tell node-red that it is at position zero. Then implement that using dashboard buttons or whatever you decide on.
Then to keep track of the actuall position feed the output from the given flow into some logic that keeps track of the current position.

1 Like

Thank you Colin, the only problem Is that Im new In node red and I don't really know how to control the encoder on the dashboard

Take one step at a time. Get the suggested flow working first.
If you are struggling with node red basics then have a look at the node red essentials guides on youtube.

Is it a educational assignment?

Something for work?

Home project?

Its for work, the leds indicate the state of a cnc, but I want to be able to indicate manualy ( thats why im using an encoder )

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