PDA

View Full Version : capture/repeat data ?



Sam
- 2nd September 2006, 21:42
Hi,
Is it possible to capture 1 small part of serial data to a pic or eprom ?

I would then like to program the pic to re-transmit it at a different time of my choosing.

Thanks for any advice.

paul borgmeier
- 3rd September 2006, 08:25
YES (you haven't given much detail so it is hard to answer in more detail - what are you trying to do?

Sam
- 3rd September 2006, 14:04
Thanks Paul,

What I would like to do is to be able to record a part of the data sent in my GM vehicle when, for example, you press window down and be able to repeat that at any time. Such as when I press window down on the driver door, it would also make all the windows go down. This is just an example.

GM uses one data wire running to all modules, when you press passenger window down, it sends data on this wire to the module in the passenger door, this module then activates the window motor. As far as I can determine, the data is called Class II and is sent at approx. 10.4 kbs.

I've hooked my o-scope up to this wire and can see the data sent.

Thank you

DynamoBen
- 3rd September 2006, 16:19
It sounds like OBDII VPW.

You may want to think about getting an OBDII to Serial converter and testing with a PC first. I have made several interfaces between these networks and pics. I find it easier to use a converter chip instead of dealing with the protocol myself.

Check out the following for more information.

This company makes the OBDII to serial chips:
www.elmelectronics.com

This company makes assembled units but also publishes pcb's and schematics for personal use:
www.scantool.net

If you want to do it yourself onboard, read the following it talks about VPW and all of its timing requirements:
http://www.circuitcellar.com/advertise/cc-advertising/Lightner-183.pdf#search=%22circuit%20cellar%20gauge%20fuel% 22

Let me know if you have more questions. :)

Sam
- 3rd September 2006, 19:14
Hey DynamoBen,

"It sounds like OBDII VPW"

I'm 99% sure that it is.

Thanks alot, I just hooked my old laptop serial input to the vehicle data line and ground (RX to data line and Ground to vehicle ground). I used fogsoft serial recorder to record the unlock and that worked. It recorded a line that appears to be ASCII ???

I'll check out the links you posted. Is it possible to use the laptop to TX this recorded data back to the vehicle's data wire? (Just to see it work)

Thanks again!

DynamoBen
- 3rd September 2006, 19:16
If it truly is VPW what you did shouldn't have worked. With VPW pulses are a specific width and occur on either the +7 side or 0. It alternates High Low and the length of time gives you the data bit either 0 or 1. It should not show up as ASCII, although the computer may think it is. What voltage is the line? VPW is around 7V according to the spec. If it is VPW, and I'm 99.9% sure it is, then you would need to have the serial to VPW convert chip that elm makes to transmit and receive messages.

You may also want to check out Serial Device Check, its what I use:
http://www.hackconsulting.com/download.html

Sam
- 3rd September 2006, 20:18
Hi,

I really appreciate all your help here! So do you think that this http://www.scantool.net/products/product_info.php?cPath=8_1&products_id=12 will allow me to Rx and Tx to the data wire?

And then can I use the serial data gathered in this way to program a PIC to send the serial data onto the data wire based on input events I choose ?

As for what voltage is on the data wire, I'm not sure, I used a LED with a 1k res inline and it would flash when data was sent. I also used a 4n25 opto to isolate the laptop but this would not work even though the opto was definatley working correctly, so I then connected direct from the data wire to the RX input on the db9 and that's when I got the (ASCII ???).

Thank you very much.

DynamoBen
- 3rd September 2006, 20:50
There are a couple of ways to do this. If you a multiple vehicles you may want to spend the extra money and get the below item to do your project testing, plus you can use it with the Scantool software and check diagnostic code on your vehicles.

http://www.scantool.net/products/product_info.php?products_id=21&osCsid=55d82a2104e0b2f8bd70eb642cf18b25

