Created
July 16, 2014 21:20
-
-
Save chadfawcett/bcaec44e32574974c3c0 to your computer and use it in GitHub Desktop.
Simple Python USB OBD II RPM and Speed Reader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serial | |
from time import sleep | |
#Play around with timeout to see if I can improve refresh rate | |
ser = serial.Serial("/dev/tty.usbserial", 38400, timeout=0.1) | |
for x in range(0, 100): | |
ser.write("01 0C\r") | |
sleep(0.05) | |
rpm_hex = ser.readline().split(' ') #Try other read methods to increase speed | |
rpm_int = int('0x'+rpm_hex[3]+rpm_hex[4], 0) / 4 | |
ser.write("01 0D\r") | |
sleep(0.05) | |
speed_hex = ser.readline().split(' ') #Try other read methods to increase speed | |
speed_double = int('0x'+speed_hex[3], 0) | |
print "rpm:", rpm_int, "\rspeed:", speed_double, "\r" | |
ser.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment