Pages: [1]   Go Down
Author Topic: using x-bee and tft display  (Read 3286 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Code:
#include <TFT.h>
#include <SoftwareSerial.h>
#include <SPI.h>
#include <Esplora.h>
#define sop '$'
#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.
Logged

US
Offline Offline
Full Member
***
Karma: 4
Posts: 183
Electronics are the new Legos
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In my experience, I was only sending from the Esplora to an Uno, the Uno wasn't sending info back but there was nothing in the project that prevented doing that.  RX and TX can be on the Tinkerkit outputs (which can be set as inputs) - hey, that's a thought - try PinMode settings for the two Tinkerkits, one for output, one for input (for xbee transmit and receive).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am not sure if pin mode  is the reason it works but it works to some extent. The display does not lock up until I read too many lines for example i got rid of this...
Code:
  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 <2; marker++){
       re = strtok(NULL, ",");
       re1[marker] = atoi(re);
        }
and replaced it with this 
Code:
while(mySerial.available() > 1){
      inChar = mySerial.read();
       if(inchar == st){
        Esplora.writeRed(200);} // did this to see if it receives the start bit and the led comes on
     for(int count = 0; count < 3; count ++){
      re[count] = mySerial.read();
      } // end for loop
    } // end if
   I noticed that if i increase (count) beyond 4 or 5 the screen locks up but below that i receive garbage and can't get it to display a real number from the receiver( this code is the transmitter) on the transmitter I am doing the same thing in reverse
Code:
             Serial.print(st);
    //Serial.print(blank);
    //Serial.print(comma);
    Serial.print(leftamps);
   // Serial.print(comma);
   // Serial.print(rightamps);
  //  Serial.print(comma);
   // Serial.print(volts);
  //  Serial.print(comma);
   // Serial.print(thermo);
   // Serial.print(comma);
   // Serial.print(RSSb);
    Serial.print(ed);
notice I tried to comment out things to simplify the transmission but I still cannot see a real number from the receiver but the receiver gets the info from the transmitter intact and all channels work
I ask you Kitty can you help? You seem to have the most experience with this. Sorry for the long delay in my response The Holidays have me busy.
Logged

US
Offline Offline
Full Member
***
Karma: 4
Posts: 183
Electronics are the new Legos
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe try to check serial available before every read as if you read without data available I'm not sure what that does.
Logged

Pages: [1]   Go Up
Jump to: