Process serial data on Arduino or on Raspberry Pi (via python)?

Hello everyone,

I am doing a small project where I am using an Arduino Mega via Software Serial to pull data (4800 baud) from my home alarm system. Ultimately I will push the data through my raspberry pi using python and flask-socketio to a web client for viewing system messages.

(Note: I know there are ready-made modules and devices others have built that do all this, but this is a learning by doing project for me. Also, I have already done a few prototypes of LED blinks where I have full end-to-end communication between my web client, python on the R Pi, and the Arduino, so I'm pretty good on the concepts there.)

The alarm system puts out chunks of usable data in roughly 20-40 byte hex packages. I'm successfully reading the data and seeing it on my serial terminal in the Arduino IDE.

The data package does require some processing in order to extract useful information that I can then push to the web client. For example, there are few bytes that need to be analyzed with bit masks to indicate various system status conditions. Also, there are 32 bytes that map to ASCII that create the alphanumeric message on the alarm system's keypads. This 32-character is something else I also want to get over to the Raspberry Pi and display on the web page via flask.)

So here is my question: Given some of the issues in handling strings on the Arduino, do you all think it is best for me to just "byte-by-byte" send over the entire block of 40 bytes to the Raspberry Pi and do all the processing of the message in Python on the R Pi, or should I do the processing on the Arduino and send over more "ready to use" data to python?

Look forward to your thoughts!

“using an Arduino Mega via Software Serial” Why? Mega has 4 serial ports: Serial, Serial1, Serial2, Serial3. Use one of those.

Your call on the data manipulation. I’d recommend: Pull it in and store it in array, do whatever manipulation, send it out.

Unfortunately I can’t use the built-in serial ports as the alarm system sends inverted - so I use SoftwareSerial instead to easily handle that.

This simple Python - Arduino demo may help.

…R

Robin, thanks very much for the link. I have actually used that code and similar for past projects to get 2way serial communication going between my Arduino and Raspberry Pi python environment.

I’m mostly wondering whether there would be pros/cons of doing the bulk of the parsing of the data on the Arduino vs Python.

steve20016:
I’m mostly wondering whether there would be pros/cons of doing the bulk of the parsing of the data on the Arduino vs Python.

It is my own policy to do as much as possible of the hard work on a PC rather than on an Arduino.

...R

steve20016:
I’m mostly wondering whether there would be pros/cons of doing the bulk of the parsing of the data on the Arduino vs Python.

Since you're sending the data to the Pi anyway, let it take care of processing it. Debugging tools are better there. The only reason I can see to parse it on the Arduino in this case would be if the data were verbose and coming quickly, but at 4800 baud, that's not likely to be a problem.

Actually, I'd be tempted to see if you could drop the Arduino entirely and give the data directly to the Pi, although you may need some level shifting hardware to deal with 3V3.