Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Electric Motors and Controllers
Post Reply
e3s   10 W

10 W
Posts: 76
Joined: Jan 08 2018 12:40pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by e3s » Jun 09 2019 12:12pm

You are right, the exclamation mark. I remembered only the circle. Has someone the measures in cm of the lcd to have an idea of the dimensions?
About the level in the display, instead the number a bar of little squares, what do you think? There is more space with a histogram

Nick   1 W

1 W
Posts: 63
Joined: Jan 11 2019 5:24pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by Nick » Jun 10 2019 7:36am

Hello everyone,

I pushed some code to the 12.3.0 branch:

I finally implemented the eeprom storage emulation. This is based on the nrf5x Flash Storage library.
This was a bitch because it depends not only on SoftDevice but also needs some special initialization there. I missed that and all writes didn't work. That is the reason why eeprom_init() has to be called after ble_init().
Also, writing to flash memory do not work in debug sessions and this gave me some headache too :(

Some words about flash memory writes:
Flash Storage has no wear leveling. All variables always go to the same flash location. The documentation states that 20.000 write/erase cycles are guaranteed. If you calc with this and write f.i. some variables like TTM or SOC every minute, there is a chance of failure after ~300 hours of operation. I think the documentation is very conservative but write failures may be an issue.
There is also the Flash Data Storage library which has wear leveling. But due to much greater memory overhead we have to split the data going to flash into pure configuration (one data block written at a stretch) and just some data written more often (like TTM / SOC / ...).

Best regards
Niklas

casainho   10 GW

10 GW
Posts: 4337
Joined: Feb 14 2011 2:43pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by casainho » Jun 10 2019 9:13am

Nick wrote:
Jun 10 2019 7:36am
Hello everyone,

I pushed some code to the 12.3.0 branch:

I finally implemented the eeprom storage emulation. This is based on the nrf5x Flash Storage library.
This was a bitch because it depends not only on SoftDevice but also needs some special initialization there. I missed that and all writes didn't work. That is the reason why eeprom_init() has to be called after ble_init().
Also, writing to flash memory do not work in debug sessions and this gave me some headache too :(

Some words about flash memory writes:
Flash Storage has no wear leveling. All variables always go to the same flash location. The documentation states that 20.000 write/erase cycles are guaranteed. If you calc with this and write f.i. some variables like TTM or SOC every minute, there is a chance of failure after ~300 hours of operation. I think the documentation is very conservative but write failures may be an issue.
There is also the Flash Data Storage library which has wear leveling. But due to much greater memory overhead we have to split the data going to flash into pure configuration (one data block written at a stretch) and just some data written more often (like TTM / SOC / ...).

Best regards
Niklas
Great!!!!!!

On LCD3 and 850C I write only after quiting configurations menu and when power off the LCD. I think this should be pretty safe for that max number of write cycles.

How is flash memory size going? How much percentage of the memory for user app is available now?
- TSDZ2 FAQ: issues and repairs, etc
- TSDZ2 OpenSource firmware

Developer of the Flexible OpenSource firmware for EBikes: TSDZ2 mid drive motor, KT motor controllers and displays: Bafang 850C color, SW102 Bluetooth and KT-LCD3.

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

Nick   1 W

1 W
Posts: 63
Joined: Jan 11 2019 5:24pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by Nick » Jun 10 2019 10:17am

Flash usage is no concern right now. We have 127 kb for application data (rest used by bootloader and SoftDevice). Eeprom emulation reserves 1 kb flash.
The basic implementation (some fonts/GFX already included) compiles around 20 kb of flash. So with some reserve we have another 80-100k for our application.

Nixunen   10 mW

10 mW
Posts: 25
Joined: Aug 27 2018 11:54am

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by Nixunen » Jun 10 2019 2:38pm

EggRider also writes ttm, traveled distance and all this kind of values only when you power down display after ride. If don't remember doing that (like power down battery first) i loose all previous trip data's etc.

casainho   10 GW

10 GW
Posts: 4337
Joined: Feb 14 2011 2:43pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by casainho » Jun 13 2019 6:00am

Nick wrote:
Jun 10 2019 10:17am
Flash usage is no concern right now. We have 127 kb for application data (rest used by bootloader and SoftDevice). Eeprom emulation reserves 1 kb flash.
The basic implementation (some fonts/GFX already included) compiles around 20 kb of flash. So with some reserve we have another 80-100k for our application.
Thanks!! I was afraid we would have very small flash available.
- TSDZ2 FAQ: issues and repairs, etc
- TSDZ2 OpenSource firmware

Developer of the Flexible OpenSource firmware for EBikes: TSDZ2 mid drive motor, KT motor controllers and displays: Bafang 850C color, SW102 Bluetooth and KT-LCD3.

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

casainho   10 GW

10 GW
Posts: 4337
Joined: Feb 14 2011 2:43pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by casainho » Jun 16 2019 3:18am

More ideas to improve our ebikes with TSDZ2 and SW102:
casainho wrote:
Jun 16 2019 3:16am
jbalat wrote:
Jun 16 2019 2:55am
For off road mountain biking it is so good I never have to change modes. It will help me when I go up steep hills and back off when I am just cruising. It seems to work out how much assist to give by what speed and how much pressure you exert but it is quick to give you full power when you need it so you dont get stuck half way up a hill.
So you mention steep hills. Before, someone did mention using an accelerometer and inclinometer to detect the start of hills and so increase automatically the motor power assistance.

All data variables like wheel speed, motor current, etc are sent to LCD. The SW102 Bluetooth LCD can also receive information from a mobile phone and I hope from other devices, like a standalone Arduino with an accelerometer and inclinometer. SW102 would then be able to change motor power assistance when detecting start of hills and also use acceleration value for maybe as input to that algorithm to improve it.

To add input to TSDZ2 of accelerometer and inclinometer without having to solder wires to the motor controller board, I think SW102 LCD will be the easiest path to do it for the final user.
- TSDZ2 FAQ: issues and repairs, etc
- TSDZ2 OpenSource firmware

Developer of the Flexible OpenSource firmware for EBikes: TSDZ2 mid drive motor, KT motor controllers and displays: Bafang 850C color, SW102 Bluetooth and KT-LCD3.

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

casainho   10 GW

10 GW
Posts: 4337
Joined: Feb 14 2011 2:43pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by casainho » Jun 22 2019 7:53am

I did agree with Nick for me to implement the configurations menu. This is the next logic step because we need to keep stored the options variables and let user change them. Finally, main menu should be implemented and then we need to make a first stable version, even of that does not implement yet all options like LCD3 has.

The configurations menu, I will try to port/adapt the one from 850C that works well.
- TSDZ2 FAQ: issues and repairs, etc
- TSDZ2 OpenSource firmware

Developer of the Flexible OpenSource firmware for EBikes: TSDZ2 mid drive motor, KT motor controllers and displays: Bafang 850C color, SW102 Bluetooth and KT-LCD3.

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

buba   10 kW

10 kW
Posts: 588
Joined: Aug 31 2018 12:36am

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by buba » Jun 26 2019 9:58pm

Getting really curious about the SW102... First time I am reading around in this thread. Have actually a lot of questions but will not bother any developer. Just keep up the good work. I really hope there will be enough space to implement everything, including future development. Would be great!

casainho   10 GW

10 GW
Posts: 4337
Joined: Feb 14 2011 2:43pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by casainho » Jun 27 2019 1:04am

buba wrote:
Jun 26 2019 9:58pm
Getting really curious about the SW102... First time I am reading around in this thread. Have actually a lot of questions but will not bother any developer. Just keep up the good work. I really hope there will be enough space to implement everything, including future development. Would be great!
I was also afraid but Nick told this recently:
Nick wrote:
Jun 10 2019 10:17am
Flash usage is no concern right now. We have 127 kb for application data (rest used by bootloader and SoftDevice). Eeprom emulation reserves 1 kb flash.
The basic implementation (some fonts/GFX already included) compiles around 20 kb of flash. So with some reserve we have another 80-100k for our application.
- TSDZ2 FAQ: issues and repairs, etc
- TSDZ2 OpenSource firmware

Developer of the Flexible OpenSource firmware for EBikes: TSDZ2 mid drive motor, KT motor controllers and displays: Bafang 850C color, SW102 Bluetooth and KT-LCD3.

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

Tsdz2Canyon   100 µW

100 µW
Posts: 7
Joined: Jun 30 2019 3:19am

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by Tsdz2Canyon » Jul 13 2019 4:51am

Hi guys,
This thread has been silent lately,
just curious if there is any progres?

Just received my display from pswpower and
I knew it was small, but didn't know it was So tiny! :thumb:
Will have a nice stealthy look!

casainho   10 GW

10 GW
Posts: 4337
Joined: Feb 14 2011 2:43pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by casainho » Jul 13 2019 6:27am

Tsdz2Canyon wrote:
Jul 13 2019 4:51am
Hi guys,
This thread has been silent lately,
just curious if there is any progres?

Just received my display from pswpower and
I knew it was small, but didn't know it was So tiny! :thumb:
Will have a nice stealthy look!
I did plan to work on this but meanwhile I decided to focus on 850C display and I was able to realease the very first version.

When I gave time I want to port the configurations menu from the 850C to this one.

I think there is an user developing right now the main screen based in the latest design file.
- TSDZ2 FAQ: issues and repairs, etc
- TSDZ2 OpenSource firmware

Developer of the Flexible OpenSource firmware for EBikes: TSDZ2 mid drive motor, KT motor controllers and displays: Bafang 850C color, SW102 Bluetooth and KT-LCD3.

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

Tsdz2Canyon   100 µW

100 µW
Posts: 7
Joined: Jun 30 2019 3:19am

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by Tsdz2Canyon » Jul 13 2019 2:19pm

casainho wrote:
Jul 13 2019 6:27am

I did plan to work on this but meanwhile I decided to focus on 850C display and I was able to realease the very first version.

When I gave time I want to port the configurations menu from the 850C to this one.

I think there is an user developing right now the main screen based in the latest design file.
Nice to hear it`s not forgotten :thumb:

I was thinking about going the 850c way, but thought sw102 is better in size.

For now I will stay with the vlcd5 and marcoq sw and wait for this one.

Thank You for the great work!

Nick   1 W

1 W
Posts: 63
Joined: Jan 11 2019 5:24pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by Nick » Jul 20 2019 5:41am

I will find some time again from August on. I am also interested to bring this project foward!

Cheers
Niklas

casainho   10 GW

10 GW
Posts: 4337
Joined: Feb 14 2011 2:43pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by casainho » Jul 20 2019 5:47am

Nick wrote:
Jul 20 2019 5:41am
I will find some time again from August on. I am also interested to bring this project foward!
Great!! I was not very happy with 850C LCD at daylight but I found it was an issue mine so my focus is now on 850C (again).

I hope you can reuse my ideas on 850C.
I just used structs for the first time to save data in eeprom but I guess the Nordic library for file system you are using is very complete anyway.

On 850C, that scheme to have layers of data that are accessed on UART interrupt, 100ms interrupt and LCD main loop, is working very well!

The graph is very nice, I am curious to try a graph on SW102 (sure it is not a priority).
- TSDZ2 FAQ: issues and repairs, etc
- TSDZ2 OpenSource firmware

Developer of the Flexible OpenSource firmware for EBikes: TSDZ2 mid drive motor, KT motor controllers and displays: Bafang 850C color, SW102 Bluetooth and KT-LCD3.

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

Tsdz2Canyon   100 µW

100 µW
Posts: 7
Joined: Jun 30 2019 3:19am

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by Tsdz2Canyon » Jul 20 2019 10:03am

Nick wrote:
Jul 20 2019 5:41am
I will find some time again from August on. I am also interested to bring this project foward!

Cheers
Niklas
Nice! :bigthumb:

shaddi   100 mW

100 mW
Posts: 43
Joined: May 30 2018 3:20pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by shaddi » Jul 30 2019 3:42am

Is there still no way of flashing the device without opening it?

geeksville   10 W

10 W
Posts: 89
Joined: Aug 02 2019 6:44pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by geeksville » Aug 02 2019 6:49pm

shaddi wrote:
Jul 30 2019 3:42am
Is there still no way of flashing the device without opening it?
Alas - I think you'll have to crack it open once (I'm assuming the stock bootloader only loads images signed by the mfg? true casainho?). But after that point, future updates of this firmware should be installable via bluetooth.

The good news is that an alpha release is getting close!

jimmyfergus   100 mW

100 mW
Posts: 49
Joined: Jul 17 2018 4:19pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by jimmyfergus » Aug 06 2019 6:24pm

Does it seem like you'll always have to physically open it for the first flash?

I've cracked the LCD on my KT-LCD3, and I'm trying to decide whether to buy another, or an SW102 (a form-factor I would prefer), or both. From the noises here, something that works isn't far off (it'll take a couple of weeks at least before I get anything)? I don't care about fancy features, but I will want to be able to change settings.

How weather resistant can the SW102 be after you crack it open?

geeksville   10 W

10 W
Posts: 89
Joined: Aug 02 2019 6:44pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by geeksville » Aug 06 2019 7:46pm

I've been working on the sw102 stuff with Casainho and Nick/Lowperformer and I think it will be ready for alpha users soon (within two weeks? Maybe one?). I have one running my my desk now and I'm switching my bike from a LCD3 to SW102 tomorrow.

jimmyfergus   100 mW

100 mW
Posts: 49
Joined: Jul 17 2018 4:19pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by jimmyfergus » Aug 07 2019 8:18am

Sounds promising - I'll order one for sure, and may just limp along with my cracked LCD3 until it's usable. I can see the battery voltage and assist level, so the bike is usable.

bingo5   10 mW

10 mW
Posts: 27
Joined: Jul 04 2019 12:37am

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by bingo5 » Aug 08 2019 12:24am

First thx @ all devs for the amazing work.
At the moment i use the standard vcd5 display (with marcoq's fork). But from time to time i have unexpected behavior, so that i like to see more information on the display (eg the temperature). And i like to change the configuartion on the fly and not only with my laptop.

So since months i think about which display i like to buy. Because the lcd3 and 850c is for me a little bit to big, i tend to the sw102.
Now my question: can i use with the sw102 a (magnetic) brake sensor?

casainho   10 GW

10 GW
Posts: 4337
Joined: Feb 14 2011 2:43pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by casainho » Aug 08 2019 1:00am

bingo5 wrote:
Aug 08 2019 12:24am
First thx @ all devs for the amazing work.
At the moment i use the standard vcd5 display (with marcoq's fork). But from time to time i have unexpected behavior, so that i like to see more information on the display (eg the temperature). And i like to change the configuartion on the fly and not only with my laptop.

So since months i think about which display i like to buy. Because the lcd3 and 850c is for me a little bit to big, i tend to the sw102.
Now my question: can i use with the sw102 a (magnetic) brake sensor?
Sure, the brake sensors are a totally different thing from the display.
- TSDZ2 FAQ: issues and repairs, etc
- TSDZ2 OpenSource firmware

Developer of the Flexible OpenSource firmware for EBikes: TSDZ2 mid drive motor, KT motor controllers and displays: Bafang 850C color, SW102 Bluetooth and KT-LCD3.

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

bingo5   10 mW

10 mW
Posts: 27
Joined: Jul 04 2019 12:37am

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by bingo5 » Aug 08 2019 3:31am

Oh okay thx, but then how is the brake sensor connected? Because the vlcd5 has extra ports for the brake sensor.

casainho   10 GW

10 GW
Posts: 4337
Joined: Feb 14 2011 2:43pm

Re: Bafang SW102 Bluetooth LCD - OpenSource firmware and mobile app

Post by casainho » Aug 08 2019 3:36am

bingo5 wrote:
Aug 08 2019 3:31am
Oh okay thx, but then how is the brake sensor connected? Because the vlcd5 has extra ports for the brake sensor.
SW102 or 850C displays are connected just like the KT-LCD3, so see on the wiki how the brake sensors are connected.
- TSDZ2 FAQ: issues and repairs, etc
- TSDZ2 OpenSource firmware

Developer of the Flexible OpenSource firmware for EBikes: TSDZ2 mid drive motor, KT motor controllers and displays: Bafang 850C color, SW102 Bluetooth and KT-LCD3.

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

Post Reply