leovz
Posts: 3
Joined: Mon Jul 11, 2016 7:34 pm

rasp < ardo data processing?

Mon Jul 11, 2016 8:08 pm

Hello,

I am stuck with my project! Who can point me in the right direction?

What is working:
arduino is dumping data on the serial port
raspberry pi B is reading it.
I can read raw data

Code: Select all

import serial

serial_bauds = 9600
serial_port = '/dev/ttyACM0'

ser = serial.Serial(serial_port, serial_bauds)

while True:
        print(ser.readline())
This is the output:

Code: Select all

H: 54.90
W: 0.0
T: 25.70
H: 54.90
W: 0.0
T: 25.70
H: 54.90
W: 0.0
T: 25.70
I want to put it in a database and show it in a website (the website part is not a problem (for now))

I am strugling with patterns and ''re" module. but haven't a clou how to tackle it.

Can some one put me on track?

Thank you!

Leo.

Bimbam
Posts: 2
Joined: Tue Jul 12, 2016 3:57 am

Re: rasp < ardo data processing?

Tue Jul 12, 2016 8:08 am

Firstly I would suggest you adjust the output from the Arduino and strip it down to minimum. You know for example that the first value it spits out is 'H', the second value is 'W', the third value is 'T'. Comma separate it so it outputs like this when printed from the Arduino:
54.90,0.0,25.70
54.90,0.0,25.70
54.90,0.0,25.70

Then you can easily parse the serial data into an array by reading the line into a variable, splitting it by comma (assume what follows is pseudocode so your mileage may vary):

Code: Select all

while True:
    while (ser.inWaiting()==0):
        pass
    serData = ser.readline()
    serData = serData .decode("utf-8").rstrip('\n').split(",")
You then know that the data at position 0 in the serData array is H, 1 is W, 2 is T and so on. Should make it easier to export to whatever format or manipulate.

My first foray into programming required I did similar http://bimbam.ddns.net/sensor-logger-arduino-pi/
Shameless plug I know, but it's all there (including the graph generation using Matplotlib). I'm still fairly new to programming so I doubt this is the most efficient way to do it. For one I dumped to CSV then read BACK from CSV to generate the graphs instead of doing it all in memory. Still need to overhaul that >.<

*EDIT* : I would definitely avoid using my script to work from as a basis of educating yourself. It is almost entirely comment-less making it a headache for me to read it and I wrote it lol. Pro Tip, COMMENT EVERYTHING YOU DO!

leovz
Posts: 3
Joined: Mon Jul 11, 2016 7:34 pm

Re: rasp < ardo data processing?

Tue Jul 12, 2016 11:43 am

Hello Bimbam,

Thank you for your effort! It is a lot to look in to. I will report progress!

greetings, Leo.

Return to “Python”