Combing code for hall effect RPM and Nextion tacho

Looking at the nextion code again I see that I failed to notice the delay right at the beginning of loop().
That is most certainly interfering with the halltach code. Also all those serial.write's in the testing indicators section are not helping either.

Start by commenting out the entire "testing indicators" section for now. then you need to get rid of the delay.

According to the comments the delay is only there to keep from updating the display to fast. Since we are getting rid of the testing indicators section, that leaves only this section:

  // Send tachometer value:
  Serial.print("tach.pic=");  // This is sent to the nextion display to set what object name (before the dot) and what atribute (after the dot) are you going to change.

  // Choose one of the folling two, on what value to send to the tachometer:
  //Serial.print(TachometerWithDeadzone);  // Send RPM smoothed and with deadzone
  Serial.print(TachometerRemapedWithoutSmoothing);  // Send RPM without any smoothing at all

  Serial.write(0xff);  // We always have to send this three lines after each command sent to the nextion display.
  Serial.write(0xff);
  Serial.write(0xff);

So lets wrap it in a timer and then remove the delay.

// Timing Variables - put these at the top with the others
unsigned long screenUpdateInterval = 20;
unsigned long previousUpdateTime;





  if(millis() - previousUpdateTime >= screenUpdateInterval )  // Timer that replaces the delay() for updating the display
 {
  // Send tachometer value:
  Serial.print("tach.pic=");  // This is sent to the nextion display to set what object name (before the dot) and what atribute (after the dot) are you going to change.

  // Choose one of the folling two, on what value to send to the tachometer:
  //Serial.print(TachometerWithDeadzone);  // Send RPM smoothed and with deadzone
  Serial.print(TachometerRemapedWithoutSmoothing);  // Send RPM without any smoothing at all

  Serial.write(0xff);  // We always have to send this three lines after each command sent to the nextion display.
  Serial.write(0xff);
  Serial.write(0xff);
 }
1 Like