XIAO+incremental encoder

i`m trying to join XIA0 and incremental encoder e6b2-cwz1x. As the latter uses 5V logic i use 5V-to-3,3V Logic Level Converter like this one - aliexpress.ru/item/4000410859489.html?sku_id=10000001694651474

i use code which works fine on arduino uno with the same encoder:

#define ENC_A 4       // encoder pin
#define ENC_B 5       // encoder pin
volatile int encCounter;
volatile boolean flag, resetFlag;
volatile byte curState, prevState;
void setup() {
  attachInterrupt(0, int0, CHANGE);
  attachInterrupt(1, int0, CHANGE);
void int0() {

void encTick() {
  curState = digitalRead(ENC_A) | digitalRead(ENC_B) << 1; 
  if (resetFlag && curState == 0b11) {
    if (prevState == 0b10) encCounter++;
    if (prevState == 0b01) encCounter--;
    resetFlag = 0;
    flag = true;
  if (curState == 0b00) resetFlag = 1;
  prevState = curState;
void loop() {
  if (flag) {
    flag = 0;

After successful uploading the code i connect XIAO with FTD1232 with 3,3V logic to pins 6,7 of XIAO(this is serial port). 4,5 pins of XIAO go to logic converter. From the other side of logic converter there are pins from encoder.
On serial port i see nothing…
Could you help please ?

[/Begin Disclaimer]
I don’t have one of your encoders so I can’t guarantee that everything I suggest will help. I do have some experience with XIAO interrupts, so, here’s hoping…
[/End Disclaimer]

First of all, you have defined the encoder connections to pins 4 and 5, but you enabled interrupts on pins 0 and 1.

What happens if you connect your encoder pins to XIAO pins 0 and 1?

Secondly, I do know for a fact that there is a bug or two in the way that the Seeed software handles the XIAO NMI (Non-Maskable Interrupt) I won’t bore you with the details, but I simply can’t get any interrupt to work on XIAO pin 4 (which is connected to the SAMD NMI input pin).

Therefore, I strongly suggest you not use XIAO pin 4 as an interrupt input. If any Seeed support engineers (or any other folks) know how to do this, maybe they can chime in here.

Thirdly, to make sure your Serial I/O is working, I suggest you put someting in your setup code to make sure things are getting started OK. Maybe something like

  while (!Serial1)
    ; // Wait for terminal connection
  Serial1.println("\nInterrupt test compiled on " __DATE__ " at " __TIME__ "\n");
  // The rest of your setup()

I attached a little project I used to test interrupts on pins 0 and 1. Try it and change encoder pin assignments to other pins and see what happens.



XIAO_TestInterrupts.zip (2.3 KB)

Thanks for quick answer!
You`re right i just forget to change pins at the start of the code - 4,5 → 0,1
And got it working !