Start a new topic

Use the TX and RX serial with a pic

Hello,


I'm trying to comunicate in serial my nextion 2.8" with my pic 18f2550 (microchip) but i don't know how i must send and receive data in asynchronous, i'm reading the tutorials and manuals but i don't find the command to read and write a byte as putsUSART() or ReadUSART() or getUSART() (talk in C lenguage)



For example:


I've create a button in the nextion display and in the "TouchPressEvent" wrote:

printh d0 a0

but when i push the button in my nextion hmi it's not send. I tried to connect in serial the nextion with my computer using hyperterminal but it don't receive data.


My questions are: 

whats is the command to write a read a byte (or bytes) in serial? 

What else should i do to transmit serial? 

and what is this 0xFF 0xFF 0xFF in the end and when is it use in my communication protocol?



Thanks,


King regards.


Hi Carlos. I am having the same issues but i figured out how to send data from the display to PIC. In your example all you have to do is:
1 - In the Nextion Editor, click on the button component. You will see at the bottom  part of your monitor two windows. One for the Touch Press Events and another for the Touch Release Events (I think those are the names).
2 - In each of these windows there is a checkbox with the label Send.
3 - Just check it and the display automatically sends the information through TX/RX.

If you check it on the Touch Press Events the display will send through TX/RX the information that you touch the button each time you press the button.

If you check it on the Touch Release Events, the display will send the informatios that you release the button.

The display will send the information using this protocol:

0X65+Page ID+Component ID+TouchEvent+End
Definition of TouchEvent: Press Event 0x01, Release Event 0X00)
Instance: 0X65 0X00 0X02 0X01 0XFF 0XFF 0XFF
Meaning: Page 0, Button 2, Press

The triple 0xFF is the "end byte" which indicate that the transmission is finished.

Unfortunatelly I have not find out how to send data from PIC to the MCU yet.

 

I am not familiar with the PIC, however, there would have to exist a serial library for the PIC by now.

Perhaps like the one found here

http://embedjournal.com/arduino-like-serial-uart-library-pic-18-microcontrollers/


Then Nextion has various instructions like the get command, or page0.t0.txt="hello"


Hope this might be of some use.


Maybe you can use ASCII communication only? Then all characters are readable and it is easy to convert them to ints in C using functions atoi () or atof().

So make answer for example
prinf "Button0=1"

And use strstr()  function to recognize "Button0=" in answer and take byte value after that.

For configuration PIC UART to work, it is very helpful to use Microchip MCC plugin that is now integrated into MPLABX IDE, you just need to install it additionally from plugins menu.

I also made short tutorial about sending receiving basic commands from Nextion display that is available at: http://www.electronics-base.com/featured-components/display/nextion-display-and-docklight-adding-gui-to-your-microcontroller-projects

I hope this helps a bit.

 

Thank you for your contribution

Login or Signup to post a comment