Hello I'm using a LCD and i got problem with the LCD i don't know why but the texte won't stop blinking and the letter is one time here one time not here I dont know what to do
here my code
#include <SD.h>
//============= BNO055=======================//
#include "BNO055_support.h" //Contains the bridge code between the API and Arduino
#include <Wire.h>
//==================LCD=====================================//
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
//======Déclaration des I/O=================================================
#define TFT_CS 7 // LCD
#define TFT_DC 6 // LCD
#define TFT_RST 5// LCD
#define TFT_BACKLIGHT 2 // LCD fond d'écran
#define BLACK 0x000
//===========Déclarations des Instances================//
//This structure contains the details of the BNO055 device that is connected. (Updated after initialization)
struct bno055_t myBNO;
struct bno055_euler myEulerData; //Structure to hold the Euler data
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
//===========================================================
const int chipSelect = SS1; // Pin utilisé pour le MKRzero (28)
unsigned long lastTime = 0;
int loadDataCheck; //Checks if data needs to be loaded
//======Choix des couleurs du LCD ===========================================
char fond1 = 0;
char fond2 = 0;
char fond3 = 0;
char text1 = 0;
char text2 = 255;
char text3 = 0;
// the setup function runs once when you press reset
// or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT); //Pin de l'arduino MKRzero utilisée
pinMode(TFT_BACKLIGHT,OUTPUT);
tft.println("DataLogger Exemple:");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) { // si la carte SD n'est pas détéctée
tft.println("Carte SD non présente,ou probleme"); // Carte SD non présente
// don't do anything more:
return;
}
tft.println("Carte Initialisée.");
//within one second to pass unstable status
delay(1000);
//======================Initialisation du LCD==============================================
tft.initR(INITR_BLACKTAB);
digitalWrite(TFT_BACKLIGHT,HIGH);
tft.setRotation(0);
uint16_t time = millis();
tft.fillScreen(ST7735_BLACK);
time = millis() - time;
Serial.println(time, DEC);
delay(500);
//============Initalisation du capteur BNO055============================
Wire.begin();
BNO_Init(&myBNO); //Assigning the structure to hold information about the device
//Configuration pour NDoF mode
bno055_set_operation_mode(OPERATION_MODE_NDOF);
//=====================================================================================
delay(500);
Serial.begin(9600);
tft.println("Système pret ._.");
}
// the loop function runs over and over again forever
void loop() {
//=====Effacement de l'écran===============================================
tft.setTextWrap(true);
tft.fillScreen(ST77XX_BLACK);
delay(500);
//======================================== Ecriture des titres================================
tft.setCursor(25, 2);
tft.setTextColor(ST77XX_YELLOW);
tft.setTextSize(2);
tft.println("POSITION EULER");
//=========================Affichhage des valeurs du capteur sur LCD=======
/*
unsigned long currentTime=millis();
if ((millis() - lastTime) >= 100) //To stream at 10 Hz without using additional timers
{
lastTime = millis();
bno055_read_euler_hrp(&myEulerData); //Update Euler data into the structure
//Serial.print(" Temps : "); //To read out the Time Stamp
// Serial.println(lastTime);
tft.setCursor(0, 50);
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(2);
tft.print(" Axe z(yaw): ");
tft.setCursor(25, 50);
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(2);
tft.println(float(myEulerData.h) / 16.00);// declarer une fonction qui prend en compte les variables x,y et z
//Serial.print(" Axe z(yaw): "); //To read out the Heading (Yaw)
//Serial.println(float(myEulerData.h) / 16.00); //Convert to degrees
// Serial.print(" Axe X(Roll): "); //To read out the Roll
// Serial.println(float(myEulerData.r) / 16.00); //Convert to degrees
// Serial.print(" Axe Y (Pitch): "); //To read out the Pitch
// Serial.println(float(myEulerData.p ) / 16.00); //Convert to degrees
//Serial.println(); //Extra line to differentiate between packets
}
if (loadDataCheck) logData();
}
void dataCheck(){
loadDataCheck=1;
}
void logData(void) {
String dataString = "";
File dataFile = SD.open("Position.txt", FILE_WRITE); // ouvrir le document sur la carte SD
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the Serial port too:
tft.println(dataString);
}
// if the file isn't open, pop up an error:
else {
tft.println("error opening datalog.txt");
}
loadDataCheck=0;
*/
}
You clear the screen, stay so half of second, than print the text and clear it again after a moment. What are you expecting from it? Of course the text will blinks with your code...
Why do you clear the screen in each call the loop? And why do you print your text again and again, if it doesn't change?
Update the screen ONLY if you changed the text on it.
plus the position is going to disappear after so it need to be clearing
when i put the value with the captor it do the same thing the value are not on the screen and keep disappear
Because when the position disppear it's goign to put this text SD okay then the Position is going to come back but I try what you said to put the clearing after the position, but i havent change anything the texte Position continue to lag
#include <SD.h>
//============= BNO055=======================//
#include "BNO055_support.h" //Contains the bridge code between the API and Arduino
#include <Wire.h>
//==================LCD=====================================//
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
//======Déclaration des I/O=================================================
#define TFT_CS 7 // LCD
#define TFT_DC 6 // LCD
#define TFT_RST 5// LCD
#define TFT_BACKLIGHT 2 // LCD fond d'écran
#define BLACK 0x000
//===========Déclarations des Instances================//
//This structure contains the details of the BNO055 device that is connected. (Updated after initialization)
struct bno055_t myBNO;
struct bno055_euler myEulerData; //Structure to hold the Euler data
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
//===========================================================
const int chipSelect = SS1; // Pin utilisé pour le MKRzero (28)
unsigned long lastTime = 0;
int loadDataCheck; //Checks if data needs to be loaded
//======Choix des couleurs du LCD ===========================================
char fond1 = 0;
char fond2 = 0;
char fond3 = 0;
char text1 = 0;
char text2 = 255;
char text3 = 0;
// the setup function runs once when you press reset
// or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT); //Pin de l'arduino MKRzero utilisée
pinMode(TFT_BACKLIGHT,OUTPUT);
Serial.println("DataLogger Exemple:");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) { // si la carte SD n'est pas détéctée
Serial.println("Carte SD non présente,ou probleme"); // Carte SD non présente
// don't do anything more:
return;
}
//tft.println("Carte Initialisée.");
//within one second to pass unstable status
delay(1000);
//======================Initialisation du LCD==============================================
tft.initR(INITR_BLACKTAB);
digitalWrite(TFT_BACKLIGHT,HIGH);
tft.setRotation(0);
uint16_t time = millis();
tft.fillScreen(ST7735_BLACK);
time = millis() - time;
Serial.println(time, DEC);
delay(500);
//============Initalisation du capteur BNO055============================
Wire.begin();
BNO_Init(&myBNO); //Assigning the structure to hold information about the device
//Configuration pour NDoF mode
bno055_set_operation_mode(OPERATION_MODE_NDOF);
//=====================================================================================
delay(500);
Serial.begin(9600);
//tft.println("Système pret ._.");
}
// the loop function runs over and over again forever
void loop() {
//======================================== Ecriture des titres================================
tft.setCursor(25, 2);
tft.setTextColor(ST77XX_YELLOW);
tft.setTextSize(2);
tft.println("POSITION");
//=========================Affichhage des valeurs du capteur sur LCD=======
unsigned long currentTime=millis();
if ((millis() - lastTime) >= 100) //To stream at 10 Hz without using additional timers
{
lastTime = millis();
bno055_read_euler_hrp(&myEulerData); //Update Euler data into the structure
//=====Effacement de l'écran===============================================
tft.setTextWrap(true);
tft.fillScreen(ST77XX_BLACK); // Effacement de l'écran
delay(1);
//Serial.print(" Temps : "); //To read out the Time Stamp
// Serial.println(lastTime);
tft.setCursor(0, 50);
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(2);
tft.print("z:");
tft.setCursor(45, 50);
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(2);
tft.println(float(myEulerData.h) / 16.00);// declarer une fonction qui prend en compte les variables x,y et z
//Serial.print(" Axe z(yaw): "); //To read out the Heading (Yaw)
//Serial.println(float(myEulerData.h) / 16.00); //Convert to degrees
// Serial.print(" Axe X(Roll): "); //To read out the Roll
// Serial.println(float(myEulerData.r) / 16.00); //Convert to degrees
// Serial.print(" Axe Y (Pitch): "); //To read out the Pitch
// Serial.println(float(myEulerData.p ) / 16.00); //Convert to degrees
//Serial.println(); //Extra line to differentiate between packets
}
if (loadDataCheck) logData();
}
void dataCheck(){
loadDataCheck=1;
}
void logData(void) {
String dataString = "";
File dataFile = SD.open("Position.txt", FILE_WRITE); // ouvrir le document sur la carte SD
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the Serial port too:
tft.println(dataString);
}
// if the file isn't open, pop up an error:
else {
tft.println("error opening datalog.txt");
}
loadDataCheck=0;
}
Sorry, don't you understand the code what you editing?
What are you expecting, when print "POSITION" and almost immediately delete it, clearing the screen?
The line
tft.fillScreen(ST77XX_BLACK);
should be BEFORE any printing , otherwise the text will be deleted.