I've been writing some of my code if preparation of my nextion screen coming in and keep getting the same error that I will paste below. I've googled every example I can find and am getting nowhere. I want to send an Arduino variable to a textbox in nextion. If I change the hourmeter in the code below to "hourmeter" will pass verification but then the textbox will show hourmeter and not the actual variable value.
code:
void hourtextPopCallback(void *ptr);
NexText hourtext = NexText(1, 5, "t0");
char buffer[100] = {0};
NexTouch *nex_listen_list[] =
{
&hourtext,
NULL
};
void hourtextPopCallback(void *ptr)
{
dbSerialPrintln("hourtextPopCallback");
hourtext.setText(hourmeter); //need variable problem line
}
And the error code is:
Arduino: 1.8.7 (Windows 10), Board: "Arduino/Genuino Uno"
C:\Users\BryanK\Desktop\code\EQUIPCONTRLVER1.00\EQUIPCONTRLVER1.00.ino: In function 'void hourtextPopCallback(void*)':
EQUIPCONTRLVER1.00:72:20: error: expected primary-expression before 'float'
hourtext.setText(float hourmeter); //need variable
^
Multiple libraries were found for "SD.h"
Used: C:\Users\BryanK\Documents\Arduino\libraries\SD
Not used: C:\Program Files (x86)\Arduino\libraries\SD
exit status 1
expected primary-expression before 'float'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
The function hourtext.setText is not surprisingly expecting a variable containing text ( the clue is in the name ), you want it to send the value of a variable so you have to convert that into a string, try:-
hourtext.setText(String(hourmeter));
As shown in https://www.arduino.cc/en/Reference.StringConstructor
Grumpy_Mike:
The function hourtext.setText is not surprisingly expecting a variable containing text ( the clue is in the name ), you want it to send the value of a variable so you have to convert that into a string, try:-
hourtext.setText(String(hourmeter));
As shown in https://www.arduino.cc/en/Reference.StringConstructor
Still causes the same error
Then post all your code not just a bit because without it I can not replicate what you have. Also include links to obscure libraries you might have used.
Please read this:-
How to use this forum for advice on how to ask a question.
It seems to be working fine like this
void hourtextPopCallback(void *ptr);
NexText hourtext = NexText(1, 5, "t0");
char buffer[100] = {0};
NexTouch *nex_listen_list[] =
{
&hourtext,
NULL
};
void hourtextPopCallback(void *ptr)
{
dbSerialPrintln("hourtextPopCallback");
bool setText(hourmeter); //need variable
}
Here's the complete code to see if the above is done correctly.
#include <doxygen.h>
#include <NexButton.h>
#include <NexConfig.h>
#include <NexCrop.h>
#include <NexGpio.h>
#include <NexHardware.h>
#include <NexHotspot.h>
#include <NexNumber.h>
#include <NexObject.h>
#include <NexPage.h>
#include <NexPicture.h>
#include <NexRtc.h>
#include <NexScrolltext.h>
#include <NexText.h>
#include <NexTimer.h>
#include "Nextion.h"
#include <NexTouch.h>
#include <NexUpload.h>
#include <NexVariable.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <AccelStepper.h>
#define motorPin1 4 //motor pin definitions
#define motorPin2 6 //motor pin definitions
#define motorPin3 7 //motor pin definitions
#define motorPin4 8 //motor pin definitions
#define HALFSTEP 8
#define ONE_WIRE_BUS 9
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
unsigned long previous; //HOURMETER VARIABLES 4 BYTE
unsigned long current; //HOURMETER VARIABLES 4 BYTE
float hourmeter; //HOURMETER VARIABLES 4 BYTE
float oilchange; //HOURMETER VARIABLES 4 BYTE
byte oilchangewarn; //HOURMETER VARIABLES 1 BYTE
float galleychange; //HOURMETER VARIABLES 4 BYTE
byte galleychangewarn; //HOURMETER VARIABLES 1 BYTE
int tps; //TPS VARIABLES 2 BYTE
int tpsprev; //TPS VARIABLES 2 BYTE
int tpsnew; //TPS VARIABLES 2 BYTE
float O2; //O2 VARIABLES 4 BYTE
float O2prev; //O2 VARIABLES 4 BYTE
float O2new; //O2 VARIABLES 4 BYTE
float O2set; //O2 VARIABLES 4 BYTE
int ets; //ETS VARIABLES 2 BYTE
unsigned long prevmillis; //IR VARIABLES 4 BYTE
unsigned long duration; //IR VARIABLES 4 BYTE
int rpm = 0; //IR VARIABLES 2 BYTE
boolean currentstate; //IR VARIABLES 1 BYTE
boolean prevstate; //IR VARIABLES 1 BYTE
float enrich; //INJ PW VARIABLES 4 BYTE
float accel; //INJ PW VARIABLES 4 BYTE
float etsenrich; //INJ PW VARIABLES 4 BYTE
byte startpress = 0; //START VARIABLES 1 BYTE
const int injpin = 5; //INJECTION VARIABLES
void hourtextPopCallback(void *ptr);
NexText hourtext = NexText(1, 5, "t0");
char buffer[100] = {0};
NexTouch *nex_listen_list[] =
{
&hourtext,
NULL
};
void hourtextPopCallback(void *ptr)
{
dbSerialPrintln("hourtextPopCallback");
bool setText(hourmeter); //need variable
}
void setup() {
stepper1.setMaxSpeed(7800);
stepper1.setAcceleration(7800);
pinMode(A3, INPUT);
prevstate = LOW;
{
hourtext.attachPop(hourtextPopCallback);
}
Serial.begin(9600); //REMOVE AFTER DEBUGGING
Serial.println("Dallas Temperature IC Control Library Demo"); //REMOVE AFTER DEBUGGIN
}
void loop() {
{
nexLoop(nex_listen_list);
}
current = millis(); //SET VARIABLE TO MILLIS
if ((current - previous) >= 900000);
hourmeter = +0.25; //INCREMENT HOURMETER EVERY FIFTEEN MINUTES
oilchange = +0.25; //INCREMENT OIL CHANGE EVERY FIFTEEN MINUTES
galleychange = +0.25; //INCREMENT GALLEY CHANGE EVERY FIFTEEN MINUTES
if (oilchange >= 50); //IF OIL CHANGE EQUALS OR IS MORE THEN FIFTY HOURS SET OIL CHANGE WARNING FOR LATER SCREEN USE
oilchangewarn = 1; //LATER SCREEN USE FOR "LED"
if (galleychange >= 500); //IF GALLEY CHANGE EQUALS OR IS MORE THEN FIVE HUNDRED HOURS SET GALLEEY CHANGE WARNING FOR LATER SCREEN USE
galleychangewarn = 1; //LATER SCREEN USE FOR "LED"
previous = current; //RESET PREVIOUS
Serial.print("hours = ");//REMOVE AFTER DEBUGGING
Serial.println(hourmeter); //WANT IT TO STORE HOUR SO NEXT POWER UP KEEPS COUNTING //REMOVE AFTER DEBUGGING
currentstate = analogRead(A3); //READ IR SENSOR FOR RPM MAY HAVE TO USE DIGITALREAD
if (prevstate != currentstate)
duration = (micros() - prevmillis);
rpm = (60000000 / duration);
prevmillis = micros();
prevstate = currentstate;
Serial.print("rpm = ");//REMOVE AFTER DEBUGGING
Serial.println(rpm); //REMOVE AFTER DEBUGGING
tps = analogRead(A1); //READ TPS POT
if ((tps > tpsprev + 300) || (tps < tpsprev - 300)); { //CHECK NEW TPS LOC
tpsnew = map(tps, 0, 1023, 0, 1600); //MAP STEPPER VALUE
stepper1.runToNewPosition(tpsnew); //MOVE STEPPER TO NEW POSITION
tpsprev = tps; //SAVE CURRENT TPS INTO PREVIOUS
Serial.print("tps = ");//REMOVE AFTER DEBUGGING
Serial.println(tps); //REMOVE AFTER DEBUGGIN
Serial.println("Requesting temperatures..."); //REMOVE AFTER DEBUGGING
sensors.requestTemperatures();
Serial.println("DONE");//REMOVE AFTER DEBUGGING
Serial.print("Temperature is:");//REMOVE AFTER DEBUGGING
Serial.println(sensors.getTempFByIndex(0));//REMOVE AFTER DEBUGGING
ets = sensors.getTempFByIndex(0); //READ ETS
Serial.print("ets="); //REMOVE AFTER DEBUGGING
Serial.println(ets); //REMOVE AFTER DEBUGGING
}
}
Thank you for all your advice and help!
I figured it out. Had to use dtostrf due to the float variable.