17.04.2017, 16:49
Zitat:Hello Paul,Nachdem ich diese Sachen auf mein Auto abgestimmt habe, und es nochmal mit dem teureren OBD-Adapter probiert habe, konnte ich nun endlich erfolgreich pyObd nutzen.
Please find paste of modified code which managed to get my RPi working with the CAN bus on my Ford.
Whilst studying the file 'obd_io.py' I misunderstood the baud rate, or rather what function it serves with the ELM327 device. I thought it had to be set at 500Kb to match the CAN bus speed of my Ford car but it doesn't. The baud rate is set by the user to one of two values. In my case, 38400Kb per sec. Your code alludes to users needing to set the baud rate and this is what led to me thinking I needed to trim the baud rate to that of the car. Not the case, as I now know. Whereas I do need to set it, fortunately in my case 38400Kb was right by default. Anyway, like I say, it should be set to communicate reliably with the ELM327 device depending on the user need at the time I guess.
In the second code snip, (again taken from 'pyOBD.io') the next modification was key to making my script working on my particular car, is the protocol value. I read into the ELM327 data sheet and found on page 25 a table containing the various protocols used by each vehicle manufacturer. In my case, Ford.
Since my vehicle was made in 2007, I needed to use 'AT SP' command (again taken from the ELM 327 data sheet) to the value '6' in order to activate the correct protocol for the CAN on my Ford and ELM to talk to each other, i.e. 'AT SP 6'. On doing this, the script burst into life and my car sent steams of data which were organised well onto the terminal window, from the Raspberry Pi.
All I need to do now is capture the speed data specifically so that I can drive a script which runs a scrolling LED matrix. I'm not sure how to achieve this yet, as integrating a 3rd party script (ldp.py), which drives the Embedded Adventures 80x8 LED matrix - Type LDP-8008, is proving difficult to pass data values to (presumably through variables). The part of pyOBD which seems to handle text output is 'obd_capture.py' but as I say work in progress at the moment. However, I realise I'm on my own with this latter modification as I know pyOBD isn't designed for this add-on functionality.
Anyway, thank you to you and to everyone who has worked on this script to make a really rewarding software application. I have great respect to you as authors and everyone involved in making theirs work for their cars.
Many thanks,
Mark
Code Snip 1: 'obd_io.py'
================================================
class OBDPort:
""" OBDPort abstracts all communication with OBD-II device."""
def __init__(self,portnum,_notify_window,SERTIMEOUT,RECONNATTEMPTS):
"""Initializes port by resetting device and gettings supported PIDs. """
# These should really be set by the user.
baud = 38400 # set the baud rate either to 9600 or 38400. In my case 38400
databits = 8
par = serial.PARITY_NONE # parity
sb = 1 # stop bits
to = SERTIMEOUT
self.ELMver = "Unknown"
self.State = 1 #state SERIAL is 1 connected, 0 disconnected (connection failed)
self.port = None
#======================================================================================
# . . . . . .
#======================================================================================
Code snip 2: 'obd_io.py'
debug_display(self._notify_window, 2, "atz response:" + self.ELMver)
self.send_command("ate0") # echo off
debug_display(self._notify_window, 2, "ate0 response:" + self.get_result())
self.send_command("AT SP 6") # telling the program to use Ford's 'ISO 15765-4 CAN' protocol
debug_display(self._notify_window, 2, "atsp response:" + self.get_result())
self.send_command("0100")
ready = self.get_result()
Quelle:http://www.cowfishstudios.com/blog/obd-pi-raspberry-pi-displaying-car-diagnostics-obd-ii-data-on-an-aftermarket-head-unit
Gruß
Timo