Arduino UART - Ikea Fyrtur shades

I've hooked up an arduino Leonardo to an Ikea Fyrtur shade by using its internal uart on the PCB. This allows me to read all the commands being sent to the motor.

For this I'm using the following code. The reading works fine, I see the commands coming in, for example I see same command

when i press the up button. This is the same format and command which is mentioned on this github:

unsigned long target_time = 0L ;

unsigned long PERIOD (10*1000L);
const uint8_t upCommand[] = {0x00, 0xff, 0x9a, 0x0a, 0xdd, 0xd7};


void setup()
{
  Serial.begin(9600); //This pipes to the serial monitor
  while(!Serial);
  Serial1.begin(2400); //This is the UART, pipes to sensors attached to board
  while(!Serial1);
}

void loop()
{
  if ((millis() - target_time) >= PERIOD)
  {
    target_time += PERIOD ;   // change scheduled time exactly, no slippage will happen

    delay(1000);
    Serial1.write(upCommand, sizeof(upCommand));   
    Serial.println("Sending up command");
    delay(1000);
  }
  
  if( Serial1.available() )
  {
    int inByte = Serial1.read();
    Serial.println( inByte, HEX );
    
    
  }
}

I'm now trying to replay that same command to the uart, by doing a Serial1.write(byteArray, size). Unfortunately, this does not work. I'm sending the same collection of bytes as what I receive when physically pushing the up button, but when sending it with Serial1.write it does not react to it. Does anybody see what i'm doing wrong here?

At the same time, serial.Print() the upCommand and the sizeof(upComand) so you can SEE what is being sent.

If i do print the data sent through serial1, it does seem to be the right data:

08:47:56.990 -> 6
08:47:56.990 -> 0FF9AADDD7
08:47:56.990 -> Sending up command

(this is my code to print out the data to serial)

Serial.println(sizeof(upCommand));
for (int i = 0; i < sizeof(upCommand); i++) Serial.print(upCommand[i], HEX);
Serial.println("");

Is this not just the way Serial.print works?
When printing Serial.print(0x00) it prints 0
When printing Serial.print(0x0A) it prints A

Correct me if i'm wrong though.

Print a space between each byte to make them easier to check at a glance.

I've put a space between the bytes;
image

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.