How to display data from sensors


3 posts
by bonylu » Thu Jul 04, 2013 10:05 am
Hi fellows,
I collect data from some sensors, such as ultrasonic, temperature, humidity, etc.
The python script of the sensor is a function, and returns a value per second.
----------------------------------------------------------------
def xxx
return xxx
----------------------------------------------------------------
I use pygame to create a window showing a live video, and wanna display the data on the video,
however,the process will wait the sensor to return value in each loop.
---------------------------------------------------------------
while
sensor1.data() <-----------wait 1 second
sensor2.data() <----------wait 1 second
display.text1
display.text2
...
updatewindow
-----------------------------------------------------------------
So the sensor collection delay will cause low fps.

Is there a good solution to eliminate the delay? subprocess?

Thanks in advance,
Bony
Posts: 3
Joined: Thu Jul 04, 2013 3:59 am
by Davespice » Thu Jul 04, 2013 3:59 pm
Yeah you can do multi threading in Python no problem;
Have a read of this; http://www.tutorialspoint.com/python/py ... eading.htm
User avatar
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 1445
Joined: Fri Oct 14, 2011 8:06 pm
Location: London, United Kingdom
by bonylu » Fri Jul 05, 2013 9:15 am
Davespice wrote:Yeah you can do multi threading in Python no problem;
Have a read of this; http://www.tutorialspoint.com/python/py ... eading.htm


Thanks. I think it useful. :P
But the question is that, how can father progress get returning value from sub-processes? :?:


Bony
Posts: 3
Joined: Thu Jul 04, 2013 3:59 am