#include "EasyNextionLibrary.h"
#include <Wire.h>
#include <Robojax_WCS.h>
#define MODEL 12 //see list above
#define SENSOR_PIN A0 //pin for reading sensor
#define SENSOR_VCC_PIN 8 //pin for powring up the sensor
#define ZERO_CURRENT_LED_PIN 2 //zero current LED pin
#define ZERO_CURRENT_WAIT_TIME 5000 //wait for 5 seconds to allow zero current measurement
#define CORRECTION_VLALUE 164 //mA
#define MEASUREMENT_ITERATION 100
#define VOLTAGE_REFERENCE 5000.0 //5000mv is for 5V
#define BIT_RESOLUTION 10
#define DEBUT_ONCE true
Robojax_WCS sensor(
MODEL, SENSOR_PIN, SENSOR_VCC_PIN,
ZERO_CURRENT_WAIT_TIME, ZERO_CURRENT_LED_PIN,
CORRECTION_VLALUE, MEASUREMENT_ITERATION, VOLTAGE_REFERENCE,
BIT_RESOLUTION, DEBUT_ONCE
);
EasyNex myNex(Serial);
int RelayStart = 9;
int Relay1 = 10;
int Relay2 = 11;
int Relay3 = 12;
int Relay4 = 7;
int T = 15000;
int T2 = 1500;
int T3 = 500;
int pin_value = 0;
int progress_value;
void setup()
{
myNex.begin(9600);
pinMode(RelayStart,OUTPUT);
pinMode(Relay1,OUTPUT);
pinMode(Relay2,OUTPUT);
pinMode(Relay3,OUTPUT);
pinMode(Relay4,OUTPUT);
digitalWrite(RelayStart,LOW);
digitalWrite(Relay1,LOW);
digitalWrite(Relay2,LOW);
digitalWrite(Relay3,LOW);
digitalWrite(Relay4,LOW);
sensor.start();
}
void loop() {
myNex.NextionListen();
sensor.readCurrent();
sensor.printCurrent();
}
void trigger0(){
digitalWrite(Relay1, !digitalRead(Relay1));
}
void trigger1(){
}
void trigger2(){
digitalWrite(RelayStart,!digitalRead(RelayStart));
}
Hi all,
Iam new to arduino and i have a question. When "sensor.printCurrent" is activated this happens in the library:
void Robojax_WCS::printCurrent()
{
Serial.print("Current:");
Serial.print(getCurrent(),2);
Serial.println("A");
Serial.println();
}//printCurrent()
I want the part " Serial.print(getCurrent(),2);" to print on my Nextion. To print variables on the Nextion i use an library which uses the code "myNex.writeNum("x0.val", Anything);" to print values to the Nextion. If i can convert the getCurrent to an int or something else i think i can print it. Does someone have an idea what to do? Thanks in Advance.
The getCurrent code:
float Robojax_WCS::getCurrent()
{
//robojax.com WCS Current Measurement for Arduino
float averageSensorValue =0;
int sensorValue ;
float voltage, current;
for(int i=0; i< _iteration; i++)
{
sensorValue = analogRead(_vin);
//Serial.print("S:");Serial.println(sensorValue);
delay(2);
voltage = (sensorValue) * (_voltageReference / (pow(2,_bitResolution)-1)) -( _quiescent_Output_voltage[_model] * _voltageReference) + _correctionValue ;
//Serial.print("V:");Serial.println(voltage);
current = voltage / _sensitivity[_model] ;
averageSensorValue += current;
}
averageSensorValue /=_iteration;
if(_zeroCurrentSet)
{
averageSensorValue -=_zeroCurrentValue;//subtract the zero current value
}
return averageSensorValue;
}//getCurrent()