BT Interface for TSDZ2 Open Source firmware - Work in progress

Electric Motors and Controllers
endlessolli   1 W

1 W
Posts: 54
Joined: Jul 31 2020 11:55am

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by endlessolli » Dec 03 2021 11:24am

mspider65 wrote:
Nov 20 2021 2:17am
Yes a reistor voltage divider works well, but in the other direction, a 5v buffer/driver is useful not only for safety reason but also to have a better connection reliability.
The cable that goes to the display is quite long an the noise margin using a 3.3v driver and a 5v receiver is small and, even though the cable going to the controller is short, it is still in a noisy environment with quite high currents switching at PWM frequency.
Hi; just wanted to report back:
I got it to work! Great, great project @mspider65!

As stated, I build it off available parts. (A bare ESP32Wroom, a tiny DC-DC Step Down Module 6-55V to 5V plus AMS1117 3.3V regulator, stacked ontop of each other.) But you and @Beli were correct in that my intended level shifter circiut (TXB0108) did NOT work! (The communication to the motor-controller did work, but not towards the display - lots of CRC errors in debug seen.
So I tried for the Rx side direct connection and the Tx side a Ohm voltage divider (both for controller & LCD). That works so far. I still need to see, if it works reliably. I cross my fingers it does, as my setup is outside of the controller / motor case.
I am happy how I got the individual parts squeezed together into a small enclosure, which will hide somewhere ontop of the motor. (Although direct soldering of the bare ESP module is tricky...)
Thanks again for sharing this, @mspider. Especially, the hall optimization, the great App and the entire concept of the 'man-in-the-middle approach'!
IMG_1657.JPG
IMG_1657.JPG (2.45 MiB) Viewed 1043 times
Attachments
IMG_1658.JPG
IMG_1658.JPG (2.32 MiB) Viewed 1043 times

mspider65   100 W

100 W
Posts: 169
Joined: Aug 04 2019 2:10pm

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by mspider65 » Dec 04 2021 4:34am

endlessolli wrote:
Dec 03 2021 11:24am
Hi; just wanted to report back:
I got it to work! Great, great project @mspider65!

As stated, I build it off available parts. (A bare ESP32Wroom, a tiny DC-DC Step Down Module 6-55V to 5V plus AMS1117 3.3V regulator, stacked ontop of each other.) But you and @Beli were correct in that my intended level shifter circiut (TXB0108) did NOT work! (The communication to the motor-controller did work, but not towards the display - lots of CRC errors in debug seen.
So I tried for the Rx side direct connection and the Tx side a Ohm voltage divider (both for controller & LCD). That works so far. I still need to see, if it works reliably. I cross my fingers it does, as my setup is outside of the controller / motor case.
I am happy how I got the individual parts squeezed together into a small enclosure, which will hide somewhere ontop of the motor. (Although direct soldering of the bare ESP module is tricky...)
Thanks again for sharing this, @mspider. Especially, the hall optimization, the great App and the entire concept of the 'man-in-the-middle approach'!
IMG_1657.JPG
Hi, I'm glad to see everything worked out well.
At first I also used a solution like yours.
I guess it is not easy to solder the bare ESP32 Wroom module. Others have successfully used the ESP32 DevKit board which is bigger and easier to solder but clearly then you need a slightly bigger case than yours.

Ssciberras   1 µW

1 µW
Posts: 3
Joined: Mar 01 2019 2:33pm

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by Ssciberras » Jan 20 2022 3:40pm

May i suggest another approach to an android app? Why not use the wifi of the esp32 as a hotspot, and use a browser based display?

mspider65   100 W

100 W
Posts: 169
Joined: Aug 04 2019 2:10pm

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by mspider65 » Jan 29 2022 10:19am

Ssciberras wrote:
Jan 20 2022 3:40pm
May i suggest another approach to an android app? Why not use the wifi of the esp32 as a hotspot, and use a browser based display?
It might be fine for some functions like updating bike firmware, but it doesn't work for real-time data display and data logging.

Wimpy747   10 mW

10 mW
Posts: 24
Joined: Apr 25 2020 12:02pm

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by Wimpy747 » Mar 19 2022 4:08am

Hey Guys, have my bike running with the esp32 for 2 years now but I would like it to start up in power mode iso torque mode.
Does anyone know how to get this done?

mspider65   100 W

100 W
Posts: 169
Joined: Aug 04 2019 2:10pm

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by mspider65 » Mar 19 2022 5:28am

Wimpy747 wrote:
Mar 19 2022 4:08am
Hey Guys, have my bike running with the esp32 for 2 years now but I would like it to start up in power mode iso torque mode.
Does anyone know how to get this done?
Everything is in the wiki.
Attachments
Screenshot_20220319-112447_Chrome.jpg
Screenshot_20220319-112447_Chrome.jpg (443.64 KiB) Viewed 588 times

Wimpy747   10 mW

10 mW
Posts: 24
Joined: Apr 25 2020 12:02pm

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by Wimpy747 » Mar 19 2022 6:38am

mspider65 wrote:
Mar 19 2022 5:28am
Wimpy747 wrote:
Mar 19 2022 4:08am
Hey Guys, have my bike running with the esp32 for 2 years now but I would like it to start up in power mode iso torque mode.
Does anyone know how to get this done?
Everything is in the wiki.
sorry!

But thanks for the answer!

Deadrabbit   1 mW

1 mW
Posts: 10
Joined: May 26 2019 9:51am

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by Deadrabbit » Mar 26 2022 12:33am

Hi,

Really great work!

I would need some advise ordering the board.
pcbway told me, that there are some parts not available.

Please see the attached calc sheet.

Can i replace item #20 with the suggested? Are there alternatives for item #1?
Attachments
Question T-M7W43264A-5sets-BOM_TSDZ2-ESP32-v4(2022-03-26).xls
(108.5 KiB) Downloaded 15 times

mspider65   100 W

100 W
Posts: 169
Joined: Aug 04 2019 2:10pm

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by mspider65 » Mar 26 2022 11:51am

Deadrabbit wrote:
Mar 26 2022 12:33am
Hi,

Really great work!

I would need some advise ordering the board.
pcbway told me, that there are some parts not available.

Please see the attached calc sheet.

Can i replace item #20 with the suggested? Are there alternatives for item #1?
For Item #20 the replacement is OK (it is just a header)
For Item #1 an alternative could be BZX584C5V1. But there are many other 5.1V Zener diodes with SOD-523 footprint.

Deadrabbit   1 mW

1 mW
Posts: 10
Joined: May 26 2019 9:51am

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by Deadrabbit » Mar 30 2022 3:04am

Hi,

thanks a lot again for your work. I've ordered five peaces of the board.

Are there plans, to adapt the firmware also for the 860c Display?

As i understand, the ESP32 works only with the stock displays.

mspider65   100 W

100 W
Posts: 169
Joined: Aug 04 2019 2:10pm

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by mspider65 » Mar 30 2022 5:54am

Deadrabbit wrote:
Mar 30 2022 3:04am
Hi,

thanks a lot again for your work. I've ordered five peaces of the board.

Are there plans, to adapt the firmware also for the 860c Display?

As i understand, the ESP32 works only with the stock displays.
If the 860c uses the OEM protocol (works with the OEM Firmware) it should work also with the ESP32 board.

Deadrabbit   1 mW

1 mW
Posts: 10
Joined: May 26 2019 9:51am

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by Deadrabbit » Mar 30 2022 6:22am

The 860c is for Bafang motors. Therefore it should use a different protocoll than the Tongsheng motor.

This leads me to conclude, that it would not work with the ESP32.

Is this correct?

mspider65   100 W

100 W
Posts: 169
Joined: Aug 04 2019 2:10pm

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by mspider65 » Mar 30 2022 7:02am

Deadrabbit wrote:
Mar 30 2022 6:22am
The 860c is for Bafang motors. Therefore it should use a different protocoll than the Tongsheng motor.

This leads me to conclude, that it would not work with the ESP32.

Is this correct?
If uses the Bafang protocol it doesn't work.

endlessolli   1 W

1 W
Posts: 54
Joined: Jul 31 2020 11:55am

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by endlessolli » Apr 04 2022 11:23am

Just wanted to say thanks again to @mspider65
Over the wintertime, I built a system according to the Github instructions (a bare bone version; see my earlier posts from Dec) - but I never had the chance to actually use it, as my bike was in a different location.
Now I am where the bike is and today I swapped the TSDZ2 (running mbrusas 1-20.1B OSF) to an 'upgraded' one running mspider's soft- & hardware. (complete and easy swap, as I had a backup TSDZ2)

Really, really cool! I could not test it throughly yet, but everything works as expected, the motor sounds even smoother than before and is very responsive, the App is working lag-free and has a clear layout.

-> Thanks again!!!

endlessolli   1 W

1 W
Posts: 54
Joined: Jul 31 2020 11:55am

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by endlessolli » Apr 05 2022 5:26am

.... now that I tested it a bit more, I am wondering how / if I can do a torque calibration through your App?
(I have the small xh-18 display, so no calibration possible there, as far as I know)
The reason I am wondering: I get on the right side roughly only half the torque than on hte left side (for equel pressure).
I think for that reason I get fluktuating support within 1 pedal rotation,
(That is also whay I am very interested in the frimware updates you discussed in another thread here on ES)
But 1st I would get the sensor calibrated - i.e. having roughly the same reading for left & right pedal pressure.

mspider65   100 W

100 W
Posts: 169
Joined: Aug 04 2019 2:10pm

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by mspider65 » Apr 05 2022 8:05am

endlessolli wrote:
Apr 05 2022 5:26am
.... now that I tested it a bit more, I am wondering how / if I can do a torque calibration through your App?
(I have the small xh-18 display, so no calibration possible there, as far as I know)
The reason I am wondering: I get on the right side roughly only half the torque than on hte left side (for equel pressure).
I think for that reason I get fluktuating support within 1 pedal rotation,
(That is also whay I am very interested in the frimware updates you discussed in another thread here on ES)
But 1st I would get the sensor calibrated - i.e. having roughly the same reading for left & right pedal pressure.
No way to solve this problem with the calibration.
Calibration is only the definition of a function which, given the ADC value of the Torque sensor, provides the real Torque value (Nm).
The SW doesn't have a reference position of the pedals (the PAS sensor doesn't provide a 0 reference position) and for this reason the SW is not able to adjust the torque value according to the pedal position.

Probably the axle, in addition to torsion (which is normal), is subject to bending.
Try to fix the problem at the hardware level.
1) Check the axle carefully if it doesn't have any small cracks
2) Try adding a bearing. (Especially if you have an axle extension for a wider bottom bracket).
3) The axle is not symmetrical along 360 degrees; try to disassemble and reassemble the cranks by turning them +/-90 degrees.

