What would be really nice: reprogram a $6 ESC!

I just had a great idea that I wanted to share: it is possible to reprogram most electronic speed controllers for hobby use. You need a programmer for a couple bucks. This could be a good business! These things are super cheap but they have all the current sensing that you need to implement FOC, I think, and they have the mosfets and probably a fast enough MCU. It might be worth looking into. If you could break out the right pins from the microcontroller maybe you could even make it interface to a sensor? That would be an accomplishment that would enable others.

I don’t think the cheap ESCs have a chip big/fast enough to run FOC. They all run a very simplified trap algorithm that could fit inside a small 8-bit chip. Even the more expensive ones run very simple algorithms and have very little memory.

The only ESC really worth reprogramming is the STM one, running the G431 chip.

Cheers,
Valentine

Hey @Anthony_Douglas ,

You’re not the first one to make this suggestion… I personally spent many months investigating different solutions. Here is a short list of the problems you will find. Not all problems apply to all controllers, but so far I have not really found anything that could not be ruled out due to one or more of these reasons.

  • the MCU on the driver is too weak. A silicon labs MCU is very typical, 8 bit, and not compatible with Arduino and therefore can’t run SimpleFOC
  • the driver only accepts 1-PWM control
  • and/or the driver only works unidirectionally
  • there are no programming interfaces, and no easy way to access the programming, debug and other comms ports of the MCU
  • driver IC doesn’t support BLDC 3-phase operation because FETs are configured in a full-bridge for DC-motor driving
  • no documentation or parts information available/visible

And the boards that are left after this, they fall into 2 categories:

  • either they’re just simple driver boards without MCU, like the L298N boards, leaving you the problem of adding a MCU board, a sensor, power distribution and all the wires needed between them. Such solutions typically don’t offer current sensing or other more interesting features either.
  • or they’re more fully featured solutions like Moteus, ODrive or the various demo boards from ST-Micro, TI, etc. But those, they’re not really normal ESCs any more, and they’re also not cheap by any means.

There’s a thread recently in the forums about the F4 flight stack modules. Attractive at first glance - 4x ESC and SMT32F4 or even F7 MCUs in a small stackable form-factor, and some pretty low-cost models are available. But unfortunately the connection between MCU and ESC is always for 1-PWM (per motor) so you can’t do FOC with those…

I haven’t actually gotten one to run well yet, but it should be possible to use hall sensors. Most of the cheap drone ESC’s have a 16MHz ATmega8 with 8K flash, 1K SRAM, and solder pads on the board for flashing the firmware. You can use those pads to dual purpose the MOSI, MISO, SCK pins as digital inputs for the hall sensors, and the two that are used as power input to the MCU during flashing can be used as power output to the sensors, making for a very clean design. Use hot glue to make a wire strain relief, otherwise the wires tend to break or the pads get peeled off the board.

Generally you have to do software PWM, because the MOSFETs are usually not connected to the hardware PWM pins.

I use the original RC servo control input method where you pulse the input wire high for 1 to 2ms, with the duration specifying the target position.

As far as I know they do not typically have current sense resistors, so you just have to do your best not to burn anything up, such as limiting PWM duty when at lower RPM.

Herein lies the problem. Not enough to hold the algorithm.

rats… too bad things aren’t more modular. The scimonk escs I got can drive the motor quietly, I haven’t checked but I think they must implement some kind of sinusoidal drive or something, otherwise the motor would make more noise. Maybe not. But there is a problem with the commutation detection and possibly current limiting, it only dries it weakly at one single speed.

The fact of only 1 pwm input might still be able to give a useable thing, they do have high resolution so you might be able to sneak enough bits across… It could be forward or reverse, with a middle length pulse the stop position. for step/direction a wide pulse could mean forward and a narrow pulse could mean backwards, possibly.

How could the driver only work unidirectionally? If the commutation is under mcu control, by changing the order with which the phases are commuted direction can be changed. In any case at least the user can reverse the rotation manually by rewiring the motor, although that wouldn’t work for a lot of applications, it would work for mine.

Yeah, the inability to reprogram them is a real issue. You can upgrade the firmware somehow, there are usually provisions for that, even on the cheapest ones. I don’t know if that means you could replace the firmware entirely.

The lack of documentation is a real barrier for a quick project, but could be overcome by looking up the part numbers etc, they must be fairly simple devices?

But yeah it would be a lot of work. If an entrepreneur could get paid by buying the units for super cheap then selling the reprogrammed units then it might make some sense to pursue it more.



for reference, there’s a cheapie, 10 amp scimonk firmware esc. It works great for what it does.

these guys are talking about the programming process, and reversing rotation Programming cheap ESCs for reverse - #3 by f.huisema - Electronics - OpenROV Forums
they say you can reprogram the one they were using with avrdude somehow. I don’t know how they connect to it. Other people are saying the bhheli software can program it through the servo pins.

oh yeah mine says s. l. on it, presumablt silicon labs, so not an avr.

I could design an ultracheap esc for you and open source it if you are so hung up on this idea, with a 32bit stm32, you can program it as much as you want. Those things literally take a weekend to design.

