2

I am new at programming and am trying to communicate with my vehicle with an OBD II device. Serial to USB. I've done what I want it to do but I get the command I entered to print out. How do I just get the information from the device?

Heres my code. I am using Python 3.2.3

import serial
import time
import string
import io
import os
import sys
ser = serial.Serial("/dev/ttyUSB1")
ser.baudrate = 38400
s = input('Enter AT command --> ')
print ('AT command = ' + s)
ser.write(bytes(s + '\r\n', encoding = 'utf-8'))
ser.timeout = 1
response = ser.read(999).decode('utf-8')
print(response)
ser.close()  

And here is what prints out when I enter the command 'atrv'.

>>> 
Enter AT command --> atrv
AT command = atrv
atrv
0.1V
>>>

How do I prevent the 'atrv' above the 0.1V from printing out?

2 Answers2

1

Send ATE0 to the ELM-device.

This disables the echo, so atrv won't be send back to you!

Have a look into this: http://elmelectronics.com/DSheets/ELM327DS.pdf , collection of lots of AT commands, could be helpful!

Eric Smekens
  • 1,602
  • 20
  • 32
0

on a raspberry PI i had to modify the code to:

import serial
import time
import string
import io
import os
import sys

ser = serial.Serial("/dev/rfcomm0")
ser.baudrate = 115200
s = input('Enter AT command --> ')
print ('AT command = ' + s)
ser.flushInput();
ser.write(bytes(s + '\r\n', encoding = 'utf-8'))
ser.flush();
ser.timeout = 1
response = ser.read(999).decode('utf-8')
print(response)
ser.close()
Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186