[help needed] HOWTO use Bluetooth module

Hardware inside and outside of the ECU
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

HOWTO use Bluetooth module

Post by AndreyB »

On eBay we have plenty of TODO, these are all based on HC04 or HC05 chips.

Image

In order to get UART via one of these Bluetooth Module (BM) you should first initialize the BM itself. One day we will implement a feature of initializing BM from stm32 code, but until we have it one would need to initialize BM with a USB TTL device. The BM initialization needs to happen only before first use, once it is done the BM configuration is stored inside the BM and it does NOT need to be configured on each use.

TODO: details details
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
jedediah_frey
contributor
contributor
Posts: 51
Joined: Tue Nov 05, 2013 1:43 pm

Re: HOWTO use Bluetooth module

Post by jedediah_frey »

The one I got on Amazon is based on the HC-06 module.

Here's a breakdown of the different versions:

HC-03/HC-04 is Industrial Standard, HC-05/HC-06 is Commercial Standard.
HC-03/HC-05 could be configured to Master/Slave by user.
HC-04/HC-06 just be Master or Slave when the factory, can't be configured by user.

It's very easy to use. You setup the Tx/Rx pins and power it up. It appears to just be another serial device. Windows 7 automatically found it and drivers. To change the settings it needs AT commands.

You could easily cycle through all of the bauds on powerup. Test for an "OK" command echo. When the echo is received use that to program it to 115200.

Now this is just for the STM32<->Bluetooth baud. The baud between the computer and bluetooth module is set when you connect to it. The only odd thing is that I get 2 serial devices (just like the linked article) but only 1 connects through.

http://www.elecfreaks.com/wiki/index.php?title=Bluetooth_Bee
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: HOWTO use Bluetooth module

Post by AndreyB »

What about RAYSON BTM238 / BTM-238? Has anyone heard of this module or it's BTM222 predecessor?
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: HOWTO use Bluetooth module

Post by puff »

what's so special about it? it's still the old bluetooth.
technically, with BLE you can be able to build a native app for iOS devices to control rusefi.
User avatar
Dron_Gus
contributor
contributor
Posts: 450
Joined: Wed Nov 13, 2013 1:11 pm
Location: S-Pb
Github Username: dron0gus

Re: HOWTO use Bluetooth module

Post by Dron_Gus »

puff wrote:
Sun Feb 02, 2020 3:34 pm
what's so special about it? it's still the old bluetooth.
technically, with BLE you can be able to build a native app for iOS devices to control rusefi.
I thought iOS has very limited BT support. Even Chinas BT OBDII scanners does not work.
May be take a look at ESP32 modules? BT + WiFi. RusEFI can have its own Web-page :)
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: HOWTO use Bluetooth module

Post by puff »

It has limited support of old-style BT, but it works perfectly fine with BLE. Anyway, it needs some efforts to develop the software.
User avatar
Dron_Gus
contributor
contributor
Posts: 450
Joined: Wed Nov 13, 2013 1:11 pm
Location: S-Pb
Github Username: dron0gus

Re: HOWTO use Bluetooth module

Post by Dron_Gus »

puff wrote:
Mon Feb 03, 2020 7:24 am
It has limited support of old-style BT, but it works perfectly fine with BLE. Anyway, it needs some efforts to develop the software.
With ESP32 you will need only web-browser... And some code for ESP side.
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: HOWTO use Bluetooth module

Post by AndreyB »

Not all Bluetooth is the same apparently, there are five different generations apparently.

HC-05 and HC-06 we usually use seems to be older Bluetooth 2.0?

Our needs are relatively slow and Bluetooth 4.0 or 5.0 could be extending the range for us?

Just ordered myself HM-10 which seems to be Bluetooth 4.0? I am hoping that HM-10 modules are direct drop-in for us.

Also just ordered myself something (maybe HM-19 maybe not?) based on CC2640r2f (OMG it has Arm Cortex-M3 inside! if it works we can call rusEFI a multi-core ECU can we?) - I think this cute Ebyte module shows a small IPX/IPEX antenna connector?

