Go Down

Topic: Displaying radio stations on the Touchshield slide (Read 1 time) previous topic - next topic

AaronD

im using this radio module https://www.sparkfun.com/products/10663 and this touch screen http://www.liquidware.com/shop/show/TSL/TouchShield+Slide+. I just learned how to send values from a module to the touchshield and it displays the value on it but the first digit doesnt appear. Example: if the radio station is 969(stations are ints), it will just show up as 69. im just trying to find a way to display the whole value on the touchscreen.

heres my code for the arduino:
Code: [Select]
#include <Si4703_Breakout.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#define RXpin 3
#define TXpin 2
char radByte;
int resetPin = 7;
int SDIO = A4;
int SCLK = A5;

Si4703_Breakout radio(resetPin, SDIO, SCLK);
int channel;
int volume;
char rdsBuffer[10];
SoftwareSerial touchSerial = SoftwareSerial(RXpin, TXpin);

void setup()
{
  touchSerial.begin(2400);
  /*Serial.println("\n\nSi4703_Breakout Test Sketch");
  Serial.println("==========================="); 
  Serial.println("a b     Favourite stations");
  Serial.println("+ -     Volume (max 15)");
  Serial.println("u d     Seek up / down");
  Serial.println("r       Listen for RDS Data (15 sec timeout)");
  Serial.println("Send me a command letter.");*/
 

  radio.powerOn();
  radio.setVolume(0);
}

void loop(){
  radByte = touchSerial.read();

    if (radByte == 'u')
    {
      channel = radio.seekUp();
      displayStation();
    }
    else if (radByte == 'd')
    {
      channel = radio.seekDown();
      displayStation();
    }
    else if (radByte == '+')
    {
      volume ++;
      if (volume == 16) volume = 15;
      radio.setVolume(volume);
    }
    else if (radByte == '-')
    {
      volume --;
      if (volume < 0) volume = 0;
      radio.setVolume(volume);
    }
    else if (radByte == 'a')
    {
      channel = 945; // Jamn 94.5 FM
      radio.setChannel(channel);
      displayStation();
    }
    else if (radByte == 'b')
    {
      channel = 969; //
      radio.setChannel(channel);
      displayStation();
    }
    else if (radByte == 'c')
    {
      channel = 1033; //
      radio.setChannel(channel);
      displayStation();
    }
}
    void displayStation(){
    touchSerial.print(channel);
    delay(1000);
    }


heres the code for the touchshield:
Code: [Select]
PImage timedis;
PImage menubut;
PImage batbar;
PImage arrowL;
PImage arrowR;
PImage volButt;
PImage button;
int volume;
char out[3];
unsigned int Xstore; //setup temporary variable
unsigned int Ystore; //setup temporary variable
void setup(){
  Serial.begin(2400);
  //open(FlashTransfer);
  background(0);
  arrowL = loadImage("arrowL.bmp");
  arrowR = loadImage("arrowR.bmp");
  volButt = loadImage("volButt.bmp");
  timedis = loadImage("timedis.bmp");
  menubut = loadImage("menubut.bmp");
  batbar = loadImage("batbar.bmp");
  button = loadImage("button.bmp");
  image(timedis,260,0);
  image(menubut,0,0);
  stroke(100);
  fill(100);
  image(batbar,136,0);
  rect(140,3,37,9);
  triangle(50,135,70,120,70,150);
  triangle(215,135,195,120,195,150);
  noFill();
  //rect(50,120,20,30);
  //rect(195,120,20,30);
  image(button,45,200);
  image(button,110,200);
  image(button,175,200);
  image(volButt,275,105);
  stroke(153);
  text("VOL",276,90,15);
  //text("15",287,170,11);
  //text("7",292,90,11);
  text("SEEK",110,90,15);
  //text("94.5",110,135,15);
  text("1",70,215,11);
  text("2",135,215,11);
  text("3",200,215,11);
  text("+",293,126,15);
  text("-",293,218,15);
}

