Test Reciver:
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <SD.h>
// TFT display and SD card will share the hardware SPI interface.
// Hardware SPI pins are specific to the Arduino board type and
// cannot be remapped to alternate pins. For Arduino Uno,
// Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK.
#define SD_CS 4 // Chip select line for SD card
#define TFT_CS 10 // Chip select line for TFT display
#define TFT_DC 9 // Data/command line for TFT
#define TFT_RST 8 // Reset line for TFT (or connect to +5V)
#define bkl 2 //LCD Black Light
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
char inData[24];
byte index;
boolean started = false;
boolean ended = false;
\
void setup(void) {
Serial.begin(9600);
pinMode(TFT_CS, OUTPUT);
digitalWrite(TFT_CS, HIGH);
pinMode(bkl, OUTPUT);
digitalWrite(bkl, LOW);
// Our supplier changed the 1.8" display slightly after Jan 10, 2012
// so that the alignment of the TFT had to be shifted by a few pixels
// this just means the init code is slightly different. Check the
// color of the tab to see which init code to try. If the display is
// cut off or has extra 'random' pixels on the top & left, try the
// other option!
// If your TFT's plastic wrap has a Red Tab, use the following:
tft.initR(INITR_REDTAB); // initialize a ST7735R chip, red tab
// If your TFT's plastic wrap has a Green Tab, use the following:
//tft.initR(INITR_GREENTAB); // initialize a ST7735R chip, green tab
Serial.print("Initializing SD card...");
if (!SD.begin(SD_CS)) {
Serial.println("failed!");
return;
}
Serial.println("OK!");
bmpDraw("welcome.bmp", 0, 0);
delay(5000);
bmpDraw("b8.bmp", 0, 0);
testfillrects(ST7735_WHITE);
tft.fillCircle(15, 103, 5, ST7735_BLACK);
tft.fillCircle(15, 121, 5, ST7735_BLACK);
tft.fillCircle(15, 139, 5, ST7735_BLACK);
}
void loop() {
delay(500);
tft.fillCircle(15, 121, 5, ST7735_BLACK);
tft.drawLine(0, 25, tft.width()-1, 25, ST7735_GREEN);
tft.setCursor(25, 6);
tft.setTextColor(ST7735_GREEN);
tft.setTextSize(2);
tft.print("DISPLAY");
tft.setCursor(5, 30);
tft.setTextColor(ST7735_BLACK);
tft.setTextSize(1);
tft.print("Temperature");
tft.setCursor(115, 30);
tft.setTextColor(ST7735_BLACK);
tft.setTextSize(1);
tft.print("C");
tft.setCursor(5, 40);
tft.setTextColor(ST7735_BLACK);
tft.setTextSize(1);
tft.print("Humidity");
tft.setCursor(115, 40);
tft.setTextColor(ST7735_BLACK);
tft.setTextSize(1);
tft.print("%");
tft.setCursor(5, 50);
tft.setTextColor(ST7735_BLACK);
tft.setTextSize(1);
tft.print("Moisture");
tft.setCursor(5, 60);
tft.setTextColor(ST7735_BLACK);
tft.setTextSize(1);
tft.print("Voltage");
tft.setCursor(115, 60);
tft.setTextColor(ST7735_BLACK);
tft.setTextSize(1);
tft.print("V");
tft.setCursor(5, 70);
tft.setTextColor(ST7735_BLACK);
tft.setTextSize(1);
tft.print("0.1 deg C");
tft.setCursor(5, 80);
tft.setTextColor(ST7735_BLACK);
tft.setTextSize(1);
tft.print("Pressure");
tft.setCursor(115, 80);
tft.setTextColor(ST7735_BLACK);
tft.setTextSize(1);
tft.print("Pa");
tft.drawLine(0, 90, tft.width()-1, 90, ST7735_GREEN);
tft.setCursor(28, 99);
tft.setTextColor(ST7735_RED);
tft.setTextSize(1.7);
tft.print("TX");
tft.setCursor(28, 119);
tft.setTextColor(ST7735_RED);
tft.setTextSize(1.7);
tft.print("RX");
tft.setCursor(28, 136);
tft.setTextColor(ST7735_RED);
tft.setTextSize(1.7);
tft.print("SD");
while(Serial.available() > 0)
{
char aChar = Serial.read();
if(aChar == '<')
{
started = true;
index = 0;
inData[index] = ' ';
}
else if(aChar == '>')
{
ended = true;
}
else if(started)
{
inData[index] = aChar;
index++;
inData[index] = '\0';
}
}
if(started && ended)
{
// Use the value
if(inData[0] == 'T')
{
inData[0] = ' ';
int windVal = atoi(inData);
Serial.println(" ");
Serial.print("Temp:");
Serial.print(inData);
Serial.print("C");
Serial.println(" ");
tft.fillCircle(15, 121, 5, ST7735_RED);
tft.fillRect(tft.width()/80 +142/2, tft.height()/10 +25/2, 40, 9, ST7735_WHITE);
tft.setCursor(70, 30);
tft.setTextColor(ST7735_RED);
tft.setTextSize(1);
tft.println(inData);
}
else if(inData[0] == 'H')
{
inData[0] = ' ';
int temp = atoi(inData);
Serial.println(" ");
Serial.print("Humidity:");
Serial.print(inData);
Serial.print("%");
Serial.println(" ");
tft.fillCircle(15, 121, 5, ST7735_RED);
tft.fillRect(tft.width()/80 +142/2, tft.height()/10 +46/2, 40, 9, ST7735_WHITE);
tft.setCursor(70, 40);
tft.setTextColor(ST7735_RED);
tft.setTextSize(1);
tft.println(inData);
}
else if(inData[0] == 'M')
{
inData[0] = ' ';
int temp = atoi(inData);
Serial.println(" ");
Serial.print("Moisture:");
Serial.print(inData);
Serial.println(" ");
tft.fillCircle(15, 121, 5, ST7735_RED);
tft.fillRect(tft.width()/80 +142/2, tft.height()/10 +67/2, 40, 9, ST7735_WHITE);
tft.setCursor(70, 50);
tft.setTextColor(ST7735_RED);
tft.setTextSize(1);
tft.println(inData);
}
else if(inData[0] == 'V')
{
inData[0] = ' ';
int temp = atoi(inData);
Serial.println(" ");
Serial.print("Voltage:");
Serial.print(inData);
Serial.print("Volts");
Serial.println(" ");
tft.fillCircle(15, 121, 5, ST7735_RED);
tft.fillRect(tft.width()/80 +142/2, tft.height()/10 +86/2, 40, 9, ST7735_WHITE);
tft.setCursor(70, 60);
tft.setTextColor(ST7735_RED);
tft.setTextSize(1);
tft.println(inData);
}
else if(inData[0] == 'F')
{
inData[0] = ' ';
int temp = atoi(inData);
Serial.println(" ");
Serial.print("Temperature:");
Serial.print(inData);
Serial.print("*0.1 deg C");
Serial.println(" ");
tft.fillCircle(15, 121, 5, ST7735_RED);
tft.fillRect(tft.width()/80 +142/2, tft.height()/10 +106/2, 40, 9, ST7735_WHITE);
tft.setCursor(70, 70);
tft.setTextColor(ST7735_RED);
tft.setTextSize(1);
tft.println(inData);
}
else if(inData[0] == 'P')
{
inData[0] = ' ';
int temp = atoi(inData);
Serial.println(" ");
Serial.print("Pressure:");
Serial.print(inData);
Serial.print(" Pa");
Serial.println(" ");
tft.fillCircle(15, 121, 5, ST7735_RED);
tft.fillRect(tft.width()/80 +142/2, tft.height()/10 +126/2, 40, 9, ST7735_WHITE);
tft.setCursor(70, 80);
tft.setTextColor(ST7735_RED);
tft.setTextSize(1);
tft.println(inData);
}
started = false;
ended = false;
index = 0;
inData[index] = ' ';
}
}
void testfillrects(uint16_t color1) {
tft.fillRect(tft.width()/2 -130/2, tft.height()/2 -110/2 , 150, 65, color1);
}