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:
Code: Select all
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
Code: Select all
# -*- coding: utf-8 -*-
###########################################################################
## Python code generated with wxFormBuilder (version Jun 17 2015)
## http://www.wxformbuilder.org/
##
## PLEASE DO "NOT" EDIT THIS FILE!
###########################################################################
import wx
import obd
import time
###########################################################################
## Class MyFrame1
###########################################################################
class MyFrame1 ( wx.Frame ):
def __init__( self, parent,id,title ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 480,320 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.Size( 480,320 ) )
self.SetBackgroundColour( wx.Colour( 0, 0, 0 ) )
gSizer3 = wx.GridSizer( 3, 3, 0, 0 )
self.time_adv_staticText = wx.StaticText( self, wx.ID_ANY, u"time_adv", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_CENTRE )
self.time_adv_staticText.Wrap( -1 )
self.time_adv_staticText.SetFont( wx.Font( wx.NORMAL_FONT.GetPointSize(), 70, 90, 90, False, "@Arial Unicode MS" ) )
self.time_adv_staticText.SetForegroundColour( wx.Colour( 0, 255, 0 ) )
gSizer3.Add( self.time_adv_staticText, 0, wx.ALIGN_CENTER, 5 )
gSizer3.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )
self.MAF_staticText = wx.StaticText( self, wx.ID_ANY, u"MAF", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_CENTRE )
self.MAF_staticText.Wrap( -1 )
self.MAF_staticText.SetFont( wx.Font( wx.NORMAL_FONT.GetPointSize(), 70, 90, 90, False, "@Arial Unicode MS" ) )
self.MAF_staticText.SetForegroundColour( wx.Colour( 0, 255, 0 ) )
gSizer3.Add( self.MAF_staticText, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
gSizer3.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )
self.SPEED_staticText = wx.StaticText( self, wx.ID_ANY, u"Km/h", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_CENTRE )
self.SPEED_staticText.Wrap( -1 )
self.SPEED_staticText.SetFont( wx.Font( 20, 70, 90, 90, False, "@Arial Unicode MS" ) )
self.SPEED_staticText.SetForegroundColour( wx.Colour( 0, 255, 0 ) )
self.SPEED_staticText.SetBackgroundColour( wx.Colour( 0, 0, 0 ) )
gSizer3.Add( self.SPEED_staticText, 0, wx.ALIGN_CENTER|wx.ALL|wx.EXPAND, 5 )
gSizer3.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )
self.Throttle_staticText = wx.StaticText( self, wx.ID_ANY, u"Throttle", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_CENTRE )
self.Throttle_staticText.Wrap( -1 )
self.Throttle_staticText.SetFont( wx.Font( wx.NORMAL_FONT.GetPointSize(), 70, 90, 90, False, "@Arial Unicode MS" ) )
self.Throttle_staticText.SetForegroundColour( wx.Colour( 0, 255, 64 ) )
gSizer3.Add( self.Throttle_staticText, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
self.RPM_staticText = wx.StaticText( self, wx.ID_ANY, u"RPM", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_CENTRE )
self.RPM_staticText.Wrap( -1 )
self.RPM_staticText.SetFont( wx.Font( 15, 70, 90, 90, False, "@Arial Unicode MS" ) )
self.RPM_staticText.SetForegroundColour( wx.Colour( 0, 255, 0 ) )
gSizer3.Add( self.RPM_staticText, 0, wx.ALIGN_CENTER|wx.ALL|wx.EXPAND, 5 )
self.Intake_staticText = wx.StaticText( self, wx.ID_ANY, u"Intake", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_CENTRE )
self.Intake_staticText.Wrap( -1 )
self.Intake_staticText.SetFont( wx.Font( wx.NORMAL_FONT.GetPointSize(), 70, 90, 90, False, "@Arial Unicode MS" ) )
self.Intake_staticText.SetForegroundColour( wx.Colour( 0, 255, 0 ) )
gSizer3.Add( self.Intake_staticText, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
self.SetSizer( gSizer3 )
self.Layout()
self.Centre( wx.BOTH )
# Every wxWidgets application must have a class derived from wx.App
class MyApp(wx.App):
# wxWindows calls this method to initialize the application
def OnInit(self):
# Create an instance of our customized Frame class
frame = MyFrame1(None, -1, "")
frame.Show(True)
# Tell wxWindows that this is our main window
self.SetTopWindow(frame)
#step up OBD connection and get update information
connection = obd.Async("/dev/rfcomm0") # same constructor as 'obd.OBD()'
connection.watch(obd.commands.RPM) # keep track of the RPM
connection.start() # start the async update loop
while(True):
r_rpm=connection.query(obd.commands.RPM).value
frame.RPM_staticText.SetLabel(str(r_rpm)+'RPM')#frame is who de shenm shen
frame.Show(True)
time.sleep(0.001)
# Return a success flag
return True
app = MyApp(0) # Create an instance of the application class
app.MainLoop() # Tell it to start processing events
Please help me, I don't know how to pursue further from here