DIY Bluetooth/BLE Adapter for Phaserunner

yannpom

1 µW
Joined
Nov 15, 2023
Messages
3
Location
Montpellier
Hello,

Some context:

I've been looking at this forum for some time but I finally registered and this is my first post.

I've build 4 electric vehicules using the Phaserunner + throttle only and I was feeling the need for a display / interface. I could have used a CycleAnalyst but as there was a RS232 port (TRRS as they call it) on the Phaserunner, I started fiddling with it. After 2 custom PCB designs and a bit of software (firmware + iOS app), here is what I got:

The DIY adapter board:
  • The adapter is a custom made PCB
  • Size is 22x56mm
  • RS232 (TRRS) port: connected to and powered by the Phaserunner.
  • GPS
  • USB-C port
  • Not just a dumb BLE bridge: it has his custom firmware + flash storage.

List of currently developped features:
  • Live data / dashboard at 10Hz (using BLE notifications which are more energy efficient for the phone)
  • Global meters, trip meter, meter that autoreset on battery charge. They cumulate over time: distance, moving time, Wh, Ah. And they work even when the phone is disconnected (values stored in the adapter flash)
  • 20h of rolling logging data (in the module flash). Automatically synced to the phone when connected.
  • GPS data included in the logs
  • In the app: a tap on the speedometer unlocks speed limitation. I really love that one. I can respect the 25km/h limit in cities, then unlock to get the full speed in the countryside.

List of possible features:
  • Using the phone inclinometer to automatically adjust power assistance levels as you go up and down hills (idea from Justin)
  • "One pedal driving", like in a Tesla, the throttle mapping can be dynamically changed based on the speed (and why not the slope) to act as both a throttle and a brake with only 1 throttle. (This works because the Phaserunner parameters can be live edited at high speed, without being saved to flash)
  • 1 click export button to post a trip online (GPS + logged data). No more need for a USB cable or SD Card reader. You can even post your trip while pedaling. It could even be live uploaded to that anyone can follow a traveller live.
  • USB-C port could be used to connect to Phaserunner suite, replacing the need for the TRRS cable.
  • And many more...

I've prototyped this over a week last July and it has been working great since. I would be pleased to answer questions and gather feedback. And we never know, maybe a bunch or people will be interested in producing a first batch.
 

Attachments

  • IMG_0920.PNG
    IMG_0920.PNG
    315 KB · Views: 16
  • unnamed.png
    unnamed.png
    160.2 KB · Views: 16
  • IMG_9818.jpeg
    IMG_9818.jpeg
    910.3 KB · Views: 16
Congratulations on designing and completing it. Having just started using a Phaserunner v6, I've begun to imagine the ways it's response could be customized for my usage on a heavy-cargo trike, so this sounds interesting.

Is it open-source, or proprietary for sale? (open source goes in the discussion threads like this, proprietary goes in the marketplace).

Just curious--does it have to be over BLE instead of BT? Because BLE requires location, GPS, etc be enabled, while BT does not, and its not always desirable to have to enable those for various people and usages.
 
For now it's neither open source nor proprietary for sale. It's just a prototype I've done "in my garage". But I'm not opposed to open sourcing it. And I think I'll need someone to help with the Android App, as I've only done the iOS app and don't have any Android phone.

When you say "BLE requires location and GPS to be enabled". Are you talking about the need to grant location/GPS permission to the App, or the need to activate the GPS globally on the phone? I just tested on iOS, and I only have to grant BLE permission to the App. And it still works fine when I globally deactivate the "Location Services". Maybe the implementation of BLE is different on Android?

But to answer to your question: the microcontroller I'm using is an ESP32-C3-WROOM-02 which only supports BLE. For sure I could use other chip that support BT+BLE but the other problem is that it's almost impossible to use BT on iOS: you need to be part of their MFI program, pay, be certified, and give them royalties for each module... That's why I'm almost always only using BLE for my projects.
 
Still waiting on Grins promised BT dongle for the phaserunner. Lol
If you can make it work on android/open source you can definitely have my $$.
 
Some Android versions require an app to request permission to access the user's location to use BLE because having the phone search for BLE beacons is a common way to determine a phone's location, particularly indoors. It's the same permission as is used by apps to access GPS, although GPS doesn't need to be enabled to use BLE. Privacy conscious users may reject giving the permission because they are bundled like that, though.