void loop(){

  gettouch();
  if(mouseX != Xstore || mouseY != Ystore){
  if(mouseX > 45 & mouseX < 95 & mouseY > 200 & mouseY < 230){
    Serial.print('a');
    stroke(0,170,80);
    text("1",70,215,11);
    stroke(153);
    text("2",135,215,11);
    text("3",200,215,11);
    stroke(0);
    fill(0);
    rect(75,120,115,30);
    stroke(153);
    //dtostrf(channel,2,0,out);
    //text(out,120,135,15);
  }
  else if(mouseX > 110 & mouseX < 160 & mouseY > 200 & mouseY < 230){
    Serial.print('b');
    stroke(0,170,80);
    text("2",135,215,11);
    stroke(153);
    text("1",70,215,11);
    text("3",200,215,11);
    stroke(0);
    fill(0);
    rect(75,120,115,30);
    stroke(153);
    //dtostrf(channel,2,0,out);
    //text(out,120,135,15);
  }
  else if(mouseX > 175 & mouseX < 225 & mouseY > 200 & mouseY < 230){
    Serial.print('c');
    stroke(0,170,80);
    text("3",200,215,11);
    stroke(153);
    text("1",70,215,11);
    text("2",135,215,11);
    stroke(0);
    fill(0);
    rect(75,120,115,30);
    stroke(153);
    //dtostrf(channel,2,0,out);
    //text(out,120,135,15);
  }
 
  if(mouseX > 195 & mouseX < 215 & mouseY > 120 & mouseY < 150){
    Serial.print('u');
    stroke(153);
    text("1",70,215,11);
    text("2",135,215,11);
    text("3",200,215,11);
    stroke(0,170,80);
    fill(0,170,80);
    triangle(215,135,195,120,195,150);
    delay(100);
    stroke(100);
    fill(100);
    triangle(215,135,195,120,195,150);
    stroke(0);
    fill(0);
    rect(75,120,115,30);
    stroke(153);
    //dtostrf(channel,2,0,out);
    //text(out,120,135,15);
  }
  if(mouseX > 50 & mouseX < 70 & mouseY > 120 & mouseY < 150){
    Serial.print('d');
    stroke(153);
    text("1",70,215,11);
    text("2",135,215,11);
    text("3",200,215,11);
    stroke(0,170,80);
    fill(0,170,80);
    triangle(50,135,70,120,70,150);
    delay(100);
    stroke(100);
    fill(100);
    triangle(50,135,70,120,70,150);
    stroke(0);
    fill(0);
    rect(75,120,115,30);
    stroke(153);
    //dtostrf(channel,2,0,out);
    //text(out,120,135,15);
  }
  if(mouseX > 280 & mouseX < 306 & mouseY > 119 & mouseY < 159){
    Serial.print('+');
    stroke(0,170,80);
    text("+",293,126,15);
    delay(100);
    stroke(0);
    fill(0);
    rect(280,160,26,17);
    volume++;
    stroke(153);
    text("+",293,126,15);
  }
  if(mouseX > 280 & mouseX < 306 & mouseY > 180 & mouseY < 225){
    Serial.print('-');
    stroke(0,170,80);
    text("-",293,218,15);
    delay(100);
     stroke(0);
    fill(0);
    rect(280,160,26,17);
    volume--;
    stroke(153);
    text("-",293,218,15);
  }
  Xstore = mouseX;
  Ystore = mouseY;
}
if(volume >= 15){
   volume=15;
}
if(volume <= 0){
   volume=0;
}
if(volume < 10){
   dtostrf(volume,2,0,out);
    text(out,281,170,11);
}else{
    dtostrf(volume,2,0,out);
    text(out,287,170,11);
  }
char charIn = 0;
byte i = 0;
char stringIn[32] = "";

while(Serial.available()){
charIn = Serial.read();
stringIn[i] = charIn;
i += 1;
}
  // Clear screen and display the serial buffer as text
  if (stringIn[0]){
    fill(0);
    stroke(0);
   rect(75,120,115,30);
   stroke(153);
   text(stringIn,120,135,15);
  }
}


wildbill

Common issue:
Code: [Select]

char charIn = 0;
byte i = 0;
char stringIn[32] = "";

while(Serial.available()){
charIn = Serial.read();
stringIn[i] = charIn;
i += 1;
}

You're building stringIn, assuming that all the channel numbers arrived at once, which is a risky thing to assume. I expect that the first time around it displays the 9 and next time overwrites it with the two that remain - 69. You should be null terminating the thing too.

AaronD

yeah thats exactly what its doing. so out of this
Code: [Select]
char charIn = 0;
byte i = 0;
char stringIn[32] = "";

while(Serial.available()){
charIn = Serial.read();
stringIn[i] = charIn;
i += 1;
}

what do i need to change or add?

wildbill

One possibility would be to use println on the sending side and then only print your string when you get the end of line marker. Alternatively send some other character as an end of packet marker.

Go Up