So I created a program to control a robot using 5 servos. I’m controlling the robot using a wireless PS4 controller using Game Controller Plus. Everything works fine when plugged in but I have to make this wireless so I decided to use a HC-05 Module to eliminate the use of the cable and I can’t figure out how to make it run properly. I uploaded StandardFirmata first on the arduino and then connected the HC-05 after and it connects with my laptop but when I run the processing program, nothing happens. The program runs and it shows that my controller is functioning when I press a button but nothing happens to the robot. My code works fine for what I need it to do when plugged in, I just need to be able to do it wireless. My HC-05 rx/tx pins are connected to the arduino tx/rx pins respectively and I do have an external power source. Any and all help is greatly appreciated! I’m new to programming so forgive me if the solution is a simple line of code it I’ve been at this for a few days now and I’m worn out. Thank you!
import processing.serial.*;
import net.java.games.input.*;
import org.gamecontrolplus.*;
import org.gamecontrolplus.gui.*;
import cc.arduino.*;
import org.firmata.*;
Serial port;
ControlDevice cont;
ControlIO control;
Arduino arduino;
float forward;
float frontTurn;
float rearTurn;
float reverse;
float shoot;
float raise;
void setup(){
size(360, 200);
//Communicating with the Game Controller Plus and finding the file to be used
control = ControlIO.getInstance(this);
cont = control.getMatchedDevice("Snake Control");
//If no file is found an error message appears
if(cont == null){
println("Error: Missing Game Controller file");
System.exit(-1);
}
//Matching servos to connected pins
println(Arduino.list());
//Error here if port is succesful
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino.pinMode(5,Arduino.OUTPUT);
arduino.pinMode(6, Arduino.SERVO);
arduino.pinMode(7, Arduino.SERVO);
arduino.pinMode(8, Arduino.SERVO);
arduino.pinMode(9, Arduino.SERVO);
arduino.pinMode(10, Arduino.SERVO);
}
public void getUserInput(){
// assign float value
forward = map(cont.getSlider("LeftStick").getValue(), -1, 1, 0, 180);
reverse = map(cont.getSlider("LeftStick").getValue(), -1, 1, 0, 180);
frontTurn = map(cont.getSlider("LeftStick2").getValue(), -1, 1, 180, 0);
rearTurn = map(cont.getSlider("RightStick").getValue(), -1, 1, 0, 180);
raise = map(cont.getButton("X Button").getValue(), -1, 1, 0, 180);
shoot = map(cont.getSlider("LeftTrigger").getValue(), -1, 1, 0, 180);
}
void draw(){
getUserInput();
background(forward,100,255);
background(frontTurn,20,110);
background(reverse,55,180);
background(shoot,68, 40);
background(rearTurn,80,200);
background(shoot,160,245);
arduino.digitalWrite(5, (int)shoot);
arduino.servoWrite(6, (int)forward);
arduino.servoWrite(7, (int)frontTurn);
arduino.servoWrite(8, (int)raise);
arduino.servoWrite(9, (int)rearTurn);
arduino.servoWrite(10, (int)reverse);
}