RA8875 textWrite Problem :)

Hi, I am having trouble writing text to tft using the textWrite() function from the Adafruit_RA8875-master library. I need to write byte by byte from a textfile in my sd card module.
Here is my code:

String orders;
char *chr;

void writeorders()
{
test1 = SD.open("sample.txt"); //the text file contains "$location 1* $location 2* @"
if (test1)
{
Serial.println("sample.txt:");
// read from the file until there's nothing else in it:
while (test1.available())
{
orders=test1.readString();
chr = orders.c_str();
}
// close the file:
test1.close();
}
else
{
//if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
int count=0;
tft.textMode();
tft.textTransparent(RA8875_BLACK);
tft.textEnlarge(1);
tft.textSetCursor(25,150+35);

for(int h=0; h<=getLength(chr);h++)
{
Serial.print(chr);
tft.textWrite(chr);
}
}
the output from my serial is correct
but the output from my tft are garbage
but when write the whole char pointer its okay
tft.textWrite(chr);
but I really need to write it 1 character at a time. Thank you in advance :slight_smile:

for(int h=0; h<=getLength(chr);h++)

Why do you have your own function that is a duplicate of strlen()? Why did you not post it?

If the string is "Sam", the length is 3. Your loop prints the 0th, 1st, 2nd, and 3rd characters of "Sam". What is the 4th character, and how do you print a NULL?

A link to the library you are using is certainly in order.

this is the library I am using sir,

for(int h=0; h<=getLength(chr)-1;h++)

is that correct now sir?

is that correct now sir?

It's better, but you still haven't posted the code of that function. Nor have you explained why you needed to reinvent strlen().

this is the library I am using sir,

So, it's as I though. The textWrite() method is defined like so:

 void textWrite(const char* buffer, uint16_t len=0);

So, when you pass it a char, instead of an array of chars, it looks in the char variable to get the address where the data is. 'd' is NOT a pointer to where a character is stored, but it is treated as one.

You should modify the library to add an overload that takes one char.

I just found the getLenght() command on google sir it is just like strlen() sorry for the confusion.

void Adafruit_RA8875::textWrite(const char* buffer, uint16_t len)
{
if (len == 0) len = strlen(buffer);
writeCommand(RA8875_MRWC);
for (uint16_t i=0;i<len;i++)
{
writeData(buffer*);*
#if defined(AVR)

  • if (_textScale > 1) delay(1);*
    #elif defined(arm)
  • // This delay is needed with textEnlarge(1) because*
  • // Teensy 3.X is much faster than Arduino Uno*
  • if (_textScale > 0) delay(1);*
    #endif
  • }*
    }
    is this the code that I should modify?

is this the code that I should modify?

Is your code really in italics?

Italics? haha the last code I send is from the ra8875 library sir

magicgreenhalaman:
Italics? haha the last code I send is from the ra8875 library sir

Does it really look like what you posted? I seriously doubt it.

There are stickies at the top of the forum. It is past time that you read them.

Yess sir it does

magicgreenhalaman:
Yess sir it does

Please compare these lines that you posted, to your actual code.

  for (uint16_t i=0;i<len;i++)
  {
    writeData(buffer);

I'm nearly certain that the ARE differences.