Good morning,
Hope that some one can assist me with the problem we are having. We have a project where a pulsar - that measures the flow of diesel being dispensed. Currently we have the setup that the ESP board will provide power to the pulsar and also receive the pulses provided. The pulses received is then "re-directed" to a DAC pin that is sent to the device that communicates to our servers. Further more we are looking at adding a second layer we want to add is that we receive a pulse for every 33 pulses received, to be sent to pin 18 in this case. Thirdly, the total count of pulses needs to be sent via the serial pins. This is where we are stuck as it does not seem to be as easy as we thought, also all of the data sent via the serial pins has to be in hex as that is the requirement of the server in order to process the data.
Below is the code we have compiled:
#include <SoftwareSerial.h>
SoftwareSerial espSerial(1, 3);
#include
#define dac1 25
using namespace std;
const int pulsePin = 34;//34 on esp
const int outPin = 25;
const int litresPin = 18;//litre pulse output to unit pin 18 on esp
const int readTimeOut = 1000;
long int t1;
long int t2;
int litrepulseCounter = 0;
int pulseCounter = 0;
int pulseState = 0;
int lastPulseState = 0;
int totalLitres = 0;
void setup()
{ pinMode(pulsePin, INPUT);
pinMode(outPin, OUTPUT);
pinMode(litresPin, OUTPUT);
Serial.begin(9600);
// main code starts here for the counter of the pulses on the incoming pulse pin as well the count
int litrepulseCounter = pulseCounter;
}
void threshholdReached()
{
digitalWrite(litresPin, HIGH);
totalLitres++;
litrepulseCounter = 0;
}
void timeOutReached()
{
espSerial.begin(9600);
{
if(espSerial.available())
''''// The esp Serial starts for the total count of pulses once the pulses stop
to be sent.
'''''
Serial.write(espSerial.read());
}
espSerial.print("4B5456"); //unique identifier for the project
espSerial.println(pulseCounter,HEX);
'''''
//total pulses received in the transaction and needs to be a hex output
'''
espSerial.print("0A0D");
''''''''''
'//there is a end of line character required of each transaction e.g.
"KTV(totalPulses)0A0D"; will have to be sent via seraial where the
pules figure is a variable.
'''''''''''''
spSerial.end();
}
while (digitalRead(pulsePin) == HIGH) {
}
while (digitalRead(pulsePin) == LOW) {
}
}
void loop()
{
int Value = 255;
pulseState = digitalRead(pulsePin);
if (pulseState != lastPulseState)
{
if (pulseState == HIGH)
{int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1023.0);
pulseCounter++;
litrepulseCounter++;
// Serial.println("HIGH");
// Serial.print("number of Pulses: ");
// Serial.println(pulseCounter);
dacWrite(DAC1, 255);
t1 = millis();
if (litrepulseCounter == 33)
''''''
//as an addition every 33 pulses of the counter output to pin 18 for
200ms
'''''''
{
threshholdReached();
}}
else
{
//
Serial.println("LOW");
dacWrite(DAC1, 0);
digitalWrite(litresPin, LOW);
}} lastPulseState = pulseState;
t2 = millis();
if (t2 - t1 > readTimeOut)
{
timeOutReached();
}}
Thanks for the assist!