Yesterday I posted a question about setting a Photon 2 to communicate with an ELM327 using a USB cable but it was quickly pointed out to me that this is not possible because Photon 2's do not have a USB host.
So now I am attempting a different route and attempting to communicate with a BT enabled ELM327 using an HC-05 BT module.
I managed to get the Photon 2 to pass inputs sent via serial monitor via Serial and then forwarded to the HC-05 board connected to Serial1. Responses from the HC-05 board are then read and forwarded back from Serial1 to Serial so that they show in the serial monitor.
So I started sending the following commands and each time receiving an "OK" response:
AT+RESET
AT+ORGL
AT+ROLE=1
AT+CMODE=0
However, as soon as I try to send the MAC address of the ELM327
AT+BIND=XXXX,XX,XX,XXXX
Returns an error.
Needless to say that the following commands do not work either.
What error is that?
The address looks odd - I'd expect someting of the form 1234,56,abcdef (only three items not four)
What state (AT+STATE?) is the board in prior the attempt to bind?
Have you tried AT+INQ to see whether your device address can be found at all?
Once you have found the device's correct address, you may want to try AT+LINK=1234,56,abcdef to check whether you can connect at all before trying to bind to it.
The error that is returned after a bind attempt is "error (0)"
Yes I did try that command but it returns "error (1F)"
The actual mac address is: 1c:a1:35:69:8d:c5. I got it by using a BT finder app which detects the OBD2 device. How do I convert that to the format that is being expected?
OK, there was some progress but I am not there yet. Here is what I am sending and what I am receiving. Can you recommend an alternate set of AT commands?
AT: OK
AT+CMODE=0: OK
AT+PSWD="1234": OK
AT+ROLE=1: OK
AT+BIND=1CA1,35,698DC5: OK
AT+CMODE=0: OK
AT+INIT: ERROR:(17)
AT+LINK=1CA1,35,698DC5: FAIL
AT+STATE?: +STATE:INITIALIZED
OK
AT+PSWD is not required for the master. This only sets the passkey when the device is running as slave. Any master that wants to connect to it has to provide that passkey in order to legitimize its access.
AT+LINK does not directly provide any means to supply the passkey.
So you may need to (once) pair the two devices
e.g.
AT+PAIR=1CA1,35,698DC5,15
This tries (for 15 seconds) to pair to the given slave device.
With that you should get some response requesting the passkey which you then need to supply within the given time.
After that you should be able to AT+LINK to the same device without further need to provide the passkey.
I'm not sure whether the order of commands is logical.
i.e. I'd remove AT+PSWD and the second AT+CMODE.
The response of AT+STATE? indicates that AT+INIT may not be needed either.
If you happen to issue AT+RESETthen you may need to follow that with an AT+INIT.
Thank you! That was very helpful and now there is some progress.
AT+RESET: OK
AT: OK
AT+CMODE=0: OK
AT+ROLE=1: OK
AT+BIND=1CA1,35,698DC5: OK
AT+PAIR=1CA1,35,698DC5,15: OK
AT+LINK=1CA1,35,698DC5: AT+STATE?: +STATE:INITIALIZED
OK
It is my understanding that once communication with ELM237 is established, I will need to pull the HC-05 out of AT mode. The KEY pin is hard wired to the 3.3V supply so that when power is applied, it goes immediately into AT mode. Is there a better way to do that? I tried experimenting with setting the KEY state using a TTL NOT gate (74LS04) but did not have much luck with getting it to switch state after initial power on.
Are you still using the Photon2 to control the HC-05?
I guess the pin is not directly connected to 3.3V but rather via a pull-up resistor.
If so I'd think you won't need additional hardware to control the key/enable pin.
You can just digitalWrite() the pin HIGH or LOW depending on what mode you want to use.
And while at it I'd also consider controling the Vcc pin via the host controller too.
The pin was wired directly to the 3.3V output of the Photon 2. I followed your suggestion and connected the enable pin to D2 with a pull up resistor and was able to get the HC-05 to switch to non AT mode (as indicated by the rapid flashing of the red led) after issuing a AT+RESET command.
I also managed to send commands t the ELM327 after reducing the baud rate but kept getting "unable to connect" errors. But that is a question for a dedicated post.
In the meantime, thank you for getting me this far.