endlessolli   1 W

1 W
Posts: 54
Joined: Jul 31 2020 11:55am

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by endlessolli » Apr 05 2022 9:15am

mspider65 wrote:
Apr 05 2022 8:05am
endlessolli wrote:
Apr 05 2022 5:26am
....
The reason I am wondering: I get on the right side only roughly half the torque than on the left side (for equal pressure).
I think for that reason I get fluctuating support within 1 pedal rotation,
(That is also why I am very interested in the firmware updates you discussed in another thread here on ES)
...
No way to solve this problem with the calibration.
Calibration is only the definition of a function which, given the ADC value of the Torque sensor, provides the real Torque value (Nm).
The SW doesn't have a reference position of the pedals (the PAS sensor doesn't provide a 0 reference position) and for this reason the SW is not able to adjust the torque value according to the pedal position.

Probably the axle, in addition to torsion (which is normal), is subject to bending.
Try to fix the problem at the hardware level.
1) Check the axle carefully if it doesn't have any small cracks
2) Try adding a bearing. (Especially if you have an axle extension for a wider bottom bracket).
3) The axle is not symmetrical along 360 degrees; try to disassemble and reassemble the cranks by turning them +/-90 degrees.
Thanks for the feedback!
(I thought that if I could make the steepness of the calibration curve double on the right side compared to the left side, I could compensate the difference in sensitivity? But in any case a clean hardware fix as you suggested would be much better.) ->