See also https://www.semiconductorstore.com/blog/2018/Bluetooth-1-0-vs-2-0-vs-3-0-vs-4-0-vs-5-0-How-They-Differ-Symmetry-Blog/3147/
Attachments
E104-BT01_UserManual_EN_v1.8.pdf
(2.05 MiB) Downloaded 479 times
CC2640R2F.jpg
CC2640R2F.jpg (63.75 KiB) Viewed 33051 times
HC-06.jpg
HC-06.jpg (80.3 KiB) Viewed 33051 times
HC-05.jpg
HC-05.jpg (65.35 KiB) Viewed 33051 times
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: HOWTO use Bluetooth module

Post by puff »

afaik, anything higher than 2.0 would require much more efforts in terms of software on the pc/smartphone side.
I bet, megalogviewer won't work witht BLE.
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: HOWTO use Bluetooth module

Post by AndreyB »

I only have time to buy (and sell) stuff :( I guess I will ship some to @kb1gtt when I will be shipping his MREadapter48 :)
Attachments
my_bt_collection.jpg
my_bt_collection.jpg (751.24 KiB) Viewed 31567 times
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: HOWTO use Bluetooth module

Post by puff »

It seems , both are of ble type. You plan to use them as a 'plain' serial communications device?
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: HOWTO use Bluetooth module

Post by AndreyB »

puff wrote:
Mon Jun 01, 2020 9:14 am
It seems , both are of ble type. You plan to use them as a 'plain' serial communications device?
that was the plan. am I missing some complications? can you elaborate?
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: HOWTO use Bluetooth module

Post by puff »

I'd say you've just obtained some pain in the ass. :D
What's the plan?
From my understanding, now you'll have to write some app (either for android/iOS or for Windows / Linux) that would communicate with that BLE module.
If the plan is to use it with rusefi console, you'd have to implement that in the code.
I haven't seen any ready to use BLE-serial library or BLE-serial driver. Some older PCs would require a BLE usb dongle.
Old-style bluetooth was the most convenient bluetooth solution...
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: HOWTO use Bluetooth module

Post by AndreyB »

Are you familiar with the concept of https://en.wikipedia.org/wiki/BLUF_(communication) ?

For example lot "HM-10 4.0 BLE Bluetooth Uart Transceiver" clearly states Uart Transceiver in description. Can you please explain what's different about HM-10 exactly and what exactly would custom app be doing?
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: HOWTO use Bluetooth module

Post by puff »

BLUF? WTF is that?
HM-10? You mean to say those CC2541 modules? They can transceive UART, but unlike HC05/06 you won't see a 'normal' com port or anything similar in '/dev/ '. You'll have to write your own code with all those peripherals, centrals, GAPs, GATTS, etc.
I don't how else I can explain it to you.

There are several BLE serial terminals for Android, but you probably don't need a terminal, you need your own custom app?
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: HOWTO use Bluetooth module

Post by AndreyB »

https://en.wikipedia.org/wiki/BLUF_%28communication%29 means a paragraph where the conclusions and recommendations are placed at the beginning of the text, rather than the end, in order to facilitate rapid decision making

BT classic has a number of standard "profiles" including SPP = Serial Port Profile = which we use to get trivial TTL. Newer BT BLE is cool and fancy but it has _no_ standard profiles everything has to be done more manually on both ends, making UART with BLE way less trivial.
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
Joey120373
donator
donator
Posts: 62
Joined: Sun May 17, 2020 8:46 am

Re: HOWTO use Bluetooth module

Post by Joey120373 »

I have worked for a little while with both the HC-05/06 and the newer HM-10 ( though some report as HM-08 when queried ).

Both are relatively easy, if not a bit finicky to set up with a serial terminal and a bog standard usb to uart adapter.

I have noticed that the AT commands don't always report back as the data sheet would claim they are supposed to, however i can get them to work.

HC-05/06 modules seem to play nice with my android devices, the HM-10 seems to play nice with IOS stuff.
I am using both in one instance, talking to an RS422 to UART converter, to monitor a serial signal at 9600 baud though i have run a few tests at 115200, and there doesn't appear to be any issues there.

Mounting both in a small enclosure seems to work fine and allows the guys at work to use whatever phone they might have to pull up a serial terminal and see the data. Both modules also seem to work fine at 3.3v for the power supply ( most cheap boards are listed at 3.6-5.5v for the power input ).

My biggest complaint would be the quality issues with so many available, and finding the correct data sheet for the module you actually got vs the one that the fleabay seller claimed it was. It can be a bit frustrating.
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: HOWTO use Bluetooth module

