Waveform op een Nextion scherm?

Arduino specifieke Software
Berichten: 22
Geregistreerd: 13 Aug 2018, 17:59
Woonplaats: Krimpen

Waveform op een Nextion scherm?

Berichtdoor swets » 13 Aug 2018, 18:12

Ik ben aan het spelen met een Arduino mega, en een Nextion scherm, en het lukt aardig, op 1 ding na...

iets zichtbaar maken in een waveform..

en ik heb al heel erg zitten zoeken op internet, maar kan het niet vinden....

Ik heb nu wel een aantal gauges werken, ik lees 7 DS 18B20 in, die laat ik zien in metertjes, met ook nog als tekst er boven.... maar nu wil ik graag nog wat data in een trend....

heeft er iemand een voorbeeld?
of kan mij op weg helpen....
oja... ik ben nog niet zo heel lang bezig met arduino, ik deed altijd meer met PIC Micro's...



dit is wat ik tot nu toe heb....
csharp code
#include <math.h>
#include <OneWire.h>
OneWire ds(22); // on pin 22 (a 4.7K resistor is necessary)

#include "Nextion.h"
#define LEVEL_HIGH (40)
#define LEVEL_LOW (0)
#define CH0_OFFSET (40-LEVEL_HIGH/2)

NexWaveform s0 = NexWaveform(0, 22, "s0");
static uint8_t ch0_data = LEVEL_LOW;

#include "DHT.h"
#define DHTPIN 24 // what pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

float celsiusArray[10];
byte CurrentSensor = 1;
byte MaxSensors = 11;
int temp;

int ScaleTemp[271] = {330, 331, 332, 333, 334, 335, 336, 337, 338, 339,
340, 341, 342, 343, 344, 345, 346, 347, 348, 349,
350, 351, 352, 353, 354, 355, 356, 357, 358, 359,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
220, 221, 222, 223, 224, 225, 226, 227, 228, 229,
230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
240
};

int ScaleTemp2[271] = {315, 316, 317, 318, 319,
320, 321, 322, 323, 324, 325, 326, 327, 328, 329,
330, 331, 332, 333, 334, 335, 336, 337, 338, 339,
340, 341, 342, 343, 344, 345, 346, 347, 348, 349,
350, 351, 352, 353, 354, 355, 356, 357, 358, 359,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
220, 221, 222, 223, 224, 225
};


byte sensorInterrupt = 0; // 0 = digital pin 2
byte sensorPin = 4;
// The hall-effect flow sensor outputs approximately 4.5 pulses per second per
// litre/minute of flow.
float calibrationFactor = 4.5;
volatile byte pulseCount;
float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitres;
unsigned long oldTime;

void setup() {

nexInit();
dbSerialPrintln("setup done");



//Serial.begin(9600);
Serial1.begin(9600);

pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);

pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0;
oldTime = 0;

// The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
// Configured to trigger on a FALLING state change (transition from HIGH
// state to LOW state)
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);



}

void loop() {

if ((millis() - oldTime) > 1000) // Only process counters once per second
{
detachInterrupt(sensorInterrupt);
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
oldTime = millis();
flowMilliLitres = (flowRate / 60) * 1000;
unsigned int frac;

// Print the flow rate for this second in litres / minute
// Serial.print("Flow rate: ");
// Serial.print(int(flowRate)); // Print the integer part of the variable
// Serial.print("."); // Print the decimal point
// Determine the fractional part. The 10 multiplier gives us 1 decimal place.
frac = (flowRate - int(flowRate)) * 10;
// Serial.print(frac, DEC) ; // Print the fractional part of the variable
// Serial.print("L/min");
// Print the number of litres flowed in this second
// Serial.print(" Current Liquid Flowing: "); // Output separator
// Serial.print(flowMilliLitres);
// Serial.print("mL/Sec");

// Print the cumulative total of litres flowed since starting
// Serial.print(" Output Liquid Quantity: "); // Output separator
// Serial.print(totalMilliLitres);
// Serial.println("mL");

Serial1.print("t22.txt="); // schrijf mililiters/sec als txt op het scherm
Serial1.print("\"");
temp = flowRate;
Serial1.print(temp);
Serial1.print(".");
Serial1.print(frac);
Serial1.print("\"");
Serial1.write(0xff);
Serial1.write(0xff);
Serial1.write(0xff);

Serial1.print("z22.val="); // beweeg de wijzer van de gauge
Serial1.print (ScaleTemp2[temp * 4]);
Serial1.write(0xff);
Serial1.write(0xff);
Serial1.write(0xff);

// Reset the pulse counter so we can start incrementing again
pulseCount = 0;

// Enable the interrupt again now that we've finished sending output
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}

readDSTemp();
readDHT();
}

void readDSTemp()
{
byte i;

byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;


if ( !ds.search(addr)) {
//Serial.println("No more addresses.");
MaxSensors = CurrentSensor ;
CurrentSensor = 1;
//Serial.println();
ds.reset_search();
delay(250);
return;
}
//Serial.print(tellerDS);

// Serial.print("ROM =");
// for ( i = 0; i < 8; i++) {
// Serial.write(' ');
// Serial.print(addr[i], HEX);
// }

// if (OneWire::crc8(addr, 7) != addr[7]) {
// Serial.println("CRC is not valid!");
// return;
// }
// Serial.println();

// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
//Serial.println(" Chip = DS18S20"); // or old DS1820
type_s = 1;
break;
case 0x28:
//Serial.println(" Chip = DS18B20");
type_s = 0;
break;
case 0x22:
//Serial.println(" Chip = DS1822");
type_s = 0;
break;
default:
//Serial.println("Device is not a DS18x20 family device.");
return;
}

ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(500); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
//webserver;

present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad

//Serial.print(" Data = ");
// Serial.print(present, HEX);
// Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
// Serial.print(data[i], HEX);
// Serial.print(" ");
}
// Serial.print(" CRC=");
// Serial.print(OneWire::crc8(data, 8), HEX);
// Serial.println();

// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
// fahrenheit = celsius * 1.8 + 32.0;
// Serial.print(" Temperature = ");
// Serial.print(celsius);
// Serial.println(" Celsius, ");
celsiusArray[CurrentSensor] = celsius;

//Serial.print(fahrenheit);
//Serial.println(" Fahrenheit");

Serial1.print("t"); // schrijf temperatuur als txt op het scherm
Serial1.print(CurrentSensor );
Serial1.print(".txt=");

Serial1.print("\"");
Serial1.print(celsiusArray[CurrentSensor]);
Serial1.print("\"");
Serial1.write(0xff);
Serial1.write(0xff);
Serial1.write(0xff);

Serial1.print("z"); // beweeg de wijzer van de gauge
Serial1.print(CurrentSensor );
Serial1.print(".val=");

temp = (celsiusArray[CurrentSensor]) * 2;
Serial1.print (ScaleTemp[temp]);
Serial1.write(0xff);
Serial1.write(0xff);
Serial1.write(0xff);

CurrentSensor = CurrentSensor + 1;
}

void readDHT() {

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(false);

float A = log(h / 100) / log(2.718282) + (17.62 * t / (243.12 + t));
float Td = 243.12 * A / (17.62 - A);
unsigned int frac;

frac = (Td - int(Td)) * 10;

Serial1.print("t23.txt=");
Serial1.print("\"");
temp = Td;
Serial1.print(temp);
Serial1.print(".");
Serial1.print(frac);
Serial1.print("\"");
Serial1.write(0xff);
Serial1.write(0xff);
Serial1.write(0xff);


// // Check if any reads failed and exit early (to try again).
// if (isnan(h) || isnan(t) || isnan(f)) {
// Serial.println("Impossible de lire la sonde DHT!");
// return;
// }

// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);

// Serial.print("Humidity: ");
// Serial.print(h);
// Serial.print(" %t");


Serial1.print("t21.txt="); // Humidity als txt op het scherm zetten
Serial1.print("\"");
Serial1.print(h);
Serial1.print("\"");
Serial1.write(0xff);
Serial1.write(0xff);
Serial1.write(0xff);

Serial1.print("z21.val="); // beweeg de wijzer van de gauge
temp = (h) * 2;
Serial1.print (ScaleTemp2[temp]);
Serial1.write(0xff);
Serial1.write(0xff);
Serial1.write(0xff);

Serial1.print("add 22,1,");
Serial1.print(h);
Serial1.write(0xff);
Serial1.write(0xff);
Serial1.write(0xff);


// Serial.print("Temperature: ");
// Serial.print(t);
// Serial.print(" *C ");
// Serial.print(f);
// Serial.print(" *Ft");
// Serial.print("Heat index: ");
// Serial.print(hic);
// Serial.print(" *C ");
// Serial.print(hif);
// Serial.println(" *F");

Serial1.print("t20.txt="); // Humidity als txt op het scherm zetten
Serial1.print("\"");
Serial1.print(t);
Serial1.print("\"");
Serial1.write(0xff);
Serial1.write(0xff);
Serial1.write(0xff);

Serial1.print("z20.val="); // beweeg de wijzer van de gauge
temp = (t) * 2;
Serial1.print (temp);
Serial1.write(0xff);
Serial1.write(0xff);
Serial1.write(0xff);


//NexWaveform wave1 = NexWaveform(0,22,"s0");
//wave1.addValue(0,t);

s0.addValue(0,CH0_OFFSET + 10 );




Serial1.print("add 22,0,");
Serial1.print(t);
Serial1.write(0xff);
Serial1.write(0xff);
Serial1.write(0xff);


}

/*
Insterrupt Service Routine
*/
void pulseCounter()
{
// Increment the pulse counter
pulseCount++;
}

Advertisement

Berichten: 340
Geregistreerd: 23 Okt 2016, 20:29

Re: Waveform op een Nextion scherm?

Berichtdoor benvo » 22 Aug 2018, 16:15

Misschien kun je hier iets mee?

http://support.iteadstudio.com/support/ ... 1000019908

Overigens worden hier wel erg veel, onnodige, includes gebruikt voor de Nextion.

Berichten: 340
Geregistreerd: 23 Okt 2016, 20:29

Re: Waveform op een Nextion scherm?

Berichtdoor benvo » 22 Aug 2018, 19:46

En dit is misschien ook een hulp?

https://www.youtube.com/watch?v=_unTRqZEF8c

Terug naar Arduino software

Wie is er online?

Gebruikers in dit forum: anuxoqe, eahagda en 22 gasten