However if you have just the one vehicle the product you selected would work great. I have all five of the receivers that Elm makes. The ELM327 mentioned above replaces the ELM320-323. It does VPW, PWM, ISO, and CAN (this is new) which is the new automotive standard. The upshot with the ELM327 is that it has a standard TTL output mode, but outputs ASCII and is large compared to the ELM322. The advantage to the ELM322 is its size and it has a packet mode (not ASCII) option, but the TX on the chip is inverted from and needs to be flipped with external hardware or via software. (see datasheet)

The beauty of the elm chips is they handle the CRC, and buss timing for you. They also have packet filtering options, so you only are presented with the packets you want to see and not those that you don't. I interface the ELM chips via the onboard UART in the pic and handle everything with interrupts. (see instant interrupts thread)

Once testing is complete, you can integrate the elm chip into your final circuit board. You should be able to Tx/Rx on the line. The hard part will be deciphering the packet and setting up the ELM chip to spoof other devices. It is really designed to act like a diagnostics tool, but it may very well work for what youre doing. I do have many of the SAE documents that I use for deciphering; however, they are $50 each. Some creative googleing may uncover the info you are looking for. I may also be of some assistance.

I have used the ELM chips for years and love them!

Sam
- 3rd September 2006, 21:19
I'm going to order the chip:http://www.scantool.net/products/product_info.php?cPath=4&products_id=8

And I'll make the pcb myself with this: ElmScan VPW Schematic/PCB 1.0/A

And then use their s/w if you think I need anything else, please advise.

I'm going to mainly use this with a 2003 Chevy Avalanche so I hope that it is the vpw that I need. I was really hoping to record the actual data from the vehicle in serial form which I think you are saying this will do it, and prog that data into the PIC and have the PIC TX it with SEROUT.Would I still need the ELM chip in the circuit in order for this to communicate with the data bus ?

The actual data I refer to is say,what is produced on the data bus only when one button is pushed. Is all this reasonable?

Thanks again!

DynamoBen
- 3rd September 2006, 21:39
You will need to use the 2.0 PCB, not 1.0.
NOTE: the schematic uses a 9.1V transistor, which could be difficult to find.

http://www.scantool.net/download/elmvpw20.pdf

You can check your vehicle to find out what data type it uses with the following link:

http://www.elmelectronics.com/obdstandard.html

On the ELM322 there is a mode called "Monitor All." Launch hyperterm and turn this mode on. Then hit the buttons you are interested in; any data on the line will show up in hyperterm.

Once you have that info that should give you an idea of what a packet looks like. There are a couple of things about the packet you need to know, for example addressing scheme of the packets. (physical or functional) I can help once you have an example of a data packet.

It would be worthwhile to grab the datasheet for the ELM322, and read it through. Its written with hobbyists in mind and talks about all the different ways the chip can be configured. Its geared toward reading the cars ECU but you can read between the lines.

Will this work? Its hard to say for sure until you have captured a packet. I think it should work fine; it will however take some creativity on your behalf. You don't need the chip to communicate on the buss, but it will make it a lot easier. If you don't use the chip your pic will need to deal with all the timing parameters for VPW and the CRC encoding and decoding. (not fun...not easy!)

DynamoBen
- 3rd September 2006, 21:47
Here is the ELM322 board that I built based on their schematic and PCB.

Two things to note:

First is that I used a DB9 instead of the DB25. (personal choice)
Second I built a DB9-->Clips adapter for testing. You may want to do the same. (all Radio Shack parts)

If you want to use it for automotive diagnostics you will need to order the cable from scantool.net when you order the chip.

Sam
- 3rd September 2006, 22:14
OK,
I downloaded the 2.0 sch. and will build that while the elm 322 chip is on its' way. The 9.1 transistor you refer to,did you mean the 9.1v zener (D3 1N5239)? I think I already have one of those and I know I have all the other parts on hand. I will order their obd cable.

Good pics,thanks, that's what I'm going to do.

"On the ELM322 there is a mode called "Monitor All." Launch hyperterm and turn this mode on. Then hit the buttons you are interested in; any data on the line will show up in hyperterm. "

