KWh pulse meter S0 uitlezen arduino uno script

Projecten die niet passen in bovenstaande onderwerpen
Berichten: 1
Geregistreerd: 03 Sep 2020, 16:44

KWh pulse meter S0 uitlezen arduino uno script

Berichtdoor Ironburn » 03 Sep 2020, 17:16

Goedendag,

ik zit met het volgende:
Ik ben opzoek naar eens script die ik via mijn arduino uno mijn kwh pulse meter op de s0 kan uitlezen. (zodat ik kan zien wat ik netto binnen haal)
Ik ben al een tijdje met dit project bezig omdat ik dit vroeger via de GPIO poort van mijn raspberrypi deed en dit sinds een update niet meer werkte.
Ik heb al verschillende scriptjes gevonden op internet maar ik gebruik domoticz om het uit te lezen en de waardes die vanaf de uno komen naar mijn raspberry en dan in domoticz zijn niet de juiste. Zo geeft domoticz aan dat ik bijv aan dat ik in 5 minuten tijd 30.245kw binnen haal..... (i wish)

Wie kan mij hierbij helpen?
In de meterkast de volgende kwh pulse meter: http://www.enteselectronics.com/dosyalar/ES_32L_%20A4264%20REV5%20A6219%20R1.pdf
En ik heb mijn arduino als volgt aangesloten: Afbeelding en dan via usb naar mijn raspberry pi 4
Dit is het een script wat wel goed zou moeten werken maar hier krijg ik foutmeldingen in.
//script by huizebruin.nl
// http://www.huizebruin.nl
// This sketch is based on http://domoticz.com/forum/viewtopic.php?f=38&t=7300
// It will update counters in Domoticz.
// dowloaded from https://www.huizebruin.nl
// Via the serial port of the Pi you can set the initial counter values.
// do this while the Arduino is connected to the Pi but Domoticz is not running.
// Set the serial port to 9600 Baud.
// If not set, the counter will not start updating.
// Send the following command (with Newline ending):
// M[number of internal S0 counter]=[value in whole liters/Wh].
// M1=100000
// M2=100000
// KWH interrupt attached to IRQ 0 = pin2 (D2)
//KWH interrupt attached to IRQ 1 = pin3
// Start with M2, then M1. As soon as M1 !=0, the counter starts sending data.
//Number of pulses, used to measure energy.

volatile unsigned int pulseCount1 = 0;

volatile long pulseCount1_sinceStart = 0;

volatile unsigned int pulseCount2 = 0;

volatile long pulseCount2_sinceStart = 0;

volatile unsigned int reportInterval = 10000; //Interval between messages being sent out (in milliseconds)

int PulseCounterID = 001;

int PulseCounterVersion = 042;

String readString = String(100); //string for fetching data from address

int ind1 = 0;

int ind2 = 0;

String valueSet;

String valueSetID;

float lastTime = 0;

// The interrupt routine

void onPulse1()

{

//pulseCounter

pulseCount1++;

pulseCount1_sinceStart++;

//Blink built-in LED on S0-pulse

}

// The interrupt routine

//void onPulse2()

//{

//pulseCounter

//pulseCount2++;

//pulseCount2_sinceStart++;

//}

void setup()

{

// KWH interrupt attached to IRQ 0 = pin2 (D2)

attachInterrupt(0, onPulse1, FALLING);

//KWH interrupt attached to IRQ 1 = pin3

//attachInterrupt(1, onPulse2, FALLING);

Serial.begin(9600);

Serial.print(“/”);

Serial.print(PulseCounterID);

Serial.print(“:S0 Pulse Counter V”);

Serial.println(PulseCounterVersion);

}

void loop()

{

// decode the start values

// it looks for M1=123456

while (Serial.available() > 0) {

char c = Serial.read();

//read char by char

// it expects a maximum of 20 char

if (readString.length() < 20) {

//store characters to string

readString +=c;

Serial.println(c);

}

//if endline has been received

if (c == ‘n’) {

Serial.println(“endline”);

if(readString.indexOf(“M”) >=0){

ind1 = readString.indexOf(‘M’);

valueSetID = readString.substring(ind1+1, ind1+2);

ind2 = readString.indexOf(‘=’);

valueSet = readString.substring(ind2+1);

if (valueSetID.toInt() == 1){

pulseCount1_sinceStart = valueSet.toFloat();

} else if (valueSetID.toInt() == 2){

pulseCount2_sinceStart = valueSet.toFloat();

} else {return;}

} // end readString M

readString = "";

} // end endline

} // end serial available

// send the data every reportInterval

if(millis() – lastTime > reportInterval) {

lastTime = millis();

// Only send the counter data if the initial pulse count is not zero

if (pulseCount1_sinceStart != 0){

Serial.print("ID:");

Serial.print(PulseCounterID);

Serial.print(":I:10:M1:");

Serial.print(pulseCount1);

Serial.print(":");

Serial.print(pulseCount1_sinceStart);

Serial.print(":");

Serial.print("M2");

Serial.print(":");

Serial.print(pulseCount2);

Serial.print(":");

Serial.println(pulseCount2_sinceStart);

pulseCount1 = 0;

pulseCount2 = 0;

} // end if not zero

} // end interval loop

} // end void loop()

Ik hoop dat iemand me hier mee kan helpen.
Alvast bedankt.

Advertisement

Terug naar Overige projecten

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 8 gasten