gbr1 / rp2040-encoder-library

Arduino quadrature encoder library based on RPI Pico pio example
GNU Lesser General Public License v3.0
19 stars 1 forks source link

Setting pins as GPIO inputs during begin #3

Closed lgbeno closed 6 days ago

lgbeno commented 1 month ago

Very helpful library, thank you for making it and sharing. One issue that I ran into is that the particular pins that I attached my encoder to were configured somewhere else as outputs. It may be a good idea to explicitly configure the GPIOs for encoder input as inputs in the begin function to avoid this confusion for others.

void PioEncoder::begin(){

    gpio_set_dir(pin, GPIO_IN);
    gpio_set_dir(pin+1, GPIO_IN);

    if (!not_first_instance){
        offset = pio_add_program(pio, &quadrature_encoder_program);
    }
    not_first_instance=true;
    if (sm==-1){
        sm = pio_claim_unused_sm(pio, true);
    }
    sm=sm;
    quadrature_encoder_program_init(pio,sm,offset,pin,max_step_rate);
}
gbr1 commented 1 month ago

@lgbeno thank you for your suggestion, can you make a PR?

gbr1 commented 6 days ago

@lgbeno fixed in https://github.com/gbr1/rp2040-encoder-library/releases/tag/0.2.0