Bluetooth flow control

I need to transfer a large file from a Teensy 4.0 to an Android device via an HC-05 (classic Bluetooth). The file can be as large a one mega byte but is normally a few tens of kilo bytes. The transfer works but as the file size increases I need to slow the transfer speed down (incluing delays) otherwise the android device seems to lock up. I have tried to use the RTS on the HC05 to drive the CTS on the Teensy but there appears to be no feedback from the Android device to the HC05 to carry out this flow control. A simple transfer can thus take up to 10 minutes. This is too long. I have stripped programs down to the bare minimum to test the speeds. I would like the Android device to control the transfer speed via the RTS so that I can interface with faster/slower Android devices. Can somebody help me here? Thanks.
bluetoothtest_file.txt (1.5 KB) bluetoothtest_file|690x275

I tried with image files, but didn't get fast speeds.

Hi Juan.
Thanks for your quick reply. That is sort of what I am trying to do as well, I stripped out all the Base64 stuff to get down to basics of file transfer. It is disapointing that you also have tried and not got fast or big transfers. Is there any chance that I could sponsor a solution to this problem? It is way too difficult for me but I guess there would be a need for this type of flow control if it is possible.
I am out for the rest of the day so I will not be able to reply until later.

I think Android Bluetooth always works at 9600 bauds. In the topic of the previous link, I set the speed of the Bluetooth module to 9600 and then I changed it to 115200, in both cases the image transmission time was the same.

I have had the experience of changing the baud rate of the Bluetooth module to 115200 and I observe that it improves the transmission speed.
I can transfer an 800 kB file in 110 seconds at 115200 baud.
Look at these examples:

Made with the HC-05 and HC-06 modules.

1 Like

Thanks for the info. I have spent the day doing some basic trials and it seems that my results basically mirror yours. However my rather old Adnroid device sometimes hangs. I have put the results in a table. The timings for the Android seem to be rather random below about a second but then correspond roughly with the send time.
When I share the files over bluetooth from my Android device to my computer the file transfer is a lot faster. Bluetooth should be able to handle large files at speed. So either my Android device is too slow/not enough buffer etc or AI is somehow slowing down the transfer.
Do you have any ideas why the android device sometimes hangs?

To carry out the examples I have used a device with Android 5 and another with Android 9 Xiaomi, in both I get the 800 kB file in 110 seconds at 115200 baud when I transmit from Arduino to the app. From the app to the Arduino it is slower.

We remember that the baud rate that we establish is to communicate the Arduino MCU with the Blutooth module, once the BT module processes the information it is transmitted with a 2.4 GHz carrier.
BTW, other RF transmission possibilities:

Thanks again, Juan. I understand that the baudrate is 'only' to communicate with the Bluetooth module itself, after that I assume that the Bluetooth module and the android device establish a communication protocol with handshaking but I have no idea how this happens. I have now made some additions to my program that slows down the UART speed depending on the file size, larger file size - slower baudrate. This works but is not an ideal solution. I suspect that a better solution would include some flow control by the android device to the Bluetooth system that then controls the RTS line on the HC-05. If anybody has any ideas as to how this can be done I would be willing to sponsor this solution.
Regarding other RF systems, I need to interface with standard android phones so I am really limited to WIFI or Bluetooth as I see it.

Make sure the Bluetooth versions on your devices are compatible, it's possibly the case that your older phone devices just can't transfer as fast as you wish. You might try streaming the data in chunks.

See my notes about Bluetooth versions:

Thanks Chris. That is really the point - I would like to be able to send to any reasonably modern Android device (say >6.0) and let the system decide the required speeds. I have contacted you privately so perhaps we can continue this conversation there.

Well we can't Nigel. Please keep your Topic Public. As a matter of fact I'm unwell so I shan't be around much this week but in any case:

Note that Forum Members should only send Private messages to Power Users when invited to do so as (a) we are a small team collectively supporting thousands of Users and (b) the person messaged could be unavailable for days or weeks and the message left unread.

By keeping the discussion on the forum, there are many people from all around the World (different time zones) who can potentially help you, not just the first responder, who may be unavailable. Plus, there is often something that many forum members can learn by reading the posts.

Be aware that the Power Users are here to help you to help yourself. We are volunteers and we want to see everybody do well and enjoy programming with AI.

1 Like

Opps. Sorry. I did not wish to annoy anyone. I have received a lot of help from this forum and am gratful for it and wish to keep everything above board. I noticed that you offer bespoke solutions on your site that you linked to, so wanted to explore that possiblity. As I said I am willing to sponsor a solution and that means (as I understand the word 'sponsor' in this context) that it would be public when available. There was no underhandedness intended and I appologise wholeheartedly if I have offended.
I hope that you get better soon.

Hello Nigel

That link is for commercial engineering projects that myself and my team take on, not normally on Android (or involving App Inventor)..No offence taken.

Where have you got in your Project?

The real-world performance of Bluetooth rarely, if ever, matches the theory. From Juan's experiments (Not with a Teensy 4.0)