Disclaimer: The opinions stated here are my own, not those of my company.
 
Last edited:
For now it's neither open source nor proprietary for sale. It's just a prototype I've done "in my garage". But I'm not opposed to open sourcing it. And I think I'll need someone to help with the Android App, as I've only done the iOS app and don't have any Android phone.
I wish I could help you wiht the android...but I'm not a programmer (understand the concepts, have done some in BASIC, assembly, etc, but nothing modern yet). I can help test or suggest UI changes, etc., if you get to that point for Android. (only IOS device I have is an ancient OS9 iPad; if your app will run on that I can test it if it will run without connecting to the BLE/PR hardware).



When you say "BLE requires location and GPS to be enabled". Are you talking about the need to grant location/GPS permission to the App, or the need to activate the GPS globally on the phone? I just tested on iOS, and I only have to grant BLE permission to the App. And it still works fine when I globally deactivate the "Location Services". Maybe the implementation of BLE is different on Android?
Yeah, on android Location is crosslinked with BLE, one doesn't work without the other. (they *could*, and they used to, but at some point Google decided to link them so a user can't have just one). On some Androids (like whatever is on my phone), location wont' enable without also enabling GPS, too...and on mine doing that eats up the battery for some reason, so I never enable it.

FWIW, It's pretty retarded to have to have location turned on to use various BLE things, for instance I have some LED bulbs that could be controlled via a phone app but only if i also turn on location (which also turns on GPS on my phone). There are setup apps for various controllers, BMS, etc that also use BLE, and have zero reason for needing location except that google decided to do it that way in the OS. :/ I had some other BLE LED bulbs that not only require location and GPS, but *also* require that Wifi and networking all be enabled, or the app won't even start, because it's probably written to "phone home" to it's server, and yet others that won't even let you use the app if you don't sign up for an account with the manufacturer, even though there is no reason and no benefit to having such an account just to control color and brightness of your home lights. :roll:

But to answer to your question: the microcontroller I'm using is an ESP32-C3-WROOM-02 which only supports BLE. For sure I could use other chip that support BT+BLE but the other problem is that it's almost impossible to use BT on iOS: you need to be part of their MFI program, pay, be certified, and give them royalties for each module... That's why I'm almost always only using BLE for my projects.
That makes perfect sense. Apple is so hard / expensive to do this stuff on for those reasons that there are many things with no IOS app out there. So it's good that you are making one. :)

It's probably not worth doing it in just BT for Android if you already have BLE working in IOS; I'd guess they're enough different methods that all the code design is different.
 
FWIW, modern Android versions do allow apps to access BLE without also requesting location as long as they are OK with filtered scan results:
If your app doesn't use Bluetooth scan results to derive physical location, you can make a strong assertion that your app never uses the Bluetooth permissions to derive physical location. To do so, complete the following steps:

Add the android:usesPermissionFlags attribute to your BLUETOOTH_SCAN permission declaration, and set this attribute's value to neverForLocation.

That said, various consumers have older versions, or apps built for older versions, or apps that request location permission for other reasons like targeting ads or reading the hardware networking address.

Disclaimer: The opinions stated here are my own, not those of my company.
 
@amberwolf-how you liking the V6 phaserunner.
Good so far. Was easy to setup for the two motors used on it so far; haven't tried doing any performance tuning since I like it when things 'just work". ;)

Only problems with it so far were with the GMAC, even though the halls in it work fine per an oscilloscope check during operation, the PR says they're not working, in various ways. IT does correctly read the halls in a DD hubmotor, so it';s not a wring issue on the controller side of things, etc
 
FWIW, modern Android versions do allow apps to access BLE without also requesting location as long as they are OK with filtered scan results:


That said, various consumers have older versions, or apps built for older versions, or apps that request location permission for other reasons like targeting ads or reading the hardware networking address.
Ah, well whatever is on my phone, v10.something I think, doesn't work that way (or at least, the apps themselves don't--anything that uses BLE in any way requires I also give permission for location and GPS; even an app for a little thermometer/humidity sensor, or those LED bulbs, etc).
 
