SkillAgentSearch skills...

Ftmsemu.github.io

No description available

Install / Use

/learn @ftmsemu/Ftmsemu.github.io
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

== The transformation of my dumb home trainer to a smart Zwift trainer ==

Contents

Part 1: The start of a journey

Part 2: I've got the power

Part 3: Interfacing all the things

Part 4: Give it back to me! – Remote controlling via FTMS

Part 5: What's left?

Part 1: The start of a journey

…to be honest – I do not remember anymore very well how it all started, but one day around June during the first big Corona wave that hit Europe last year I received a parcel from my friend Luca from Italy whom I met during various CTF events where we competed in.

The parcel contained a microcontroller board. A nRF52 DK ( https://www.nordicsemi.com/Software-and-tools/Development-Kits/nRF52-DK) from Nordic Semiconductor which is equipped with a nRF52832 ARM Cortex M4 core. Nordic is best known for their excellent Bluetooth and ANT/ANT+ support in their chips. Luca worked with these chips some years ago during a project at work and had some spare board and challenged me to have a look at them, as he thought I could have a lot of fun with them. I am not an embedded developer though I have a couple of boards ranging from the old Atmel AVR days (memories…) before Microchip bought them off, Arduinos, Leonardos, some TI Launchpads, Raspberries and recently also some STM32 boards. All this stuff was basically waiting for me to do some great things with it. And now I had another nice dark-blue PCB with a lot of headers and that Nordic chip on it.

I had no knowledge of Bluetooth or Bluetooth Low Energy whatsoever but as most of the planned summer activities fell victim to Corona and I am indeed a sucker for cool embedded technology I was happy to have something I could devote myself to and learn a new thing or two. So instead of wasting the days during the summer months by doing nothing, I started reading the manuals and spec sheets of the Nordic board…

Over the course of the next weeks, I got acquainted with the SDK and implemented some simple Bluetooth services by following along the tutorials that were available from the Nordic site (some very well done tutorials I'd like to add!) which explained the concepts of Bluetooth advertisements, characteristics, custom services etc. You can read more about it here:

https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/ble-advertising-a-beginners-tutorial

Though I have to agree with the opinion of those which say the SDK has a steep learning curve and could be less complicated at times I was pretty impressed by the quality of the code and especially of the provided demo programs which did a great job of not just showing how to write programs to implement Bluetooth but also how it‘s supposed to be done from an architectural perspective.

There is also a PC based app called "NRF Connect" which lets you scan and connect to existing Bluetooth devices or emulate one by combining and defining services and their characteristics via a nice UI. The app is available for Windows, Mac and Linux thanks to being developed with the Electron framework. There's also a version for iOS and Android though that one is to be used a little bit differently and due to the iOS Bluetooth foundation, not all features can be used the same way as on Windows for example. NRF Connect shows its real power when you have another Nordic device, like for example a nRF52840 Dongle (https://www.nordicsemi.com/Software-and-tools/Development-Kits/nRF52840-Dongle), that you can use as a client (or server!) and connect to your app, that runs on the DK. Due to the interactivity of the tool you can for example address individual parts/services of your app and send commands/data in order to trigger some behavior or just use the app as a client. Since the iOS variant was not without problems this tool proved to be very valuable and helpful!

As I said, I had little knowledge about how Bluetooth actually works apart from that my heart rate sensor for fitness activities used Bluetooth Low Energy and my ear pods for hearing music but what I learnt was that it was actually not magic what was happening there, and one could basically write cool applications using Bluetooth.

After these first successful baby steps with that new platform, it was then that I remembered that I had plans to replace my old cheesy home trainer bike I bought at a local discounter some years ago with a cool "trainer" which everyone seems to be using now that Corona forced many of us to stay indoors.

I used to do one-hour rides daily on this home trainer while watching TV with the family but having done that for some time it actually started to become quite dull just pedaling away without much "feedback". The home trainer could restrain my attempts with up to 400W over 32 difficulty levels (however I almost never went past level 10), had various exercise programs (that, granted, I never actually used…) and the various standard features like display of cadence, km/h, burned calories, distance, etc.

So, I was on the lookout for one of these smart trainers that you could connect your bike to the virtual words of Zwift, Tacx, The Sufferfest, Kinomap and various other apps. Those apps combine the fitness training with gamification: In Zwift, for example, you can compete online live against other riders in those virtual worlds, do workouts or just ride for your enjoyment through the cities of London, Paris, New York or Innsbruck. That was indeed promising much more fun, diversion and motivation than just pedaling away on my own in our top floor sleeping room while watching some TV series.

Though those hardware devices are definitely no cheap invest and you will need to have an accompanying (racing) bike it turned out it was easier said than done as all these kind of products had been sold out and were on back order for MONTHS. So even if I had a racing bike (which I did not) and I was ready to spend a lot of money on them (which I considered), I would not have had any luck in getting my hands on any of those. It was not only the top range of products with integrated magnet brakes and all kind of technical finesse but also the cheap variant where you just have a roll pressed against your tire to simulate the resistance that were ridiculously hard to get.

It was not until Christmas until the situation improved and stores were restocked slowly. These smart trainers are connected via Bluetooth or ANT+ with the smartphone apps and using those apps you can then control the devices by setting the difficulty level, simulating various terrain you are riding on, incline, set a target power to achieve and keep and so on and so forth. Of course, also those apps come for a price and you must have a subscription to use them. In return you get a rich eco system with their own community, virtual riding clubs and lots of events and virtual landscapes you can ride in. How about riding the Tour de France from your home? Just how cool would it be to mimic such a smart trainer to be able to use those apps for my rides, I thought? Well of course such an elaborate device was not to be simulated but all I had was my cheesy home trainer. Well, it is not that my home trainer was THAT bad. It HAD all those nifty readings like cadence, speed, total miles traveled, burned calories and so on and so forth. It just had no means of actually exposing them to the outside and just displayed them on the cheap mounted LCD display. The trainer was about 5 years old and back then nobody seemed to care about those features unless you were cycling on a professional basis.

But also for those not equipped with the latest and greatest in sports technology, the vendors of those apps have something to offer to enable you to use (i.e. pay for) their services. You can attach a cadence and speed sensor to your bike (actually two sensors: one to the pedal crank and one to the wheel hub) so you can at least deliver those basic parameters to the app so they can see how fast you go. "Real" smart trainers deliver this and much more like the wattage/power you deliver while riding, the relation between the forces on the left and right side of the pedal, average measurements, etc. etc. So, I thought "Well, let's go for the very basic setup at least then!"

There was only one problem (well actually there were a few, but one stood out). My home trainer had no actual wheels, just an internal rotation disc that was slowed down by magnets to create the desired resistance for the rider.

So while I had a crank to fix a cadence sensor to, I had no place where to put an actual speed sensor and unfortunately it was primarily the speed sensor that those apps want to have data from and cadence data was just "nice to have". So I couldn’t even fulfill the most basic requirements to use those apps. Bummer… So, what to do?

It was then that I learnt that according to the Bluetooth Low Energy (BLE) standard your application could be both – a server ("peripheral") and a client ("central") at the same time.

And – guess what – the Nordic SDK also had an example for that use case. It demoed connecting to a device offering the heart rate sensor service (HRS) aka "a heart rate sensor" as well as a device that offers a running speed and cadence sensor service (RSCS) aka "a running sensor" and providing a unified view to a 3rd party app. This is something to build on, isn't it? For the most basic setup I would need to provide the "Cycling speed and Cadence" in a device that Zwift connects to and Zwift would then continuously read the speed and cadence readings from it and use it in its in-game representation of your virtual rider.

I spent the next week adapting the example to my needs

View on GitHub
GitHub Stars19
CategoryDevelopment
Updated3mo ago
Forks6

Security Score

67/100

Audited on Dec 23, 2025

No findings