That, I think, is basically what I did with the Fogsoft program this morning but I didn't understand the output from it. It's on the other old laptop and I'll post it here later on.

I'll get the data sheets and start studying them. Thanks, this is all vey much appreciated ! I can't wait to get this working.

DynamoBen
- 3rd September 2006, 23:03
Once you get it assembled post a string and I will do my best to decypher it for you.

BTW if you ever decide to go with the ELM327 the ELM website has the PCB and schematic for that board, scantool doesn't.

Sam
- 5th September 2006, 18:34
Hi, here is the email I sent to elm.....
--------------------------------------------------------------------------

I'm very interested in purchasing your products, mainly to start with, the elm322.
My question is, with your product can I record a specific section of data from the vehicle, for example, window down, and then be able to re-transmit that section of data back to the vehicle to perform the window down function ?

Thank you for any information on this
--------------------------------------------------------------------------

Here is what elm says...
--------------------------------------------------------------------------
Hello:
Thank you for your interest in our products. Sorry, but our OBD ICs can not do that for you.


J. Nagy
Elm Electronics
--------------------------------------------------------------------------


Maybe I didn't word things right to them or do their chips communicate with the ecm on something other than class II ? What do you think about this ?

DynamoBen
- 5th September 2006, 18:47
That is not the original intention of the device; so he is correct. However I know your application and I think it will work. I also know Jim (J Nagy) very well; he created the chips and is the owner of the company. He and I are in contact quite a bit.

I think the issue is how the email reads. Most times window up/down is electrical; not data. In your case its data, assuming it is VPW this device should work great.

Remember, worst case, if it doesn't work and you have diagnostics device for your vehicle.

I emailed Jim some of the back-story for clarification. He likes to hear about new uses for his chips.

Sam
- 5th September 2006, 19:54
Yeah, I think you're right about the wording.
And that's true as for the worst case, I'd like to have that anyway.

Thanks and, do you have a 2500 HD by chance?

DynamoBen
- 5th September 2006, 20:01
What is a 2500 HD?

Sam
- 5th September 2006, 20:25
A 2500 HD is a 3/4 ton heavy duty chevy truck.
The reason I asked is I read on another forum about allot of class II details written by a very smart guy named Ben.(who has a 2500 HD)

Nevermind, I'll stick to what we're doing here.

Thanks

DynamoBen
- 5th September 2006, 21:44
Nope not me; although Ben's do tend to be a smart bunch. ;)

Do you mind posting the location of the info you are talking about? Then I can study up a bit.

Sam
- 6th September 2006, 00:13
Hi,
I'll find the post and repost here. I've placed my order for the elm chip and will be building the pcb for it while it's on the way.

Also here is what I recorded from the data bus using "serial file" from fogsoft and the serial input on my laptop.... this was door unlock button press...turning the ignition on produced a tremendous amount of data,(not posted here ofcourse)each line here actually showed up as one continuous line,so here each line picks up after the previous one...


L'>'&L2>'IRd+!I4R)'LM I*",
J24B
CL&>'
)?>!H &4Jd+!I&3Y'42'A4R>!R&'a'' 4Rsa &2' 3B'`[Z &U')2' 3BKBd+!IL2+!%">L2+&*'iCl6bJ J'BlT'y-
JLf&$"
BS 3B!?I'?."m3ZssLBI&e' 3B!)C??c"m%H %&X-RLB%aJ,' &0 0H's42" BX'"XT&' "R?" X'"X3 BH
H'L&"$"
BSL&0 0H'sL2>'IR,
)i'4R)'R6L2M
''f5ZjY''L3-L P-RL&"$"
BSLf&$"
BSL2>'I2,
)i'4'' 34''S
$-Lf&$"
BS4 'L&&$"
BSL2>'I',
)i'4R)) M )Q>
&42'CZ%k 3KB$-Lf&$"
BSL>'IR,
)i'4)'LM I*42'%H 3BKB

