Problem running code via HC-05 module

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);
  
}
1 Like

Hi @masterjader “HC05 rx/tx pins are connected to the arduino tx/rx pins”. The Arduino tx+rx pins are connected to the usb-to-serial chip, so you have a wire with 2 devices trying to drive it. This won’t work. There are instructions out there for similar situations, and they take the Ard (UNO) chip out of it’s socket, and put it back with one pin not in the socket. I don’t want to do that and you can’t if the Ard chip is not in a socket.

I have a few remote projects where the HC05 tx+rx pins are connected to ordinary digital pins on the Ard, then use the software serial library. File, Examples, SoftwareSerial…
Not sure how that fits with using Firmata (import software serial, change which serial device Firmata is using? can it be that simple?), I use my own (copied from somewhere) protocol. Suggest you play with that example then think where to go next.

1 Like

Hello,

What model of Arduino?

Did you use correct voltage levels connecting the Arduino Tx (5V or 3.3V depending on device) to the HC-05 Rx (3.3V)?
I have seen many HC-05 devices fail because they did not use correct logic level translation.

If you provide minimal code (using Firmata) to control Arduino LED 13 (on and off) from Processing I will try it.
Write code for USB serial and the BlueTooth serial.
The code will help me understand your hardware configuration as well.
I have several Arduinos and HC-05s and will try this once I scrutinize it.

Resources:
http://www.martyncurrey.com/arduino-with-hc-05-bluetooth-module-in-slave-mode/
https://www.arduino.cc/en/Reference/softwareSerial

:)

2 Likes