I have got my hands full with these other 2 projects, I would not be able to take it to market :frowning: although I greatly appreciate the offer. After the economics of manufacturing I don’t think it would be cheap to the user anyway. The interesting idea is to take these already extremely cheap and common devices and get them to work well.

this guy claims generic escs can be reprogrammed. I think I will try this. How to Flash BLHeli with ANY Arduino! | Create ESC Linker, 1wire interface - YouTube

You realize we are talking here less than a starbucks cup of coffee to manufacture them. Anyway, it’s a good educational experience reverse engineering the existing ones. More power to you.

Surely if these ones I got are $6, even with all the volume and efficiency of that system, making a custom unit would not be very cost effective? Fundamentally, the mcu can be reprogrammed, the video above indicates that strongly. I know it’s just a video, but… the hard part is writing the software for it. But software, once written can be distributed across the world and benefit a great many people.

We should come together as a community and fund someone to do something here, it looks doable. Maybe full FOC control, but I take seriously the point that it may not be possible to fit that firmware in. Surely just sinusoidal drive with precise rpm control and sensorless feedback. Or, fundamentally, just make them more general purpose building blocks. That’s the best idea, convert them into general purpose building blocks. I guess they are, from the looks of things, except that you have to know how to write software for them. It’s great that the manufacturer’s put provisions in there to reprogram them.

I guess all I really need is some good documentation on them and the software tool stack that it takes to program them, then I could probably write the program I need in C, for sinusoidal control with sensorless feedback. As it stands, that is beyond me, practically.

I am open to collaboration on the subject, if anyone knows enough of the software engineering to do this… I could even pay you concievably. Probably it would not be sane for me to pay much. I hope to make some money for my development time on the energy recovery ventilator project, but I am skeptical I will even be able to pay for my own development time.

We need something like gitcoin for open hardware. Lots to be done, lots to be done. Lots of potential, if we can come together enough. Exciting times.

I investigated reprogramming these boards, and although they are totally usually reprogrammable, one major issue that came up is the slow switching speeds, especially on the high side, that many exhibit. This document https://github.com/bitdump/BLHeli/blob/master/SiLabs/BLHeli%20supported%20SiLabs%20ESCs.pdf says that the one I have, the emax 12, exhibits “slow switching speeds”. It doesn’t indicate how slow. The comments on the other units seem to indicate that “slow” means something like 2.5 microseconds or longer.

There is an option in BL Heli for sinusoidal drive at least for some units, which is getting closer to foc.

In conclusion, it looks like converting these into certainly more general purpose units could be done, maybe with foc maybe not, you would want to pick a very common and low cost yet relatively good performing (switching speed etc.) unit to work on. The silicon labs ones use an adc to monitor current and voltage (or at least the back emf voltage for commutation), while the Atmega ones only use a comparator, so less flexible probably.

You can definitely reprogram most of them using just an arduino as the interface to the pc, there is software to do that.

I would try reprogramming mine but there is a good chance it won’t work anyway for what I need, the scimonk firmware couldn’t handle the gimbal motor, probably the KV rating of it confuses the unit, the back emf to rpm ratio is too high for it to make sense of the signal, or maybe it is something else. Fundamentally it is not general purpose enough. The board I got no amazon works, but it is not sinusoidal drive, so it makes too much noise.

I considered trying to highjack the driver stage by removing the mcu and soldering to the pads. That might work well with some models and should definitely be investigated as an option for use as a general purpose driver board, because there are no driver boards that can do that on the market right now at a reasonable price, apparently. Just give you 3 half -bridges with separate control of each transistor.

The thing is, the timing limitations of the l298N board is the prime suspect for the incapacity of that board to work in this role, at least not without closed loop current compensation, or at least modifications to the simpleFOC software (compensating the values in the lookup table, I suppose).

Car/Truck/Ground vehicle ESCs work in this way, because they need to go in reverse. Quad-copter (drone) ESCs do not - each propeller turns only in one direction, at different speeds.

These PWM inputs I was talking about are the inputs to the driver, so commutation on a 1-PWM driver is not under MCU control, the driver IC is doing it.

Other drivers have 3-PWM control, but that’s not the typical ESC/flight controller setup.

Normally, yes. It can be a multi-step process of first flashing a new boot loader, and then a new firmware. But normally if you can update them, you can also replace the software completely.

IMHO this is quite unlikely - from the point of view of the driver architecture, MCU power and connectivity. You’d need closed loop control, so sensor inputs, etc…

It all depends on your goals. To do FOC control effectively you want something like a SimpleFOC shield, for use with an external MCU, or something like a Dagor or Moteus driver, for direct mount on a motor. Hacking up a driver that wasn’t intended for this use will have so many problems and disadvantages, that for most people, it won’t be worth the price difference.
The thought of making many units of a hacked up driver where you have solder cables to it, re-program it, etc… isn’t exactly a viable economic proposition in my opinion.
The idea of making a new, simple and cheap driver as valentine suggests is probably much better. There have been several recents threads in the forum describing such controllers, though mainly for higher power levels than you seem to need.

I was able to reprogram my esc, just using an arduino and the blheli software. The main problem was finding the right combination of the different firmwares, and boards and pinouts. Nobody wants to just tell you how it works, it is these quick tutorials that only work for exact models of board etc. that are never what you have and have no information on how to do things more generally, or nothing at all.

Anyway, you can reprogram these things without too much difficulty. I think I got the wrong firmware onto the esc, though, because it overheated, although it still works.

Warning: the blheli overwrites the arduino bootloader, so now I have to reload the bootloader on to the arduino with another arduino…

It was still not able to drive the motor except in the exact same way as the scimonk firmware. I fear the test may not have been very good in that regard because it had the wrong firmware. The pinout of the microcontroller probably didn’t match the output stage, so some of the transistors gave a short circuit during some periods. Yet it still drove the motor. I could try again, but this test told me that sinusoidal drive is not supported by this model of esc in the blheli firmware anyway, so it probably won’t be any more quiet. Thus, I do not think I will pursue this avenue further, I have too much else to do to advance the project, I can’t get bogged down too much here.

Nevertheless, it does prove that you can reprogram these things. If you were a real wizard with the programming you could probably do something good here. There are many different models of esc, but it appears that there are only a few basic design patterns that most of them follow, and most of them can be reprogrammed.

The sensor input could be the back emf, potentially? I know there are drawbacks to that, it doesn’t work at low speed. But with a sensible startup routine it could work. Conceivably, carefully watching the inductance of the coils could give info about the position of the motor relative to the magnetic poles, since it is a lump of magnetic stuff that gets closer to and farther from the coil… I just like the idea of being clever about what we have, providing value like that, instead of requiring expensive encoders etc., which are irreplaceable for some applications but are not needed for many.

If you can make a simple, cheap driver available, that would be awesome. I noticed there are some good chips for the purpose. It’s just that that’s not really happening. You can’t even buy the output stage at this point. When I go to make a system that is built of building blocks, I am faced with a huge selection of inadequate options, instead of a foundation to stand upon and reach further.

You wouldn’t have to solder cables to it, you can just have electrical contacts that come down and touch the pads briefly. Right now, if it’s a simple foc shield for $45 CAD after shipping and tax (like 30 euros), or a $6 CAD esc that takes 10 seconds to reprogram, that’s some good money on an hourly basis.

I know it can be a bother all this downward price pressure, but we have to respect that something like a motor driver board is only a small component of a much larger system, which still only provides small amounts of real world benefit to people. The price has to be commensurate with that or the big picture of the project becomes non viable.

I am faced with trying to produce an ERV unit for less than 800 CAD or so, but when you add all the labor of the printing, motors, drivers, bearings, couplers, testing, power supply, arduino, even the screws at like 12 cents each, cheapest I can get them. More advanced products aren’t possible in an ecosystem where the basic building blocks are $45 each.

Got the esc working with the gimbal motor with the right firmware. It was not the auto-detected firmware, it was the one indicated by using the pdf document with pictures of the different compatible ESCs and using the recommendations that went with the picture that matched most closely.

So this does nothing but prove that these motors can be controlled by cheap escs with the right firmware, so if I can find one that can do sinusoidal control, then I might be in business. Otherwise trying to get a set of half h bridges that works ok is the next hope. Maybe I could use simplefoc to give sinusoidal control and then monitor the back emf with the arduino so I can at least detect stalls and restart if that happens. Then I can use one output stage to drive both motors at once, possibly… probably, trying to control two motors with one sensorless esc will not go down well… and I have to terminate this, I am already way overbudget on the development time. Maybe I will just add some rubber to the mounting of the motors and go with that…

Video that shares some information for the next person trying to drive a gimbal motor with an esc. Scimonk firmware can’t drive an 280KV motor, probbaly the KV is too low. Blheli can, though. This video tells you some of what you need to know to reprogram an esc.

BTW, I found out that there are some ESC that have 32 bit MCUs. They might be expensive anyway, though, which defeats the purpose of trying to reprogram them, mostly. If a cheap one could be found and modified it might be able to do most of what the other drivers do and at a lower price. You can access several of the pins of the microcontroller, and the pwm line can be used as a data line. You could probably make it capable of accepting sensor input, and implement the foc control software. Might be good for applications that need large current draws or something. Or design and produce a good quality cheap board, whatever is easier and cheaper and gets it done. Just that right now there are definitely some gaps in the ecosystem.

After considering my options, I will probably just go with the reprogrammed esc for a while, and some rubber mounts on the motors to reduce the noise coming from them.

It also appears possible and maybe practical to remove the MCU and acces the half hbridges directly, by soldering on some wires there. That may be the only viable method to get the mythical 6 pin pwm for a lot of people, because apparently you cannot buy high side switches ready to use anywhere, you would have to buy the components and roll your own. This is slight progress, and may be economical. You can get 30 amp escs for 6 bucks CAD, which is like 4 bucks US. Including shipping, that’s going to be hard to beat any other way.