BLDC joystick too sensitive

Status
Not open for further replies.

edrummer

Well-known member
I have a BLDC motor with an ESC controlled by a joystick connected to the Arduino. The motor wants to run when the joystick is in the off position. I have to jingle the stick to get it to shut off and it will run if I just barely touch it. It does the same with other joysticks, how can I make it less sensitive, adjust the code so that the off position is bigger in both directions?

Code:
#include <Servo.h> //Using servo library to control ESC
Servo esc; //Creating a servo class with name as esc
void setup()
{
esc.attach(9); //Specify the esc signal pin,Here as D9
esc.writeMicroseconds(1000); //initialize the signal to 1000
Serial.begin(9600);
}
void loop()
{
int val; //Creating a variable val
val= analogRead(A0); //Read input from analog pin a0 and store in val
val= map(val, 0, 1023,1000,2000); //mapping val to minimum and maximum(Change if needed)
esc.writeMicroseconds(val); //using val as the signal to esc
}
 
A dead zone in the middle could help.

First of all measure the adc reading with joystick centered, my experience is that this will be close to 511 (for 10 bits) but not equal.
Save this value as something like adc_center.

Code:
void loop()
{
  int val, mappedval; //Creating a variable val
  val= analogRead(A0); //Read input from analog pin a0 and store in val
  mappedval = 1500;    // Default center value
  if (val < adc_center-10) {
    mappedval= map(val, 0, adc_center-10,1000,1500); //mapping lower range of val
  }
  if (val > adc_center+10) {
    mappedval= map(val, adc_center+10,1500,2000); //mapping upper range of val
  }
  esc.writeMicroseconds(mappedval); //using mappedval as the signal to esc
}

The size of +- 10 for the deadzone can be adjusted as needed.
 
Thanks, I get this error though. (adc_center' was not declared in this scope) I'm not sure how to declare it.
 
Slightly modified versionof mlu's code.

Code:
#include <Servo.h> //Using servo library to control ESC
Servo esc; //Creating a servo class with name as esc

int val,adc_center,mappedval; 
int deadzone =10; 

void setup()
{
esc.attach(9); //Specify the esc signal pin,Here as D9
esc.writeMicroseconds(1000); //initialize the signal to 1000
Serial.begin(9600);
}
void loop()
{
 val= analogRead(A0); //Read input from analog pin a0 and store in val
  if (val < adc_center-deadzone) {
    mappedval= map(val, 0, adc_center-deadzone,1000,1500); //mapping lower range of val
  }
  if (val > adc_center+deadzone) {
    mappedval= map(val, adc_center+deadzone,1023,1500,2000); //mapping upper range of val
  }
  esc.writeMicroseconds(mappedval); //using mappedval as the signal to esc
}
 
Oops forgot to declare a default value for adc centre. Try this
Code:
int val,mappedval; 
int deadzone =10; change this value to increase/decrease dead zone size
adc_center = 511; // default value with joystick centered
 
I guess I have another problem now, the esc shuts down sometimes at full throttle. I've been doing some research and while it could be several other things, one person had the issue and solved it this way;
(Problem solved. just shortened the operating range from 0-180 to 30-150. My esc's operates now without trouble). I don't see where in the code you could change the operating range.
 
I think this is proabably using the servo.write(nn) method rather than servo.writemicroseconds(nn).
On a continuous rotation servo, this will set the speed of the servo with 0 being full-speed in one direction, 180 being full speed in the other, and a value near 90 being no movement. So you amend your code to use esc.write.instead
If using esc.writeMicroseconds with a standard servo a parameter value of 1000 is fully counter-clockwise, 2000 is fully clockwise, and 1500 is in the middle. So you could try something like:

Code:
#include <Servo.h> //Using servo library to control ESC
Servo esc; //Creating a servo class with name as esc

int val,mappedval; 
int deadzone =10; change this value to increase/decrease dead zone size
adc_center = 511; // default value with joystick centered

void setup()
{
esc.attach(9); //Specify the esc signal pin,Here as D9
esc.writeMicroseconds(1000); //initialize the signal to 1000
Serial.begin(9600);
}
void loop()
{
 val= analogRead(A0); //Read input from analog pin a0 and store in val
  if (val < adc_center-deadzone) {
    mappedval= map(val, 0, adc_center-deadzone,1100,1500); //reduced mapping lower range of val
  }
  if (val > adc_center+deadzone) {
    mappedval= map(val, adc_center+deadzone,1023,1500,1900); //reduced mapping upper range of val
  }
  esc.writeMicroseconds(mappedval); //using mappedval as the signal to esc
}

Take a look at the Arduino servo.h for a more detailed explanation.
 
Thanks again, I wish I new more about this, I'm more focused on design and building. Things in the code are hidden from me and I don't know what to tweak. I'll try it when I can, this is for a boat and of coarse it's all sealed so I have to take everything apart to get to the USB.
 
Status
Not open for further replies.
Back
Top