How to monitoring serial port and displayed it on a OLED display

Hi all,

I hope you can help a newbie.

im trying to

Hardware setup:

Equipment that sends RS232 level -12V to 12V - Baud rate 2400 with average of 48 bytes per second.
Protocol setup: 8 data bits, no parity, 1 stop-bit
Data stream: 0xFF,{data1},{data2},{data3},{data4},{data5}
(Value of the data bytes 1 to 5 is always between 0 and 0xFE (254). After 10 data sets of normal information an alternating data set is send.)

The idea is now to monitoring the serial data like this:

Equipment RS232
Pin out 2,3 and 5 --> MAX3232 - RS232 to TTL Serial Port Converter -->

Pin out
(MAX3232) --> (Particle electron)
GND --> GND
TXD --> TX
RXD --> RX
VCC --> 3V3


2nd part of hardware - OLED display

Pin-out
(OLED) -> (Particle Electron)
GND -> GND
VCC -> 3V3
SCL -> D1
SDA -> D0


How can i monitoring the serial data and displayed it / print it to the OLED display

Hope for some help here.
Thanks

/Meg

@MegZamani, at 48 bytes per second, exactly what are you expecting to display? That is, how do you want to digest and display your data?

There should be two parts to your code. One will receive and parse your data sets and another will be to analyze and display your data on the OLED.

@peekay123 - Telemetry data viewer, but for a test i´m going to use a OLED or 16x2 display and later on change it to a bigger display 800x480

@MegZamani, not sure what you mean by “Telemetry data viewer”. However, at 48 bytes/s, if you display each byte as a HEX number, you will not be able to ready anything. I’m still not clear how you would use an OLED or 16x2 display to show your data unless you are processing it somehow. This is what you need to clarify.

The reason I ask is that one part of the code will receive and buffer and/or process the data. Another part will display that data. Are you asking how to capture the data or how to display it or both?

@peekay123

The reason I ask is that one part of the code will receive and buffer and/or process the data. Another part will display that data. Are you asking how to capture the data or how to display it or both?

As what i do understand by reading about serial commands since I don't really program, (but trying) then i will need to receive and parse the data.

I know the oled display is not the best for the job is the plan to maybe use a Nextion LCD display.
It is drone engine telemetry data a real time monitoring of the temperature, speed on board the aircraft.

@MegZamani, ok, now I understand. In order to capture the serial data, you will need to be looking for characters from Serial1 on a continuous basis in loop(). You can use Serial1.available() for that combined with Serial1.read().

The trick is to create a simple finite state machine (FSM) that looks for the starting 0xFF byte. After that you can read the remaining bytes into a char array buffer.

So basically the FSM looks a bit like this:
State 1: wait on serial byte being available and when it is, check that it’s a 0xFF. If it is, go to State 2.

State 2: wait on serial bytes being available and when they are, read (only) 5 of them (use a counter). Once you have 5, you have captured the entire set so go to State 3. Otherwise keep waiting and checking. If at any point you read a 0xFF during the byte count, restart State 2 - something went wrong.

State 3: Display your data. This needs to be quick so you don’t miss any serial data coming in (only 32 bytes are buffered by the system firmware). Once displayed, go back to State 1 for the next set of data.

You could make it so instead of displaying the data on each set, you average the data and other code in your loop displays it every second (for example).

The idea behind the FSM is that it is non-blocking and runs on each loop(). The FSM is always only in one state (until changed) so it is easy to write code that “steps” through whatever steps are needed to do the job.

Hope this makes sense :wink:

2 Likes

Thanks for your input @peekay123
If you have any tutorials / links, - where and how to start the project. please let me know