How to control a Brushless DC Motor?

Hello group,

I'm trying to control a Brushless DC motor with a ESC using Node Red in my Raspberry Pi 3b+, but until now I've not been sucessfull :disappointed_relieved:

My node is very simple, only a PWM output to a Raspberry Pi pin with a frequency of 2000kHz, but the motor behaves in a strange way, increasing and decreasing the speed constantly. My objetive is to create an "open loop" control, changing the motor speed with a linear gauge node from Node Red.

Did any of you ever tried to control a Brushless DC motor w/ Node Red? I searched over the forum but I did not found anything similar to my problem. I really apreciate the support.

Bruno.

What motor/driver board are you using?

But my initial thoughts are that the PWM output of you Pi is varying - which is not unusual as Pi isn't a real-time system and the standard PWM output is software generated

You might get better results using the Pigpiod node


as its PWM is derived from a much more accurate PWM source
1 Like

I'm currently using the motor A2212/1000kV with an ESC 30A. Ok, I'll try to use this node instead, thanks @cymplecy. Do you know if I need to calibrate the ESC before starting the test?

I know nothing about ESCs except that they are used in quad-copters

Any particular reason for using this PWM frequency ? Did you try with lower frequencies ?

Agree and because of that I would consider using a dedicated device to control the motor. A good choice might by the PCA9685. This board is capable of generating PWM signals that could control servos, motors, LED brightness,etc. Since I had motors and ESCs laying around (from the early days of electric flight hobby). I tested controlling a motor from Node-RED with and it worked very well. Here is a link to a video demo. The video is low quality since it is not easy to shot and command the dashboard at the same time (and keep the motor from flying away, even if a propeller is not attached to it).

1 Like

Hello Andrei! With lower frequencies I did not have any response from the motor.. So I've decided to test with a higher frequency.

@cymplecy I downloaded the pi gpiod node but there is no option to set the frequency. Is there a way to change it?

@Andrei thank you for the video and for the proposal of using PCA9685, I did not think of that! Do you have the nodes you used?

mm- so there isn't :frowning:
Have you tried using it? Does it need the frequency changing?

If you look at the file pi-gpiod.js
around line 122 you can probably add
PiGPIO.set_PWM_frequency(frequency_required);
but you'll need to read the pigpio docs to work out what he units are etc (and allowable ranges) - probably here - http://abyz.me.uk/rpi/pigpio/cif.html#gpioSetPWMfrequency

Yep - I've asked the question on twitter to see if anyone has used the facility before diving in with a PR :slight_smile:

Yes, I need to have the possibility to change the frequency. I'm using Node Red for my graduation final paper, where I'm developing a test bench for Brushless DC motor to be used at an Aerodesign competition. This test bench will be responsible for testing a whole bunch of brushless motors, not simultaneously. Since different motors might have different specification, I must have the possibility to change the frequency.

I have in mind two types of tests: open loop, where the user will be responsible for changing the motor speed and; closed loop, when the user chooses for a specific speed mode ie fast mode, slow mode etc.

The user interface is almost done, the only thing left is the motor control. I'll check the documentation @dceejay to trying figuring it out!

Thank you in advance!

Andrei, I have one question. In your experiment, did you calibrated the ESC?

Hi @brunozanardi, yes calibrating the ESC was the very first thing I did. Just used the standard process for analog ESCs.

Back to a question I did not reply before. Here is my flow. The inject nodes have been added exactly for the purpose of calibrating the ESC.

a-01

As you can see I am not using contrib nodes. I installed though the two key libraries:

/home/pi
├── i2c-bus@5.2.0
└── pca9685@4.0.3

My setup is not useful for you if you are not using standard frequency of RC servos = 50 Hz.

2 Likes

Thanks! Do you know a way of calibrating the ESC without using the PCA9685 function node? I have a python script where I successfully calibrated the esc and put the motor to work, but since my objective is to use Node Red for the whole project, I want to "convert" the script inside Node Red. bldc.txt (839 Bytes)