What do you think, should it look like this?
EDIT: I just noticed that the original file on the old laptop has allot of "black boxes" in the data but when I copied/pasted so I could email it to this computer the boxes were replaced by various characters ??? mostly the up/down arrows and >>> I even sent as an attatchment and no black boxes.

Thanks allot

DynamoBen
- 6th September 2006, 00:31
Yeah thats pretty much nothing.

It does however make sense that more data will flow when the ignition is on. Lets see what we get once your PCB is complete.

Sam
- 6th September 2006, 00:39
Yeah thats pretty much nothing.

It does however make sense that more data will flow when the ignition is on. Lets see what we get once your PCB is complete.

Right, I figured there's alot of communication btwn the modules and bcm when the ignition is switched on.

I'll get the pcb completed quickly, I can't wait to see what it produces.

Oh, and now the boxes are there,forget the edit.

Talk to you soon

Sam
- 23rd September 2006, 03:07
OK, I've got the elm322 chip, etched and built the pcb and it works !

I'm using hyperterminal and it's displaying all the data on the bus. I'll post the data I'm interested in for programming into the PIC asap.

It appears that it will display the data in ascii or hex.

Thanks for steering me to this setup.

DynamoBen
- 23rd September 2006, 03:48
I would never lead someone astray when it comes to OBDII ;)

Post your data so we can get you rolling. I'm as interested as you are.

precision
- 23rd September 2006, 07:04
You need all codes and error code to control with pic, download all codes

http://www.troublecodes.net/technical/
http://www.obd-2.de/down.html
http://www.planetfall.com/~jeff/obdii/
http://www.ems-tuning.nl/

DynamoBen
- 23rd September 2006, 16:06
precision it seems you didn't read through the entire thread. He is not trying to read OBDII error codes from the ECU, thats easy. He is trying to control devices on the VPW data buss, a little more difficult task; but it is well in hand.

Sam
- 23rd September 2006, 17:20
DynamoBen,
should I post the data in hex or ascii or both ?

DynamoBen
- 23rd September 2006, 17:25
Hex first.

Sam
- 23rd September 2006, 20:46
OK,
Here it is.
Again, I want to be able to program a PIC to,for example, fold mirrors in when a pin goes high. Just don't know where to start ???



MIRROR FOLD IN:

02
06 03 00 0B
12 00 40
21 26
20 91 00
20 D8 00
06
06 03 00 0B
51
20 D8 00
30 01 01 16 02 12 01 17
0C B3 00
06 98
06 98
30 04 01 0C 02 10 01 0D
20 D8 00
05 B3 00 00
85 00
05 00
05 B3 00 00
20 D8 00
20 D8 00
20 D8 00
20 D8 00
20 D8 00

MIRROR FOLD OUT:

02
06 03 00 0B
86 1E
21 26
20 91 00
20 D8 00
07 02
47
61 22
06 00
20 D8 00
30 01 01 16 02 12 01 17
06
06 03 00 0B
06 98
30 04 01 0C 02 10 01 0D
20 D8 00
05 B3 00 00
05 B3 00 00
20 D8 00
20 D8 00
20 D8 00
20 D8 00
20 D8 00

DynamoBen
- 23rd September 2006, 21:00
I need you at do an ATH1, then ATMA. Then fold the mirrors.

DynamoBen
- 24th September 2006, 15:43
This time post the ASCII version.

Sam
- 26th September 2006, 01:53
Here is what is supposed to be ASCII but it wont copy and paste accuratelyfor some reason.