Post by AndreyB »

Well, back to Bluetooth.

We actually have BT initialization code in rusEFI itself

Code: Select all

#if EFI_BLUETOOTH_SETUP
	// Usage:   "bluetooth_hc06 <baud> <name> <pincode>"
	// Example: "bluetooth_hc06 38400 rusefi 1234"
	addConsoleActionSSS("bluetooth_hc05", bluetoothHC05);
	addConsoleActionSSS("bluetooth_hc06", bluetoothHC06);
	addConsoleActionSSS("bluetooth_spp", bluetoothSPP);
	addConsoleAction("bluetooth_cancel", bluetoothCancel);
#endif /* EFI_BLUETOOTH_SETUP */
for end users that mean that if one uses rusEFI console, the following commands are available:

bluetooth_hc05
bluetooth_hc06
bluetooth_spp
bluetooth_cancel


I believe I had those working and that's how I got my HC initialized.

We need to make nicer TS button for same logic https://github.com/rusefi/rusefi/issues/1685
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
tmbryhn
Posts: 169
Joined: Wed Feb 12, 2020 2:40 am
Location: Norway

Re: HOWTO use Bluetooth module

Post by tmbryhn »

I'm currently working on BT implementation for my next rev.:
https://rusefi.com/forum/viewtopic.php?f=2&t=1820&p=38811#p38811

I've had great success with multiple generic HC-05 "fleeBay" modules that has been set up for MS-based ECUs through a simple terminal program using the AT-commands, and been paired directly through TS. I've experienced reasonable reception, even when enclosed in an aluminum case and mounted on the opposite side of the firewall. I however recommend mounting the ECU on the inside for increased coms reliability.

The Proteus STM32F427ZGT6 utilizes "USART3" on the same port pin names as the STM32F407VGT6 used in the MRE v0.5.0:
TX: PB10, pin# 69
RX: PB11, pin# 70.

As far as I understand, all official RusEfi firmware builds are currently released with Bluetooth code included.

Firmware:
- Is the BT code by default for the UART3/USART3 regardless of MCU?
- Does the firmware require additional activation by any means, or is the UART port continuously standing by for incoming messages on the RX pin?
- Will the firmware auto-detect BT module baud rate? Eg. will it be possible to set up the module for 115200 for potential increased data rate?

BT module options:
- Current firmware supports HC-05, HC-06 and SPP-C modules?
- Are there support for other modules, eg. with coax connector for external antenna?

HW-Implementation:
- When making the next PCB rev. with built-in bluetooth footprint, are there any considerations other than routing the TX->RX and RX->TX that should be taken into account?
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: HOWTO use Bluetooth module

Post by AndreyB »

No. rusEFI uses whatever UART is specified in the specific board file. Different boards are potentially compiled with different pins, that's out of scope of this BT thread. Primary UART channel is hard-coded because that's part of recovery, there is also secondary UART which is somewhat flexible. Some binaries are compiled with USB as primary communication channel and the only UART is flexible. It's a complicated (potentially for no good reason) area.

rusEFI does not auto-detect BT module, rusEFI is mostly not aware of the fact that UART is routed to BT. While we have some BT initialization logic in rusEFI, it's on-demand commands not part default start-up code. This means that any pre-initialized module is supported and there is very little connection between rusEFI and BT in general.
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
tmbryhn
Posts: 169
Joined: Wed Feb 12, 2020 2:40 am
Location: Norway

Re: HOWTO use Bluetooth module

Post by tmbryhn »

I poked around in the board source file; found some UART related in the MRE board_configuration.cpp, but nothing in the Proteus file.

What's the best approach to get an extra UART set up for BT on Proteus if not already ready in current firmware bundle release?
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: HOWTO use Bluetooth module

Post by AndreyB »

I would assume that Proteus as any other rusEFI board has at least one UART configured. Just hook up pre-configured BT module to that UART and you are good to go!
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
tmbryhn
Posts: 169
Joined: Wed Feb 12, 2020 2:40 am
Location: Norway

Re: HOWTO use Bluetooth module

Post by tmbryhn »

