Hi all, this is my first post here but I have used this forum at great length to solve many problems I have faced - so thank you to all those who have unknowingly helped.
There is a new problem I face that I have not been able to solve - one that is a little difficult to search for so I am posting here.
Essentially, I have some odd characters showing on my screen where there should be none. I have attached two images which show what I mean:
ard1.jpg shows what the problem looks like
ard2.jpg shows what it should look like (though they are slightly different given that they were taking at slightly different stages of development, it should be clear what the problem is)
The hardware I am using is pretty much the really cheap, eBay versions of a 3.2 touch LCD, Arduino Mega2560 and display shield.
My code is below, and undoubtedly, there will be all sorted of issues with structure, syntax, wasted memory and so on. Since this is my first ever code I expect it to, in many ways, suck, but I would be VERY happy to hear some advice, particularly on reading the DS18B20 sensors - this seems to take ages and I cant seem to get it to happen faster.
I have commented out some items, just to check they werent causing the problem, so as of right now, the issue is still there. I have included the font files, just in case they are what is causing the problem. The font files all came from the Rinky-Dink website.
Thanks, my code is below.
#include <SPI.h>
#include <SD.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// This program requires the UTFT library.
#include <UTFT.h>
// Declare which fonts we will be using
extern uint8_t SevenSegNumFont[];
extern uint8_t SevenSegSmall[];
extern uint8_t BigSymbols[];
extern uint8_t SmallSymbols[];
extern uint8_t arial[];
extern uint8_t arialB[];
// Remember to change the model parameter to suit your display module!
UTFT tft(ITDB32S,38,39,40,41);
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 8
#define TEMPERATURE_PRECISION 9
#define BAUD_RATE 115200
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
File myfile;
int x=0;
float inTemp;
float outTemp;
float ambientTemp;
float EGT;
float effValue;
int effValueScreen;
// For the pressure sensor (MPX5500DP)
int rawValue = 0; // Variable stores value coming from the sensor
int offset = 38; // zero pressure adjust
int fullScale = 500; // max pressure (span) adjust
int boost; // final pressure
//For the plotting of the graph
int previous_boostYaxis;
int boostY_axis=238;
int previous_ambientTempYaxis;
int ambientTempY_axis=238;
int previous_inTempYaxis;
int inTempY_axis=238;
int previous_outTempYaxis;
int outTempY_axis=238;
int x_axis=0;
// position of the line on screen
int xPos = 0;
int plot;
void setup(void)
{
// start serial port
Serial.begin(115200);
// Use this initializer if you're using a 1.8" TFT
tft.InitLCD(); // initialize screen
tft.clrScr();
// Start up the OneWire library
sensors.begin();
sensors.setResolution(9);
//setupSD();
// write the static content to the screen
// set the font color to white
tft.setColor(255, 255, 255);
// draw some boxes
tft.setColor(80,80,80);
tft.fillRect(0,0,319, 30);
tft.setColor(150,150,150);
tft.drawLine(0,30,319,30);
// set the font size
tft.setFont(arialB);
// write, colour & position the text labels
tft.setColor(0, 255, 0);
tft.print("Amb", 2, 40);
tft.setColor(255, 0, 0);
tft.print("Pre", 110, 40);
tft.setColor(0, 0, 255);
tft.print("Post", 220, 40);
tft.setColor(200, 200, 200);
tft.print("Eff (%)", 20, 70);
tft.print("Boost", 205, 70);
tft.setColor(150,150,150);
tft.drawLine(0,148,319,148);
tft.setColor(30,30,30);
tft.fillRect(0,149,319,239);
}
void checkX_axis(){
x_axis++;
if(x_axis==319){ //returns the graph to the left of the screen to scroll across again
tft.setColor(30,30,30);
tft.fillRect(0,149,2,239);
x_axis=0;
}
}
void graphErase(){
tft.setColor(150,150,150);
tft.drawLine(x_axis+12, 149,x_axis+12,239);
tft.setColor(30,30,30);
tft.fillRect(x_axis+1, 149,x_axis+11,239);
}
void plotBoost(int previous_Yaxis,int y_axis){
tft.setColor(200, 200, 200);
tft.drawLine(x_axis-1,previous_boostYaxis , x_axis, boostY_axis); // x axis
}
void plotAmbientTemp(int previous_ambientTempYaxis,int ambientTempY_axis){
tft.setColor(0, 255, 0);
tft.drawLine(x_axis-1,previous_ambientTempYaxis , x_axis, ambientTempY_axis); // x axis
}
void plotInTemp(int previous_inTempYaxis,int inTempY_axis){
tft.setColor(255, 0, 0);
tft.drawLine(x_axis-1,previous_inTempYaxis , x_axis, inTempY_axis); // x axis
}
void plotOutTemp(int previous_outTempYaxis,int outTempY_axis){
tft.setColor(0, 0, 255);
tft.drawLine(x_axis-1,previous_outTempYaxis , x_axis, outTempY_axis); // x axis
}
//------------------ READ SENSORS AND PERFORM EFFICIENCY CALC ----------------------------
void loop(void)
{
sensors.requestTemperatures(); // Send the command to get temperatures
inTemp = (sensors.getTempCByIndex(0)); //Put sensor data into variables
outTemp = (sensors.getTempCByIndex(1));
ambientTemp = (sensors.getTempCByIndex(2));
effValue = ((inTemp-outTemp) / (inTemp-ambientTemp)*100); //calculate cooler efficiency
effValueScreen = effValue;
effValueScreen = constrain(effValueScreen, 0, 100 ); //Hold value (percentage) to within 0-100
//------------------ READ BOOST THEN GRAPH IT ------------------------------
// For reading the boost...
rawValue = analogRead(A0);
boost = (rawValue - offset) * 500.0 / (fullScale - offset); // pressure conversion
boost=map(boost, 0, 300, 0, 150);
boost = constrain(boost, 0, 30 ); //Hold value (psi) to within 0-30
// For graphing the boost...
checkX_axis(); //Check to make sure the 'x' axis is still on-screen
previous_boostYaxis=boostY_axis;
boostY_axis=(239-boost*3);
plotBoost(previous_boostYaxis,boostY_axis);
previous_inTempYaxis=inTempY_axis;
inTempY_axis=(239-inTemp*1.5);
plotInTemp(previous_inTempYaxis,inTempY_axis);
previous_outTempYaxis=outTempY_axis;
outTempY_axis=(239-outTemp*1.5);
plotOutTemp(previous_outTempYaxis,outTempY_axis);
previous_ambientTempYaxis=ambientTempY_axis;
ambientTempY_axis=(239-ambientTemp*1.5);
plotAmbientTemp(previous_ambientTempYaxis,ambientTempY_axis);
graphErase();
//setup screen variable colour scheme
tft.setFont(SevenSegSmall);
tft.setColor(255, 255, 255);
tft.setBackColor(0,0,0);
//print variable values to screen
tft.printNumI(ambientTemp, 60, 35);
tft.printNumI(inTemp, 165, 35);
tft.printNumI(outTemp, 285, 35);
//Efficiency and Boost variables get a bigger font
tft.setFont(SevenSegNumFont);
tft.printNumI(effValue, 35, 90);
tft.printNumI(boost, 240, 90);
// writeSD();
//---------------- SETUP THE TOUCH AREAS OF THE SCREEN FOR PAGING ---------------
//tft.setFont(BigSymbols);
//tft.setColor(190,190,190);
//tft.setBackColor(80,80,80);
//tft.print("R", 0,0); //arrow left
//tft.print("S", 288,0); //arrow right
}
void setupSD(void){
Serial.print("Initializing card...");
// declare default CS pin as OUTPUT
pinMode(53, OUTPUT);
if (!SD.begin(4)) {
Serial.println("initialization of the SD card failed!");
return;
}
Serial.println("initialization of the SDcard is done.");
}
void writeSD(){
myfile = SD.open("sensordata.txt", FILE_WRITE);
if (myfile)
{
Serial.print(myfile);
Serial.print("Writing to the text file...");
myfile.println("Congratulations! You have successfully wrote on the text file.");
myfile.close(); // close the file:
Serial.println("done closing.");
} else
{
// if the file didn't open, report an error:
Serial.println("error opening the text file!");
}
// re-open the text file for reading:
myfile = SD.open("textFile.txt");
if (myfile)
{
Serial.println("textFile.txt:");
// read all the text written on the file
while (myfile.available())
{
Serial.write(myfile.read());
}
// close the file:
myfile.close();
} else
{
// if the file didn't open, report an error:
Serial.println("error opening the text file!");
}
}
arial.c (16.1 KB)
arialB.c (16.1 KB)
BigSymbols.c (60.6 KB)
SevenSegmentSmall.c (3 KB)
SevenSegSmall.c (2.99 KB)
SmallSymbols.c (16.1 KB)