Hi can anyone help me out, I am trying to make this nextion digital dash https://hackaday.io/project/168272-motorcycle-dashboard for my go kart with a motorcycle engine and I am getting an error message shown in the screenshot. the code can be found in the link. thanks
Edit: Sorry, here is the error message and code
Arduino: 1.8.15 (Mac OS X), Board: "Arduino Pro or Pro Mini, ATmega328P (5V, 16 MHz)"
/Users/evannichols/Downloads/DashBoard_Final_Test/DashBoard_Final_Test.ino: In function 'void timedChecks()':
DashBoard_Final_Test:622:18: error: 'DEVICE_DISCONNECTED_C' was not declared in this scope
if (tempC != DEVICE_DISCONNECTED_C)
^~~~~~~~~~~~~~~~~~~~~
/Users/evannichols/Downloads/DashBoard_Final_Test/DashBoard_Final_Test.ino:622:18: note: suggested alternative: 'DEVICE_DISCONNECTED'
if (tempC != DEVICE_DISCONNECTED_C)
^~~~~~~~~~~~~~~~~~~~~
DEVICE_DISCONNECTED
exit status 1
'DEVICE_DISCONNECTED_C' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
#include <doxygen.h>
#include <NexButton.h>
#include <NexCheckbox.h>
#include <NexConfig.h>
#include <NexCrop.h>
#include <NexDualStateButton.h>
#include <NexGauge.h>
#include <NexGpio.h>
#include <NexHardware.h>
#include <NexHotspot.h>
#include <NexNumber.h>
#include <NexObject.h>
#include <NexPage.h>
#include <NexPicture.h>
#include <NexProgressBar.h>
#include <NexRadio.h>
#include <NexRtc.h>
#include <NexScrolltext.h>
#include <NexSlider.h>
#include <NexText.h>
#include <NexTimer.h>
#include <Nextion.h>
#include <NexTouch.h>
#include <NexUpload.h>
#include <NexVariable.h>
#include <NexWaveform.h>
#include <EEPROM.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include<math.h>
const byte PulsesPerRevolution = 2;
const unsigned long ZeroTimeout = 60000;
const byte numReadings = 10;
byte TachometerDeadzoneSamples = 2;
volatile unsigned long LastTimeWeMeasured;
volatile unsigned long PeriodBetweenPulses = ZeroTimeout + 1000;
volatile unsigned long PeriodAverage = ZeroTimeout + 1000;
unsigned long FrequencyRaw;
unsigned long FrequencyReal;
unsigned long RPM;
unsigned int PulseCounter = 1;
unsigned long PeriodSum;
unsigned long LastTimeCycleMeasure = LastTimeWeMeasured;
unsigned long CurrentMicros = micros();
unsigned int AmountOfReadings = 1;
unsigned int ZeroDebouncingExtra;
unsigned long readings[numReadings];
unsigned long readIndex;
unsigned long total;
unsigned long average;
int TachometerWithDeadzone;
int TachometerRemaped;
int maxRPM;
const float Pi = 3.141593;
#define RpmPin 3
#define SpeedPin 17
#define IndexPin 8
#define BatteryPin A0
#define EngTempPin A1
#define ClockPin_1 A2
#define Clock_Pin_2 A3
#define NeutralPin 10
#define FuelPin 6
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
unsigned long minCounter = 0;
unsigned long minCounterHours = 0;
float currentHourCount;
int hourToSend;
float distanceWithOneRotation;
int voltage;
float currentDistance = 0;
int DistanceKM;
int tripA;
int tripB;
float start, finished;
float elapsed;
int speedk = 0;
bool isHighTempOn = true;
bool isBatteryLow = true;
float radiusMagnet;
float radiusWheel;
bool tempChange = 0;
int biggestSpeed = 0;
int engTempInt;
NexNumber n0 = NexNumber(1, 3, "n0");
NexText t3 = NexText(1, 4, "t3");
NexPage page1 = NexPage(1, 1, "page1");
NexNumber mRpm = NexNumber(1, 9, "n2");
NexNumber whRad = NexNumber(1, 12, "n4");
NexHotspot hotSpotA = NexHotspot(6, 2, "m1");
NexHotspot hotSpotB = NexHotspot(7, 2, "m1");
NexNumber tempNex = NexNumber(0, 14, "n3");
NexTouch *nex_listen_list[] =
{
&t3,
&n0,
&mRpm,
&whRad,
&hotSpotA,
&hotSpotB,
&tempNex,
NULL
};
void setup()
{
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(RpmPin), Pulse_Event, RISING); // Enable interruption pin 2 when going from LOW to HIGH.
attachInterrupt(digitalPinToInterrupt(SpeedPin), speedCalc, FALLING);
delay(1000);
Serial.print("baud=115200");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Serial.end();
Serial.begin(115200);
analogReference(DEFAULT);
start = millis();
sensors.begin();
t3.attachPush(t3PushCallback);
hotSpotA.attachPush(hotSpotAPushCallback);
hotSpotB.attachPush(hotSpotBPushCallback);
tempNex.attachPush(tempNexPushCallback);
delay(500);
eepromReads();
}
void speedCalc()
{
DistanceCounter();
if ((millis() - start) > 100) // 100 millisec debounce
{
//calculate elapsed
elapsed = millis() - start;
//reset start
start = millis();
//calculate speed in km/h
speedk = round((3600 * distanceWithOneRotation) / elapsed);
}
}
void loop() // Start of loop:
{
if (millis() - start > 1000) {
speedk = 0;
}
if (speedk > biggestSpeed) {
biggestSpeed = speedk;
Serial.print("page9.n0.val=");
Serial.print(biggestSpeed);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
Serial.print("page0.n0.val=");
Serial.print(speedk);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
if (millis() - minCounter >= 2000) {
minCounter += 2000;
timedChecks();
}
cycleCheck();
nexLoop(nex_listen_list);
//RPM gauge
LastTimeCycleMeasure = LastTimeWeMeasured; // Store the LastTimeWeMeasured in a variable.
CurrentMicros = micros(); // Store the micros() in a variable.
if (CurrentMicros < LastTimeCycleMeasure)
{
LastTimeCycleMeasure = CurrentMicros;
}
FrequencyRaw = 10000000000 / PeriodAverage; // Calculate the frequency using the period between pulses.
if (PeriodBetweenPulses > ZeroTimeout - ZeroDebouncingExtra || CurrentMicros - LastTimeCycleMeasure > ZeroTimeout - ZeroDebouncingExtra)
{ // If the pulses are too far apart that we reached the timeout for zero:
FrequencyRaw = 0; // Set frequency as 0.
ZeroDebouncingExtra = 2000; // Change the threshold a little so it doesn't bounce.
}
else
{
ZeroDebouncingExtra = 0; // Reset the threshold to the normal value so it doesn't bounce.
}
FrequencyReal = FrequencyRaw / 10000;
// Calculate the RPM:
RPM = FrequencyRaw / PulsesPerRevolution * 60;
RPM = RPM / 10000;
// Smoothing RPM:
total = total - readings[readIndex];
readings[readIndex] = RPM;
total = total + readings[readIndex];
readIndex = readIndex + 1;
if (readIndex >= numReadings)
{
readIndex = 0;
}
average = total / numReadings;
TachometerRemaped = map(average, 0, maxRPM, 0, 100); // Remap the smoothed RPM to match the tachometer value range.
TachometerRemaped = constrain(TachometerRemaped, 0, 100); // Constrain the value so it doesn't go below or above the limits.
int TachoWithDead = average + ((average - TachometerWithDeadzone) / TachometerDeadzoneSamples);
TachometerWithDeadzone = TachometerWithDeadzone + ((TachometerRemaped - TachometerWithDeadzone) / TachometerDeadzoneSamples);
if (TachometerRemaped == 0) // If RPM is 0:
{
TachometerWithDeadzone = 0; // Show real tach as 0.
}
// Max limit:
if (TachometerRemaped >= 100) // If the RPM is above or equal the maximum limit:
{
TachometerWithDeadzone = 100; // Show tach as maximum limit.
}
Serial.print("page0.j0.val=");
Serial.print(TachometerWithDeadzone);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Serial.print("page0.n1.val=");
Serial.print(TachoWithDead);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
if (millis() - minCounterHours >= 360000) {
minCounterHours += 360000;
if (TachoWithDead > 500) {
currentHourCount = currentHourCount + 0.1;
hourToSend = currentHourCount * 10;
EEPROM.update(20, hourToSend);
Serial.print("page9.x0.val=");
Serial.print(hourToSend);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
}
//RPM gauge end
} // End of loop.
void Pulse_Event()
{
PeriodBetweenPulses = micros() - LastTimeWeMeasured;
LastTimeWeMeasured = micros();
if (PulseCounter >= AmountOfReadings)
{
PeriodAverage = PeriodSum / AmountOfReadings;
PulseCounter = 1;
PeriodSum = PeriodBetweenPulses;
int RemapedAmountOfReadings = map(PeriodBetweenPulses, 40000, 5000, 1, 10);
RemapedAmountOfReadings = constrain(RemapedAmountOfReadings, 1, 10);
AmountOfReadings = RemapedAmountOfReadings;
}
else
{
PulseCounter++;
PeriodSum = PeriodSum + PeriodBetweenPulses;
}
} // End of Pulse_Event.
void DistanceCounter() {
currentDistance = currentDistance + distanceWithOneRotation;
if (currentDistance >= 1000) {
DistanceKM++;
tripA++;
tripB++;
currentDistance = 0;
EEPROM.put(5, DistanceKM);
EEPROM.put(7, tripA);
EEPROM.put(9, tripB);
Serial.print("page0.n2.val=");
Serial.print(DistanceKM);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Serial.print("page0.n4.val=");
Serial.print(tripA);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Serial.print("page0.n5.val=");
Serial.print(tripB);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
}
void t3PushCallback(void *ptr) {
uint32_t getvalue = 0;
uint32_t rpmvalue = 0;
uint32_t whRadius = 0;
n0.getValue(&getvalue);
mRpm.getValue(&rpmvalue);
whRad.getValue(&whRadius);
EEPROM.update(0, getvalue);
EEPROM.update(1, rpmvalue);
EEPROM.update(3, whRadius);
radiusMagnet = EEPROM.read(0) * 0.1;
radiusWheel = EEPROM.read(3);
maxRPM = EEPROM.read(1) * 1000;
delay(100);
Serial.print("page 0");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
void hotSpotAPushCallback(void *ptr) {
tripA = 0;
EEPROM.put(7, tripA);
Serial.print("page0.n4.val=");
Serial.print(tripA);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Serial.print("page 0");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
void hotSpotBPushCallback(void *ptr) {
tripB = 0;
EEPROM.put(9, tripB);
Serial.print("page0.n5.val=");
Serial.print(tripB);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Serial.print("page 0");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
void eepromReads() {
Serial.print("page1.n0.val=");
Serial.print(EEPROM.read(0));
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Serial.print("page1.n2.val=");
Serial.print(EEPROM.read(1));
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Serial.print("page1.n4.val=");
Serial.print(EEPROM.read(3));
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Serial.print("page9.x0.val=");
Serial.print(EEPROM.read(20));
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
hourToSend = EEPROM.read(20);
radiusMagnet = EEPROM.read(0) * 0.001;
radiusWheel = EEPROM.read(3) * 0.01;
maxRPM = EEPROM.read(1) * 1000;
TachometerDeadzoneSamples = EEPROM.read(3);
distanceWithOneRotation = 2 * radiusWheel * 3.1415;
EEPROM.get(5, DistanceKM);
EEPROM.get(7, tripA);
EEPROM.get(9, tripB);
//Trip A
Serial.print("page0.n4.val=");
Serial.print(tripA);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
//Trip B
Serial.print("page0.n5.val=");
Serial.print(tripB);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
//FullDistance
Serial.print("page0.n2.val=");
Serial.print(DistanceKM);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
void timedChecks() {
//Battery voltage
voltage = (analogRead(BatteryPin) * (5.0 / 1023) * ((68 + 35) / 68) * 1000);
if (voltage <= 1200 && isBatteryLow == false) {
Serial.print("vis p10,1");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
isBatteryLow = true;
}
else if (voltage > 1200 && isBatteryLow == true) {
Serial.print("vis p10,0");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
isBatteryLow = false;
}
//Fuel sign
if (digitalRead(FuelPin) == true) {
Serial.print("vis p5,1");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
else {
Serial.print("vis p5,0");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
//Temperature
engTempInt = getTemp();
if (engTempInt >= 95 && isHighTempOn == false) {
Serial.print("vis p3,1");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
isHighTempOn = true;
}
else if (engTempInt < 95 && isHighTempOn == true) {
Serial.print("vis p3,0");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
isHighTempOn = false;
}
if (tempChange == 1) {
Serial.print("page0.n3.val=");
Serial.print(engTempInt);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
else {
//Outside temp
sensors.requestTemperatures();
float tempC = sensors.getTempCByIndex(0);
if (tempC != DEVICE_DISCONNECTED_C)
{
int outTempInt = round(tempC);
Serial.print("page0.n3.val=");
Serial.print(outTempInt);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
else {
Serial.print("page0.n3.val=");
Serial.print(123);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
}
}
void cycleCheck() {
//Index
if (digitalRead(IndexPin) == true) {
Serial.print("vis p4,1");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
else {
Serial.print("vis p4,0");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
/*
//High beam
if (digitalRead(NeutralPin) == true) {
Serial.print("vis p9,1");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
else {
Serial.print("vis p9,0");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
*/
}
void tempNexPushCallback(void *ptr) {
if (tempChange == 0) {
tempChange = 1;
}
else {
tempChange = 0;
}
}
int getTemp()
{
// Converts input from a thermistor voltage divider to a temperature value.
// The voltage divider consists of thermistor Rt and series resistor R0.
// The value of R0 is equal to the thermistor resistance at T0.
// You must set the following constants:
// adcMax ( ADC full range value )
// analogPin (Arduino analog input pin)
// invBeta (inverse of the thermistor Beta value supplied by manufacturer).
// Use Arduino's default reference voltage (5V or 3.3V) with this module.
//
const int analogPin = 0; // replace 0 with analog pin
const float invBeta = 1.00 / 3470.00; // replace "Beta" with beta of thermistor
const float adcMax = 1023.00;
const float invT0 = 1.00 / 298.15; // room temp in Kelvin
int adcVal, i, numSamples = 5;
float K, C;
adcVal = 0;
for (i = 0; i < numSamples; i++)
{
adcVal = adcVal + analogRead(analogPin);
delay(100);
}
adcVal = adcVal / 5;
K = 1.00 / (invT0 + invBeta * (log ( adcMax / (float) adcVal - 1.00)));
C = round(K - 273.15); // convert to Celsius
return C;
}