Start a new topic

Nextion and 1wire library issue ?

Hi all,


After doing examples and tests screens successfully I'm trying to work on my first real project with a Nextion HMI display and an Arduino board.


And I'm facing an issue.

I'm using the official Nextion library

I need to read 2 DS18B20 1wire temp sensors so I'm also using the 1wire library and the Dallastemperature library


I'm able to read the temperature sensors and display them with a number object on the Nextion display.

But none of the callback function respond, I tried with a button, a dualstate button, a slider... 

Is there a none issue with 1wire devices ?


I tried to remove the 1wire parts in my Arduino source code and then all my callback function begin to work, as soon as I activate the 1wire code none of the callback function respond. So I guess the issue is between the Nextion lib and the 1wire lib.


Thank you for your help


Here is a simple debug sketch which is not working.

I can send the temperature reading to the display but the dual state button could not light the 13 pin led.

ino

Good reading.

http://playground.arduino.cc/Learning/OneWire


I don't know how you coded your one wire, (and will not be debugging it)

however, an except from


Program timing for other functions


Arguably the biggest problem with using the above methodology is that unless threading measures are undertaken, the device must sit (hang) and wait for the conversion to take place if a hardcoded wait time is included. This presents a serious problem if other timed processes exist, and even if they don't -- many programs wait for user input, process data, and perform many other functions that cannot be put on hold for the time necessary for a temperature conversion process. As noted above and below, a 12-bit conversion process for a DS18B20 can take as long as 750ms. There is no reason to use the wait method, unless it is desired that the controller do nothing (at all) until the measurement conversion is complete. It is far more efficient to issue a conversion command and return later to pick up the measurement with a Read Scratchpad command once the conversion is complete.


So it is possible that you are not allowing the time needed in your coding techniques for nextion to be heard.

Thank you for your reply.

I posted at the same time an example sketch.


As you can see I read the DS18B20 only two times per second, and I tried to touch the Nextion screen when there is no 1wire communication but the issue is still present.

I can see the RX/TX leds blinking on the Arduino board so the screen is sending the information when touching the screen

I tried changing the 1wire input port on the Arduino.


I tried some debug and it seems I never enter the callback function.

OK, you're right. It's a timing problem.


I raised my update frequency to two seconds for the 1wire reading and now the callback function works sometimes.

But I'm not good enough to program the 1wire protocol by myself, thats' why I'm using the libraries. I have to find another way


Thank you for you help :)

If I am not mistaken the DS18B20 needs 750ms. Twice per second is 1.5s of every second

- perhaps lending to the choking the Nextion data from being received and processed

... almost but not really.


I might suggest researching and using the Read ScratchPad method.


A Polling technique is where you use most of the MCU/CPU time to check if data is there

An Interrupt method allows a small "interruption in code" to allow a byte to be received when it arrives and to be handled at another time.


Polling uses high cycles (% of MCU time) to get few bytes

Interrupts use few cycles only as needed - MCU idles most of the time.


But there are many other issues explained within the OneWire page,

researching these issues may indeed help iron out your code.

@M4vrick

One thing you can try is to change line 46 in the file 'DallasTemperature.cpp' in the library:  

waitForConversion = false;  // ORIGINAL: true


Then in your sketch you change the order of the lines inside the function 'TempUpdate()':

void TempUpdate()
{
    //sensors.requestTemperatures();  // ==> Move this line down
    temperature = sensors.getTempCByIndex(0);
    Txt_Temp.setValue((int)temperature);
    sensors.requestTemperatures();  // <== Put it here
}

That way the function will first read the temperature measured after the previous request (1 second earlier), and then it sends a new request for the next cycle (1 second later).

The function 'sensors.requestTemperatures()' will not block the code for 1 second since the parameter 'waitForConversion' has been changed to false.


(I have not exactly tested the code as it is written here, so some extra adjustments may be needed.)


1 person likes this

Wow... I didnt see this option in the DallasConversion file.

This is exactly what I'm trying to do by myself/


Thank you :)


1 person likes this
Login or Signup to post a comment