This is my first post here, im running into trouble with my code and im not sure where im going wrong. I want to control a bldc motor with my ps4 controller, the dc motor is a Firma Spektrum 6000kv BLDC. When I run an arduino code I can use the dc motor with a potentiometer just fine, and the code below worked with two regular DC motors hooked up through a mosfet. I think its the ESC thats causing me trouble, im just not sure how to code that. Hopefully someone can tell me where i went wrong, Thanks! The error I get when I run this is:
=======================================================
Failed to initialize device HIDI2C Device because of: java.io.IOException: Failed to acquire device (8007001e)
NullPointerException
import processing.serial.*;
import net.java.games.input.*;
import org.gamecontrolplus.*;
import org.gamecontrolplus.gui.*;
import cc.arduino.*;
import org.firmata.*;
ControlDevice cont;
ControlIO control;
Arduino arduino;
//int fbThrusterX = 50; // 0 - 255
int fbThrusterY = 0;
float thumbY;
//float thumbX;
void setup() {
//color box repersting range of motion of controller
size(360, 200);
control = ControlIO.getInstance(this);
cont = control.getMatchedDevice("thrust");
//if controller is not plugged in or connected
//this error message will pop up and the program will stop
if (cont == null) {
println("nope");
System.exit(-1);
}
//println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 57600);
for(int i=0; i<= 50; i++)
arduino.pinMode(3, Arduino.SERVO);
}
public void getUserInput(){
//assign our float value
//to access controller
thumbY = map(cont.getSlider("fbThrusterY").getValue(), -1, 1, 0, 100);
//thumbX = map(cont.getSlider("fbThrusterX").getValue(), -1, 1, 0, 100);
//println(thumb);
}
void draw(){
getUserInput();
background(thumbY, 100, 255, 0);
//background(thumbX, 0, 255, 100);
arduino.analogWrite(3, (int)thumbY);
//arduino.analogWrite(5, (int)thumbX);
}
Heres my latest update after changing the last line,
arduino.analogwrite(3, (int)thumbY)
to
arduino.servoWrite(3, (int)thumbY)
this is the error I get now, which makes even less sense to me.
Failed to initialize device HIDI2C Device because of: java.io.IOException: Failed to acquire device (8007001e)
Failed to poll device: Device is released
Failed to poll device: Device is released
Failed to poll device: Device is released
Failed to poll device: Device is released
Failed to poll device: Device is released
Failed to poll device: Device is released
Failed to poll device: Device is released
Could not run the sketch (Target VM failed to initialize).
For more information, read Help ? Troubleshooting.
Im not sure what the Target VM is, I read through the trouble shooting guide and didnt see anything helpful. Thanks again everyone!
Final update incase others in the future have a similar issue. I got it to work, I just started from scratch. I think what happened is when I initially did this with two micro DC motors I needed to add a few other things, but when a ESC is used like a servo, so I deleted some stuff and sure enough it works! Heres my code if any one is curious:
import processing.serial.*;
import net.java.games.input.*;
import org.gamecontrolplus.*;
import org.gamecontrolplus.gui.*;
import cc.arduino.*;
import org.firmata.*;
ControlDevice cont;
ControlIO control;
Arduino arduino;
float thumbY;
void setup() {
size(360, 200);
control = ControlIO.getInstance(this);
cont = control.getMatchedDevice("thrust");
if (cont == null) {
println("nope");
System.exit(-1);
}
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino.pinMode(10, Arduino.SERVO);
}
public void getUserInput(){
thumbY = map(cont.getSlider("thrust").getValue(), -1, 1, 0, 100);
}
void draw(){
getUserInput();
background(thumbY, 100, 255, 0);
arduino.servoWrite(10, (int)thumbY);
}