Arduino to Axoloti, how to read correct values


#1

Hello,
I'm trying to send datas from Arduino to Axoloti via UART. It seems to be ok if I use a 8bit integer (0-255). But I would like to have the maximum resolution, from 0 to 1023, with some sensors. I understand that I have to send an identification byte (in order to set the courrent sensor) followed by 2 different bytes, so I created this test sketch:

for (uint16_t i=0; i<1024; i++){
uint8_t i1=i/256;
uint8_t i2=i%256;
byte buf[2]={i1,i2};
Serial.print("a");
Serial.write(buf,2);
delay(100);
}

The message is composed by a character that identifies the sensor, and a 16bit integer. In Axoloti patch I made a script2 object with this sketch:

void loop(void) {
// read all pending bytes, value to out1
while(!sdGetWouldBlock(&SD2)){
char x = sdGet(&SD2);
switch(x){
case 'a': {
uint8_t i1 = sdGet(&SD2)*256;
uint8_t i2 = sdGet(&SD2);
uint32_t tot = i1+i2;
out1 = tot<<16;
}
}
}
}

But it doesn't work correctly. Some ideas?
Thank you!!
Stefano