I have a LCD connected to an Arduino which displays images and the image is shown on the serial if it is touched. I want to send the data written on the serial to a PC using Xbee. I have configured the Xbee modules and they are working fine.
The problem i am facing is that the data to the PC is not being sent automatically. Instead if i write something in the serial then it is being shown on the PC. The code im using is
// UTFT_SdRaw_800x480_Demo
// Copyright (C)2015 Graham Lawrence (GHLawrence2000). All Rights reserved.
// web: https://github.com/ghlawrence2000/UTFT_SdRaw
//
// This program is a demo of how to use the functions provided by UTFT_SdRaw.
//
// This program requires the UTFT, UTouch, UTFT_Buttons and SdFat libraries.
//
#include <SPI.h>
// SdFat lib from here :-
// https://github.com/greiman/SdFat/archive/master.zip
#include <SdFat.h>
#include <UTFT.h>
#include <UTouch.h>
#include <UTFT_SdRaw.h>
#include <SoftwareSerial.h>
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
#define SD_CHIP_SELECT 53 // SD chip select pin
// file system object
SdFat sd;
// print stream
SoftwareSerial XBee(10, 11); // RX, TX
// Initialize display
// ------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield : <display model>,19,18,17,16
// Standard Arduino Mega/Due shield : <display model>,38,39,40,41
// CTE TFT LCD/SD Shield for Arduino Due : <display model>,25,26,27,28
// Teensy 3.x TFT Test Board : <display model>,23,22, 3, 4
// ElecHouse TFT LCD/SD Shield for Arduino Due : <display model>,22,23,31,33
//
// Remember to change the model parameter to suit your display module!
//UTFT myGLCD(CPLD, 38, 39, 40, 41);
//UTFT myGLCD(CTE50, 38, 39, 40, 41);
UTFT myGLCD(CTE70, 38, 39, 40, 41);
// Initialize touchscreen
// ----------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield : 15,10,14, 9, 8
// Standard Arduino Mega/Due shield : 6, 5, 4, 3, 2
// CTE TFT LCD/SD Shield for Arduino Due : 6, 5, 4, 3, 2
// CTE TFT LCD/SD Shield for Arduino Due (JP10): 6, 5,32, 3, 2
// Teensy 3.x TFT Test Board : 26,31,27,28,29
// ElecHouse TFT LCD/SD Shield for Arduino Due : 25,26,27,29,30
//
UTouch myTouch(6, 5, 4, 3, 2);
UTFT_SdRaw myFiles(&myGLCD);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
XBee.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for DUE & Leonardo only
}
Serial.println(F("Initialising SD card..."));
bool mysd = 0;
// see if the card is present and can be initialized:
while (!mysd) {
if (!sd.begin(SD_CHIP_SELECT, SPI_FULL_SPEED)) {
Serial.println(F("Card failed, or not present"));
Serial.println(F("Retrying...."));
} else {
mysd = 1;
Serial.println(F("Card initialised."));
}
}
Serial.println(F("Initialising LCD."));
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
Serial.println(F("LCD initialised."));
myGLCD.clrScr();
myFiles.load(0, 0, 800, 480, "lcd1.raw", 2, 0);
}
byte dispScreen = 1; // Currently displayed screen, screens shown below //
// 1-home, 2-lights, , 3-temp, 4-fogger, 5-mister, 6-fan, 7-clock, 8-screen //
void processMyTouch() {
myTouch.read();
int x = myTouch.getX();
int y = myTouch.getY();
switch (dispScreen) { // //
// //
case 1: // home screen //
// do stuff here for screen 1
if ((x > 650 && x < 800) && (y > 20 && y < 460)) {
//button 'back'
myGLCD.clrScr();
dispScreen = 2; // <======================================= change screen each time you go to a new screen
myFiles.load(0, 0, 800, 480, "lcd_2.raw", 2, 0);
}
if ((x > 19 && x < 340) && (y > 21 && y < 212)) {
//button 'news'
Serial.println("Drinks");
}
if ((x > 400 && x < 5700) && (y > 21 && y < 212)) {
//button 'news'
Serial.println(F("Food"));
}
if ((x > 19 && x < 340) && (y > 240 && y < 448)) {
//button 'news'
Serial.println(F("Tea"));
}
if ((x > 400 && x < 550) && (y > 240 && y < 448)) {
//button 'news'
Serial.println(F("Water"));
}
break;
case 2:
// do stuff here for screen 2
if ((x > 170 && x < 430) && (y > 21 && y < 212)) {
//button 'news'
Serial.println(F("news"));
}
if ((x > 17 && x < 100) && (y > 30 && y < 400)) {
//button 'news'
myGLCD.clrScr();
dispScreen = 1; // <======================================= change screen each time you go to a new screen
myFiles.load(0, 0, 800, 480, "lcd1.raw", 2, 0);
}
if ((x > 530 && x < 750) && (y > 21 && y < 212)) {
//button 'news'
Serial.println(F("light."));
}
if ((x > 530 && x < 750) && (y > 240 && y < 448)) {
//button 'news'
Serial.println(F("Blanket"));
}
if ((x > 170 && x < 430) && (y > 240 && y < 448)) {
//button 'news'
Serial.println(F("Medic"));
}
break;
}
}
unsigned long prevMillisTouch = 0; // track time between touches //
unsigned long TouchRepeatDelay = 500; // millis //
void loop() {
unsigned long currentMillis = millis(); // get current millis //
if (myTouch.dataAvailable()) { // //
// make sure it's been .5 sec (initially) between touches //
if (currentMillis - prevMillisTouch > TouchRepeatDelay) { //
// //
prevMillisTouch = currentMillis; // reset the touch timer //
processMyTouch(); //
} // //
} //
//
if (Serial.available()) {
// If data comes in from serial monitor, send it out to XBee
XBee.write(Serial.read());
}
if (XBee.available()) {
// If data comes in from XBee, send it out to serial monitor
Serial.write(XBee.read());
}
}
Example:
if ((x > 19 && x < 340) && (y > 21 && y < 212)) {
//button 'news'
Serial.println("Drinks");
'Drinks" is displayed on the serial if i touch the above coordinates. However, the data is not sent to the other Xbee module. if i manually write drinks in the serial, it shows on the other Xbee module.
Any solutions.
Thanks