Bluetooth shield help
i have arduino uno seeduino shield running code
now, works fine. have tact switch hooked using reference page , used example sketch provided know hooked correctly. i'm not sure how program code send command second arduino when push button.
what trying accomplish making bluetooth remote bluetooth v2 robot robotshop. want move forward when push button, move backward when press , on. if can example of how add above code should able add others. thank in advance. sorry if screwed layout of post, has been awhile since last post.
code: [select]
#include <softwareserial.h> //software serial port
#define rxd 7
#define txd 6
#define debug_enabled 1
string retsymb = "+rtinq=";//start symble when there's return
string slavename = ";bluetooth_bee_v2";// caution ';'must included, , make sure slave name right.
int nameindex = 0;
int addrindex = 0;
string recvbuf;
string slaveaddr;
string connectcmd = "\r\n+conn=";
softwareserial bluetoothserial(rxd,txd);
void setup()
{
serial.begin(9600);
pinmode(rxd, input);
pinmode(txd, output);
setupbluetoothconnection();
//wait 1s , flush serial buffer
delay(1000);
serial.flush();
bluetoothserial.flush();
}
void loop()
{
char recvchar;
while(1){
if(bluetoothserial.available()){//check if there's data sent remote bluetooth shield
recvchar = bluetoothserial.read();
serial.print(recvchar);
}
if(serial.available()){//check if there's data sent local serial terminal, can add other applications here
recvchar = serial.read();
bluetoothserial.print(recvchar);
}
}
}
void setupbluetoothconnection()
{
bluetoothserial.begin(38400); //set bluetoothbee baudrate default baud rate 38400
bluetoothserial.print("\r\n+stwmod=1\r\n");//set bluetooth work in master mode
bluetoothserial.print("\r\n+stna=seeedbtmaster\r\n");//set bluetooth name "seeedbtmaster"
bluetoothserial.print("\r\n+stpin=1234\r\n");//set pincode master. has same slave
bluetoothserial.print("\r\n+stauto=0\r\n");// auto-connection forbidden here
delay(2000); // delay required.
bluetoothserial.flush();
bluetoothserial.print("\r\n+inq=1\r\n");//make master inquire
serial.println("master inquiring!");
delay(2000); // delay required.
//find target slave
char recvchar;
while(1){
if(bluetoothserial.available()){
recvchar = bluetoothserial.read();
recvbuf += recvchar;
nameindex = recvbuf.indexof(slavename);//get position of slave name
//nameindex -= 1;//decrease ';' in front of slave name, position of end of slave address
if ( nameindex != -1 ){
//serial.print(recvbuf);
addrindex = (recvbuf.indexof(retsymb,(nameindex - retsymb.length()- 18) ) + retsymb.length());//get start position of slave address
slaveaddr = recvbuf.substring(addrindex, nameindex);//get string of slave address
break;
}
}
}
//form full connection command
connectcmd += slaveaddr;
connectcmd += "\r\n";
int connectok = 0;
serial.print("connecting slave:");
serial.print(slaveaddr);
serial.println(slavename);
//connecting slave till connected
do{
bluetoothserial.print(connectcmd);//send connection command
recvbuf = "";
while(1){
if(bluetoothserial.available()){
recvchar = bluetoothserial.read();
recvbuf += recvchar;
if(recvbuf.indexof("connect:ok") != -1){
connectok = 1;
serial.println("connected!");
bluetoothserial.print("connected!");
break;
}else if(recvbuf.indexof("connect:fail") != -1){
serial.println("connect again!");
break;
}
}
}
}while(0 == connectok);
}
now, works fine. have tact switch hooked using reference page , used example sketch provided know hooked correctly. i'm not sure how program code send command second arduino when push button.
what trying accomplish making bluetooth remote bluetooth v2 robot robotshop. want move forward when push button, move backward when press , on. if can example of how add above code should able add others. thank in advance. sorry if screwed layout of post, has been awhile since last post.
what using send bluetooth data ?
what data "remote" send?
does match expect receive (send out serial pc)
if of above correct, code parse not working, else there transmission problem or miss understanding of expect receive "remote"
i.e break problem down smaller chunks , 1 bit working @ time.
what data "remote" send?
does match expect receive (send out serial pc)
if of above correct, code parse not working, else there transmission problem or miss understanding of expect receive "remote"
i.e break problem down smaller chunks , 1 bit working @ time.
Arduino Forum > Using Arduino > Project Guidance > Bluetooth shield help
arduino
Comments
Post a Comment