I'm sure you see that and say - not very fast! BLE5 would possibly be faster but all devices would need to support recent version BLE. I see that the Teensy supports USB data transfer, have you tried that? App Inventor has a USB serial Library and Juan has an example in the Tutorial & Guides section of the forum. Apart from that, more traditional methods such as ftp via a server are fast.

Hello Chris
Thank you for your comments.
Perhaps I should point out that the Android part of the project plays a very minor role in the overall system and has been 'tacked on' to a project that started over 55 years ago when we were school children and so is pretty subordinate to the whole.
However, the project is nearly finished but the last part - the Bluetooth connection - was giving us problems. I think that most of these came from trying to interface with rather old Android systems (6.0). Trying the Bluetooth using a newer system (9.0) we get better results. So it seems that the transmission is probably not the problem but the internal handling of the files causing the Android system to crash when too much info comes too quickly.
We have now come to a resolution of the problem and have satisfactory transmission speeds by adjusting the baudrate according to the file size. This is not an ideal solution (in fact it is a horrible solution) and some sort of flow control would be preferable. However this is way above my pay grade so we have gone with the easier solution until something better can be arranged.
We do get comparable results to Juan (sometimes a bit faster!) and am grateful for his input, not only here but in other parts.
We do use the Teensy 4.0 USB connection for system diagnostics but we think that our customers will require a 'clean' solution i.e. no cables draped over their system - hence the wireless connection.
Thanks again for your input and help.

Hello Nigel
You might like to experiment with BLE then. BLE streams data in 'packets' and it is possible to programmatically define the size of those (a typical Bluetooth packet is 32 or less bytes, not all of which is actual data -but the maximum transmission unit (MTU) of the Bluetooth device can often be resized to a max payload (for BLE v4.2/v5.0) of 247 bytes. See my website to discover more.

Next item of interest - the Teensy. I see there is actually a huge range of them, all under the label of 4.0/4.1+. Some are more than a development board. I'm guessing that the initial attraction was size? A board with a fast processor, such that it does not cause a bottleneck, could well help things, along with some control of the environment - It's critical that adequate cooling is provided for example. The Bluetooth module that you use would need to support BLE and the two together need to be able to enable the MTU tweaking. Juan probably has an example using a different microcontroller but many, including Teensy, can be programmed via the Arduino IDE. App Inventor has a dedicated BLE Extension produced by MIT, so you can get BLE advice straight from the horse's mouth.

Personally, I would avoid any board with BLE/BT built in, at least to begin with - you are immediately limited in the Libraries you can use and they are not necessarily 100% compatible with the standards - some people on this forum have invested in such boards thinking they would be easier to use and found them to actually be more difficult.

Fifty five years is quiet a long Project duration :thinking:

1 Like

Hi chris
I will certainly look at BLE - thanks for the tip and link. Up till now I had assumed that BLE was for small packets of data (IOT) that needed to be transmitted with minimum power usage. Both of those criteria rather suggested slow and limited data. But a second look costs nothing. But it will probably take me some time to get my mind round all those definitions.
You are right - the Teensy is fast and small. It uses a lot of power but that is not a big problem as we have adequate cooling. Before the Teensy I had used the Due but this proved to be physically too big to fit in the limited dimensions. But the Teensy was an easy transition thanks to the Arduino/Teensyduino IDE.
Yes, 55 years and counting is a long time but we started as kids and then came careers, children and other stuff, so it was not continuous. Now that we are retired we have time to invest in old projects. It helps keep the grey cells going :slightly_smiling_face:

BLE is good for streaming but your own code will need to chop the data into chunks. You will have nifty controlled flow, reducing the possibility of failure, but how fast it will ultimately be I don't know. What I do know is that you will quickly develop silky locks of grey hair and a love-hate relationship with the microcontroller.

1 Like

Thanks Chris. At my age any form of locks would be good! At the moment I am still in awe of the Teensy 4.0 - and you guys at AI2 - and I hope to keep it that way. When I get some results with BLE I will report back, but I fear that it will take me some time to get anywhere. Thanks again for your help and advice.

i'am doing a very similar thing.

File Transfer from ESP32 to AI2 App (saving as file) and i'am also searching for a faster Transfer Data Rate

actual i'am getting 12000Bytes per second.

Hi John. It's good to know that there are others in the same boat and looking for faster file transfer. All I have discovered so far is that using the HC05 board the transfer rate is dependent on two things. One: the receiving device and two: the file size being transferred. Using my (very old) mobile phone (Android 6.0) with a file size of 2Mbytes I get a transfer rate of about 2Kbytes/sec. Using a faster device (Android 9) with 2Mbyte file I can transfer at over 15Kbytes/sec - i.e. a great increase in speed. I am hoping to get some more information using other devices but this will take time.
What I was really hoping for was a way of getting the receiving device to control the UART RTS line to control the speed of transmission. But I have no idea how this can be done.
I also have zero experience with an ESP32.
I see that you are using BLE so I will keep my eye on your thread as Chris' suggestion is that I go that way. But I need to do a lot of work before I comprehend the BLE system.

I did some more test on ESP32 and i have now a stable Data Rate of 40kBytes/Sec