An Open Source Ebike

In the ebike world, there are two paths. The first is a homemade kit bike with motors and controllers from China. The second is a prebuilt bike from a manufacturer like Giant, with motors and controllers from China, which will be half as fast and cost three times as much. The choice is obvious, and there are other benefits to taking the first path as well, such as using this equipment which now has an open source firmware option.

The Tong Sheng TSDZ2 drive is popular in the ebike world because it’s an affordable kit motor which has a pedal-assist mode using torque sensors, resulting in a more polished experience. In contrast, other popular kit motors tend to rely on less expensive cadence sensors which are not as smooth or intuitive. This new open source firmware for the TSDZ2 further improves on the ride by improving the motor responsiveness, improving battery efficiency, and opening up the ability to use any of a number of color displays. (More information is available on a separate Wiki.)

If you have a TSDZ2-based ebike it might be time to break out the laptop and get to work installing this firmware. If you’re behind the times and still haven’t figured out that ebikes are one of the best ways to travel, here is the proof you need.

Thanks to [coaxial] for the tip! Photo via Reddit user [PippyLongSausage].

47 thoughts on “An Open Source Ebike

    1. Good call, I prefer the rear hub motor to the mid mount ones. While front wheel hubs are not so good due to the way they pull the bike and are driving the wheel that you steer with, I don’t understand why it has become conventional wisdom in the cycling world to recommend mid mount motors. Apart from looking hideous, they put so much strain on the chain and just don’t feel natural to ride.

      1. I prefer mid-drives, especially those that have torque sensing like the TSDZ2. It’s so much more natural (it’s just like pedaling, the motor’s power adjusting to how hard or light you push on the pedals), it keeps the gravity center to the middle of the bike, and if you have any hills you can use your gears to climb where a hub drive will leave you unable to make the climb.

        As for chain strain, be careful and don’t shift under full load! Then it’s just exactly like a regular bike. Push lightly on the pedals to change gears and resume pumping once the gear is shifted.

        1. I just use cheap but overbuilt taiwanese mid drive with a throttle and reduced current (40A to 15A). No need for shift, cadence, torque or speed sensor. just throttle, controler and motor. Nothing unimprotant to break and stop it unnecesarily, like speed sensor on a BOSCH drive. This thing is governed only by self preservation instinct and current limiter, and i like it that way. It can do both of these two things: almost keep pace with city motor traffic and climb backflip inducing inclines with barely reaching body temperature. There is only one downside, those butter metal chainwheels on the crankset.

      2. I have a mid drive and I like that it keeps the extra weight centered on the frame. As for the chain, I ride mine to work every day and my last chain lasted 2 years! The key is to never shift under load, that’s how I eventually broke my chain :). I have brake lever sensors, so I just tap the brake lever lightly before I shift, very similar to a motorcycle clutch actually.

      1. Really looking forward to an axial flux BLDC for bike use. Those are really revolutionary motors with a brilliant configuration for EVs of all kinds. Might have to wait out another fucking patent though 😔 or else figure out how to engineer one myself and deal with the quality reductions therein. They’re way lighter for a given amount of power though, and more efficient and torquey too. Look up how one works someday. Once it clicks into place you’ll wonder why we ever wasted time with other magnet and coil arrangements.

        1. Why axial flux? The bearing tolerances are normally much tighter in radial direction than in axial. So you can make the airgap smaller and get more efficiency and power. There must be a reason why industrial motors and generators use the conventional radial flux arrangement.

          1. yes, that reason is mainly a patent and the general inertia towards change…the one big thing axial flux has going for it is the possibility of going coreless without sacrificing efficiency. This does not benefit the typical industrial application, but is important for vehicles, as it saves weight and gets rid of losses at high speed.

    2. If you like hub motors get whatever your like! leaf and edge 1500w motors are amazing! but then use a kuntang controller and these guys have a firmware for them! they can do a quasi FOC but are amazing for general ebike use!

    3. I added a front and rear hub motors with dual batteries this is especially great in the winter months with 2wd feature and adding studded all terrain tires gives it the kick i need.

  1. Was also thinking I really want good regenerative braking/charging which is impossible on these mid drives. I wonder if there is a way to flip the motor and drive via a belt direct to a disc brake shimano to 6 bolt disc adapter that has a suitable belt pulley incorporated in its design. Neat, rear drive, lightish and with regen braking……. so the downhills can assist your uphills.

    1. I have a Harley with belt drive. I was doubtful when I bought it, but it has turned out to be the leastbhassle way of sending power to the back wheel. Shaft drives are heavy, chains don’t last long, but belts are cheap, low maintenance, and lightweight, including the pulleys. My HD is an 883 (actually 848cc, which makes it cheaper to tax and insure) Belt drives are worth serious consideration.

    2. I’ve been chasing regen capability, but there’s a lot of people saying it barely makes any difference on an ebike. I wonder though under what conditions this is determined, and whether the riders have been properly “re-programmed” to take advantage of it. i.e. you know you’ve got it, so you time/space all your planned braking to use regen only.

      For instance. In my area there are a lot of pointless stop signs and four way stops, whereas in an enlightened country they’d be using mostly yields and roundabouts. Go any distance across the city and you’re guaranteed to have to come to a complete stop a dozen times. I can’t see how regen won’t give you at least 3 more starts up to “cruising speed” out of that. However, if you go 10 miles rural, that might be all non-stop so unless it was hilly you wouldn’t get anything from it. Anyway, hard to tell who exactly is saying regen is useless, open space flatlanders, or actual stop start city riders.

      I see a number of folks wishing for light regen while pedalling also, I guess expecting something like a minute of hill boost for every 15 minutes flat pedalling with slight drag.

      1. Indeed, regen is going to be so dependent on riding conditions. However the energy a pedal cycle has in it is pretty low, so I’d doubt regen will achieve all that much no matter how good the terrarin and rider are for regen.
        In the end I expect the complexity and mass added to make regen a thing might as often as not make it worse than just going for pure efficiency for the driving side (if you have ever ridden a really light road bike and then compared it to your bulky hybrid/mountain bike you will know mass of the bike makes a really huge difference)

        Back of the envelope type math says the total recoverable energy of me pedaling my bike flat out coming to stop is pretty tiny – and I am neither light nor maxing out at low speeds (not sure if could go that fast anymore but I used to run up to 30mph on my way to the train every day for years – only way to stay alive was to never ever be slower than the traffic on some of those roads)..

        Also in city I would not expect to be able to use regen braking much – tend to need to stop more suddenly than it would allow. Makes some sense on hilly/mountain routes though – on the downhill I’d expect riding the brakes some anyway to stay in control – if you can get some of that back to help you get up the next one it makes sense to me.

        The idea of light regen while pedaling on the flat however does have me intrigued.. My journey home was always horrible right at the end all that sprint cycling so the cars won’t run you down followed by a hill.. Little aid up that hill would have been lovely.. Not sure what the best way to achieve that would be – a hub motor at the front has some advantages for being able to pack all the electronics out the way and running off the big flywheel.. While the midline motor has the advantage of being right at your crank so the load could be adapted to keep your effort needed highly consistent and using the geared chain to drive at the right speeds….

        1. “might as often as not make it worse than just going for pure efficiency for the driving side”

          I guess, since a motor/generator is usually neither particularly efficient as a motor or a generator. Though for conventional coil/magnet motors there was a way to let the commutator shift according to which way the torque was applied, so you at least got the brushes leading the right way.

          Maybe it would help to have the exact impacts easy to calculate from available motor and battery specs, for instance if you can have a 90% efficient drive only motor, vs 80% efficient motor capable of regen with only 50% regen efficiency.

        2. There is no mass added to achieve regen with brushless motors on ebikes. The ESC that drives the motor already has all the components needed, it’s just a matter of commutating the transistors with different timing.

          The only complexity is that you will probably want to add a button or brake lever of some kind to activate the regen. On some controllers like VESC, you can just use part of your throttle range to activate regen.

          1. I’d expect there to be fairly significant added mass if you are really trying to make regen effective.
            Sure the stuff on most e-bikes can handle something resembling regen but you want to actually get some energy back. And if you do make it efficient enough you will need charge controller and tougher batteries so you can charge all the cells safely and I would think a much bulkier motor/generator will be a part of making it good enough.

          2. @Foldi-One

            Sorry, but your expectations are pretty much all wrong.

            Charging is the opposite of discharging. An ebike will have a battery, motor and motor controller that is capable of propelling the bike when discharging the battery. If the charge current is limited to the same amount as the discharge current, none of these parts need to change. Usually you would limit the charge current to be less than the discharge current, to be gentler to the battery.

            Regen doesn’t need to be high to be effective. Losses are going to go up with the square of current, so a lighter regen will be more efficient.

          3. @Addy771
            With how effective normal ebikes are on regen you might as well not bother. To get meaningful energy out you will want different bits all of which as far as i can see are much heavier… And if you actually start to get reasonable recovery % of your lost momentum you will need charge controller and protection so you don’t overvolt/current the cells riding down a steep hill – and ideally you would want to be able to harvest all that lovely power so you want high charge rate batteries.

            Overall I don’t think regen makes much sense anyway, save the brake pads on your bike – they cost nothing and take years to wear out anyway, get a tiny tiny fraction of your energy back – again so little return why bother (at least on current ebike).

            That said i’m not really sold on ebikes at all, adding all that mass to a human powered device just makes it less easy for humans to power. I never owned a proper road bike – it would die round here in pothole central, and be nearly impossible to slow on the steeper hills with so little contact area – but having ridden one compared to my lump of steel seems pretty clear even a very basic one is a huge gain, and much of that gain can be had with sturdier bikes if you can afford it too.

            As for walking up hills even with the right gearing there are some hills round here you will never cycle up unless you manage to carry serious momentum into them – a few are steep enough that a little rain/leaf litter/ice/snow and decent cars struggle to grip well enough. While you can technically cycle up them once you end up going slower than a walking pace in the low gears you might as well just hop off and walk up anyway and at that low speed on steep crappy roads balance isn’t a trivial problem either.

          4. @Foldi-One

            Please educate yourself before making incorrect statements about regen. Here is a good thread discussing whether regen is worth it:


            Basically, you can get 5-10% energy recovery depending on your route. For an ebike with a limited battery capacity, this is definitely worth it.

            Once again, you don’t need to add other equipment like charge controllers. The motor controller is already capable of this. Programmable controllers like VESC allow you to configure the maximum charge current and also battery min/max voltages.

            It’s understandable that some people don’t want to add the weight of an ebike drive system to their bikes. However, if you already have that drive system on your bike and it is capable of regen, you would be foolish to not use it.

      2. You may only get 5% energy recovery from regen braking, but the biggest benefit to regen is reducing the wear on your mechanical brakes. You can do almost all your braking with regen and pretty much never have to replace your brake pads.

        As for light regen while pedalling, it would be much more efficient to just save your energy to pedal later when you need to, instead of losing efficiency converting your pedalling into battery charge and back into motor power.

        1. You make a good point on wear on the conventional brakes. As for light regen I can see the point – great for the easy flat/slight incline type bits where you don’t need the help to generate the go to get you up the hills. Is it less efficient yes – but it also lets you ride up hills you would end up walking up instead.

          1. I think you won’t need to walk up hills if you have the right gearing.

            If your ebike uses a hub motor (the most common ebike motor) you can feel the drag created by the motor iron losses if you pedal without activating motor power. It’s as if your tires are slightly flat and there’s a significant drag. This would be much worse if you are actually trying to regen and capture more energy.

  2. You can build a fantastic ebike at home in your garage for a fraction of what a manufacturer does.
    A kit with battery shouldn’t cost more than around £600 if you look in the right place. But be very careful when buying kits as it’s a minefield buying on AliExpress and Alibaba. Quality can be low, returning goods not possible and refunds non existent. But when you get it right it’s fantastic!

      1. The obvious method, and one which all the youtube experts that ain’t getting the views to get manufacturer freebies won’t admit they use, is to buy $15,000 of random crap on Ali-wotevs cherry pick it for what works, and dump the rest to emptors that ain’t too cavey on craigslist.

  3. I am very happy to see a post on Hackday about the firmware I started and keep developing, and I love so much ;-)

    For the ones that prefer a mid drive motor, I also developed OpenSource firmware for the popular, good, widely available and cheap KT motor controllers, that also implement FOC:

    My main motivation is to develop OpenSource knowledge and technology about motors and ebikes – this is strategic, for environmental and also health reasons.

    TSDZ2 is probaly the most small and light DIY ebike motor with torque sensor, that when running our OpenSource firmware is very powerful, energy efficient and responsive — really good for the ones looking for build MTB or road ebikes that are light and not much bulky.
    And yes, our OpenSource firmware not only runs on the motor controller and implements FOC, it was also developed for 2 popular, good, widely available and cheap displays: 850C big color display and SW102 small B/W with Bluetooth.

    See the project main page wiki to get the all information:

  4. The latter is just an import version, in wich case the importer carries the name and warrantee. Ive seen tongsheng in a handful of different brands/stickers here in The Netherlands, this is one of them ;)

  5. Love the TSDZ2 motor. I have mine running a 15ah battery and the standard VLCD5 display with Opensource firmware. It still needs some minor tweaking of the parameters to make it perfect, but the experience is much nicer that the out of the box firmware already. The only glitches so far are the speedo takes a minute of riding before it starts working, and when switching the illumination on the display at night an error code flashes up briefly.
    An easy 60 miles per charge? Yes. It is brilliant.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.