I have a project where I need to send an array of hex bytes from an Arduino Uno to a third party device through serial communication, the device performs an action, and replies with an array of bytes, also in hex after a short time (+-500ms).
A third-party USART USB interface is used to record the response from the third-party device to a computer, with a Bluetooth link between the third-party device TX and the USART RX. The Arduino TX and third-party device RX are wired.
Now the problematic bit:
My project requires that the Arduino also captures the response from the third-party device, processes the response, and depending on the value, triggers different outputs (LED's).
I also need the ability to debug the Arduino, to make sure that the hex values that it receives are being processed correctly and that the output is accordingly triggered.
The code that I currently have (compiling, but not working as I anticipate it) is hown below:
byte one_shot_FAST[] = {0xAA, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x02, 0x23};
int IncomingByte = 0;
uint8_t q1 = 0;
uint8_t q2 = 0;
uint16_t qtot = 0;
int qVal = 0;
int qValMax = 65535;
const int triggerPin = 2;
int triggerState = LOW;
void setup() {
Serial.begin(19200);
pinMode(triggerPin, INPUT);
Serial.println("<Arduino is ready>");
}
void loop() {
triggerState = digitalRead(triggerPin);
if (triggerState == HIGH){
Serial.write(&one_shot_FAST[0], sizeof(one_shot_FAST));
//while(!Serial.available());
IncomingByte = Serial.read();
for (int i=0; i<13; i++) {
while(!Serial.available()); //wait for character
IncomingByte = Serial.read();
Serial.println(IncomingByte,HEX);
delay(10);
}
I expect the following response: AA 00 00 22 00 03 00 00 03 2B 01 E1 35
but I get a string of "#" and a square block after each "#"