Reg. 1) This is a brand new replacement axle / torquesensor unit, so it should not have cracks
Reg. 2) I have already extra bearings on both sides (3 in total)
reg. 3) I did not think about this non-symmetry (sensor vs pedal orientation)! Thanks for that suggestion - I will try that & report back!

endlessolli   1 W

1 W
Posts: 54
Joined: Jul 31 2020 11:55am

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by endlessolli » Apr 05 2022 11:30am

hmmm - the more I investigate, the more confused I am....

So, rotating the Pedals by 90deg DOES makes a difference - but the bigger difference comes from in which Pedal-Position I turn the system on (-> Zeroing the torque-value):
Looking at the 'raw' ADC values, they range from 195 to 215 depending on what the Pedal Position (angle) is (- all without weight on the Pedals).So, this gives already a variation of '20'.

The next strange thing: Putting my max weight (100kg) on either pedal, I only achieve a max ADC value of 250.

So, the ADC range from 'no weight' (195 to 215) to 'max weight' (250) is pretty small - is that normal / an acceptable range??

Also: How does your software know which ADC range it can expect?

(I am asking all this, because I have the feeling that I do not get good support from the motor currently.
Pls note that I think that this is looks like a hardware problem not related to your Software / Firmware. Unfortunately, this motor never ran with a different Firmware...)

