How can i print this value to my Nextion?

#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()

Try... int getCurrent(),

1 Like

Thanks for your response, int getCurrent(); does not cause any errors but when i try to send it to Nextion it doesn`t work.

int getCurrent();
myNex.writeNum("x0.val", getCurrent);

Don't redefine the function. Only tell the compiler to add code to convert from float to int in the print/write situation.

"Doesn't work " tells nothing.

Ok so i added the int getCurrent(); how should i continue?

int tempInt = temperature*10;      // Convert the float to int. Multiply it x10                       
myNex.writeNum("x1.val", tempInt); // Write it to x1 Xfloat component on Nextion

This is an example of a piece of code that does work.
I want to send the getCurrent to change "x0.val"

@PerryBebbington sounds like one for you.

Hi Bob,
Thanks but @shieftech is using @Seithan's Easy Nextion Library, about which I know nothing. Maybe @Seithan can help.

Moved to the display section as this is about a display.

It looks like You have changed the original code You posted. Don't do that! Post new or changed code in Your following posts. Now I don't find the print/write line of code.

Post the original code down here.

I haven`t changed the code. The piece of code i provided in my last answer is just an example code from the owner of the library. The original code is still the same as the one I posted the first time.

Here i have the piece of code which should send the data to my Nextion:

{
  int current = getCurrent; 
   myNex.writeNum("x0.val", current);
   Serial.print(getCurrent(),2);
Serial.println();
  
 
}```

`But when I try to upload this I get the error message: cannot convert 'Robojax_WCS::getCurrent' from type 'float (Robojax_WCS::)()' to type 'int'.

Okey. I had a slow day...
In my first reply what I suggested should look like this:

Your later attempt, redfineing the float function getCurrent to be an int.... Drop that!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.