Have connected a generic HC-05 to my board running the latest Proteus firmware and STM32F427ZGT6:
HC-05-TX -> UART_RX (PD6, pin# 122)
HC-05-RX -> UART_TX (PD5, pin# 119)

Paired just fine in TS with the std. 1234 passkey, but no coms.
Can't see any reaction on wither TX/RX pins with my scope when I hit the "Test Port" button.
Tried to change baud to 115200 with the "AT+UART=115200,0,0" command that I've used with my MS ECUs. Programs the module just fine, but still no coms. Tried to change back to 38400 with same AT+UART command, but my terminal program then gives an error for some reason.

What am I missing?
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: HOWTO use Bluetooth module

Post by AndreyB »

All those random bluetooth modules without clear part number without a datasheet in English are getting annoying.
https://github.com/rusefi/alphax-2chan/issues/14 is a sad story and https://rusefi.com/forum/viewtopic.php?f=13&t=1999 with random sourcing is not much better

We need a part number which I can order from digikey or mouser, with a datasheet in English, which is clearly a device for our needs according to English datasheet.

There is DFR0781 but I am concerned by lack of .pdf file https://wiki.dfrobot.com/Audio_BLE_SPP_Pass_Through_Module_Bluetooth_5.0_SKU_DFR0781#target_9 is sad

aliexpress is full of JDY-33 which has nice datasheet but it's aliexpress not USA distributors :(
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: HOWTO use Bluetooth module

Post by puff »

nrf5822?

From my understanding, with alphax, you need first to flash "serial to BT" firmware to that chip (before soldering it onto the board). Then you'll need some special software supporting BLE on the PC side.
my bad. just found the datasheet on jlcpcb. will comment later.
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: HOWTO use Bluetooth module

Post by puff »

okay. don't know how to comment on github.

The bluetooth module in alphax is definitely a BLE device (bursts of data, rather than old-style SPP profile)

After you connect it to the MCU, (MCU's TX to WL9981TC RX, MCU's RX to WL's TX, Paragraph 4 of the datasheet), after power up you should see 'READY!' message on the MCU, meaning that Initialization is completed, connection is allowed, and the module is ready for pairing.
If your Windows PC supports BLE, I suggest using something like https://www.nordicsemi.com/Products/Development-tools/nRF-Connect-for-desktop
When you launch it, you should see the module in advertising mode. After you choose it and hit 'connect' button, you'd see 'Connect!' message on the MCU side. If I understand chineese correctly, PIN5 should go HIGH when there is a connection between the module and the PC/mobile. After this, you can probably start sending and receiving messages.
default settings (for the MCU side) should be 115200, 8N1 with no flow control.

"To ensure complete data transmission, each data packet sent by the HOST is required to be less than or equal to 256 bytes, and the sending interval is greater than or equal to 2ms." - don't know what this means. splitting binary file into chunks?

Keep in mind that as long as the Bluetooth device is in a disconnected state, this Pin 5 always outputs a low level.

A nice find, by the way, but almost no electrical specifications in the datasheet (consumption at various states)
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: HOWTO use Bluetooth module

Post by AndreyB »

puff wrote:
Tue Jan 18, 2022 11:08 am
After you connect it to the MCU, (MCU's TX to WL9981TC RX, MCU's RX to WL's TX, Paragraph 4 of the datasheet), after power up you should see 'READY!'
And that's not happening. I have no time to waste on this WL9981TC I have to move on so taking hopefully safer https://github.com/rusefi/alphax-2chan/issues/23 route
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: HOWTO use Bluetooth module

Post by AndreyB »

puff wrote:
Tue Jan 18, 2022 11:08 am
okay. don't know how to comment on github.
1) login to github
2) comment?
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: HOWTO use Bluetooth module

Post by AndreyB »

AndreyB wrote:
Tue Jan 18, 2022 4:12 am
aliexpress is full of JDY-33
got some of these JDY-33
a bit of unusual thing zero marking on the chip, i do not see any writing
powered by 3v it's broadcasting two TWO different device names JDY-33-SPP and JDY-33-BLE which reiterates that those are two quite different things
when I connect to JDY-33-SPP at least I got something in terminal at default 9600
on the other hand I am failing to get AT via terminal to echo or to do anything so far
image.png
image.png (4.82 KiB) Viewed 23537 times
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: HOWTO use Bluetooth module

Post by puff »

Post Reply