mspider65   100 W

100 W
Posts: 169
Joined: Aug 04 2019 2:10pm

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by mspider65 » Apr 05 2022 1:42pm

endlessolli wrote:
Apr 05 2022 11:30am
hmmm - the more I investigate, the more confused I am....

So, rotating the Pedals by 90deg DOES makes a difference - but the bigger difference comes from in which Pedal-Position I turn the system on (-> Zeroing the torque-value):
Looking at the 'raw' ADC values, they range from 195 to 215 depending on what the Pedal Position (angle) is (- all without weight on the Pedals).So, this gives already a variation of '20'.

The next strange thing: Putting my max weight (100kg) on either pedal, I only achieve a max ADC value of 250.

So, the ADC range from 'no weight' (195 to 215) to 'max weight' (250) is pretty small - is that normal / an acceptable range??

Also: How does your software know which ADC range it can expect?

(I am asking all this, because I have the feeling that I do not get good support from the motor currently.
Pls note that I think that this is looks like a hardware problem not related to your Software / Firmware. Unfortunately, this motor never ran with a different Firmware...)
If the raw torque ADC value without any weight on pedals changes with the position of the pedals, the problem should be electrical not mechanical.
Perhaps the two discs of the torque sensor are not perfectly matched? Are the springs correctly positioned?

