Nextion Intelligent GPIO to Drive Adafruit MAX31855

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.

Kind regards,
Max