Just curious if anyone has attempted to use an imp with a nextion display? I am working on an AC controller which will have a temp sensor, the imp and a display. I was able to read from the temp sensor (I2C) very easily, but I am struggling to send commands to the display. Right now all I want to do is update a number on the LCD which requires something like “temp.val=70” to be sent using serial. The quirk with this display is that you need to send your command and then three bytes of 0xFF to signal the end of the command. Knowing this I also tried writing “temp.val=70ÿÿÿ” which still does not work.
I read that using uartXX.write sends a minimum of 20 bytes which I think might be the issue. Is there a way to send a single byte of data? Right now this portion of my code only consits of two lines.
I can talk to the display fine with an arduino using the following code.
serial.print(“temp.val=70”);
serial.write(0xFF);
serial.write(0xFF);
serial.write(0xFF);
In the uart.write documentation page it says:
"By default, the transmit FIFO is set at 80 bytes is size. However, under impOS Release 32 and up, the size of the FIFO may be altered using settxfifosize()." https://electricimp.com/docs/api/hardware/uart/write/
If you then go to the settxfifosize page it says:
"This method allows you to change the size of the output FIFO stack on the target UART serial bus. The default size is 80 bytes, but this can be changed to any size of 20 bytes or greater. " https://electricimp.com/docs/api/hardware/uart/settxfifosize/
Writing to UART adds the blob bytes, string bytes or integer values to the buffer. When the buffer fills, it’s transmitted. flush() forces the buffer to be sent no matter how many bytes it has provided it’s not empty.
uart.flush() is simply a blocking method. the uart tx buffer will empty of its own accord as soon as you load data with uart.write(). The tx buffer size is adjusted to avoid any unhelpful blocking while the uart transmit shift register is slowly shifting bits onto the wire.
Yes, @coverdriven you’re right; serial behaves as it always has. When the number of bytes in the fifo transitions from zero to one, the transmission is started. You configure a bigger FIFO if you want to more data in there at once; I’m not aware of any reason you’d want a smaller FIFO aside from for saving memory.
uart.flush() blocks until the fifo has totally emptied and the last byte has exited the UART hardware (as I remember).