Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quad encoder, 5752 setEncoderPosition() does not work #25

Closed
JeremyLaurenson opened this issue Feb 27, 2024 · 2 comments
Closed

Quad encoder, 5752 setEncoderPosition() does not work #25

JeremyLaurenson opened this issue Feb 27, 2024 · 2 comments

Comments

@JeremyLaurenson
Copy link

JeremyLaurenson commented Feb 27, 2024

This issue has been brought up before on the single encoders, and marked as completed here: #20

The current shipping (Feb 2024) 5752 encoders setEncoderPosition() does not work.

  • Arduino board: Adafruit I2C Quad Rotary Encoder Breakout with NeoPixel - STEMMA QT / Qwiic

  • Arduino IDE version (found in Arduino -> About Arduino menu): 2.3.2

Run this simple code to reproduce:


 // set start positions
delay(1000);
for (int i = 0; i < 4; i++) {
ss.setEncoderPosition(50, i);
}
delay(1000);
for (int i = 0; i < 4; i++) {
Serial.println(ss.getEncoderPosition(i));
}
}

This should print four "50"s

/*
 * This is a demo for a QT Py RP2040 connected to a quad rotary encoder breakout
 * using the onboard Stemma QT Port
 * https://www.adafruit.com/product/4900
 * https://www.adafruit.com/product/5752
 * 
 */
#include "Adafruit_seesaw.h"
#include <seesaw_neopixel.h>

#define SS_NEO_PIN       18
#define SS_ENC0_SWITCH   12
#define SS_ENC1_SWITCH   14
#define SS_ENC2_SWITCH   17
#define SS_ENC3_SWITCH   9

#define SEESAW_ADDR      0x49

Adafruit_seesaw ss = Adafruit_seesaw(&Wire);
seesaw_NeoPixel pixels = seesaw_NeoPixel(4, SS_NEO_PIN, NEO_GRB + NEO_KHZ800);

int32_t enc_positions[4] = {0, 0, 0, 0};

void setup() {
  Serial.begin(115200);
  while (!Serial) delay(10);

  Serial.println("Looking for seesaw!");
  
  if (! ss.begin(SEESAW_ADDR) || !pixels.begin(SEESAW_ADDR)) {
    Serial.println("Couldn't find seesaw on default address");
    while(1) delay(10);
  }
  Serial.println("seesaw started");
  uint32_t version = ((ss.getVersion() >> 16) & 0xFFFF);
  if (version  != 5752){
    Serial.print("Wrong firmware loaded? ");
    Serial.println(version);
    while(1) delay(10);
  }
  Serial.println("Found Product 5752");

  ss.pinMode(SS_ENC0_SWITCH, INPUT_PULLUP);
  ss.pinMode(SS_ENC1_SWITCH, INPUT_PULLUP);
  ss.pinMode(SS_ENC2_SWITCH, INPUT_PULLUP);
  ss.pinMode(SS_ENC3_SWITCH, INPUT_PULLUP);
  ss.setGPIOInterrupts(1UL << SS_ENC0_SWITCH | 1UL << SS_ENC1_SWITCH | 
                       1UL << SS_ENC2_SWITCH | 1UL << SS_ENC3_SWITCH, 1);

  // get starting positions
  for (int e=0; e<4; e++) {
    enc_positions[e] = ss.getEncoderPosition(e);
    ss.enableEncoderInterrupt(e);
  }

  Serial.println("Turning on interrupts");

  pixels.setBrightness(255);
  pixels.show(); // Initialize all pixels to 'off'


delay(1000)  


  // set start positions
delay(1000);
for (int i = 0; i < 4; i++) {
ss.setEncoderPosition(50, i);
}
delay(1000);
for (int i = 0; i < 4; i++) {
Serial.println(ss.getEncoderPosition(i));
}
}

void loop() {

  // don't overwhelm serial port
  delay(100);
}


uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return seesaw_NeoPixel::Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if (WheelPos < 170) {
    WheelPos -= 85;
    return seesaw_NeoPixel::Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return seesaw_NeoPixel::Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}



@caternuson
Copy link
Contributor

This is a dupe of #20 which has been resolved by #21.

It's possible some encoders are still shipping with older firmware. For that, please see here:
adafruit/Adafruit_Seesaw#90 (comment)

@cnc4less
Copy link

After updating the firmware yes now working fine, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants