Hello all
So Im trying to make a robotic arm move via wireless using bluetooth but it seems to not be working. Im not sure if I did anything wrong in the process so Im seeking advice for this.
my setup: Imgur: The magic of the Internet
Hardware:
1x arduino nano
1x arduino uno
2x hc05 bluetooth (master and slave paired)
1x ax12 robotic arm
1x dynamixal shield (Smart Arduino Digital Servo Shield for Dynamixel AX - DFRobot)
What i found out is that the slave does not seem to receive any bluetooth data if i include the library of the dynamixal shield. although im not sure if i did something wrong with my programming. Any help will be greatly appreciated!
Master
#include <SoftwareSerial.h>
SoftwareSerial BTserial(10, 11);
int state = 0;
const int ledPin = 12; //the pin your led is connected to
//const int buttonPin = 2; //the pin your button is connected to
//int state = 0;
void setup() {
Serial.begin(115200);
BTserial.begin(38400);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin,LOW);
//pinMode(buttonPin, INPUT);
}
void loop() {
// buttonState = digitalRead(buttonPin);
state=Serial.read();
if(state=='1'){
BTserial.write('1');
Serial.println("Arm is moving =O");
delay(20);
}
if (state=='2') {
digitalWrite(ledPin, HIGH);
delay(20);
Serial.println("LED:ON");
BTserial.write('2'); //sends a 1 through the bluetooth serial link
delay (20);
}
else if(state=='3'){
BTserial.write('3');
digitalWrite(ledPin, LOW);
Serial.println("LED:OFF");
BTserial.write('3');
delay(20);
}
}
Slave
#include <SoftwareSerial.h>
SoftwareSerial BTserial(10, 11);//10 is Tx in bt and 11 is RX
#include <SPI.h>
#include <ServoCds55.h>
#include "pins_arduino.h"
ServoCds55 myservo;
int state = 0;
void setup() {
// initialize digital pin 8 as an output.
Serial.begin(115200);
BTserial.begin(38400);
digitalWrite(SS,HIGH);
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV8);
pinMode(8, OUTPUT);
}
void loop() {
Serial.println("dog");
Serial.println("BTnumber:"+ BTserial.read());
if (BTserial.available() > 0) { // Checks whether data is comming from the serial port
state = BTserial.read(); // Reads the data from the serial port
Serial.println("cat");
}
if(state>0){
switch(state){
case '1':
myservo.setVelocity(20);
delay(10000);
Serial.println("robot");
myservo.write(2,180);//Sets the position of motor 2 and 3 to an angle
myservo.write(3,180);
delay(3000);
myservo.write(4,160);
myservo.write(4,160);
state=0;
break;
case '2':
Serial.println("light");
digitalWrite(8,HIGH);//LED ON
state=0;
break;
case '3':
Serial.println("dark");
digitalWrite(8,LOW);//LED OFF
state = 0;
break;
}
}
// // Controlling the LED
// if (state == '2') {
// digitalWrite(8, HIGH); // LED ON
// Serial.println("dog");
// state = 0;
//
// }
// else if (state == '0') {
// digitalWrite(8, LOW); // LED ON
// Serial.println("CAT");
// state = 0;
}