Goal Use Pulse Width Modulation (I think that is the standard approach) to control the speed of my BLDC.

I have tried so many things

#include <stdio.h>
#include <inttypes.h>
#include <wiringPi.h>
#include <softPwm.h>

int main() {
    uint32_t start;
    int dc;
    int iores = wiringPiSetupGpio();// init by BCM pin numbering
    if (iores == -1)
        return 1;

    softPwmCreate(13, 0, 255);

    start = millis();

    dc = 25;

    //while ((millis() - start) < 20000)
        //softPwmWrite(13, dc);  //  
        //softPwmWrite(18, 0);

        // debug:

    for (int i = 0; i < 512; i++) {
        softPwmWrite(13, i);
        delay(500);        //}

    softPwmWrite(13, 0);  // digitalWrite don't work then here

    return 0;

This is the current state of my code. It is a copy and paste from one of the articles I read. My usual approach is to build a base line and grow from there.

I can currently use pwm to slowly increase and decrease the brightness of an led. I understand the beginnings of how commandline with gpio works. I can modify gpio mode and set values in the command line for pwm and binary output. I can do the LED hello world with Digital write and pwmwrite, but for some reason I just for the life of me can not get my motor to spin.

MOTOR: ReadyToSky RS2212-320KV —https://www.amazon.com/dp/B075DD16LK/ref=cm_sw_r_cp_api_i_YXAM97TXS8AN9C1WX9MH?_encoding=UTF8&psc=1

ESC: ReadyToSky 30A. —- https://a.co/d/hDVOBIf

Battery: LiPo 7.4V/1600mAh PI: 3 b+

My black Wire from the Esc goes to a colored wire My White Wire goes to a white wire


step 1: baseline - What am I missing in the code in a Hello World kind of way?

step 2: googling hasn't gotten me there I have tried a lot - What books can i read? Suggestions on educational resources I am in love with this stuff and really want to understand it and soon i would like to be able to do this without libraries straight at the register, but one step at a time.


All my motor does is beep every second.

I have read that it needs to be calibrated, but I have not read how.

  • 1
    White Wire goes to a white wire is meaningless ... any wire could be any color ... your question is not about the Raspberry Pi until you get the wiring sorted out
    – jsotola
    Oct 1, 2022 at 2:55
  • that is a fair point... I dont know which is ground and power yet on the esc so i use that pattern to keep it straight but your comment is a fair point
    – thomedy
    Oct 1, 2022 at 2:57
  • you provided almost zero information about what you are doing
    – jsotola
    Oct 1, 2022 at 2:57
  • I have tried multple gpio pins
    – thomedy
    Oct 1, 2022 at 2:57
  • im not sure what to add i have the code i have tried multiple pins what more can i do to communicate more i want to be as clear as i can i just dont know what to add im sorry
    – thomedy
    Oct 1, 2022 at 2:58

1 Answer 1


The salient point is you are using an ESC to control the motor.

You need to control the ESC.

You control the ESC as you would a servo.

Look up servo and ESC and Raspberry Pi.

I suggest you use pigpio rather than wiringPi for servo/ESC control.

  • That actually i hope is helpful thanks. I didn’t realize servos and bldc have that in common and I already switched to pig pio
    – thomedy
    Oct 1, 2022 at 12:41
  • I suggest you experiment with the pigs s command.
    – joan
    Oct 1, 2022 at 13:31
  • You wrote pigs correct? If so, thank you. eventually I want to write without a library because that is always my preferred choice. I will experiment with the pig command. As an experiment can i control a servo/bldc/esc directly with Command line?
    – thomedy
    Oct 1, 2022 at 13:51
  • Yes, pigs s 4 1500 from the command line will send 1500µs pulses at 50Hz to GPIO 4. A servo connected to GPIO 4 will go to its centre position.
    – joan
    Oct 1, 2022 at 15:18
  • Thanks I already started reading pigs man Page it’s long
    – thomedy
    Oct 2, 2022 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.