I am new to the forums here and would like to know if anyone has any experience with this or not.
I have a NX8048P070_011.
I have the breakout for the GPIO ports.
I am making a thermostat.
I know how to use timers to fire code you want to run and I can get the GPIO ports on the display to fire relay boards and signal led’s.
The issue I am trying to accomplish is to use the GPIO ports directly on the display to pull the temp sensor data from the Adafruit MAX31855. I have seen others use an Arduino but I am trying to do this directly on the display so that there is less hardware to repair and less hardware to “accidentally” get damaged.
Any help would be appreciated as I am a beginner level coder at best.
Hi and welcome @Dichani!
I agree with your attitude of reducing potential failure points. However, in my opinion a dedicated microcontroller would be the better solution. It is much easier to write sensor interfaces in a “real” programming language than on Nextion - and it’s much, much faster. If you want to hear more about this topic, check out this post where I dived into all the details: Touch dragable ring slider? - #13 by Max
In case you really want to do it in Nextion anyways…
Edit: The speed calculations below apply to 48MHz Nextion only (Basic series, Enhanced series excluding 5 and 7 inch). Discovery series (64MHz) shouldn’t bee too far away, but Intelligent (200MHz, different CPU architecture) can’t easily be related to these values
- Nextion doesn’t give you access to the functionalities of it’s microcontroller required for efficient communication with the sensor. Luckily, this sensor seems to have a pretty simple serial interface (basically anything else wouldn’t be possible on Nextion). Nonetheless, you must implement the whole serial interface yourself:
- Generate a clock signal
- Read the bit sent each clock cycle into a temporary variable
- Shift the bit value into some storage variable
- This is not too hard, but you have to do all these steps for every bit, which limits how fast you can read the data.
- As I mentioned above, Nextion’s code is running quite slowly (thousands! of times slower than most Arduino compatible microcontrollers). It takes at least 40us per instruction - potentially more depending on what command you use. My back-of-the-envelope math counts at least 8 instructions to read one bit. At 40us/instruction you get 320us per bit or about 3kHz clock frequency. Remember, this is a best-case scenario. It could be below 1kHz as well. For comparison: similar serial interfaces (I2C f.ex.) read at 100kHz, 400kHz or more. This sensor in particular supports up to 5000kHz (5MHz).
- It’s not clear whether or not the sensor even supports such a low clock frequency; the datasheed doesn’t specify a minimum. While that is good, it doesn’t guarantee success because <3kHz is indeed lower than usual. It’s also unclear whether or not a symmetric clock signal is necessary (though I haven’t looked too closely at the datasheet). If it is, then you’d have to hook up a scope to your Nextion and adjust the order of the lines in your reading code until the signal is (mostly) symmetric.
- Again, the protocol of the sensor is really simple, so you only need to read one 32bit word, without requiring any sort of configuration. 32bits * 320us per bit => 10ms minimum for reading one value from the sensor without doing anything else. Realistically I’d expect at least 30ms (you have to process the value, too. Also, there’s overhead from calling the “function” that reads the sensor, etc). Just to put that into perspective: if you read this sensor 10 times per second you’d already consume 30% of the processing power of Nextion - thirty percent just for reading the most simple sensor possible.
As most of the times with this sort of “can it be done” questions, the shortened answer is yes. And the full answer is no, you shouldn’t. As a challenge and/or learning exercise about serial protocols it’s interesting. For productive usage just take an Arduino, write about three lines of code and never worry about it again.
Thank you for your reply. I figured it would go along those lines. I just had to ask if someone had done it and if it was easy. This is going into a commercial gas fired fryer with an electronic ignition module and automated lift actuators for the baskets. I eventually plan on adding wifi capability and possibly an app link style setup so that a group of the units could be controlled from one device. But right now I am still in the design process of the stand alone model so I was wondering if I could skip the Arduino board setup easily for testing. But meh. . . . . To the Microcontrollers I go!! Wish me luck.
I overlooked that you’re using an Intelligent series screen. Sorry for that. Those are clocked at 200MHz instead of 48MHz (see edit of my previous reply), so it wouldn’t run as slow as described above. Though still miles away from native code for sure. Doesn’t make a difference for the effort required to implement it of course.
Another option might be to omit Nextion instead. Especially if you plan on WiFi etc. it might be worth looking at an ESP32 or similar which are powerful enough to run a graphics library like lvgl. This should not only lower BOM cost but also increase flexibility and capabilitites since you’re no more limited by Nextions restrained ecosystem. Of course it’s not without cost; the learning curve is steeper.
In any case, please remember that Nextion is focussed on simplicity. There are no “more powerful” tools/instructions/… available if you decide to scale up your application or its features. This has bitten more than one forum user here (including myself) whose applications have outgrown Nextion and now have to painfully work around its limitations because they’re out there in their devices. In my case I didn’t expect my project to grow as far as it has, but since you explicitly mentioned adding functionality I’d really think twice about what you might add in the future and whether or not you really want to do that on Nextion.