x @ϊá@8ǡ!&JΦj@ C@ g` @|ހ@ g@!&c@a&
`0s
`0
0

0
j 3@ ؊@ g@ g@ j@
@ g>



Here is HEX

>ATZ
ELM322 v2.0

>AT H1
OK

>ATMA
88 FF A0 02 78
8A C2 A0 12 00 40 CF
8A C3 A1 12 00 40 38
8A C7 A0 A1 22 78
6A EA 40 20 9E 00 E0
49 FE 1A 06 75
EB C6 40 61 22 62
8A EA 40 20 D8 00 67
49 FE 98 06 24
8A EB 60 30 01 01 16 02 12 01 17 73
6A 94 80 06 98 C5
8A EB 80 30 04 01 0C 02 10 01 0D A2
6A C2 A0 85 00 33
8A EA 40 20 D8 00 67
6A C2 A0 05 00 FA
AA 95 A7 05 B3 00 00 05
8A EA 40 20 D8 00 67
8A EA 40 20 D8 00 67
8A EA 40 20 D8 00 67
8A EA 40 20 D8 00 67

What do you think ?

DynamoBen
- 26th September 2006, 03:22
Ok, that tells me a lot. Heres the story.

First off, yes this is the standard protocol that I had expected. It follows the J2178 SAE standard.

This is in a 3 byte form meaning the first byte is Priority/Type, second is Target Address (Functional), Third is Source Address.

All the Sources are "Body Controllers."
A0-BF are "Convience (Doors, Seats, Windows)"

The Target Address is Functional which means its value determines the item being controlled.

6A C2 A0 05 00 FA

Lets use the above to describe what is what. C2 is the mirrors being sent a message from A0 a source inside the vehicle. 05 is telling the mirror to retract.

05=retract mirror
06=extend mirror

SAE J2178 part 2 describes the packet, and J2178 Part 4 describes the functional addresses. If you google you may run across these documents.

Sam
- 1st October 2006, 00:03
Thanks DynamoBen,
I'll try to figure this out.

Sam
- 25th November 2006, 19:05
Hi All,

DynamoBen,thanks to this forum I've started learning to program serial into the PIC !

Here is the code I'm using: (forgot how to do the code quote here)

'12F675
_CONFIG
_INTRC
_NOCLKOUT
_WDT_ON
_PWRTE_ON
_MCLRE_OFF
_BODEN_ON
DEFINE OSCCAL_1K 1
INCLUDE "modedefs.bas"
TX_Pin VAR GPIO.0 'To DB9 RX pin 2
RX_Pin VAR GPIO.1 'To DB9 TX pin 3

TRISIO.0 = 0 'Set GPIO.0 to output.
TRISIO.1 = 1 'Set GPIO.1 to input

ANSEL = 0 'disable ADCs
CMCON = 7 'disable comparator

AChar VAR BYTE
tx_pin = 0 'inverted mode idle state

achar="A"
Pause 100 'OSC settle time...

loop:
SerOut tx_pin,N9600,["AT SH 6A C2 00 ",13,10] 'set header
Pause 2000
SerOut tx_pin,N9600,["85 00",13,10] 'fold mirrors in


Problem is the elm322 and the vehicle does not respond at all. I've tried sending inverted and non inverted but the data light on the elm never activates as it does when I send this same data to the vehicle with the laptop.

Do I need to use a MAX232 for this or maybe modify the elm circuit as talked about in the elm docs ?

I can read it all in hyperterminal fine, any advice and guidance is much appreciated.

DynamoBen
- 26th November 2006, 03:39
You don't need a max232. First thing to check is that Tx and Rx are crossed over. TX to RX and RX to TX. That would be enough to cause your problem.

Also on page 17 of the datasheet it talks about about RX input being inverted based on the TTL standard. You would need to reinvert this line for this to work properly. This can be done via software or hardware.

Let me know what you find.

Sam
- 26th November 2006, 14:32
Hey Ben,
You were right, I had to switch the serial output of the PIC from the 2 pin on the DB9 cable to the 3 pin. But, that still didn't work so I then removed the 1k resistor that I had inline btwn the PIC and the DB9 and directly connected it to the 3 pin of the DB9 and it worked perfectly!

Now I have to learn SERIN,the code I posted actually came from a post from Mister_e because it seemed perfect for my project (thank you Mister_e) and then I just changed the output data. But, when I try to send anything from hyperterminal to the 12F675 nothing happens,nothing in the terminal window will show up regardless of any key I press???

Here is the actual code from Mister_e's post that I need help with getting the SERIN part working if anyone has some suggestions on why it's not working for me.



'12F675
@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
DEFINE OSCCAL_1K 1
INCLUDE "modedefs.bas"
TX_Pin var GPIO.0 'To DB9 RX pin 2
RX_Pin var GPIO.1 'To DB9 TX pin 3

TRISIO.0 = 0 'Set GPIO.0 to output.
TRISIO.1 = 1 'Set GPIO.1 to input

ANSEL = 0 'disable ADCs
CMCON = 7 'disable comparator

AChar var byte
tx_pin = 0 'inverted mode idle state

achar="A"
Pause 100 'OSC settle time...

loop:
SerOut tx_pin,N2400,["Waiting for ",achar,13,10]
SERIN rx_pin,N2400,[achar]
serout tx_pin,N2400,["Got it...",13,10]
goto loop


Thanks again, this is great!

DynamoBen
- 26th November 2006, 16:08
When you communicate with a PC you are now working with RS232 which requires a MAX232 or other circuitry to convert to TTL (the elm devices uses that circuitry for serial in/out). However, with the elm device you are talking TTL and can connect directly to a pic. BTW you can eliminate all the serial circuitry between the elm and pic (you will still need to flip Rx in software or add circuitry to do it via hardware).

Sam
- 26th November 2006, 16:29
Please check out this thread: http://www.picbasic.co.uk/forum/showthread.php?t=1166&highlight=hyperterminal

This is where I found the code I'm trying and they say a MAX232 isn't needed and I can read the data from the 12F675 in hyperterminal with only a 1k resistor in line with pin 2 direct to the pc which is running hyperterminal.

However, I cannot get anything to show up in hyperterminal when I try typing on that pc. Nothing that I type shows in the hyperterminal window regardless if the DB9 is connected to the 12F675 or not. This is the same pc that I've used to communicate with the elm322 and when doing that,I'm able to enter characters in the h/t window.

I'm certainly not doubting your previous statement at all but the guys in the thread above seem to have it working without a MAX232 chip so I thought it would work with my pc (laptop).

DynamoBen
- 26th November 2006, 18:24
The reason you see what youre typing with the elm chip is because it is echoing the characters youre typing.

In HyperTerm under Properties, there is a Settings tab. Under that there is ASCII Setup button and a check box that says Echo Typed Characters Locally. Check that box and try it again.

mister_e
- 26th November 2006, 18:53
AND there's some chance it don't work as their internal OSC is sometime pretty poor. You may need to calibrate it AND/OR using the DEFINE OSCCAL_1K 1

DEBUG is recommended for those nifty PIC.

Sam
- 26th November 2006, 19:27
Hi,
I had tried the echo setting but nothing, I've tried every setting I can think of in H/T and still no characters show up in window.

mister-e,I'm fairly sure I have the define already in the code.I think it's something with the H/T because no matter what I do, nothing.

Does the tx line from the pc need to see a weak pull up or down or something before the typing will show up?

I'm going to go see if I can find a MAX232 chip and try that.

Thanks for your patience and help!

DynamoBen
- 26th November 2006, 19:38
Tie CTS and RTS together.

Sam
- 27th November 2006, 00:30
I had to do 2 things, 1-tie cts and rts together,2-switched from my old HP laptop that I've been using for the comms and tried my newer Compaq laptop that I've been using to program PICS and for internet.

So now it's working,finally, cts and rts tied together and communicating with a newer pc. THANK YOU!

I do have another question, in the code where achar="A",how can I get more than one letter to work in place of "A" ? Such as something like 8A 45 A0.

Thank you all very much,
Sam

Sam
- 27th November 2006, 03:19
Nevermind, I remembered to re read the manual.

I did away with "Achar var byte" and achar="A"

And added this:

SerIn rx_pin,N9600,["8A 45 A0"]

I think this is right,seems to work???