TFT displaying odd characters - Updated

I have successfully managed to send various messages from one Arduino to another. I have set up one with four buttons and a an RF transmitter. I'm using the Virtual Wire library. When an individual button is pressed, the RF receiver on the second Arduino displays the message in it's Serial Monitor. I want this message also appear on a TFT that is also attached to the second Arduino. The problem is that the TFT displays odd characters.

For instance, if I send the message "Message 1", the TFT displays y 1/4 1/2 1/2 a N W h
If I send "Message 2", the TFT displays y 1/4 1/2 1/2 a N W i

Obviously y = M, 1/4 = e, 1/2 = s ...and so on

***There's a letter missing in each of the example above, I think it corresponds to the 5th character. I'll check when I get a chance tomorrow)

(The fractions above are one character each and the N has a line above it).

The code to print to the Serial Monitor is
Serial.print((char )buf*);*
The code to print to the TFT is
tft.print(((char )buf*), ST7735_WHITE);*
Any help would be appreciated

Forget about messages coming from the other Arduino for now, can you print strings to the TFT display from the Arduino that it is connected to ?

Hi

I've modified the post. Yes, I can print strings to the TFT

The code to print to the Serial Monitor is
Serial.print((char )buf);

The code to print to the TFT is
tft.print(((char )buf), ST7735_WHITE);

What type is buf? Why do you need to cast to char? To char * might make sense. To char does not.

Where is the rest of your code? http://snippets-r-us.com is down the road a ways.

Hi Paul

Thanks for posting.

I am getting the message from an RF receiver and successfully seeing this via the Serial Monitor. Here is the loop code

void loop()
{
  
    tft.fillScreen(ST7735_BLACK);
    tft.setTextSize(2);
    tft.setCursor(10, 20);
    tft.setTextWrap(true);

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

    for (i = 0; i < buflen; i++)
	{
    tft.print(((char )buf[i]), ST7735_WHITE);
    Serial.print((char )buf[i]);
    }
    Serial.println(""); 
    delay (10000);
 }
}

I don't understand why you
A) Can't post ALL of your code
B) Don't NULL terminate the array and use it as a string
C) Use Tools + Auto Format to fix your horrid indenting

    if (vw_get_message(buf, &buflen)) 
    {
       buf[buflen] = '\0';
       tft.print(buf, ST7735_WHITE);
       Serial.print(buf);
    }

Some casting may be required, depending on how buf is defined.

Hi

I don't have access to the actual code until later; I have it in text format (Notepad file). Here it is

#define sclk 13
#define mosi 11
#define cs   10
#define dc   9
#define rst  8


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

Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst);
float p = 3.1415926;


void setup()
{
    tft.initR(INITR_BLACKTAB);
  
    Serial.begin(9600);
  
    vw_set_rx_pin(7);           
    vw_set_ptt_inverted(true); 
    vw_setup(2000);	 
    vw_rx_start();      
}


void loop()
{
  
    tft.fillScreen(ST7735_BLACK);
    tft.setTextSize(2);
    tft.setCursor(10, 20);
    tft.setTextWrap(true);

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

    for (i = 0; i < buflen; i++)
	{
    tft.print(((char )buf[i]), ST7735_WHITE);
    Serial.print((char )buf[i]);
    }
    Serial.println(""); 
    delay (10000);
 }
}

Paul

Apologies for the delay (I've not been able to get online). Your suggestion of using char * worked like a dream.

Thanks again

Rob