Hi
I'm working on project with 2.4" TFT LCD Shield Touch Panel Display for Arduino MEGA. I've two flow sensors and I need to built two graphs, one for each sensor and introduce it on the screen.
Do you have any tips or works that you know that can help me?
Thanks,
Hila
All you really need to do is use the flow output, or a sensible multiple thereof, as the y-coordinate. The X is usually done by a counter in the loop, one dot per count. When you run out of dots, clear the screen and start over. This is with the UTFT library, but I imagine they are all much the same.
Hi Nick,
Thank you.
Do you have something that can help?
Here is my code for reading data from the sensors
/*
Pulse Period Measurement of 2 Flow Sensors
• accurate measurements by using Arduino micros() function
• determines leading edge of pulses without use of iterrupts
• calculates pulse periods, frequencies, flow rates, totalized volumes
• includes pulse generator for testing, simulation and troubleshooting
• easily adapted for testing other sensors and pulse quantities (energy, optic, etc.)
- dlloyd ----------------------------------------------------------------------------*/
// constants
const byte pgenPin = 13; // PGEN pin number
const byte CLEAR = 12; // CLEAR pin number
const byte inputs[] = {2, 4}; // input pins
const double pulseConstant[] = {7.5, 7.5}; // pulse constants
const byte qty = sizeof(inputs);
// variables
double pgenFrequency = 7.5; // pulse generator frequency (Hz)
long previousMillis = 0;
long pgenInterval = 1000000 / (pgenFrequency * 2);
byte pgenState = LOW;
long pgenPreviousMicros = 0;
long startTime[qty];
byte inputsState[qty];
byte inputsPrevious[qty];
double pulsePeriod[qty];
double pulseFrequency[qty];
double pulseMultiplier[qty];
double flowRate[qty];
double pulseVolume[qty];
double totalVolume[qty];
void setup() {
Serial.begin(9600);
Serial.print("");
pinMode(pgenPin, OUTPUT);
pinMode(CLEAR, INPUT_PULLUP);
for (int i = 0; i < qty; i++) {
pinMode(inputs*, INPUT_PULLUP);*
pulseVolume = 1.0 / (pulseConstant * 60);
pulseMultiplier = 1.0 / (pulseConstant*);*
}
clr(); // initialize arrays
}
void loop()
{
pgen(); // run pulse generator
if (digitalRead (CLEAR) == LOW) { // check CLEAR push button
* clr();*
}
pulseMeasure(); // run flow tests, calculations and print results
}
// functions -----------------------------------------------------
void pulseMeasure() {
for (int i = 0; i < qty; i++) {
inputsState = digitalRead(inputs*); // read the inputs*
if ((inputsState == 1) && (inputsPrevious == 0)) { // if rising
pulsePeriod = (micros() - startTime_) * 0.000001; // test duration (sec)
pulseFrequency = 1 / pulsePeriod*; // input frequency (Hz)*
flowRate = pulseFrequency * pulseMultiplier; // 1.0 / pulseConstant (L/min)
totalVolume = totalVolume + pulseVolume*; // totalized volume (L)*
* if (millis() - previousMillis > 250) { // update interval (milliseconds)
Serial.print(i); Serial.print(": ");
Serial.print(pulsePeriod, 6); Serial.print(" sec, ");
Serial.print(pulseFrequency, 3); Serial.print(" Hz, ");
Serial.print(flowRate, 3); Serial.print(" L/min, ");
Serial.print(totalVolume, 6); Serial.print(" L");
Serial.println();
previousMillis = millis();
}
startTime = micros();
}_
inputsPrevious _= inputsState;
}
}
void pgen() {
// check to see if it's time to pulse the PGEN; that is, if the*
// difference between the current time and last time you pulsed
// the PGEN is bigger than the interval to changed its output state.
unsigned long pgenCurrentMicros = micros();
if (pgenCurrentMicros - pgenPreviousMicros > pgenInterval) {
* // save the last time you pulsed the PGEN*
* pgenPreviousMicros = pgenCurrentMicros;
// if the PGEN output is off turn it on and vice-versa:
if (pgenState == LOW)
pgenState = HIGH;
else*
* pgenState = LOW;
digitalWrite(pgenPin, pgenState);
}
}
void clr() {
for (int i = 0; i < qty; i++) {
startTime = micros();
inputsState = 0;
inputsPrevious = 1;
pulsePeriod = 0;
pulseFrequency = 0;
flowRate = 0;
totalVolume = 0;
}
}*_
Thanks Nick
How can I introduce the graphs on TFT screen shield after i'll get the graphs?