I was inspired by this post I discovered today and started wondering if this could be extended to other ergometer types.
In particular, my question would be if I could use a Nano 33 BLE to receive data from a speed and cadence sensor over BLE, handle the data internally (you can usually derive power from speed and cadence information on most ergometers) and then forward the data to a PC for logging/further use also via BLE.
So, is this device able to receive and re-send BLE data sequentially, being connected to the sensor and the PC at the same time?
I think you will encounter two main issues with this both stem from how the Nano 33 BLE's Bluetooth works, I would suggest you take a look here for more details.
The Nano 33 BLEs use a particular type of Bluetooth, Bluetooth Low Energy (BLE), which is different from Bluetooth "Classic". BLE devices work with a "Peripheral/Central" style where one device is in Peripheral mode and broadcasts data out to any Central device(s) that is/are listening out for it.
Therefore, first of all, your ergometer has to be a BLE ergometer and you will need your Nano 33 (in Central mode) to know what to listen out for. Then, secondly, your Nano will have to switch to Perperipheral mode (which I have never tested) to then connect to the PC. This would also mean that there would be a delay between disconnecting from the ergometer and then connecting to the PC, so even if it did work, there would be a lag in the stream of data as it switches and connects back and forth.
Having said that, I can see three possible solutions depending on whether you need to communicate to the PC via Bluetooth or not.
You could connect the Nano to the PC via a Serial connection and log the data that way
You could probably use a separate classic Bluetooth module which would either receive data or send data with the BLE module doing the opposite thing (this would probably be a little more complicated coding-wise)
Or you could add an SD card to your BLE circuit and just log the data there and review it later
matt_lee_smith:
BLE devices work with a "Peripheral/Central" style where one device is in Peripheral mode and broadcasts data out to any Central device(s) that is/are listening out for it.
This is only true for the advertisement data. For all other data, the GATT protocol is used, and data must be read by the central device when it is connected to the peripheral. Otherwise, the data is not sent (this is part of the low energy in BLE, data is only sent when requested.).
matt_lee_smith:
Therefore, first of all, your ergometer has to be a BLE ergometer and you will need your Nano 33 (in Central mode) to know what to listen out for.
This is likely the case (unless it is ANT+). I do not believe there are Bluetooth Classic cycling sensors out there. They would not work for too long on a coin cell.
matt_lee_smith:
Then, secondly, your Nano will have to switch to Peripheral mode (which I have never tested) to then connect to the PC. This would also mean that there would be a delay between disconnecting from the ergometer and then connecting to the PC, so even if it did work, there would be a lag in the stream of data as it switches and connects back and forth.
This would not work in this case. I suspect Armored76 wants this to work with off the shelf BLE products. When the device switches the PC central would be disconnected.
I have done a little experiment. It looks like the Arduino Nano 33 BLE can be a peripheral and a central at the same time. I have done the following.
Nano 33 IoT with one service and characteristic blinking a LED and setting the characteristic to 0x0 and 0x1
Nano 33 BLE with one service and characteristic reading the characteristic from the Nano 33 IoT and setting the value on its own characteristic.
connected BLE Scanner on iOS to the Nano 33 BLE
I can see the LED blink at the same speed (200 ms ON 200 ms OFF) and the value gets updated in the app. This should be enough for cycling sensors. I suspect they do not update very often.
This will need some experimenting to get the code to do more (e.g., some power computation) and to be more robust.
Thank you for your comments on my comments! Very much happy to learn more and glad to see that you can run both a peripheral and central at the same time, they should definitely make that more apparent in the libraries, perhaps with an example such as yours.