Hi. My setup is this: I've got a computer program sending 5 byte messages to Arduino Uno, the first one (0x80) just says to write the next bytes into a buffer, the last one (0x81) just says to stop writing to the buffer and declare that there is new data, so the buffer itself is only 3 bytes. I am drawing info to an ILI9341 screen using a library called PDQ_GFX, which is nearly identical to the Adafruit GFX library except it draws much faster. the first byte dictates whether the messages deals with a parameter value, or a parameter name. if byte Buffer[0] is 0x82, then it will draw the value of byte Buffer[2] in decimal form at an x/y position dictated by byte Buffer[1]. The Buffer[2] value never goes above 0x7F, which is how this all works. if Buffer[0] is 0x83, then it grabs a parameter name from program memory at Buffer[2] and draws it at Buffer[1]. The serial code is mostly taken from the Serial Input Basics thread. This works mostly well, until the parameter values from the computer change too quickly, and then the Arduino freezes. I'm sure there's a way to get around this. Here is my code
#include <SPI.h>
#include <PDQ_GFX.h>
#include "ilicfg.h"
#include <PDQ_ILI9341.h>
#include <Fonts/ElfBoyClassic11.pck.h>
PDQ_ILI9341 tft;
byte Buffer[3];
bool newData = false;
const char s1[] PROGMEM = "P01";
const char s2[] PROGMEM = "P02";
const char s3[] PROGMEM = "P03";
const char s4[] PROGMEM = "P04";
const char s5[] PROGMEM = "P05";
const char s6[] PROGMEM = "P06";
const char s7[] PROGMEM = "P07";
const char s8[] PROGMEM = "P08";
const char s9[] PROGMEM = "P09";
const char s10[] PROGMEM = "P10";
const char s11[] PROGMEM = "P11";
const char s12[] PROGMEM = "P12";
const char s13[] PROGMEM = "P13";
const char s14[] PROGMEM = "P14";
const char s15[] PROGMEM = "P15";
const char s16[] PROGMEM = "P16";
const char* const stab[] PROGMEM = {s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16};
char prmBuf[3];
void setup() {
#if defined(ILI9341_RST_PIN)
FastPin<ILI9341_RST_PIN>::setOutput();
FastPin<ILI9341_RST_PIN>::hi();
FastPin<ILI9341_RST_PIN>::lo();
delay(1);
FastPin<ILI9341_RST_PIN>::hi();
#endif
tft.begin();
tft.setRotation(1);
tft.fillScreen(0x0000);
tft.setFont(&ElfBoyClassic11);
tft.setTextColor(0xffff);
tft.setTextSize(2);
Serial.begin(115200);
}
void loop() {
recv();
drawShit();
}
void recv() {
static bool readState = false;
static byte ndx = 0;
byte rb;
while(Serial.available() > 0 && newData == false) {
rb = Serial.read();
if(readState == true) {
if(rb != 0x81) {
Buffer[ndx] = rb;
ndx++;
if(ndx >= 3) {
ndx = 2;
}
}
else {
readState = false;
ndx = 0;
newData = true;
}
}
else if(rb == 0x80) {
readState = true;
}
}
}
void drawShit() {
if(newData == true) {
if(Buffer[0] == 0x82) {
tft.fillRect((Buffer[1]%4)*65+20, (Buffer[1]/4)*60+8, 60, 20, 0x0000);
tft.setCursor((Buffer[1]%4)*65+20, (Buffer[1]/4)*60+20);
tft.print(Buffer[2], DEC);
newData = false;
}
if(Buffer[0] == 0x83) {
tft.fillRect((Buffer[1]%4)*65+20, (Buffer[1]/4)*60+38, 60, 20, 0x0000);
tft.setCursor((Buffer[1]%4)*65+20, (Buffer[1]/4)*60+50);
strcpy_P(prmBuf, (char*)pgm_read_word(&(stab[Buffer[2]])));
tft.print(prmBuf);
newData = false;
}
}
}
Any help is appreciated, thanks.