jamon / pi-pico-pio-quadrature-encoder

Raspberry Pi Pico PIO Quadrature Encoder
Other
56 stars 12 forks source link

Not working with arduino-pico? #4

Open myreauks opened 1 year ago

myreauks commented 1 year ago

Hi!

I am trying to get the quadrature.pio.h working with arduino-pico on RP2040. Everything compiles fine but for some reason the program is not registering any changes in the encoder. I have checked that the hardware is fine by testing it with Circuitpython code and I successfully read the values changing while rotating the encoder.

Here is my code:

#include "hardware/pio.h"
#include "quadrature.pio.h"

#define QUADRATURE_A_PIN 27
#define QUADRATURE_B_PIN 28

PIO pio = pio0;
uint offset, sm;

void setup() {
  Serial.begin();
  offset = pio_add_program(pio, &quadrature_program);
  sm = pio_claim_unused_sm(pio, true);
  quadrature_program_init(pio, sm, offset, QUADRATURE_A_PIN, QUADRATURE_B_PIN);
}

void loop() {
  pio_sm_exec_wait_blocking(pio, sm, pio_encode_in(pio_x, 32));
  uint encoder_value = pio_sm_get_blocking(pio, sm);
  Serial.println(encoder_value);
  delay(200);
}

Would you happen to know why this might be? Best, Miro

ardlc-1212 commented 1 year ago

Can you:

  1. Check whether if your pico is able to read the encoder with basic digital read commands?
  2. Send your Serial Monitor output to us
myreauks commented 1 year ago

Hi, I have a program now running with the quadruture.pio.h succesfully with other GPIO. However, I never managed to get GPIO 26-28 working for reading a rotary encoder. I wonder if it has something to do with them also functioning as analog inputs?

As I am writing this, it just occurred to me that the reason I never got them to work is that I should use the AGND pin with them instead of the other GND pins?

ardlc-1212 commented 1 year ago

All of the GND pins should be connected to ground net on our board, and ideally to a low impedance ground plane to minimise noise and EMC emissions. There is an AGND pin on Raspberry Pi Pico and Raspberry Pi Pico W, which is intended to be used as a low noise ADC return path. As we are not using the ADC in this application, we simply connect this to regular GND.

From the system design guide. So no it shouldnt be a problem

My guess is it was a cold solder joint that caused it, or something along those lines