apologizes in advance for
spellings
grammar
and knowledge
what im trying to do:- read a Amp value that has been read and mapped into a int.
the issue:- the code i have pulled (from the web) no longer seems to wok and i am unable to find a solution i can make work(web page below).
what i want it to do]:- give me the mAh used in a whole number (no decimals)
so i can print it to my nextion display.
here is the code i have so far i have tried to comment out as best as i could
this is not the complete code as i am just concentrating on the final section at the moment witch is a standalone section
int S0 = 2 ;
int S1 = 3 ;
int S2 = 4 ;
int S3 = 5 ;
void setup()
{
Serial.begin(9600);
}
void loop()
{
// Amp meter on C3
//set MXu to C3
digitalWrite(S0,HIGH);
digitalWrite(S1,HIGH);
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
// read the sensor
int ampVal = analogRead(A0);
// map the value to usable data
int amps =map(ampVal, 532, 1023 , 0 , 80);
// print to nextion disply (current amp draw)
Serial.print("n25.val=");
Serial.print(amps);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
// enagy consumption calc
//code pulled form net!
long milisec = millis(); // calculate time in milliseconds
long time = milisec / 1000 ; // convert milliseconds to seconds
long totamps =totamps + amps; // calculate total amps
long avgamps = totamps / time ; // average amps
long amphr = (avgamps * time ) / 3600 ; // amp-hour
long milamphr = (amphr * 1000 ) ; // mAh
//code pulled form net! end
// print to nextion diplay (consumption)
Serial.print("n26.val=");
Serial.print(milamphr);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
this calculation section was puled form a energy meter build on instructables
I am reading a analog voltage from a hallefect current meter
and i have mapped it as such
532 = 2.6v input to A0 = 0 amps
1023 = 5v input to A0 = 80 amps
As for the nextion on the serial port that's how its coms are set up it has no other means of transferring data (that I know of)
I don't know because i have not done this type of project before (heavy arduino code)
and i whish to give it a go.
Before you ask yes i have done a lot of googleing and have not come across any help advice or examples that work or give me a clue how to make it work.
So i have come to you smart people to ask for advice so i may learn how it works and why this code that was working on the example is no longer working.
thankyou for you reply
i may have readed it and got the impression of aggression so my appolageys if i have affended you for asking my question
I am reading a analog voltage from a hallefect current meter
And getting what actual values? You can't guess.
As for the nextion on the serial port that's how its coms are set up it has no other means of transferring data (that I know of)
Then bend the two pins that connect to the hardware serial pins (pins 0 and 1) so they don't connect, and then connect the bent pins to some other pins, and use SoftwareSerial on those pins to talk to the nextion.
Suppose that you have a problem at school, and you need to see the principal. Now, suppose that the principal is busy sorting her comic books, and can't see you. What are you going to do?
Now, suppose that the comic books could be sorted by someone else, freeing up the principal to see you.
There is nothing wrong with the principal sorting comic books UNTIL you need to see her.
The same is true for dedicating the hardware serial port to talking to the nextion - works fine UNTIL you need to debug your program.
the readings from the halleffect sensor is 2.5v @0A and 5v @80A
i see what you are saying for the hwserial and will look in to swserial
i will remove all nextion stuff till i can get this calculation to work.
the transduer data sheet states that at 0Amps it will output a voltage of 2.5v
i could not make to much sence of the graphs the data sheet has on it for the out put per amp
so i ran a pratical test up to 6A and saw the output voltage rise as i would of exspected.
i dont currently have the transduser infornt of me and cannot post the data sheet .
never the less i can test the voltage input by using a pot to get the output from the mapped vaule
witch to my understanding will give the "int amps"a value of 0 to 80 so why dose this not go through the calculations, it seems to brake at this code line.
long totamps =totamps + amps; // calculate total amps
when i output this to the serial monitor i get 0 regardless of any imput