Regarding the torque calculation, the SW at startup reads the ADC value of the torque sensor and saves this value as a zero reference value (this is the reason why you shouldn't put your feet on the pedal during power up).
it is also possible not to have the zero reference calculated at startup by specifying its value directly in the configuration parameters.
Then the SW calculates the difference between the actual ADC value and the zero reference value (torque ADC Delta).
For power mode then the SW multiplies the torque ADC delta by the config. parameter "Torque ADC factor" to calculate the actual torque in Nm.
Then, if you have a limited torque ADC range you should increase this parameter.
For Torque mode instead, the delta is multiplied by the current torque level assist factor.
Again, limited torque range ‐> increase the torque mode assist factors.

endlessolli   1 W

1 W
Posts: 54
Joined: Jul 31 2020 11:55am

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by endlessolli » Apr 05 2022 2:15pm

mspider65 wrote:
Apr 05 2022 1:42pm

If the raw torque ADC value without any weight on pedals changes with the position of the pedals, the problem should be electrical not mechanical.
Perhaps the two discs of the torque sensor are not perfectly matched? Are the springs correctly positioned?

Regarding the torque calculation, the SW at startup reads the ADC value of the torque sensor and saves this value as a zero reference value (this is the reason why you shouldn't put your feet on the pedal during power up).
it is also possible not to have the zero reference calculated at startup by specifying its value directly in the configuration parameters.
Then the SW calculates the difference between the actual ADC value and the zero reference value (torque ADC Delta).
For power mode then the SW multiplies the torque ADC delta by the config. parameter "Torque ADC factor" to calculate the actual torque in Nm.
Then, if you have a limited torque ADC range you should increase this parameter.
For Torque mode instead, the delta is multiplied by the current torque level assist factor.
Again, limited torque range ‐> increase the torque mode assist factors.
Thanks for your help on this!
It could be that the disks have a 'wobble' causing the fluctuation of the raw ADC baseline (I bought this broken motor and repaired it - there was some mistreatment on one of the disks, if I remember correctly... )

Now to the compensation of my limited torque range in power mode (my preferred mode):
When you state to adjust
'the config. parameter "Torque ADC factor"' - is that the "Torque sensor ADC step" Parameter
(w/ default value of 67) in the "System" menu of "Bike Configuration" in your App?

Thanks again for your help on this!

(Also - is there an outlook when your new firmware version might be ready? If I understand correctly, you are averaging torque data form a complete pedal rotation; that could me help a lot with the fluctuation I am seeing, I guess.)

mspider65   100 W

100 W
Posts: 169
Joined: Aug 04 2019 2:10pm

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by mspider65 » Apr 06 2022 3:09am

endlessolli wrote:
Apr 05 2022 2:15pm
Thanks for your help on this!
It could be that the disks have a 'wobble' causing the fluctuation of the raw ADC baseline (I bought this broken motor and repaired it - there was some mistreatment on one of the disks, if I remember correctly... )

Now to the compensation of my limited torque range in power mode (my preferred mode):
When you state to adjust
'the config. parameter "Torque ADC factor"' - is that the "Torque sensor ADC step" Parameter
(w/ default value of 67) in the "System" menu of "Bike Configuration" in your App?

Thanks again for your help on this!

(Also - is there an outlook when your new firmware version might be ready? If I understand correctly, you are averaging torque data form a complete pedal rotation; that could me help a lot with the fluctuation I am seeing, I guess.)
Yes, for Power Mode you have to increase the "Torque Sensor ADC Step" and you have to manually enter in the configuration the Torque ADC Offset (the zero torque ADC reference), but if you have a maximum range of 40 and a fluctuation of 20, I think you can't satisfactorily solve the problem with the software.

Regarding the new version, unfortunately at the moment I am not able to use the bike, but soon I will be able to start again and therefore I should be able to test the new version well.

endlessolli   1 W

1 W
Posts: 54
Joined: Jul 31 2020 11:55am

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by endlessolli » Apr 06 2022 8:53am

mspider65 wrote:
Apr 06 2022 3:09am

Yes, for Power Mode you have to increase the "Torque Sensor ADC Step" and you have to manually enter in the configuration the Torque ADC Offset (the zero torque ADC reference), but if you have a maximum range of 40 and a fluctuation of 20, I think you can't satisfactorily solve the problem with the software.

Regarding the new version, unfortunately at the moment I am not able to use the bike, but soon I will be able to start again and therefore I should be able to test the new version well.
... with Torque Sensor ADC Step = 100 and setting T ADC Offeset = 205 (mean of baseline min and max) I get a decent reaction.
Thanks - again! (Also I finally understand now, what these parameters mean / do)
I will ride with these values for now - until I have time to dismantle the unit.

Other than that: I cross my fingers for your firmware-testing!

kyej   1 µW

1 µW
Posts: 1
Joined: Feb 06 2022 2:01am

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by kyej » Apr 07 2022 2:26am

Hi. I'm looking at getting some of these boards made.
The DDZ9689T-7 Zener Diode 5.1V SOD523 is out of stock.
Would anyone be able to suggest an alternative part?

endlessolli   1 W

1 W
Posts: 54
Joined: Jul 31 2020 11:55am

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by endlessolli » Apr 07 2022 4:05am

kyej wrote:
Apr 07 2022 2:26am
Hi. I'm looking at getting some of these boards made.
The DDZ9689T-7 Zener Diode 5.1V SOD523 is out of stock.
Would anyone be able to suggest an alternative part?
This was already asked and answered by @mspider65 a couple of entries up in this thread:
"...alternative [for DDZ9689T-7] could be BZX584C5V1. But there are many other 5.1V Zener diodes with SOD-523 footprint."
Hope this helps.

Beli   1 W

1 W
Posts: 55
Joined: Dec 07 2020 5:08pm

Re: BT Interface for TSDZ2 Open Source firmware - Work in progress

Post by Beli » Apr 07 2022 4:45pm

@mspider65

I was just about to implement some changes in my adapted ESP32 LCD version concerning torque (my earlier recorded Torque/'Newton table to get reasonable human power values and connected to that I was wondering if it would make sense to linearize the torque values like it was done for other displays before).
Now I had a look at your resent changes and my question now: what is the idea behind your "torque smoothing"?

Post Reply