Alright, so my program looks like this now:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
uint8_t autobaud[]={0x55}; //command 1 autobaud
uint8_t arr[]={0x42, 0x10, 0xCC}; //command 2 change background to color 0x10CC
uint8_t new_arr[]={0x00,0x00,0x00,0x00,0x00,0xFF}; // command 3 draw a circle at x= 0x50 y=0x3F radius=0x22 color=0x001F
void setup()
{
delay(1000);
pinMode(13, OUTPUT);
Serial.begin(9600);
mySerial.begin(9600);
delay(1000);
dostuff(autobaud, sizeof(autobaud));
dostuff(arr, sizeof(arr));
delay(2000);
dostuff(new_arr, sizeof(new_arr));
}
void loop()
{
serial_response();
}
void dostuff(uint8_t *buffer, int len)
{
mySerial.write(buffer, len); // Serial.write wants the array pointer and the number of elements
// Serial.print("Command: ");
// Serial.write(buffer, len);
// Serial.println("|");
serial_response();
}
void serial_response(){
byte incomingByte=0;
while(mySerial.available() <= 0); //Do nothing until there are bytes to be read.
// Serial.print("Response: ");
incomingByte=mySerial.read();
if(incomingByte==0x06){
Serial.print(incomingByte, HEX); //when there are bytes, print them to the monitor.
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}
else if(incomingByte==0x15){
Serial.println("NAK");
}
else{
Serial.println(incomingByte, HEX);
}
}
I have intentionally put in command #3 improperly, so I could make sure I was getting 0x15, or negative acknowledgement of a bad command. The screen is doing exactly what it is supposed to, and this is the output from the monitor:
6655
FE
NAK
AB
FE
66 is confirmation of command 1 and 2.
NAK is confirmation of a bad command, command 3.
I don't know what the other junk is. Is it normal for devices like this to spit out junk data like that?