Thanks for the tutorial, very useful, looking to convert forward backward PWM inputs that usually drive a brushed motor controller IC from a stock RC receiver to drive an external ESC, seems like nobody has done this?! Why not let Blheli handle dead zone by its built-in calibration routine? Same for arming by holding throttle down, no?
Hi, thanks for this video! I am with a project where I precisely need to rotate the BLDC motor in both directions... I have a Emax Blheli-s Bullet 15A, do you know if I could configure it to be bidirectional? Thanks again!
All BL Heli escs should be reversible at this point. However if you want precise control over a bldc motor, you probably want to go with a sensored motor and a controller like a vesc. Sensorless bldc has a hard time with slow speed and precision
Hi Mike, I have a question: It is possible to make any ESC bidirectional ?? either software ? Or is it mechanical ? And if mechanical, assuming i have a normal ESC, normally I'd switch the brushless motors pins to achieve a spin to the oppose direction. Is there anything i can to achieve a bidirectional without having to switch pins ??
No, not every esc can handle bidirectional operation. This is a limitation in software, it needs to be able to trigger the poles and sense the induction in both directions. Theoretically you could use a dual pole dual throw relay to change the motor wiring on the fly. If you reverse two of the three wires the motor spins in the other direction. But to be honest this seems needlessly complicated. The two most common firmwares I have found are SimonK and blheli. Both of these have versions that can be reversed. Some cheap option, probably not.
Hey Mikey, I thanks for making this video. I have a few questions, as I am trying to implement a raspberry pi for drone motor control (not the best choice of course, but I want to see what i can do with it). By " #define ESC_MIN_THROTTLE 1070 " do you mean a duty cycle width of 1070 microseconds? If so, what frequency is this PWM running at? I have been able to get decent control of my motors using the Pi's PWM (3.3V amplitude @ 580 Hz). I get a starting speed around 44% duty cycle and a final speed around 97% duty cycle. I am also using an op amp to amplify the 3.3V to 5V. Also, how would you recommend about finding the PWM signal to "initialize" the ESC? Learning that there is an initialization makes my tests make more sense now, as sometimes we didnt get any motor response (we must have not initialized properly). Thank you so much for the video!
Hey, I was watching this video because I am working on a project similar to yours controlling the motor with a raspberry pi. How were you able to edit the ESC's BLHeli settings with the pi?
The PWM frequency is just the default for the Arduino, yes with PWM The signal is between 1000 and 2000. I set the minimum micro second to 1070 as that gives a bit of a dead region at the start of the stick, I do the same for the top end. Using an opamp for the 5v conversion is interesting, I would have just used a transistor :) The pattern is usually min-max-min this allows the ESC to learn the signal range :)
Follow up: I was able to get my ESC driving a motor in bidirectional mode with my Raspberry Pi Zero. I would not recommend doing this as whenever the motor nears 0 throttle, the motor starts to stutter and causes backcurrent to flow into the pi and causes it to reset.
@@DSdvdDS I am using a pi 4 and i have no back plow into the rpi, maybe you have a ground loop thats doing that? I was able to get very fine control using a raspberry pi. are you using an amplifier circuit with the pi? if so, what kind?
It is also worth noting you should create a dead range in the middle where +/- 10 sends 0. This gives a stop range so if the value fluctuates around 0, the motor does not stutter
Hi Mikey, I am working on a project using the Flysky ibus signal to control 3 dc motors and 1 servo by an Arduino nano and TB6612FNG motor drivers. I can understand by your example how the Arduino can read the ibus signal, but how are the channels identified ? example: Ch1 = servo 1 Ch2 = motor driver pwm in, Ain1 and Ain2 etc. I noticed you had included servo library for the pwm signal, but then got a bit lost in the brushless motor esc setup. I could sure use some advise on this subject. Thanks in advance.
Of course, he says as he loads the code to remember himself. I am using newer code than what was in this video, since I found some major optimizations, you can find the new code here: github.com/MikeysLab/BrushlessESCviaPWM/tree/master/EscPWMTesting Okay, so the serial data out of the ibus receiver comes in as a byte stream. We listen to the stream until we detect the header of a packet (since we can jump in at any point and the data wont make sense if we are not at the start of the fame. So we are looking for 0x20 followed by 0x40 which is the packet header. At that point, in the new code, we fill a buffer the size of the the full iBus frame, once we have that buffer full we do a mem copy to an array rcValue[IBUS_MAX_CHANNELS]; from there we need to scale the values contained in the array, why? because rc values sent from any type of controllers will have values between 1000 - 2000 micro seconds. But there are dead zones at the beginning and top end of that range, so we scale the value we received to make it a value in a 1000 - 2000 ms range. At this point, we are ready to output the PWM value we just scaled. We do this WriteSpeed() in here we impose both a middle dead zone and an anti-flutter calculation. So essentially, as we receive the values out of the serial stream, we write them to the rcValues[], So channel 1's value is in rcValues[0], Channel 2 is in rcValues[1] ... and so on. I think this answers your question, if not let me know :) also check out the video on controlling a brushless ESC with PWM as I go a little more into this there.
@@MikeysLab Hi again Mikey, I have just opened the full text content of the reply, and can see you have given me more detail than the github link. I can understand the working principle, but not know how to set out the code in the Arduino IDE. I tried to use your code from your rover project, and change some details, but could not get past the compiler. A friend managed to arrange the channels into an array, so I type in the output pins in that channel column, change the channel in use number, and is good to go. I use it on a Mega to control 4x tb6612fng motor drivers and operate 8x dc motors on a rc excavator. The project I am working on is an articulated steer 4 wheel drive dumper. The steering motor is servo controlled, and needs the library included, but I cant seem to break into the code without dismantling the whole code to change the pwm output. I wonder if you would be able to find a solution to my trouble. Thanks for your reply.
I would love to help, but I am not really sure of your problem. Can you reach out via the Mikeys Lab page on Facebook and share the code you are working with?
Thank you so much for te video! I’m using a NRF24LO1 module to control the throttle do you know how can I implement it in your code? (Just the receiver part)
That depends what format you are receiving the data in. It would need to be translated into a value for the pwm signal. So for example if you are getting direction and speed as separate values, you would need to convert that to the pwm value the esc is expecting.
@@MikeysLab Thank you for your answer, I am using a joystick so I want to make it go in a direction from 0 to 450 and in the other using values from 600 to 1023 (these values are maped from 0 to 180) but I don't know how to tell the esc to go in one specific direction by using only pwm signals (generated by the servo.h library). (I have the same esc as yours)
Ah, you have to configure the esc for bidirectional mode, they are often not set to that by default. Then the esc will change motor direction around a value of 1000 depending on the settings in the esc.
oneshot is a little more complicated than that. True, that is the first step, but oneshot is only supposed to send updates to all motors when the value has changed. At most frequently at the speed on the control loop in the controller.
Yes, almost all ESC's understand pwm, it is only once you start using one shot and d shot that you need specific esc's. Sorry about the delayed response, you tube did not notify me of you comment.
Thanks for the video! This is exactly what I was looking for for my hovercraft build :)
You can get rid of that noise by turning on your 20 MHz filter with your o-scope. There should be a setting in one of those menus on the top.
Thanks for the tutorial, very useful, looking to convert forward backward PWM inputs that usually drive a brushed motor controller IC from a stock RC receiver to drive an external ESC, seems like nobody has done this?! Why not let Blheli handle dead zone by its built-in calibration routine? Same for arming by holding throttle down, no?
You're amazing, dude!
Hi, thanks for this video! I am with a project where I precisely need to rotate the BLDC motor in both directions... I have a Emax Blheli-s Bullet 15A, do you know if I could configure it to be bidirectional? Thanks again!
All BL Heli escs should be reversible at this point. However if you want precise control over a bldc motor, you probably want to go with a sensored motor and a controller like a vesc. Sensorless bldc has a hard time with slow speed and precision
@@MikeysLab thanks!
Hi Mike,
I have a question: It is possible to make any ESC bidirectional ??
either software ? Or is it mechanical ?
And if mechanical, assuming i have a normal ESC, normally
I'd switch the brushless motors pins to achieve a spin to the oppose direction.
Is there anything i can to achieve a bidirectional without having to switch pins ??
No, not every esc can handle bidirectional operation. This is a limitation in software, it needs to be able to trigger the poles and sense the induction in both directions. Theoretically you could use a dual pole dual throw relay to change the motor wiring on the fly. If you reverse two of the three wires the motor spins in the other direction. But to be honest this seems needlessly complicated. The two most common firmwares I have found are SimonK and blheli. Both of these have versions that can be reversed. Some cheap option, probably not.
Hey Mikey, I thanks for making this video. I have a few questions, as I am trying to implement a raspberry pi for drone motor control (not the best choice of course, but I want to see what i can do with it). By " #define ESC_MIN_THROTTLE 1070 " do you mean a duty cycle width of 1070 microseconds? If so, what frequency is this PWM running at? I have been able to get decent control of my motors using the Pi's PWM (3.3V amplitude @ 580 Hz). I get a starting speed around 44% duty cycle and a final speed around 97% duty cycle. I am also using an op amp to amplify the 3.3V to 5V. Also, how would you recommend about finding the PWM signal to "initialize" the ESC? Learning that there is an initialization makes my tests make more sense now, as sometimes we didnt get any motor response (we must have not initialized properly). Thank you so much for the video!
Hey, I was watching this video because I am working on a project similar to yours controlling the motor with a raspberry pi. How were you able to edit the ESC's BLHeli settings with the pi?
The PWM frequency is just the default for the Arduino, yes with PWM The signal is between 1000 and 2000. I set the minimum micro second to 1070 as that gives a bit of a dead region at the start of the stick, I do the same for the top end. Using an opamp for the 5v conversion is interesting, I would have just used a transistor :) The pattern is usually min-max-min this allows the ESC to learn the signal range :)
Follow up: I was able to get my ESC driving a motor in bidirectional mode with my Raspberry Pi Zero. I would not recommend doing this as whenever the motor nears 0 throttle, the motor starts to stutter and causes backcurrent to flow into the pi and causes it to reset.
@@DSdvdDS I am using a pi 4 and i have no back plow into the rpi, maybe you have a ground loop thats doing that? I was able to get very fine control using a raspberry pi. are you using an amplifier circuit with the pi? if so, what kind?
It is also worth noting you should create a dead range in the middle where +/- 10 sends 0. This gives a stop range so if the value fluctuates around 0, the motor does not stutter
Thank so much, It is amazing !!, muchas gracias!!
Hi Mikey, I am working on a project using the Flysky ibus signal to control 3 dc motors and 1 servo by an Arduino nano and TB6612FNG motor drivers. I can understand by your example how the Arduino can read the ibus signal, but how are the channels identified ? example: Ch1 = servo 1 Ch2 = motor driver pwm in, Ain1 and Ain2 etc. I noticed you had included servo library for the pwm signal, but then got a bit lost in the brushless motor esc setup. I could sure use some advise on this subject. Thanks in advance.
Of course, he says as he loads the code to remember himself. I am using newer code than what was in this video, since I found some major optimizations, you can find the new code here:
github.com/MikeysLab/BrushlessESCviaPWM/tree/master/EscPWMTesting
Okay, so the serial data out of the ibus receiver comes in as a byte stream. We listen to the stream until we detect the header of a packet (since we can jump in at any point and the data wont make sense if we are not at the start of the fame. So we are looking for 0x20 followed by 0x40 which is the packet header. At that point, in the new code, we fill a buffer the size of the the full iBus frame, once we have that buffer full we do a mem copy to an array rcValue[IBUS_MAX_CHANNELS]; from there we need to scale the values contained in the array, why? because rc values sent from any type of controllers will have values between 1000 - 2000 micro seconds. But there are dead zones at the beginning and top end of that range, so we scale the value we received to make it a value in a 1000 - 2000 ms range. At this point, we are ready to output the PWM value we just scaled. We do this WriteSpeed() in here we impose both a middle dead zone and an anti-flutter calculation.
So essentially, as we receive the values out of the serial stream, we write them to the rcValues[], So channel 1's value is in rcValues[0], Channel 2 is in rcValues[1] ... and so on. I think this answers your question, if not let me know :) also check out the video on controlling a brushless ESC with PWM as I go a little more into this there.
The consuming iBus video, sorry got my wires crossed.
@@MikeysLab ?? Is this a reply to someone else question ?
@@MikeysLab Hi again Mikey, I have just opened the full text content of the reply, and can see you have given me more detail than the github link.
I can understand the working principle, but not know how to set out the code in the Arduino IDE. I tried to use your code from your rover project, and change some details, but could not get past the compiler. A friend managed to arrange the channels into an array, so I type in the output pins in that channel column, change the channel in use number, and is good to go. I use it on a Mega to control 4x tb6612fng motor drivers and operate 8x dc motors on a rc excavator. The project I am working on is an articulated steer 4 wheel drive dumper. The steering motor is servo controlled, and needs the library included, but I cant seem to break into the code without dismantling the whole code to change the pwm output. I wonder if you would be able to find a solution to my trouble. Thanks for your reply.
I would love to help, but I am not really sure of your problem. Can you reach out via the Mikeys Lab page on Facebook and share the code you are working with?
Thank you so much for te video! I’m using a NRF24LO1 module to control the throttle do you know how can I implement it in your code? (Just the receiver part)
That depends what format you are receiving the data in. It would need to be translated into a value for the pwm signal. So for example if you are getting direction and speed as separate values, you would need to convert that to the pwm value the esc is expecting.
@@MikeysLab Thank you for your answer, I am using a joystick so I want to make it go in a direction from 0 to 450 and in the other using values from 600 to 1023 (these values are maped from 0 to 180) but I don't know how to tell the esc to go in one specific direction by using only pwm signals (generated by the servo.h library). (I have the same esc as yours)
Ah, you have to configure the esc for bidirectional mode, they are often not set to that by default. Then the esc will change motor direction around a value of 1000 depending on the settings in the esc.
Check out this video: ua-cam.com/video/6EGLtEcdoBI/v-deo.html
To switch it to oneshot125, would it work if i just change the min pulse length to 125 and max pulse length to 250, then map the values to 125,250?
oneshot is a little more complicated than that. True, that is the first step, but oneshot is only supposed to send updates to all motors when the value has changed. At most frequently at the speed on the control loop in the controller.
Mikey's Lab how do i use oneshot then? Is there an existing library?
I am not familiar with a library, but take a look at the multi Wii source. They implemented it for there flight controllers.
Mikey's Lab i see. Just an additional question, do you know how to transition between different mixers mid-flight using inav?
can i do that with any other esc? what abut a vesc ?
Yes, almost all ESC's understand pwm, it is only once you start using one shot and d shot that you need specific esc's. Sorry about the delayed response, you tube did not notify me of you comment.