Controlling Brushless Motors with 1Sheeld

Hi guys, I'm new to this. So I would appreciate your help with project of mine. I've got the wiring of the motors and all the connections with the ESC correct. But I don't have the code.

I did my research and connected all (X4 4500 kV) Brushless DC Motors with their own ESCs and I've made a distributor for those ESCs for power supply. I dedicated their PWM pins and upload a few codes. But those codes just trigger it to spin in a specific speed that I had to put in during uploading the code. Please anyone help me with project.

Please show your code, using code tags </>.

I tried to go to simple first, so I did tried with the push button shield. Here is te code:

/* Include 1Sheeld library. */
#include <OneSheeld.h>
int STATE = 1;
int Arming_Time = 100; 
int pin = 3;
int Pulse = 1000;
int Speed = 1350;

void setup()
{
  /* Start communication. */
  OneSheeld.begin();
  pinMode(pin, OUTPUT);
for (Arming_Time = 0; Arming_Time < 500; Arming_Time +=1)
  {
  digitalWrite(pin, HIGH);
  delayMicroseconds(1100);
  digitalWrite(pin, LOW);
  delay(20-Pulse/1000);
  }
}

void loop()
{
  /* Always check if the push button is pressed. */
  if(PushButton.isPressed())
  {
  digitalWrite(pin, HIGH); 
  delayMicroseconds(Speed); 
  digitalWrite(pin, LOW); 
  delay(20-(Speed/1000));
  }


}

You have to add code (and hardware?) to change Speed at runtime.

you see the portion

int Speed = 1350;

if I wanna change the speed I do it by changing the value in the variable "Speed" then I upload it again.

Most importantly the code doesn't work. Yeah it does pair and other things like blinking an LED works but the motor doesn't spin. I hear it being armed but doesn't spin.

Your code is for PCM (model car remote control), not for PWM. If you ESC wants PWM, use analogWrite() instead of your code.

How do you want to change the speed? Wireless brain transmission does not yet work, you need some input device.

I tried with, analogWrite(), it just keeps beeping. That means it’s not receiving any signal right?

I hope to increase it by increment of 50. For example, each time I press the button it will increase the speed.

I tried it like this

</>
Speed = Speed + 50;
</>
but sometimes works and sometimes doesn’t.

Today I updated to this code:

#define CUSTOM_SETTINGS
#define INCLUDE_SLIDER_SHIELD
#define INCLUDE_GAMEPAD_SHIELD

/* Include 1Sheeld library. */
#include <OneSheeld.h>
int value;
int STATE = 1;
int Arming_Time = 0;
int m1 = 3;
int m2 = 5;
int m3 = 6;
int m4 = 9;
int Pulse = 1000;
int Speed = 1300;

void setup() 
{
  //Serial.begin(9600);
  OneSheeld.begin();  
  pinMode(m1,OUTPUT);
  pinMode(m2,OUTPUT);
  pinMode(m3, OUTPUT);
  pinMode(m4, OUTPUT);      
for (Arming_Time = 0; Arming_Time < 500; Arming_Time +=1)
  {
   digitalWrite(m1, HIGH);
   digitalWrite(m2, HIGH);
   digitalWrite(m3, HIGH);
   digitalWrite(m4, HIGH);
   delayMicroseconds(1100); 
   digitalWrite(m1, LOW);
   digitalWrite(m2, LOW);
   digitalWrite(m3, LOW);
   digitalWrite(m4, LOW);
   delay(20-Pulse/1000);
  }
}

void loop() 
{
   /*Slider Begin */
  value = Slider.getValue();
  Serial.println(value);
  delay(1000);
   {
   digitalWrite(m1, HIGH);
   digitalWrite(m2, HIGH);
   delayMicroseconds(value); 
   digitalWrite(m1, LOW);
   digitalWrite(m2, LOW);
   delay(20-(value/Pulse));
   }  

  if(GamePad.isUpPressed())
  {
    digitalWrite(m3, HIGH);
    digitalWrite(m4, HIGH);
    delayMicroseconds(1300);
    digitalWrite(m3, LOW);
    digitalWrite(m4, LOW);
    delay(20-(1300/Pulse));
  }
  else if (GamePad.isRightPressed())
  {
    digitalWrite(m3, HIGH);
    digitalWrite(m4, LOW);
    delayMicroseconds(1300);
    digitalWrite(m3, LOW);
    digitalWrite(m4, LOW);
    delay(20-(1300/1000));
  }

  else if (GamePad.isLeftPressed())
  {
    digitalWrite(m3, LOW);
    digitalWrite(m4, HIGH);
    delayMicroseconds(1300);
    digitalWrite(m3, LOW);
    digitalWrite(m4, LOW);
    delay(20-(1300/1000));
  }

  else if (GamePad.isDownPressed())
  {
    digitalWrite(m3, LOW);
    digitalWrite(m4, LOW);
    delayMicroseconds(1300);
    digitalWrite(m3, LOW);
    digitalWrite(m4, LOW);
    delay(20-(1300/1000));
  }
}

Actually the project is a hovercraft, my concept is hover the craft by the slider shield from 1Sheeld and navigating it by the gamepad shield.

But as always same results “Failure”

You should study the data sheets of your ESC, before you start coding. Also learn how to write non-blocking code, without delay().

hi, i already control brushless motor (multirotor) using servo library. Maybe youcan try this basic code to start spin your brushless motor.

becareful. motor start spinning when code uploaded

#include <Servo.h>

Servo motor_1;

void setup() {
  Serial.begin(9600);
  motor_1.attach(3);
}

void loop() {
  motor_1.write(1100);   //your speed

}

Hi,
Welcome to the Forum.

I think you need to go back to simple code, just to control the ESC, forget the rest for the moment.

You need to use a potentiometer on an analog input of your controller to allow you to input live values for your speed control.

What model Arduino are you using?
What ESC are you using, links to data/spec?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile: