Im using a PS4 controller with the game control plus library in processing with a DC motor wired to an electronic speed controller in pin 2 of my arduino. The DC motor runs on 12-16Vs so my battery is a 14.8V and connected to the ESC.
Now for some background: I had another DC motor with an ESC built in, so the motor had a power wire, a signal wire coming from the ESC and an on off switch. This set up worked great but the motor wasn’t powerful enough so I swapped it out, the hardware is essentially the same just bigger. The problem is I can only get it to work sometimes in Arduino IDE and not once so far in processing. Normally the right hat would spin the motor clockwise and the left hat would rotate the motor CCW.
ESC work like servos right? Thats at least how I have been controlling my other DC motors. My code is below so hopefully someone sees something that doesnt make sense. Also, I cant use serial for this, I have to be running standard firmata because I have multiple sensors and cant run an arduino sketch. Thanks!
Heres a real simple sketch that I wrote to try and control these motors:
import processing.serial.*;
import net.java.games.input.*;
import org.gamecontrolplus.*;
import org.gamecontrolplus.gui.*;
import cc.arduino.*;
import org.firmata.*;
ControlDevice PS4;
ControlIO control;
Arduino arduino;
float thumbRH1;
float thumbRH2;
public void setup() {
size(200, 200);
control = ControlIO.getInstance(this);
PS4 = control.getMatchedDevice("control");
if(PS4 == null) {
println("No controller");
System.exit(-1);
}
arduino = new Arduino(this, "COM4", 115200);
arduino.pinMode(2, Arduino.SERVO);
arduino.pinMode(3, Arduino.SERVO);
}
public void getUserInput() {
thumbRH1 = map(PS4.getSlider("Forward").getValue(), -1, 1, 0, 100);
thumbRH2 = map(PS4.getSlider("Forward").getValue(), -1, 1, 0, 100);
}
public void draw() {
background(100, 100, 100);
arduino.servoWrite(2, (int)thumbRH1);
arduino.servoWrite(3, (int)thumbRH2);
}