Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArduinoUno-StandardFirmata with Processing Java over bluetooth HC-05 #476

Open
kxm-alb opened this issue Jan 5, 2021 · 0 comments
Open

Comments

@kxm-alb
Copy link

kxm-alb commented Jan 5, 2021

I am able to make my Xbox 360 controller / Processing sketch work over USB cable on Arduino Uno without any issues on an RC CAR. Standard firmata loaded onto Uno and USB cable connecting to PC.
I am using the same code over blue tooth (HC-05) and Uno. I am able to connect to the UNO over bluetooth COM8 outgoing port. When I press the control buttons on the Controller, RC makes a very feeble sound and only able to move the steer left and right option ( very slow though), but no success in moving the car backward or forward. I am using standard Firmata on the Uno in both cases. If I remove the HC05 module from port # 0,1 on Arduino board and connect the USB cable directly from PC, the rc car works with out any issues. The code is based on tutorial from Processing's YouTube video.

Here is my code if any one gets a chance. I have made sure the baud rate of outgoing com8 port, Processing's , Firmata code's rate is set to 57600. HC05 baud rate configuration was done using SET command.

import net.java.games.input.;
import org.gamecontrolplus.
;
import org.gamecontrolplus.gui.*;

import cc.arduino.;
import g4p_controls.
;

import org.firmata.*;

import processing.serial.*;

ControlDevice cd ;
ControlIO cio;
Arduino arduino;
//boolean goF, goB, sL, sR;
boolean goF=false;
boolean goB=false;
boolean sL=false;
boolean sR=false;
boolean sA=false;

int drFwd = 12;
int drBkwd= 13;
int strLeft = 7;
int strRight= 8;
int enblA = 3;
int enblB = 6;
String mode=null;

int COM_PORT = 0;
int BAUD_RATE =57600;

int FWD_PWM_VALUE=180;
int BKWD_PWM_VALUE=180;
int STR_PWM_VALUE=180;

void setup() {

size(400,200);

cio = ControlIO.getInstance(this);

cd = cio.getMatchedDevice("rcPosv2");

if (cd == null ){
println("No COM PORT found");
System.exit (-1);
}
else {
println(cd);
}

arduino = new Arduino(this, Arduino.list()[COM_PORT],BAUD_RATE);
arduino.pinMode(drFwd,Arduino.OUTPUT);
arduino.pinMode(drBkwd,Arduino.OUTPUT);
arduino.pinMode(strLeft,Arduino.OUTPUT);
arduino.pinMode(strRight,Arduino.OUTPUT);
arduino.pinMode(enblA,Arduino.OUTPUT);
arduino.pinMode(enblB,Arduino.OUTPUT);

}

public void getUserInput() {

 if (cd.getButton("Button 3").pressed()){
  
     goF=true;
     goB=false;
     sL=false;
     sR=false;
     sA=false;
     mode="F";
   
     
 }else
  if (cd.getButton("Button 0").pressed()){
  
   
   goB=true;
   goF=false;
   sL=false;
   sR=false;
   sA=false;
   mode="B";
   
  
}else
 if(cd.getButton("Button 1").pressed()){
  
   sR=true;
     println("sr  is getting ");
   sL=false;
    sA=false;
   mode="sR";
 
 } else
 if (cd.getButton("Button 2").pressed()){
  
   sL=true;
   sR=false;
   sA=false;
   mode="sL";
 } else
 if (cd.getButton("Button 5").pressed()){
  
   sA=true;
   sL=false;
   sR=false;
   goF=false;
   goB=false;
   mode="sA";
 } 

println(mode);

}

void draw() {

getUserInput();
printMode(mode);
if(goF){
driveForward();

}else
if (goB) {

driveBackWard();

}

if (sR){
steerRight();
}
if (sL) {
steerLeft();
}if (sA) {
stopDrive();
}

}

void driveForward() {
println("F" );
arduino.analogWrite(enblB, FWD_PWM_VALUE);
arduino.digitalWrite(drFwd,Arduino.HIGH);
arduino.digitalWrite(drBkwd,Arduino.LOW);

}

void driveBackWard() {
println("B");
arduino.analogWrite(enblB, BKWD_PWM_VALUE);
arduino.digitalWrite(drBkwd,Arduino.HIGH);
arduino.digitalWrite(drFwd,Arduino.LOW);

}

void steerLeft(){
arduino.digitalWrite(strRight,Arduino.LOW);
arduino.analogWrite(enblB, 0);
arduino.analogWrite(enblA,STR_PWM_VALUE);
arduino.digitalWrite(strLeft,Arduino.HIGH);
println("in steering Left .......");

}

void steerRight(){
arduino.digitalWrite(strLeft,Arduino.LOW);
arduino.analogWrite(enblB, 0);
arduino.analogWrite(enblA, STR_PWM_VALUE);
arduino.digitalWrite(strRight,Arduino.HIGH);
println(" in steering Right ");

}

void stopDrive(){
arduino.analogWrite(enblB, 0);
arduino.analogWrite(enblA, 0);
arduino.digitalWrite(strLeft,Arduino.LOW);
arduino.digitalWrite(strRight,Arduino.LOW);
print("in the Stop All ");

}

void printMode(String mode){

println("mode is "+mode);

}

@kxm-alb kxm-alb changed the title ArduinoUno-StandardFirmata over bluetooth Processing ArduinoUno-StandardFirmata with Processing Java over bluetooth HC-05 Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant