RF 433 sending message and show in TFT 1.8 , PROBLEM !

Good Morning Everyone,

I thinking to recive message from a TX Rf 433 and showing this in a TFT 1.8 display.

have a problem, i cannot show in TFT 1.8 display a message capture from TX, a simple text “Hello World” .

My Code for RX is;

#include <VirtualWire.h>
#include <Adafruit_ST7735.h>
#include <Adafruit_GFX.h>
 #include <SPI.h>

#define TFT_CS     10
#define TFT_RST    8                      
#define TFT_DC     9
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS,  TFT_DC, TFT_RST);

// Option 2: use any pins but a little slower!
#define TFT_SCLK 13   // set these to be whatever pins you like!
#define TFT_MOSI 11   // set these to be whatever pins you like!
 
 char myString = "22";
 char msj = "";
 char text = "";
 char ch = "";

 
void setup()
{
    tft.initR(INITR_BLACKTAB);
    tft.fillScreen(ST7735_BLACK); 
    printUI();
    delay(1000);
 
  // Bloques de Texto
  //testdrawtext("Bloque de texto", ST77XX_WHITE);
 
  
     Serial.begin(9600);  // Debugging only
     Serial.println("Emisor: Setup");

       // Se inicializa el RF
    vw_set_ptt_inverted(true); // Inicializa el software de VirtualWire
    vw_setup(2400);  // velocidad: Bits per segundo
    vw_set_rx_pin(2);    //Pin 2 como entrada del RF
    vw_rx_start();       // Se inicia como receptor
}


void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    //verificamos si hay un dato valido en el RF
    if (vw_get_message(buf, &buflen)) 
    {
  int i;

  digitalWrite(13, true); 
  Serial.print("Mensaje: "); 
  
  for (i = 0; i < buflen; i++)
  {

      char msj = (buf[i]);
      Serial.write(msj);
      String msjString = String(msj);
  
      char ch = Serial.read();
      text = ch;

      //printText(msj, ST7735_RED,0,100,1); [b]// When put this code, don't work and reset tft display ,..[/b]
      //printText(ch, ST7735_RED,0,100,1); [b]// When put this code, don't work and reset tft display ,..[/b]

  }
  
  Serial.println("");
        digitalWrite(13, false);
    }
}

void printText(char *text, uint16_t color, int x, int y,int textSize)
{
  tft.setCursor(x, y);
  tft.setTextColor(color);
  tft.setTextSize(textSize);
  tft.setTextWrap(true);
  tft.print(text);
}
void testdrawtext(char *text, uint16_t color) {
  tft.setCursor(0, 0);
  tft.setTextColor(color);
  tft.setTextWrap(true);
  tft.print(text);
}

void printUI() {
  tft.setRotation(2);
  tft.fillScreen(ST77XX_BLACK);
  tft.setTextWrap(false);
  tft.fillScreen(ST77XX_BLACK);
  tft.setCursor(0, 5);
  tft.setTextColor(ST77XX_GREEN);
  tft.setTextSize(1);
  tft.println("Menu 1");
  tft.setCursor(25, 70);
  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(2);
  tft.println("SMS RF");
  tft.setCursor(0, 150);
  tft.setTextColor(ST77XX_GREEN);
  tft.setTextSize(1);
  tft.println("Menu 2");
  tft.setCursor(0, 100);
      delay(2000);


  tft.fillScreen(ST77XX_BLACK);
  tft.setTextWrap(false);
  tft.fillScreen(ST77XX_BLUE);
  tft.setCursor(0, 5);
  tft.setTextColor(ST77XX_GREEN);
  tft.setTextSize(1);
  tft.println("Menu 3");

  
  tft.setTextColor(ST77XX_RED);
  tft.setTextSize(1);
  printText(ch, ST7735_RED,0,100,1); [b]// HERE need  show the msg capture from TX, this command don't work ,..[/b]

  tft.setCursor(0, 50);
  tft.setTextColor(ST77XX_GREEN);
  tft.setTextSize(1);
  testdrawtext(msj, ST77XX_WHITE); [b]// HERE need  show the msg capture from TX, this command don't work ,..[/b]

  
}
//void printUI()
//{
   // tft.setRotation(2);
  // printText("Mensaje Recibido", ST7735_GREEN,10,5,1);  

//}

Anyone can let know , what i can do for see the message in the TFT display,

thanks !

pd: sorry for my bad english …

 char myString = "22";
 char msj = "";
 char text = "";
 char ch = "";

Single quotes are for single characters. Single characters can be stored in a char variable.

Double quotes are for strings. A string can NOT be stored in a char variable. They can be stored in a char array.

You are using scalar variables where you need arrays.

thanks for you reply PaulS,

how i can edit the code for get the message in the TFT 1.8 ,

thanks..

how i can edit the code for get the message in the TFT 1.8 ,

Getting the message doesn't appear to be the problem. The code appears to already do that.

Putting the message on the TFT appears to be the problem. And, the problem is that printText() takes a string - a NULL terminated array of chars, and you don't have any strings, because the only array you have is not a char array and it is not NULL terminated.

You could lie to the function, and tell it that the byte array is a char array:

printText((char *)buf, ST7735_RED, 0, 100, 1); // Note the cast. Spaces added for readability

However, that still won't work, because buf is not NULL terminated. But, that is easy to fix: uint8_t buf[VW_MAX_MESSAGE_LEN + 1]; uint8_t buflen = VW_MAX_MESSAGE_LEN; //verificamos si hay un dato valido en el RF if (vw_get_message(buf, &buflen)) { buf[buflen] = '\0';

thanks for you reply,

edit the code, first put ;
this is how a declare a “chair array” ?

 char myString [30];
 char msj [30];
 char text [30];
 char ch [30];

then edit this;

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN+1];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    
    if (vw_get_message(buf, &buflen)) 
    {
  int i;

  digitalWrite(13, true); 
  Serial.print("Mensaje: "); 
  
  for (i = 0; i < buflen; i++)
  {
      buf[buflen] = '\0';
      char msj = (buf[i]);
      Serial.write(msj);
      String msjString = String(msj);
      char ch = Serial.read();
   

  }

to finish wait print the TFT with;

  tft.setTextColor(ST77XX_RED);
  tft.setTextSize(1);
  printText((char *)msj, ST7735_RED,0,100,1);

  tft.setTextColor(ST77XX_RED);
  tft.setTextSize(1);
  printText((char *)buf, ST7735_RED,0,100,1);

  tft.setTextColor(ST77XX_GREEN);
  tft.setTextSize(1);
  testdrawtext(msj, ST77XX_WHITE);

But don’t work, the message don’t appears in TFT…

you alright to say “Putting the message on the TFT appears to be the problem” this the problem.

thanks…

You should write a small sketch just to try writing to your TFT.

That would help you understand what you are doing wrong!

.

thanks for you reply ieee488,

i can show text in the TFT display, whit a simple code;

  tft.setTextColor(ST77XX_GREEN);
  tft.setTextSize(1);
  testdrawtext("Hello World", ST77XX_WHITE);

the problem is store the message capture from TX an show in the TFT display.

{
    uint8_t buf[VW_MAX_MESSAGE_LEN+1];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    
    if (vw_get_message(buf, &buflen)) 
    {
  int i;

  digitalWrite(13, true); 
  Serial.print("Mensaje: "); 
  
  for (i = 0; i < buflen; i++)
  {
      buf[buflen] = '\0';
      [b]char msj = (buf);      // i think the "msj" contain the message capture form TX , but "msj" don't show TFT. [color=red][/color][/b]
      Serial.write(msj);      //  Here message print in the serial no problem ..
      String msjString = String(msj);
      char ch = Serial.read();
   

  }

thanks…

Just use this call, after terminating the string in buf[] with zero as described in reply #3.

printText((char *)buf, ST7735_RED, 0, 100, 1); // Note the cast. Spaces added for readability

Please use code tags when posting code. You can edit your original post to replace the quote tags.

thanks for you reply, i tried put

printText((char *)buf, ST7735_RED,0,100,1);

but don’t work,

you can write the code, how as you think this work!

thanks…

Define "but don't work". Post the error message(s) and/or describe what happens.

Always post your current code, using code tags, so we can see what you are doing wrong.

For example, most of this is wrong:

      buf[buflen] = '\0';
      [b]char msj = (buf);      // i think the "msj" contain the message capture form TX , but "msj" don't show TFT. [color=red][/color][/b]
      Serial.write(msj);      //  Here message print in the serial no problem ..
      String msjString = String(msj);
      char ch = Serial.read();

Tanks for you reply,

i need send by RF a message to receptor and putting this message in TFT display.

Actually i can recive the message and show in “Monitor Serial” into arduino program.

the problem i can’t putting TFT display the message recive .

this is TX emisor code;

#include <VirtualWire.h>

void setup()
{
    Serial.begin(9600);  
    Serial.println("Emisor: Setup");

    // Se inicializa el RF
    vw_setup(2400); // velocidad: Bits per segundo
    vw_set_tx_pin(12); //Pin 2 como salida para el RF 
}

void loop()
{
    const char *msg = "Prueba Coneccion";

    digitalWrite(13, true); // Parpadeamos  el led al enviar 
    vw_send((uint8_t *)msg, strlen(msg));
    vw_wait_tx(); //Esperamos hasta que el mensaje se envie
    digitalWrite(13, false);
    delay(2000);
}

this is RX receptor code;

#include <VirtualWire.h>
#include <Adafruit_ST7735.h>
#include <Adafruit_GFX.h>
 #include <SPI.h>

#define TFT_CS     10
#define TFT_RST    8                      
#define TFT_DC     9
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS,  TFT_DC, TFT_RST);

// Option 2: use any pins but a little slower!
#define TFT_SCLK 13   // set these to be whatever pins you like!
#define TFT_MOSI 11   // set these to be whatever pins you like!
 
 char myString = "22";
 char msj = "";
 char text = "";
 char ch = "";

 
void setup()
{
    tft.initR(INITR_BLACKTAB);
    tft.fillScreen(ST7735_BLACK); 
    printUI();
    delay(1000);
 
  // Bloques de Texto
  //testdrawtext("Bloque de texto", ST77XX_WHITE);
 
  
     Serial.begin(9600);  // Debugging only
     Serial.println("Emisor: Setup");

       // Se inicializa el RF
    vw_set_ptt_inverted(true); // Inicializa el software de VirtualWire
    vw_setup(2400);  // velocidad: Bits per segundo
    vw_set_rx_pin(2);    //Pin 2 como entrada del RF
    vw_rx_start();       // Se inicia como receptor
}


void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    //verificamos si hay un dato valido en el RF
    if (vw_get_message(buf, &buflen)) 
    {
  int i;

  digitalWrite(13, true); 
  Serial.print("Mensaje: "); 
  
  for (i = 0; i < buflen; i++)
  {

      char msj = (buf[i]);
      Serial.write(msj);
      String msjString = String(msj);
  
      char ch = Serial.read();
      text = ch;

      //printText(msj, ST7735_RED,0,100,1); [b]// When put this code, don't work and reset tft display ,..[/b]
      //printText(ch, ST7735_RED,0,100,1); [b]// When put this code, don't work and reset tft display ,..[/b]

  }
  
  Serial.println("");
        digitalWrite(13, false);
    }
}

void printText(char *text, uint16_t color, int x, int y,int textSize)
{
  tft.setCursor(x, y);
  tft.setTextColor(color);
  tft.setTextSize(textSize);
  tft.setTextWrap(true);
  tft.print(text);
}
void testdrawtext(char *text, uint16_t color) {
  tft.setCursor(0, 0);
  tft.setTextColor(color);
  tft.setTextWrap(true);
  tft.print(text);
}

void printUI() {
  tft.setRotation(2);
  tft.fillScreen(ST77XX_BLACK);
  tft.setTextWrap(false);
  tft.fillScreen(ST77XX_BLACK);
  tft.setCursor(0, 5);
  tft.setTextColor(ST77XX_GREEN);
  tft.setTextSize(1);
  tft.println("Menu 1");
  tft.setCursor(25, 70);
  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(2);
  tft.println("SMS RF");
  tft.setCursor(0, 150);
  tft.setTextColor(ST77XX_GREEN);
  tft.setTextSize(1);
  tft.println("Menu 2");
  tft.setCursor(0, 100);
      delay(2000);


  tft.fillScreen(ST77XX_BLACK);
  tft.setTextWrap(false);
  tft.fillScreen(ST77XX_BLUE);
  tft.setCursor(0, 5);
  tft.setTextColor(ST77XX_GREEN);
  tft.setTextSize(1);
  tft.println("Menu 3");

  
  tft.setTextColor(ST77XX_RED);
  tft.setTextSize(1);
  printText(ch, ST7735_RED,0,100,1); [b]// HERE need  show the msg capture from TX, this command don't work ,..[/b]

  tft.setCursor(0, 50);
  tft.setTextColor(ST77XX_GREEN);
  tft.setTextSize(1);
  testdrawtext(msj, ST77XX_WHITE); [b]// HERE need  show the msg capture from TX, this command don't work ,..[/b]

  
}
//void printUI()
//{
   // tft.setRotation(2);
  // printText("Mensaje Recibido", ST7735_GREEN,10,5,1);  

//}

if anyone can write the correct code for show the message captured in line “char msj = (buf*);” and show in TFT display, i appreciative this.*
thanks.

As I said, all of this is wrong. Delete it.

    if (vw_get_message(buf, &buflen))
    {
 for (i = 0; i < buflen; i++)
  {

      char msj = (buf[i]);
      Serial.write(msj);
      String msjString = String(msj);
 
      char ch = Serial.read();
      text = ch;

      //printText(msj, ST7735_RED,0,100,1); [b]// When put this code, don't work and reset tft display ,..[/b]
      //printText(ch, ST7735_RED,0,100,1); [b]// When put this code, don't work and reset tft display ,..[/b]

  }.

Replace it with:

    if (vw_get_message(buf, &buflen))
    {
    buf[buflen]=0;
    Serial.println(buf);
    }

When you have verified that the above works and prints the correct message on the serial monitor, replace the “Serial.println(buf)” with something like “printText(buf, ST7735_RED,0,100,1);”

Thanks for you reply,

i tried with you code, delete and replace , but when compile says error ;

call of overloaded ‘println(uint8_t [80])’ is ambiguous

i edit like that

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
   
    if (vw_get_message(buf, &buflen)) 
  {
    buf[buflen]=0;
    Serial.println(buf);
    }
  
  Serial.println("");
        digitalWrite(13, false);
    }
}

i tried second option, compile but don’t get the message in “serial monitor”

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
   
    if (vw_get_message(buf, &buflen)) 
  {
    buf[buflen]=0;
    Serial.println((char)buf);
    }
  
  Serial.println("");
        digitalWrite(13, false);
    }
}

in this option get the message in the “serial monitor” but can’t to putting in TFT display ;

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
   
    if (vw_get_message(buf, &buflen)) 
                     {
  int i;

  digitalWrite(13, true); 
  Serial.print("Mensaje: "); 
  
  for (i = 0; i < buflen; i++)
  {
      char msj = (buf[i]);
      String msj1 = (char *)buf;
                Serial.write(msj);

  }
  
  Serial.println("");
        digitalWrite(13, false);
    }
}

i can’t putting the message capture to TFT Display :’(

call of overloaded 'println(uint8_t [80])' is ambiguous

The problem is your variable type definition "uint8_t buf[]", which is what vw_get_message() expects.

One way to fix this is by declaring buf[] to be a different but equivalent variable type for Serial.println().

    if (vw_get_message(buf, &buflen))
    {
    buf[buflen]=0;
    Serial.println((char *)buf); //redefine buf[] to be of type (char *)
    }

You have started a very complex project without learning the programming language first. You can expect many more such difficulties.

Thanks for you reply,

i edit the code, and get the message in "Serial Monitor";

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
   
    if (vw_get_message(buf, &buflen))
    {
    buf[buflen]=0;
    Serial.println((char *)buf); //redefine buf[] to be of type (char *)

    }
}

when i tried to putting the message in TFT Display don't work,

    if (vw_get_message(buf, &buflen))
    {
    buf[buflen]=0;
    Serial.println((char *)buf); //redefine buf[] to be of type (char *)
    printText((char *)buf, ST7735_RED,0,100,1);

    }
}

i tried with;

printText(buf, ST7735_RED,0,100,1);
printText((char *)buf, ST7735_RED,0,100,1);

what i can do?

thanks ,..

Stop what you are doing now. First learn how to print to the TFT display using examples provided with the library, before incorporating it into a more complex project.

Again: "don't work" is not a description of your problem. Please read the "How to use this forum" post and follow the directions.

    Serial.println((char *)buf); //redefine buf[] to be of type (char *)

That is NOT what the cast does. It causes the variable to be interpreted (NOT redefined) as a char array.

Thanks all for you reply,

i will putting message in TFT Display .

the problem was initialization the RF module in "void printUI()" this controller TFT display ,added 2 code;

void printUI() {

  initialize_receiver();

///my code Menu....

}

second added code;

void initialize_receiver() {
  /* Initialises the DIO pin used to receive data from the Rx module */
  vw_set_rx_pin(2);  
  /* Receive at 2000 bits per second */
  vw_setup(2400);
  /* Enable the receiver */
  vw_rx_start();  
}

after that with this command the TFT Print the Message captured.

    printText((char *)buf,ST7735_RED,5,10,1);

thanks all for you reply.

It causes the variable to be interpreted (NOT redefined) as a char array.

Pointless point. The semantics are completely lost here.