Rotary with Espruino Pico

Posted on
  • Hey guys,
    I've purchased a Pico and this Rotary https://shop.pimoroni.com/products/rotar­y-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.

  • 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/

  • This may help:
    https://www.espruino.com/Pico+Buttons
    Using the button and LED on the Pico

    clearWatch(); // 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__glo­bal_pinMode

    pinMode(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

  • 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-qOFGz­MJqfYSmxUY3ZzbjRvZVU/view?usp=sharing

  • So does that work ?

  • 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:)

  • 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.

  • Have a look at the drawing. A and B are the encoder outputs and C the Vcc of the encoder (use it with the espruino encoder module). Pins 1 - 5 are for the three led's (1|2|4), the button (3) and Vcc (5).

  • 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?

  • Rotary → Pico
    A → A1
    B → A2
    C → 3.3v

    It 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,functio­n (direction) {
          step += direction;
          print(step);
    });
    
  • 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.

  • @luwar, thanks a million just what I needed. And for the button to work, is that "3" ... if so, where does this go on the Pico?

  • 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 });
    
  • This is SOOO awesome, thanks @ClearMemory041063 and @luwar for your help!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Rotary with Espruino Pico

Posted by Avatar for user71789 @user71789

Actions