-1

So I have coded C++ file that sets the parameters for the Six servo motor robot arm I have built. What I am trying to do is figure out how to code an application that uses sliders to move the servos in the corresponding direction. I am using an HC-05 bluetooth chip and Arduino UNO, aswell as a HCPCA9685 servo driver. I have tried using NetBeans and made a JFrame application although im not sure if it can communicate with the C++ file or if i can add bluetooth with it. I am wondering what language or program I can use to create such a windows application, and how I would do so. It doesn't have to be in detail just basics and I can figure the rest out.

Here is the c++ code for the servo's

#include <SoftwareSerial.h>
#include <Servo.h>
#include <HCPCA9685.h>

//Set up bluetooth based off pins in the Arduino UNO board. 0 = BluetoothTx, 1 = BluetoothRx
SoftwareSerial Bluetooth(0, 1); 

#define  I2CAdd 0x40
HCPCA9685 HCPCA9685(I2CAdd);

void setup() 
{
  /* Initialize the library and set it to 'servo mode' */ 
  HCPCA9685.Init(SERVO_MODE);
 
  /* Wake the device up */
  HCPCA9685.Sleep(false);

  Serial.begin(4800);
  
  delay(3000);
}


Servo servo01,servo02,servo03,servo04,servo05,servo06;

//initial parking position of the motor
const int servo01PPos = 60;
const int servo02PPos = 60;
const int servo03PPos = 70;
const int servo04PPos = 47;
const int servo05PPos = 63;
const int servo06PPos = 63;

//Degree of robot servo sensitivity - Intervals
int servo01Pos_increment = 20;
int servo02Pos_increment = 20;
int servo03Pos_increment = 20;
int servo04Pos_increment = 50;
int servo05Pos_increment = 60;
int servo06Pos_increment = 40;

//Keep track of the current value of the motor positions
int servo01Pos_i = servo01PPos;
int servo02Pos_i = servo02PPos;
int servo03Pos_i = servo03PPos;
int servo04Pos_i = servo04PPos;
int servo05Pos_i = servo05PPos;
int servo06Pos_i = servo06PPos;


//Minimum and maximum angle of servo motor
int servo01_min_pos = 10;
int servo01_max_pos = 180;

int servo02_min_pos = 10;
int servo02_max_pos = 180;

int servo03_min_pos = 10;
int servo03_max_pos = 400;

int servo04_min_pos = 10;
int servo04_max_pos = 380;

int servo05_min_pos = 10;
int servo05_max_pos = 380;

int servo06_min_pos = 10;
int servo06_max_pos = 120;

int servo01_pos = 0;
int servo02_pos = 0;
int servo03_pos = 0;
int servo04_pos = 0;
int servo05_pos = 0;
int servo06_pos = 0;

char state = 0; // Changes value from ASCII to char
int response_time = 5;
int response_time_4 = 2;
int loop_check = 0;
int response_time_fast = 20;
int action_delay = 600;
String dataln = "";

// Check for incoming data
  if (Bluetooth.available() > 0) {
    dataIn = Bluetooth.readString(); } // Read the data as string

As explained above^ I tried to use NETBEANS although am unsure if that would work. I know that I still need to code the actions the servo's will make after receiving said data, although first I need to find out how to send data to it in a program i can make a windows application with.

  • A quick search for "arduino hc05 struct" has turned up lots of results. The first one was https://forum.arduino.cc/t/send-receive-struct-data-one-way-in-serial-retrieve-in-pure-form/669505/3 which seemed to be OK for the Arduino. You can test your Arduino code is working by using something like https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal&hl=en_GB&gl=US&pli=1 . – ukBaz Jul 19 '23 at 05:52
  • It looks like you want the other end of the Bluetooth link to be done in Java on a Windows PC. A search for "windows java bluetooth serial port hc05" has turned up https://stackoverflow.com/questions/33473926/best-practice-java-serial-bluetooth-connection-hc-05 as the top answer. It was written a number of years and I'm not familiar enough with Java to know if it is still what is required. – ukBaz Jul 19 '23 at 05:57

1 Answers1

0

Don't shout at me for what I'm going to say but probably the easiest way is not to use BL but rather WiFi, don't even need an UNO you could have everything self contained on a single tiny ESP32 and control the motors straight from any browser, even on your phone, no need for an app. The ESP (or UNO with a Wifi shield) runs a small web server that serves a html page with sliders and send your interactions as http requests back to Arduino.

If you really need BL and an app, I've do things like that in the past using Node.js running as little server, if you want it as a desktop app just wrap it inside Electron or talk to it through a web browser, the interface is quick to build in plain HTML. There are a few Node.js bluetooth libraries and on Arduino you use the same Bluetooth Serial interface as you already do.