Only problems with it so far were with the GMAC, even though the halls in it work fine per an oscilloscope check during operation, the PR says they're not working, in various ways. IT does correctly read the halls in a DD hubmotor, so it';s not a wring issue on the controller side of things, etc

Don't want to derail original topic, but a quick peanut gallery comment: With my custom FOC controller code as well as VESC setup, a similar DD vs geared hub motor behavior is observed. Hall sensor signal in geared seems proper in standalone unit test, but geared motor runs likes a grinder, which disappears upon switching to sensorless on VESC (mine not yet sensorless). My theory is that the small mechanical angle (in relation to diameter at the point where magnet exists) between halls is causing sensor signals to go wrong at normal speeds.

EDIT (Last statement wasn't what I wanted to express, probably was too focused on peanuts ;)):
Less mechanical spacing (per pole) between hall sensors amplify the effect of improper sensor to sensor placement (which lead/lag of hall timing can't fix)
 
Last edited:
Well, the GMAC *can* work sensored, it does for others. Just not mine, but mine has had some problems prior to my using it (see the SB Cruiser thread) so I suspect it has to do with that. Just don't really see how. (it did work for it's previous owner, too). The PR reports (AFAICR) that the hall pattern is wrong, but again, I don't see how since that would be a wiring issue, and first it is a Grin product just like the GMAC so it should be prewired to match all the wiring, and being FOC it should be able to just autodetect the right hall / phase combo anyway. (it does this correctly on the DD hubmotor that is not a grin product and whose hall / phase wires are "randomly" connected).

If your geared hubmotor has advanced or retarded hall timing, rather than neutral, you should be able to change an FOC controller's timing to compensate for that. I don't know how in yours or VESC, but it should be possible. (I haven't looked into this for the PR for my GMAC issue, but I guess I should check that out).
 
Last edited:
Well, the GMAC *can* work sensored, it does for others. Just not mine, but mine has had some problems prior to my using it (see the SB Cruiser thread) so I suspect it has to do with that. Just don't really see how. (it did work for it's previous owner, too). The PR reports (AFAICR) that the hall pattern is wrong, but again, I don't see how since that would be a wiring issue, and first it is a Grin product just like the GMAC so it should be prewired to match all the wiring, and being FOC it should be able to just autodetect the right hall / phase combo anyway. (it does this correctly on the DD hubmotor that is not a grin product and whose hall / phase wires are "randomly" connected).

If your geared hubmotor has advanced or retarded hall timing, rather than neutral, you should be able to change an FOC controller's timing to compensate for that. I don't know how in yours or VESC, but it should be possible. (I haven't looked into this for the PR for my GMAC issue, but I guess I should check that out).

Lead/lag of hall timing is not making any discernible difference with mine as well as VESC, this issue is observed with 2 different geared motors, while DD doesn't. Need to investigate more at an appropriate time.
 
Thank Inanek for your explanation on BLE & location on Android. So allowing location will be depending on Android version. We will just use "neverForLocation" in the attributes.

Ok, so to move forward, I have 3 PCBs ready to be soldered. I have all the components in stock except the GPS, but I'll order them. Then next week I can assemble them and have 2 ready to be dispatched for those interested in testing the app and providing feedback. For the Android app, maybe I could use a cross-platform framework like React Native to write a single app for both iOS and Android. I will give it a try and see if I can easily port my current app.

So who would like to be a beta tester? I can also give you the gerber file & BOM if you're in a mood of soldering it yourself.

I've begun to imagine the ways it's response could be customized for my usage on a heavy-cargo trike

Do you have something specific in mind?
 
I can take one and hook it up to my Grin Baserunner and/or CycleAnalyst if you think it is compatible and want feedback on those.

Wife won't let me own anything as fast as a Grin Phaserunner after my last crash, haha
 
Do you have something specific in mind?
Not that I've sat down and typed up, just bits and pieces I've pondered while riding. Have to congeal them in my head and squeeze them out into a post. :)
 
Ok, so to move forward, I have 3 PCBs ready to be soldered. I have all the components in stock except the GPS, but I'll order them. Then next week I can assemble them and have 2 ready to be dispatched for those interested in testing the app and providing feedback.
I'm actually looking to remove my Cycle Analyst and was browsing around for something light to replace it with for the few instances I want a display. Let me know if you still have a unit for testing (or purchase).
 
Back
Top