I have a problem with my T200 thruster and an ESC. I am using 3 buttons to control the motors. However, when we tested the motor with a known working controller it would go forward but backward would not work.
We used an oscilloscope to read the PWM signal and it would give 1100 to 1900 μs signal with both a working controller and my Arduino. However, when we plugged it into the Arduino it would not spin at all. Even if it gave the beeps correctly for initializing the ESC. Here is the code we are using.
// Include the Servo library
#include <Servo.h>
// Define the pins for the buttons and motors
#define BUTTON1_PIN 2
#define BUTTON2_PIN 3
#define BUTTON3_PIN 7
#define MOTOR1_PIN 8
#define MOTOR2_PIN 9
// Define the initial values for the motors and escs
int motor1_value = 1500;
int motor2_value = 1500;
// Create servo objects for the motors
Servo motor1;
Servo motor2;
// Setup function
void setup() {
// Attach the motors to their respective pins
motor1.attach(MOTOR1_PIN);
motor2.attach(MOTOR2_PIN);
pinMode(LED_BUILTIN, OUTPUT);
delay(7000);
// Set the initial positions for the motors
motor1.writeMicroseconds(motor1_value);
motor2.writeMicroseconds(motor2_value);
// Set the button pins as inputs
pinMode(BUTTON1_PIN, INPUT_PULLUP);
pinMode(BUTTON2_PIN, INPUT_PULLUP);
pinMode(BUTTON3_PIN, INPUT_PULLUP);
//Set serial comms
Serial.begin(9600);
}
// Loop function
void loop() {
// Read the state of the buttons
int button1_state = digitalRead(BUTTON1_PIN);
int button2_state = digitalRead(BUTTON2_PIN);
int button3_state = digitalRead(BUTTON3_PIN);
// Check if button 1 is pressed (Up Power)
if (button1_state == LOW) {
// Increase the motor values by 100
motor1_value += 100;
motor2_value += 100;
digitalWrite(LED_BUILTIN, HIGH);
delay(250);
// Check if the motor values are greater than 1900
if (motor1_value > 1900) {
// Set the motor values to 1900
motor1_value = 1900;
motor2_value = 1900;
}
if (motor1_value < 1100) {
motor1_value = 1100;
motor2_value = 1100;
}
// Write the new motor values to the motor
motor1.writeMicroseconds(motor1_value);
motor2.writeMicroseconds(motor2_value);
}
// Check if button 2 is pressed (Down Power)
if (button2_state == LOW) {
// Decrease the motor values by 100
motor2_value -= 100;
motor1_value -= 100;
digitalWrite(LED_BUILTIN, HIGH);
delay(250);
// Check if the motor values are greater than 1900
if (motor1_value > 1900) {
// Set the motor values to 1900
motor2_value = 1900;
motor1_value = 1900;
}
if (motor1_value < 1100) {
motor1_value = 1100;
motor2_value = 1100;
}
// Write the new motor values to the motor
motor2.writeMicroseconds(motor2_value);
motor1.writeMicroseconds(motor1_value);
}
// Set motors too off
if (button3_state == LOW) {
motor1_value = 1500;
motor2_value = 1500;
digitalWrite(LED_BUILTIN, HIGH);
}
motor1.writeMicroseconds(motor1_value);
motor2.writeMicroseconds(motor2_value);
digitalWrite(LED_BUILTIN, LOW);
Serial.print("motor 1 ");
Serial.println(motor1_value);
Serial.print("motor 2 ");
Serial.println(motor2_value);
}
What would cause the motor to not spin?