Blynk and Nextion

Three backticks for and aft, not two :slight_smile:

Blynk%20-%20FTFC

dohhh sorry about that :confused: i shall rememebr that for future posts, cheer Gunner. Just to add, its when i uncomment //bt1.setValue(1); or //bt1.setValue(0); on my skimmer button BLYNK_WRITE(V2){ i get the compling issue.

As I donā€™t have NexHardware.h I just used an empty file and complied for Mega 2560 using IDE 1.8.7 on Win8.1 (also 1.8.8 on Win10) and the latest Blynk lib.
No errors with bt1.setValue(1); and bt1.setValue(0); uncommented in BLYNK_WRITE(V2). :+1:

strangly i just tried it with no errors to,very strange as i havnt chnaged anything. upoon tetsing, sometimes blynk misses the button pressed on the nextion and dosnt act and vice verser. how could i get round this? should i add flags

I think Iā€™ve found something worth looking at: Itā€™s the way the two DS18B20 are set (resolution) and how they are interrogated (blocking).

According to the datasheet (https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf table on page 3) it takes 750ms (!) (at 12 bit resolution) to get the temperature.

take_temp_readings() is called once per second (not sure if that is practically necessary). This is close to the time it takes to read the temperature from the sensors.

What I would change in the first place:

void take_temp_readings() 
{
  [...]
  //Serial.println();     
  tanktemp = DS18B20.getTempCByIndex(0);
  sumptemp = DS18B20.getTempCByIndex(1);
  DS18B20.requestTemperatures(); 
  
  [...] 
}
void setup()
{
  [...]
  DS18B20.begin(); 
  DS18B20.setResolution(Probe01,10);  
  DS18B20.setResolution(Probe02,10);
  
  DS18B20.setWaitForConversion(false); // make reading NON blocking
  DS18B20.requestTemperatures();       // start conversion for first reading 
  
  [...]
  
  timer.setInterval(2000L, take_temp_readings);  // Setup a function to be called every 2 seconds

  [...]
}//--(end setup )---

thank you for noticing that :slight_smile: i have made the changes and the code seems much sommer now :slight_smile: and is no longer missing a button press either from the nextion. thank you so much for your help. If theres anything else that catches your eye please shout :slight_smile:

Update, my idea with changing the button value works but if I change the page on the nextion and go back to the original page, all the settings are gone -.-

@Bundy FYI, as your issueā€™s posts got longer, I moved them all into your own topic.

I also have a 2.4" Nextion display, but has so far it is only used it as a Weather Display for Blynk Data and I have not integrated any touch functions back to Blynk, so this is interesting reading for when I finally get around to that.

Sweet cheers Gunner :slight_smile: ahh fair enough, I guess that data is refreshed at a set interval? Iā€™m thinking this part may have something to do with it

// Page change event:
void page0PushCallback(void *ptr)  // If page 0 is loaded on the display, the following is going to execute:
{
 CurrentPage = 0;  // Set variable as 0 so from now on arduino knows page 0 is loaded on the display
}  // End of press event

Maybe set the button values again here although Iā€™m not sure how to store a button value as a int instead of this uint32_t number5 = 0; where I could then use a statement like bt0.setValue(number5); so when the page is loaded so is the button value

@Bundy: Good to hear! :sunglasses:

No reason to shout :grin: Just one more thing worth looking at is the use of the timers as you use a number of them and many run functions in parallel. It does not seem to be an issue as the functions do not block.

But, anyhow itā€™s always a good idea to have a look at @Gunnerā€™s collection C++ Blynk (Legacy) - Code Examples for Basic Tasks - #49 by Gunner - in this particular case Iā€™d
recommend the topic ā€œ#12 - Timers simplifiedā€¦ perhapsā€¦ā€ ā†’ ā€œStaggering Timersā€

Sweet thank you Iā€™ll take a look into that and make the required changes. Once iv added all my features, Iā€™ll then go back through it all and add arrays and try to make things more compact and simplified.

Continuing on from my previous issue, I think iv found the solution.

This video shows how to store the button value within the nextion editor and then call up that variable when you change pages. Perfect! Keeps a bit of code off the arduino :smiley:

Next step is, display hour, minute and second in text boxes on the home screen

1 Like

Failing miserably at sending of the time to a txt box -.- I tried calling the hour by

String hour1 = String hour(); 

And then sending that as a String to the txt box but nothing happens :confused:

Not sure if I need to convert it to the buffer and then send it like I did with the temperature or what.

If anyone has any ideas or examples that may help me that would be great :slight_smile:

@Bundy: What I usually do to display date and time in the app is to put everyting (with leading zeros) into a string using sprintf([ā€¦],[ā€¦]). Should work in an equivalent way in your case.
Example:

void dateTimeDisplay()
{
  char currentTime[20];
  sprintf(currentTime,"%02u.%02u.%02u / %02u:%02u",day(),month(),year(),hour(),minute());
  Blynk.virtualWrite(V10, currentTime);  
}

Sorry I mean sending to the nextion, I have the time displayed on the blynk app at the moment. Another issue I have found with the buttons is that I canā€™t seem to change the variables I set for each button from the arduino. If I press a button on page 2, it turns a button on on page 1 like itā€™s suppose to for the nextion. But if I change the state or variable from the arduino it seems to ignore it. I must be setting the variable wrong.