I want to display serial data to my 2.8" TFT, i have the data in my string "inputString" im using TFTLCD lib. and the "tft.drawString(170, 213, xxxxxx, RED, 2);" i think that i have to convert the "inputString" to some thing and then put it where the "xxxxxx" are but dont now how
Can you masters please teach me how?
Not all that easy in that snippet. Where is inputString defined?
It must be a String, though, or
inputString += inChar;
wouldn't work.
The String class has a toCharArray() method to get the char array that the object wraps. That char array can then be passed to the function to display text on the touch screen.
Not all that easy in that snippet. Where is inputString defined?
It must be a String, though, or
inputString += inChar;
wouldn't work.
The String class has a toCharArray() method to get the char array that the object wraps. That char array can then be passed to the function to display text on the touch screen.
I got this " String inputString = ""; ""at start in the code
Can you please write a example because i dont understand what you candly tell.
I have a bug in the code, im sending 2 diferent wire: Wire.write("1234567890qweyuiopt") and Wire.write("1234567890XXXXXXXXt") to simulate diderent incoming data.
#include "TFTLCD.h"
#include <EEPROM.h>
#include <Wire.h>
#include <TimedAction.h>
String inputString = "";
boolean stringComplete = false;
byte atm = 50;
char* tok = "";
TimedAction timedAction = TimedAction(11,QW);
char value1[5] ;
char value2[5] ;
char value3[50] ;
void setup(void) {
Wire.begin(2);
Serial.begin(9600); // start serial for output
}
void loop() {
timedAction.check();
} // FIM DE LOOP ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
void QW(){
Wire.onReceive(receiveEvent); // register event
}
void receiveEvent(int howMany)
{
while(Wire.available()) // slave may send less than requested
{
char inChar = (char)Wire.read(); // receive a byte as character
inputString += inChar;
if (inputString.startsWith("12")) {
if (inChar == 't') {
stringComplete = true;
if (inputString[2]=='3'&&inputString[3]=='4'&&inputString[4]=='5')
Serial.println(inputString);
inputString.toCharArray(tok,atm); // THE LINE PROBLEM ++++++++++++
tft.drawString (1, 113, tok, RED, 2);
}
}
}
inputString = "";
tok = "";
atm = 0;
}
Im using here a simplifide code and Serial.println(inputString); to debug. If i tacke off this line "inputString.toCharArray(tok,atm);" that i need to displas incoming data to tft it works great i get "1234567890qweyuiopt" and "1234567890XXXXXXXXt" over and over again, with the "inputString.toCharArray(tok,atm);" it stacks on the 1st Wire.write that gets.
Please hellp me.
char* tok = "";
inputString.toCharArray(tok,atm); // THE LINE PROBLEM ++++++++++++
Of course it's a problem. And you've already been told why and what to do about it.
The tok variable is a pointer. It points to one byte of memory. You are lying to the toCharArray function, telling it that it is OK to extract up to 50 characters into this one element memory location. IT IS NOT.
inputString.toCharArray(tok,atm); // THE LINE PROBLEM ++++++++++++
Of course it's a problem. And you've already been told why and what to do about it.
The tok variable is a pointer. It points to one byte of memory. You are lying to the toCharArray function, telling it that it is OK to extract up to 50 characters into this one element memory location. IT IS NOT.
I change to char tok[50]; and Serial.println(inputString); but when do Serial.println(tok); for debuging i still get the same starting problem, do i need to empty char tok[50];? if yes please teache how.
Frankly, I can't figure out why you need the String class in the first place. Get rid of the String object. Get the data from the Wire object, and store in in the char array, with the resource wasting actions of the String class.
PaulS:
Frankly, I can't figure out why you need the String class in the first place. Get rid of the String object. Get the data from the Wire object, and store in in the char array, with the resource wasting actions of the String class.
Hi,
Im very confuse now can you please show me a example Dear Sir ?
You know that you are sending 50 or fewer bytes. So, try something like this:
char buffer[50];
byte index;
void receiveEvent(int howMany)
{
index = 0;
while(Wire.available()) // slave may send less than requested
{
char inChar = (char)Wire.read(); // receive a byte as character
buffer[index++] = inChar; // Store the character and advance the pointer
buffer[index] = '\0'; // NULL terminate the string
]
// All the received data is now in buffer. Send it to the TFT
tft.drawString (1, 113, buffer, RED, 2);
}