@jmcdeg
Did you ever progress with this issue. I am trying to pair the 8Ch Encoder unit with an M5Dial and am getting no-where. Fairly sure like you its an I2C issue.
Strangely I had no problem getting it to work on a bare bones ESP32 Dev Module on the default I2C pins. https://www.az-delivery.de/en/products/esp32-developmentboard
See Code Below for that working example.
Somewhat Ironic that when trying to pair it with one of their own Boards (M5Dial) it doesn't work out of the box. UIFlow2 works fine. I just cant for the life of me get the Arduino framework example they provide to work.
// ========== SETUP & LOOP ========== //
void setup() {
Serial.begin(115200);
sensor.begin(&Wire, ENCODER_ADDR, 21, 22, 100000UL);
while (!Serial); // Wait for serial
Serial.println("System Ready - Send 'enc all set zero' to reset encoders");
// Initialize to first state
sensor.setAllLEDColor(0xff0000); // Start main LEDs RED
}
/*
* Sequential Non-Blocking LED Control for UNIT_8ENCODER
* - Main LEDs complete full cycle first
* - Then Channel 0 LED runs its cycle
* - Continues in this sequential pattern
*/
#include "UNIT_8ENCODER.h"
UNIT_8ENCODER sensor;
// ========== TIMING CONTROL ========== //
unsigned long prevLedUpdate = 0;
unsigned long prevEncoderReport = 0;
const long LED_UPDATE_INTERVAL = 1000; // 1 second per color for main LEDs
const long CH0_LED_INTERVAL = 250; // 250ms per color for channel 0
const long ENCODER_REPORT_INTERVAL = 2000; // Report every 2 seconds
// ========== SYSTEM STATE ========== //
enum SystemMode { RUNNING_MAIN_LEDS, RUNNING_CH0_LED };
SystemMode currentMode = RUNNING_MAIN_LEDS;
// ========== LED STATE MACHINES ========== //
enum MainLedState { MAIN_RED, MAIN_GREEN, MAIN_BLUE, MAIN_OFF, MAIN_COMPLETE };
MainLedState mainLedState = MAIN_RED;
enum Ch0LedState { CH0_RED, CH0_GREEN, CH0_BLUE, CH0_OFF, CH0_COMPLETE };
Ch0LedState ch0LedState = CH0_RED;
// ========== ENCODER FUNCTIONS ========== //
void show_encoder_values() {
Serial.println("\n----- Encoder Report -----");
for (int i = 0; i < 8; i++) {
Serial.printf("Encoder CH-%d: %ld\n", i, sensor.getEncoderValue(i));
Serial.printf("Button CH-%d: %d\n", i, sensor.getButtonStatus(i));
}
Serial.printf("Switch: %s\n", sensor.getSwitchStatus() ? "ON" : "OFF");
}
void Zero_All_Encoders() {
for (int i = 0; i < 8; i++) {
sensor.resetCounter(i);
}
Serial.println("All encoders zeroed!");
}
// ========== SEQUENTIAL LED CONTROL ========== //
void update_leds_sequentially() {
unsigned long currentMillis = millis();
switch(currentMode) {
case RUNNING_MAIN_LEDS:
if (currentMillis - prevLedUpdate >= LED_UPDATE_INTERVAL) {
prevLedUpdate = currentMillis;
switch(mainLedState) {
case MAIN_RED:
sensor.setAllLEDColor(0xff0000); // RED
mainLedState = MAIN_GREEN;
break;
case MAIN_GREEN:
sensor.setAllLEDColor(0x00ff00); // GREEN
mainLedState = MAIN_BLUE;
break;
case MAIN_BLUE:
sensor.setAllLEDColor(0x0000ff); // BLUE
mainLedState = MAIN_OFF;
break;
case MAIN_OFF:
sensor.setAllLEDColor(0x000000); // OFF
mainLedState = MAIN_COMPLETE;
break;
case MAIN_COMPLETE:
// Main cycle complete, switch to channel 0
currentMode = RUNNING_CH0_LED;
ch0LedState = CH0_RED; // Reset channel 0 state
prevLedUpdate = currentMillis; // Reset timer for channel 0
break;
}
}
break;
case RUNNING_CH0_LED:
if (currentMillis - prevLedUpdate >= CH0_LED_INTERVAL) {
prevLedUpdate = currentMillis;
switch(ch0LedState) {
case CH0_RED:
sensor.setLEDColor(0, 0xff0000); // RED
ch0LedState = CH0_GREEN;
break;
case CH0_GREEN:
sensor.setLEDColor(0, 0x00ff00); // GREEN
ch0LedState = CH0_BLUE;
break;
case CH0_BLUE:
sensor.setLEDColor(0, 0x0000ff); // BLUE
ch0LedState = CH0_OFF;
break;
case CH0_OFF:
sensor.setLEDColor(0, 0x000000); // OFF
ch0LedState = CH0_COMPLETE;
break;
case CH0_COMPLETE:
// Channel 0 cycle complete, switch back to main LEDs
currentMode = RUNNING_MAIN_LEDS;
mainLedState = MAIN_RED; // Reset main LED state
prevLedUpdate = currentMillis; // Reset timer for main LEDs
break;
}
}
break;
}
}
// ========== SETUP & LOOP ========== //
void setup() {
Serial.begin(115200);
sensor.begin(&Wire, ENCODER_ADDR, 21, 22, 100000UL);
while (!Serial); // Wait for serial
Serial.println("System Ready - Send 'enc all set zero' to reset encoders");
// Initialize to first state
sensor.setAllLEDColor(0xff0000); // Start main LEDs RED
}
void loop() {
// Handle serial commands
if (Serial.available() > 0) {
String input = Serial.readStringUntil('\n');
input.trim();
input.toLowerCase();
if (input == "enc all set zero") {
Zero_All_Encoders();
} else {
Serial.println("Unknown command. Try: 'enc all set zero'");
}
}
// Update LEDs sequentially
update_leds_sequentially();
// Periodic encoder reports
if (millis() - prevEncoderReport >= ENCODER_REPORT_INTERVAL) {
prevEncoderReport = millis();
show_encoder_values();
}
}