Using my Esplora I am sending commands via the tinker kit connectors 11,3 and software Serial to a x-bee to a Arduino UNO and the uno needs to send info. back to the Esplora so it can be displayed on the TFT display. and the code works one way. I can send packets using a start character, commas as the delimiters, and a end character. The UNO receives the information intact. I can comment out the transmit portion of the code and receive the packets intact. It is when I try to send and receive, the TFT screen locks up. but the processor is still running because the UNO still responds to the joystick. Here is the code please help.
#include <TFT.h>
#include <SoftwareSerial.h>
#include <SPI.h>
#include <Esplora.h>
#define sop '
I have read the 21stcentury bloodspot extensively but I cannot find anything covering sending and receiving these types of packets while using a TFT display too.
I am also wandering If instead of transmitting everything in mySerial.print is not the best way of sending info. this may be causing conflict.
#define eop ':'
#define st '^'
#define ed '&'
#define comma ','
int potx = 0;
int poty = 0;
int x = 0;
int y = 0;
int xr = 0;
int yr = 0;
int leftfwd = 0;
int leftrev = 0;
int rightfwd = 0;
int rightrev = 0;
int potz = 0;
int z = 0;
int jbutton = 1;
int ubutton = 1;
int dbutton = 1;
int lbutton = 1;
int rbutton = 1;
int blank;
char inData[25];
byte index;
char tempPrintout[3];
char buffer[5];
char inChar;
char *temp, *re ;
int temp1[10];
int re1[10];
SoftwareSerial mySerial(11,3);
void setup(){
mySerial.begin(57600);
EsploraTFT.begin();
// clear the screen with a black background
EsploraTFT.background(0,0,0);
// set the text color to magenta
EsploraTFT.stroke(200,20,180);
// set the text to size 2
EsploraTFT.setTextSize(2);
// start the text at the top left of the screen
// this text is going to remain static
EsploraTFT.text("Watt Lt:\n ",0,0);
EsploraTFT.text("Watt rt:\n ",0,17);
EsploraTFT.text("Volts :\n ",0,35);
EsploraTFT.text("RSSI :\n ",0,53);
EsploraTFT.setTextSize(1);
EsploraTFT.text("HEATSINK TEMP:\n ",0,70);
EsploraTFT.text("RIGHT FOWARD POS:\n ",0,80);
EsploraTFT.text("RIGHT REVERSE POS:\n ",0,90);
EsploraTFT.text("LEFT FOWARD POS:\n ",0,100);
EsploraTFT.text("LEFT REVERSE POS:\n ",0,110);
}
void loop(){
while(mySerial.available() > 0)
{
while(inChar != st){
inChar = mySerial.read();
}
while(inChar != ed){
inChar= mySerial.read();
inData[index] = inChar;
delay(1);
index++;
inData[index] = '\0';
}
temp = strtok(inData,",");
temp1[0] = atoi(temp);
for(int marker=0; marker <8; marker++)
{
re = strtok(NULL, ",");
re1[marker] = atoi(re);
}
index = 0;
}
potx=Esplora.readJoystickX();
poty=Esplora.readJoystickY();
potz=Esplora.readSlider();
jbutton=Esplora.readJoystickButton();
ubutton=Esplora.readButton(SWITCH_UP);
dbutton=Esplora.readButton(SWITCH_DOWN);
lbutton=Esplora.readButton(SWITCH_LEFT);
rbutton=Esplora.readButton(SWITCH_RIGHT);
potx=potx+7;
poty=poty-8;
x=map(potx,-512,512,-250,250);
y=map(poty,-512,512,-250,250);
z=map(potz,0,1023,0,250);
if(x<=0){
xr=x*-1;
x=0;}
if(y<=0){
yr=y*-1;
y=0;}
if(yr>=1){
leftfwd=yr;
rightfwd=yr;
leftrev=0;
rightrev=0;}
if(y>=1){
leftfwd=0;
rightfwd=0;
leftrev=y;
rightrev=y;}
if(x>=1 && leftfwd>=1){
leftfwd=leftfwd-x;
if(leftfwd<=0){
leftfwd=0;}}
if(xr>=1 && rightfwd>1){
rightfwd=rightfwd-xr;
if(rightfwd<=0){
rightfwd=0;}}
if(x>=1 && leftrev>=1){
leftrev=leftrev-x;
if(leftrev<=0){
leftrev=0;}}
if(xr>=1 && rightrev>=1){
rightrev=rightrev-xr;
if(rightrev<=0){
rightrev=0;}}
if(x==0 && y==0 && yr==0 && xr==0){
leftfwd=0;
leftrev=0;
rightfwd=0;
rightrev=0;}
EsploraTFT.stroke(255,255,255);
EsploraTFT.text(itoa(rightfwd, buffer ,10),120,80);
EsploraTFT.text(itoa(rightrev, buffer ,10),120,90);
EsploraTFT.text(itoa(leftfwd, buffer ,10),120,100);
EsploraTFT.text(itoa(leftrev, buffer ,10),120,110);
EsploraTFT.text(itoa(re1[0], buffer ,10),120,0);
EsploraTFT.text(itoa(re1[1], buffer ,10),120,17);
EsploraTFT.text(itoa(re1[2], buffer ,10),120,35);
EsploraTFT.text(itoa(re1[3], buffer ,10),120,53);
EsploraTFT.text(itoa(re1[4], buffer ,10),120,70);
mySerial.print(sop);
mySerial.print(blank);
mySerial.print(comma);
mySerial.print(leftfwd);
mySerial.print(comma);
mySerial.print(leftrev);
mySerial.print(comma);
mySerial.print(rightfwd);
mySerial.print(comma);
mySerial.print(rightrev);
mySerial.print(comma);
mySerial.print(z);
mySerial.print(comma);
mySerial.print(jbutton);
mySerial.print(comma);
mySerial.print(ubutton);
mySerial.print(comma);
mySerial.print(dbutton);
mySerial.print(eop);
delay(50);
EsploraTFT.stroke(0,0,0);
EsploraTFT.text(itoa(rightfwd, buffer ,10),120,80);
EsploraTFT.text(itoa(rightrev, buffer ,10),120,90);
EsploraTFT.text(itoa(leftfwd, buffer ,10),120,100);
EsploraTFT.text(itoa(leftrev, buffer ,10),120,110);
EsploraTFT.text(itoa(re1[0], buffer ,10),120,0);
EsploraTFT.text(itoa(re1[1], buffer ,10),120,17);
EsploraTFT.text(itoa(re1[2], buffer ,10),120,35);
EsploraTFT.text(itoa(re1[3], buffer ,10),120,53);
EsploraTFT.text(itoa(re1[4], buffer ,10),120,70);
}
I have read the 21stcentury bloodspot extensively but I cannot find anything covering sending and receiving these types of packets while using a TFT display too.
I am also wandering If instead of transmitting everything in mySerial.print is not the best way of sending info. this may be causing conflict.