0

I am total beginner in programming. I already start a small project by using raspberry PI connect to the car OBD port and reading the data to the wxpython GUI. The OBD library I was using from http://brendan-w.com/work/python-obd By using the instruction above, I could successful print living rpm data in the python shell line by line. Code is here:

import obd
import time 

connection = obd.Async("/dev/rfcomm0") # same constructor as 'obd.OBD()'
cmd = obd.commands.RPM 

connection.watch(cmd) # keep track of the RPM

connection.start() # start the async update loop

while(True):

           response_rpm = connection.query(cmd).value

           print(response_rpm) # non-blocking, returns immediately

           time.sleep(0.01)

#obd.debug.console = True

After this, I created the GUI by using wxformbuilder and change to wxpython code. I test the GUI wxpython code in raspberry PI which was no problem. But after add my OBD library code into it and, the whole frame is not working The thing that I want to do is to using the staticText.SetLabel() to display the living data in a while loop. The Code after add OBD library is here :http://pastebin.com/4HYXn4cv after running this in the raspberry Pi I only got a gray frame and nothing work

Enzo Jia
  • 1
  • 1

1 Answers1

0

The problem is you blocking the GUI with the sleep statement in the tight while(True) loop. You are essentially polling the sensor in fixed time intervals.

The smart way to poll in wxPython is using a timer (wx.Timer). You can let call it the content of your while loop (do not call more then 20 times per second, more is just useless and will clog up the event loop). The sleep has to be removed, because it is eating up all the unscheduled time and is blocking the GUI.

python-odb is itself already ansynchronuous (see, second example), but the solution above requires the least restructuring of your program.

nepix32
  • 3,012
  • 2
  • 14
  • 29