Start a new topic

Read variable value in PIC microcontroller (CCS)

Hello, I would greatly appreciate an orientation.

I am trying to read the data or variables sent by a NEXTION display.


all right. It sends via RS232 the following string of values:

0x3B 0x00 0x00 0x00


these values are the number "59".


What I need is to store that string in a variable with the value "59" in the microcontroller.

Is it possible to send the whole value: "59" from the screen?


Does anyone have a routine in CCS or MPLAB X8 (c language) to read the values that the screen sends?


I would appreciate your contribution.

In brief, Nextion can be used with 

  65000+ MCUs in 100+ programming languages

User choice of which MCU and in what programming language

Nextion has text based instructions for commands

   and Formatted Return Data in response

Every good compiler for microprocessors will have a serial routine

 - learn from the compiler how to push a byte and read a byte.

as 0x3B 0x00 0x00 0x00 is decimal 59 in 32 bit little endian order

 - then isn't Nextion indeed already sending "59" from the screen?  

Thank you very much for your help.

Let me ask you a question.

In the Nextion debug option (simulation), the display sends the variable as follows:


Do I really get ASCII spaces inbetween bytes ? 

And do I really get "0x" in ASCII characters in front of each byte ?

Is there a way to connect the display to the computer or is there an option in the Nextion simulator that allows me to observe the data sent by the display in real time? (having the display connected to the PC?)

Just to get a better handle on how to relate things to you

Do you have other computer experience, or is this your first

Indeed there are ways of hooking it up for a "real time" view

Depends on what tools you have, what and how you want to see

- I might argue a "real time" view will happen so quick

  you wouldn't visually see it occur, such as an oscilloscope.

But can you explain what your background is

Thanks again

My purpose is:


Observe how the exact format of the data returns the display.

So my previous question:

In the Nextion debug option (simulation), the display sends the variable as follows:


Do I really get ASCII spaces inbetween bytes ? 

And do I really get "0x" in ASCII characters in front of each byte ?

I can directly connect the screen with this cable to the computer (included + 5Volt and ground and obviously RX and TX? The nextion Editor have anyting serial monitor or debug in real time hardware?

I am a Mechatronic engeenier. and I have knowledge of the subject

Okay, considering your background

I think the piece you maybe missing is a programming fundamental

10 even time width electrical pulses on a wire make up a byte

 - start bit always low

 - 8 data bits (sent least significant first)

 - stop bit always high

of the 8 data bits, although does make a byte ... but also an unsigned char

It is how you format the data structure as to how you see/view it

0x02 0x00 0x00 0x00 would be 32-bit or 4 bytes (in little endian order)

   decimal value 2, binary 10, as a char not printable, as hex 02, as octal 002

Hex is chosen as all values from 0 to 255 can be seen

   noted by the prefix "0x", the next two chars are hexadecimal or 4 bit nibbles

If you were to loop Nextion output to a serial terminal

   the values 0 to 31 and others are not printable and empty - therefore missing

So hex is the standard that is used.

    So you actually are indeed seeing exactly what will be returned

To see the Nextion device actually send this then

  (assumed connected via a USB to TTL serial adapter or TTL FTDI) 

In the debug change Send Command to: from Current Simulator


   to Nextion Device at the top, select comport and connect

You will see the Nextion uploaded with the same will send the same in the

   User MCU  Return Data section.  0x02 0x00 0x00 0x00

4 bytes of hexadecimal returned.

I hope this maybe helps explain what you seemed to be missing

For correctness

   RS232 does not equal TTL, RS232 will kill a Nextion

   and rs232c is low voltage on idle, TTL is high voltage on idle

If you now understand the byte representation of the 0x02 in Hex

I would suggest using the Nextion Return Data format (as per Nextion Instruction Set)

   - your print command is not Nextion Return Data formatted

     (get n0.val would have returned 0x71 0x02 0x00 0x00 0x00 0xFF 0xFF 0xFF)

Mixing both Formatted and Freelanced Data to your MCU

   - will require two sets of routines, one to handle each

     and using much more MCU side code to accomplish the same

Attempting to only go with print and Freelanced Data

   is to ignore the many Nextion informational statuses

ok, thank very much. 

I will keep you informed. If I can do the CCS routine for the microcontroller, I will post it here for people to use.

PIC is quite a few controllers

 - as such, is it now somewhat important to mention which controller

 - as well as hardware usart support or bitbanging two pins, or other?

But the example in the ccs manual not sufficient?

Login or Signup to post a comment