-
• #2
The pimoroni link you cited points to this tutorial for Arduino. Looks like it uses ground and two digital input pins.
http://bildr.org/2012/08/rotary-encoder-arduino/
If needed you can examine the encoder module code that is located here.
http://www.espruino.com/modules/ -
• #3
This may help:
https://www.espruino.com/Pico+Buttons
Using the button and LED on the PicoclearWatch(); // remove our last watch setWatch(function(e) { digitalWrite(LED1, e.state); presses++; console.log("Pressed "+presses); }, BTN, { repeat: true, debounce : 50 });
Now using Pin B4 instead of the button, connect one of the encoder output to pin B4 and the other common wire to ground.
Use pinMode(B4,input_pullup)
http://www.espruino.com/Reference#l__global_pinModepinMode(B4,input_pullup); setWatch(function() { digitalPulse(LED2, 1, 50); }, B4, { repeat: true, debounce : 50, edge: "rising" }
See if the LED blinks as you turn the shaft encoder
-
• #4
Hi ClearMemory041063
Thanks a lot for all your help, I really appreciate you spending time on this. I've tried to connect the two components in a diagram:https://drive.google.com/file/d/0B-qOFGzMJqfYSmxUY3ZzbjRvZVU/view?usp=sharing
-
• #5
So does that work ?
-
• #6
ClearMemory041063 I dont know, this was just how I read your suggestion, does it look right? I haven't got my breadboard yet, so before I go solder anything, I would like to know if it's right:)
-
• #7
Now you have me a bit worried. The oriental specifications for this device are sketchy at best.
It seems to contain 3 switches, 3 resistors and have 8 pins.
Connecting both ground and 3.3V from the Pico to this device without a proper diagram runs the risk of shorting 3.3 to ground and popping the fuse on the Pico, A Bad thing :(
If you have an ohmmeter that would provide a way to probe the device safely and figure out how it is wired. Short of that connect ground only and not the 3.3V. use the pin setup with pull up. The code that reads a Pico pin to light the LED can then be used as a test probe to puzzle out a proper wiring sequence. -
• #9
Hi Spocki, thank you, this looks right. I dont need the LEDs, only the rotate and button functionality. Do you know how I connect it to the Pico?
-
• #10
Rotary → Pico
A → A1
B → A2
C → 3.3vIt is possible that you have to swap A1 and A2. It depends on the detents of the encoder. Then use the sample code of the encoder module:
var step = 0; require("Encoder").connect(A1,A2,function (direction) { step += direction; print(step); });
-
• #11
It was stupid from me to use A1 and A2 in the code above. It is hard to wire on the pico. Just use some other pins like B3 and B4.
-
• #13
When using the switch you need pin 5 of the rotary too.
Rotary → Pico
5 → 3.3V
3 → B5 (or any other input pin)As @ClearMemory041063 mentioned above it is easy to watch a pin:
// some untested code pinMode(B5, "input_pulldown"); setWatch( function( event ) { console.log( event.state ? "Button released" : "Button pressed") }, B5, { repeat: true, debounce: 50 });
-
• #14
This is SOOO awesome, thanks @ClearMemory041063 and @luwar for your help!
Hey guys,
I've purchased a Pico and this Rotary https://shop.pimoroni.com/products/rotary-encoder-illuminated-rgb and would like to solder this to my Pico. I'm new to this and trying to create a prototype, so hopefully, you can help me. Which arms on the rotary goes to where on the Pico? I found this https://www.espruino.com/Encoder Looks like they need to connect to A1, A2 and 3.3v.