The throttle calibration process is quite simple. You want to create a Node-Red flow with an inject node that triggers a 1 ms width pulse (1000 micro seconds) and another one to trigger a 2 ms width pulse (2000 micro seconds). Standard ESC will work nicely with 50 Hz frequency. Your ESC will be connected to the GPIO pin that generates those signals. First off you click on the inject node to start generating the high throttle endpoint. Then you will connect the power to your ESC. You will hear a sequence of tones coming from the motor. At this time you click on the other inject node to trigger the low throttle endpoint (1ms). You will hear another sequence of tones confirming the ESC is calibrated. There are many videos on youtube that shows how the process looks like for air models (or multirotors). The idea is the same but instead of using the an RC transmitter you will be generating the PWM signals from Node-Red.

1 Like

So, for example: if I use a node of 50 hz of frequency I should calibrate um 10% of PWM (2000us) for maximum throttle and 5% (1000us) for minimum, right? Please, correct if I'm wrong. I tried to do as you specified but it did not work, the motor did not biped.

[{"id":"c102f50f.16a8a8","type":"rpi-gpio out","z":"469b1a3.f3bf364","name":"","pin":"36","set":"","level":"0","freq":"50","out":"pwm","x":350,"y":320,"wires":[]},{"id":"5a44eed6.a5592","type":"inject","z":"469b1a3.f3bf364","name":"","topic":"","payload":"5","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":320,"wires":[["c102f50f.16a8a8"]]},{"id":"7fff65d5.a5247c","type":"inject","z":"469b1a3.f3bf364","name":"","topic":"","payload":"10","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":360,"wires":[["c102f50f.16a8a8"]]}]

This is what the servo mode can do for you by default.

The motor did not beep while trying to calibrate or the motor is never beeping at all ? What happens if you generate an 1.5ms pulse and then connect the ESC to the power source ?

Additional questions:

What is your power source for the motor (Lipo battery perhaps) ? Is it charged enough to not activate the ESC protection ?
Do you have the ESC manual to understand the sequence of tones ?

Note that I am using an external board to generate 5V PWM signals. You are connecting your ESC directly to the GPIO pin that provided 3.3V PWM signals. In general an ESC would accept 3.3V but in some cases they may fail to work with this signal level. I can´t tell if this is the case for your ESC or not. Do you have an additional ESC (another model / manufacturer) to test ?

Hello Andrei! After some unsuccessful tests, my battery discharged at a level that the esc was not being triggered. Today I recharged it and followed the procedures you mentioned above.

I sent a PWM signal using pigpiod node for the maximum thrust (100), and then I connected the ESC to the Power supply. After two seconds, I sent a signal for minimum thrust (0) and I've heard the final "bip" from the motor. After that the motor was ready to work!!!

Check the nodes I used here:

[{"id":"dafffbca.592528","type":"inject","z":"469b1a3.f3bf364","name":"","topic":"","payload":"100","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":360,"wires":[["e266e5b7.2fbaa8"]]},{"id":"1a5e149d.164cdb","type":"inject","z":"469b1a3.f3bf364","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":440,"wires":[["e266e5b7.2fbaa8"]]},{"id":"e266e5b7.2fbaa8","type":"pi-gpiod out","z":"469b1a3.f3bf364","name":"","host":"localhost","port":8888,"pin":"16","set":"","level":"0","out":"ser","sermin":"1000","sermax":"2000","x":260,"y":440,"wires":[]},{"id":"da17f916.8d98d8","type":"ui_slider","z":"469b1a3.f3bf364","name":"","label":"slider","tooltip":"","group":"20b7d0bd.c079","order":0,"width":0,"height":0,"passthru":true,"outs":"all","topic":"","min":0,"max":"100","step":1,"x":80,"y":520,"wires":[["e266e5b7.2fbaa8"]]},{"id":"20b7d0bd.c079","type":"ui_group","z":"","name":"PWM","tab":"dd86238.30ebee","order":1,"disp":true,"width":12,"collapse":false},{"id":"dd86238.30ebee","type":"ui_tab","z":"","name":"Teste PWM","icon":"dashboard","order":6,"disabled":false,"hidden":false}]

I'm attaching here the video where I calibrate the ESC and put the motor to work:

2 Likes

Well done !! Congratulations. I am happy it is working.