Bluetooth bee and bluetooth mate gold, possible for communication?

Hello,
I have a bluetooth bee, an xbee explorer, an ardouin pro and a bluetooth mate gold. I was woundering if I can use the bluetooth bee as an usb adapter for my pc trough the xbee explorer and send serial data to my arduino witch has the bluetooth mate gold on it? Is that possible at all, or does it not work?
I have a bluetooth bee, an xbee explorer, an ardouin pro and a bluetooth mate gold. I was woundering if I can use the bluetooth bee as an usb adapter for my pc trough the xbee explorer and send serial data to my arduino witch has the bluetooth mate gold on it? Is that possible at all, or does it not work?
2012-09-26 18:41:31 Because they're using the same Bluetooth chip, so they should work properly without any complex configuration together.
;)
Lauren
;)

2012-09-26 18:41:31 Because they're using the same Bluetooth chip, so they should work properly without any complex configuration together.
;)
Lauren
;)

2012-09-26 09:00:44 Will this one communicate with the bluetooth bee fine?: [url=https://www.dfrobot.com/index.php?route=product/product&path=45&product_id=360]https://www.dfrobot.com/index.php?route=product/product&path=45&product_id=360[/url]
Does it need any configuration?
The Crusher
Does it need any configuration?

2012-09-26 09:00:44 Will this one communicate with the bluetooth bee fine?: [url=https://www.dfrobot.com/index.php?route=product/product&path=45&product_id=360]https://www.dfrobot.com/index.php?route=product/product&path=45&product_id=360[/url]
Does it need any configuration?
The Crusher
Does it need any configuration?

2012-09-25 01:21:36 Haha,
Yes, I think you could try it. And I used the cellbots before. And works with Bluetooth Bee/Romeo and xbee shield on 4WD properly.
[code]#include <Metro.h>//version 0.2
#define LF 0
#define RT 1
#define ECHO 8
#define INIT 9
#define BINH 10
#define TimerAmp 64
Metro MotorGap = Metro(TimeAmp(3),true);
Metro SensorGap = Metro(TimeAmp(50),true);
Metro UpdateCmd = Metro(TimeAmp(10),true);
Metro printGap = Metro(TimeAmp(100),true);
int E1 = 5; //M1 Speed Control
int E2 = 6; //M2 Speed Control
int M1 = 4; //M1 Direction Control
int M2 = 7; //M1 Direction Control
#define IrNumber 2
float iR[IrNumber];
float iRraw[IrNumber];
float iRoffset[IrNumber] = {
0,0};
int ultraValue = 0;
int cmdSpeed = 127;
int Heading = 120;
boolean RemoteMode = false;
void setup(){
int i;
for(i = 4;i <= 7;i++) pinMode(i, OUTPUT);
Serial.begin(9600); //Set Baud Rate
/********** Initialize URM05 **********/
pinMode(ECHO, INPUT);
pinMode(INIT, OUTPUT);
pinMode(BINH, OUTPUT);
digitalWrite(INIT, LOW);
digitalWrite(BINH, LOW);
setPwmFrequency(6,64);
}
void loop(){
if(SensorGap.check()){
setPwmFrequency(6, 64);
SensorData();
setPwmFrequency(6, 1);
}
if(MotorGap.check()){
setPwmFrequency(6, 1);
MotorControl();
}
//cmdSpeed = 0;
if(UpdateCmd.check() && !RemoteMode) DataProcessing();
//if(printGap.check()) DataPrinter();
AttachCmd();
}
int BluetoothCmd[15];
int BlankPos[5];
int BlankCount = 0;
int Endbyte = 0x0A;
void AttachCmd(){
if(Serial.available()){
unsigned long timer = millis();
int i = 0;
int RetryCounter = 0;
int num = 0;
boolean valid = true;
for(int j = 0; j<10; j++)
BluetoothCmd[j] = 0;
byte firstByte = Serial.read();
//Serial.println(input,BYTE);
if(firstByte >= 'a' && firstByte <= 'z')
{
//Serial.println("PassHeader");
switch(firstByte){
case 'w':
BlankCount = 0;
for(i = 0;i < 5; i++) BlankPos[i] = 0;
RemoteMode = true;
break;
case 's':
RemoteMode = true;
break;
default:
break;
}
}
BluetoothCmd[0] = firstByte;
i = 1;
while(true){
if(Serial.available()){
BluetoothCmd[i] = Serial.read();
//Serial.print(BluetoothCmd[i],HEX);
//Serial.print("\t");
if(BluetoothCmd[i] == 0x20){
BlankPos[BlankCount] = i;
BlankCount ++;
}
if(BluetoothCmd[i] == Endbyte){
BlankPos[BlankCount] = i;
break;
}
else if(i >= 14){
Serial.flush();
valid = false;
break;
}
i++;
}
else delayMicroseconds(100);
}
//Serial.println("");
if(valid){
if(BluetoothCmd[0] == 's' && BluetoothCmd[1] == 0x0A){
Heading = 120;
cmdSpeed = 127;
//Serial.println("Stop Command!");
}
if(BluetoothCmd[0] == 'w' && BluetoothCmd[i] == 0x0A){
/*
for(int j = 0; j <= BlankCount ; j++){
Serial.print(BlankPos[j]);
Serial.print("\t");
}
Serial.println("Running Command!");
*/
char cmd[BlankPos[1] - BlankPos[0]];
for(int j = 0; j < (BlankPos[1] - BlankPos[0]) ; j++){
cmd[j] = BluetoothCmd[j + 1 + BlankPos[0]];
}
char Scmd[BlankPos[2] - BlankPos[1]];
for(int j = 0; j < (BlankPos[2] - BlankPos[1]) ; j++){
Scmd[j] = BluetoothCmd[j + 1 + BlankPos[1]];
}
/*
Serial.print("cmd:\t");
Serial.print(atoi(cmd));
Serial.print("\t");
Serial.println(atoi(Scmd));
*/
int left = atoi(cmd);
int right = atoi(Scmd);
float para = float(left) / float(right);
if( para > 2 ){
Heading = 255;
cmdSpeed = map(left,-45,45,0,255);
//Serial.print(cmdSpeed);
//Serial.println("\tTurn right big");
}
else if( para > 1.2 ){
Heading = 240;
cmdSpeed = map(left,-45,45,0,255);
//Serial.print(cmdSpeed);
//Serial.println("\tTurn right small");
}
else if( para > 0.8 ){
Heading = 120;
cmdSpeed = map((left + right) / 2,-45,45,0,255);
//Serial.print(cmdSpeed);
// Serial.println("\tStraight");
}
else if( para > 0.5 ){
Heading = 15;
cmdSpeed = map(right,-45,45,0,255);
//Serial.print(cmdSpeed);
//Serial.println("\tTurn left small");
}
else{
Heading = 0;
cmdSpeed = map(right,-45,45,0,255);
//Serial.print(cmdSpeed);
//Serial.println("\tTurn left big");
}
cmdSpeed = constrain(cmdSpeed ,0 ,255);
}
//Serial.println("Pass");
//Serial.println(millis() - timer);
}
else Serial.println("Invalid");
}
else Serial.flush();
}
void DataPrinter(){
for(int i = 0;i < IrNumber; i++){
Serial.print(iR[i]);
Serial.print("\t");
}
Serial.println(ultraValue);
}
unsigned long stopTimer = 0;
int disErr = 0;
void DataProcessing(){
boolean BackRun = false;
irReader();
disErr = iR[0] - iR[1];
UpdateCmd.interval(TimeAmp(10));
if(ultraValue > 45){
cmdSpeed = 255;
Heading = 120;
if(iR[LF] < 30){
cmdSpeed = 160;
Heading = 240;
//UpdateCmd.interval(500);
}
if(iR[RT] < 30){
cmdSpeed = 160;
Heading = 15;
//UpdateCmd.interval(500);
}
}
else if(ultraValue > 35){
cmdSpeed = 240;
if(disErr < -10) Heading = 245;
else Heading = 10;
//UpdateCmd.interval(200);
}
else if(ultraValue > 25){
cmdSpeed = 230;
if(disErr < -10) Heading = 255;
else Heading = 0;
//UpdateCmd.interval(200);
}
else{
cmdSpeed = 0;
if(disErr < -10) Heading = 0;
else Heading = 255;
BackRun = true;
UpdateCmd.interval(64000);
}
/*
Serial.print(cmdSpeed);
Serial.print("\t");
Serial.println(Heading);
*/
}
void irReader()
{
static float IRdata[IrNumber];
for(int h=0;h<IrNumber;h++)
{
float volts = analogRead(h);
iRraw[h] = (6787 / (volts - 3)) - 4 + iRoffset[h];
if(iRraw[h] < 10) iRraw[h] = 80;
//if(h = 1) iR[h] -= 1;
iRraw[h] = min(iRraw[h],80);
iRraw[h] = max(iRraw[h],10);
}
for(int h=0;h<IrNumber;h++)
{
iR[h] = iRraw[h];
iR[h] = smooth(iR[h],0.2,IRdata[h]);
IRdata[h] = iR[h];
}
}
float smooth(float newdata, float filterVal, float smoothedVal)
{
if (filterVal > 1)
filterVal = .99;
else if (filterVal <= 0)
filterVal = 0;
smoothedVal = (newdata * (1 - filterVal)) + (smoothedVal * filterVal);
return smoothedVal;
}
void SensorData(){
int val = 0;
int timecount = 0;
digitalWrite(INIT, HIGH);//??????
delayMicroseconds(900);
digitalWrite(BINH, HIGH);//??????
do
{
val = digitalRead(ECHO);//????????????? if (timecount >= 200) break;
timecount ++;
delayMicroseconds(53);
}
while(val == LOW);
digitalWrite(INIT, LOW);
digitalWrite(BINH, LOW);
ultraValue = timecount + 10;//??????????? //Serial.println(ultraValue);//??€??????????
}
void MotorControl(){
analogWrite (E1,cmdSpeed); //PWM Speed Control cmdSpeed
digitalWrite(M1,HIGH);
analogWrite (E2,Heading); //Heading
digitalWrite(M2,HIGH);
}
long TimeAmp(int input){
return input * TimerAmp;
}
void setPwmFrequency(int pin, int divisor) {
byte mode;
if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {
switch(divisor) {
case 1:
mode = 0x01;
break;
case 8:
mode = 0x02;
break;
case 64:
mode = 0x03;
break;
case 256:
mode = 0x04;
break;
case 1024:
mode = 0x05;
break;
default:
return;
}
if(pin == 5 || pin == 6) {
TCCR0B = TCCR0B & 0b11111000 | mode;
}
else {
TCCR1B = TCCR1B & 0b11111000 | mode;
}
}
else if(pin == 3 || pin == 11) {
switch(divisor) {
case 1:
mode = 0x01;
break;
case 8:
mode = 0x02;
break;
case 32:
mode = 0x03;
break;
case 64:
mode = 0x04;
break;
case 128:
mode = 0x05;
break;
case 256:
mode = 0x06;
break;
case 1024:
mode = 0x7;
break;
default:
return;
}
TCCR2B = TCCR2B & 0b11111000 | mode;
}
}
[/code]
Lauren
Yes, I think you could try it. And I used the cellbots before. And works with Bluetooth Bee/Romeo and xbee shield on 4WD properly.
[code]#include <Metro.h>//version 0.2
#define LF 0
#define RT 1
#define ECHO 8
#define INIT 9
#define BINH 10
#define TimerAmp 64
Metro MotorGap = Metro(TimeAmp(3),true);
Metro SensorGap = Metro(TimeAmp(50),true);
Metro UpdateCmd = Metro(TimeAmp(10),true);
Metro printGap = Metro(TimeAmp(100),true);
int E1 = 5; //M1 Speed Control
int E2 = 6; //M2 Speed Control
int M1 = 4; //M1 Direction Control
int M2 = 7; //M1 Direction Control
#define IrNumber 2
float iR[IrNumber];
float iRraw[IrNumber];
float iRoffset[IrNumber] = {
0,0};
int ultraValue = 0;
int cmdSpeed = 127;
int Heading = 120;
boolean RemoteMode = false;
void setup(){
int i;
for(i = 4;i <= 7;i++) pinMode(i, OUTPUT);
Serial.begin(9600); //Set Baud Rate
/********** Initialize URM05 **********/
pinMode(ECHO, INPUT);
pinMode(INIT, OUTPUT);
pinMode(BINH, OUTPUT);
digitalWrite(INIT, LOW);
digitalWrite(BINH, LOW);
setPwmFrequency(6,64);
}
void loop(){
if(SensorGap.check()){
setPwmFrequency(6, 64);
SensorData();
setPwmFrequency(6, 1);
}
if(MotorGap.check()){
setPwmFrequency(6, 1);
MotorControl();
}
//cmdSpeed = 0;
if(UpdateCmd.check() && !RemoteMode) DataProcessing();
//if(printGap.check()) DataPrinter();
AttachCmd();
}
int BluetoothCmd[15];
int BlankPos[5];
int BlankCount = 0;
int Endbyte = 0x0A;
void AttachCmd(){
if(Serial.available()){
unsigned long timer = millis();
int i = 0;
int RetryCounter = 0;
int num = 0;
boolean valid = true;
for(int j = 0; j<10; j++)
BluetoothCmd[j] = 0;
byte firstByte = Serial.read();
//Serial.println(input,BYTE);
if(firstByte >= 'a' && firstByte <= 'z')
{
//Serial.println("PassHeader");
switch(firstByte){
case 'w':
BlankCount = 0;
for(i = 0;i < 5; i++) BlankPos[i] = 0;
RemoteMode = true;
break;
case 's':
RemoteMode = true;
break;
default:
break;
}
}
BluetoothCmd[0] = firstByte;
i = 1;
while(true){
if(Serial.available()){
BluetoothCmd[i] = Serial.read();
//Serial.print(BluetoothCmd[i],HEX);
//Serial.print("\t");
if(BluetoothCmd[i] == 0x20){
BlankPos[BlankCount] = i;
BlankCount ++;
}
if(BluetoothCmd[i] == Endbyte){
BlankPos[BlankCount] = i;
break;
}
else if(i >= 14){
Serial.flush();
valid = false;
break;
}
i++;
}
else delayMicroseconds(100);
}
//Serial.println("");
if(valid){
if(BluetoothCmd[0] == 's' && BluetoothCmd[1] == 0x0A){
Heading = 120;
cmdSpeed = 127;
//Serial.println("Stop Command!");
}
if(BluetoothCmd[0] == 'w' && BluetoothCmd[i] == 0x0A){
/*
for(int j = 0; j <= BlankCount ; j++){
Serial.print(BlankPos[j]);
Serial.print("\t");
}
Serial.println("Running Command!");
*/
char cmd[BlankPos[1] - BlankPos[0]];
for(int j = 0; j < (BlankPos[1] - BlankPos[0]) ; j++){
cmd[j] = BluetoothCmd[j + 1 + BlankPos[0]];
}
char Scmd[BlankPos[2] - BlankPos[1]];
for(int j = 0; j < (BlankPos[2] - BlankPos[1]) ; j++){
Scmd[j] = BluetoothCmd[j + 1 + BlankPos[1]];
}
/*
Serial.print("cmd:\t");
Serial.print(atoi(cmd));
Serial.print("\t");
Serial.println(atoi(Scmd));
*/
int left = atoi(cmd);
int right = atoi(Scmd);
float para = float(left) / float(right);
if( para > 2 ){
Heading = 255;
cmdSpeed = map(left,-45,45,0,255);
//Serial.print(cmdSpeed);
//Serial.println("\tTurn right big");
}
else if( para > 1.2 ){
Heading = 240;
cmdSpeed = map(left,-45,45,0,255);
//Serial.print(cmdSpeed);
//Serial.println("\tTurn right small");
}
else if( para > 0.8 ){
Heading = 120;
cmdSpeed = map((left + right) / 2,-45,45,0,255);
//Serial.print(cmdSpeed);
// Serial.println("\tStraight");
}
else if( para > 0.5 ){
Heading = 15;
cmdSpeed = map(right,-45,45,0,255);
//Serial.print(cmdSpeed);
//Serial.println("\tTurn left small");
}
else{
Heading = 0;
cmdSpeed = map(right,-45,45,0,255);
//Serial.print(cmdSpeed);
//Serial.println("\tTurn left big");
}
cmdSpeed = constrain(cmdSpeed ,0 ,255);
}
//Serial.println("Pass");
//Serial.println(millis() - timer);
}
else Serial.println("Invalid");
}
else Serial.flush();
}
void DataPrinter(){
for(int i = 0;i < IrNumber; i++){
Serial.print(iR[i]);
Serial.print("\t");
}
Serial.println(ultraValue);
}
unsigned long stopTimer = 0;
int disErr = 0;
void DataProcessing(){
boolean BackRun = false;
irReader();
disErr = iR[0] - iR[1];
UpdateCmd.interval(TimeAmp(10));
if(ultraValue > 45){
cmdSpeed = 255;
Heading = 120;
if(iR[LF] < 30){
cmdSpeed = 160;
Heading = 240;
//UpdateCmd.interval(500);
}
if(iR[RT] < 30){
cmdSpeed = 160;
Heading = 15;
//UpdateCmd.interval(500);
}
}
else if(ultraValue > 35){
cmdSpeed = 240;
if(disErr < -10) Heading = 245;
else Heading = 10;
//UpdateCmd.interval(200);
}
else if(ultraValue > 25){
cmdSpeed = 230;
if(disErr < -10) Heading = 255;
else Heading = 0;
//UpdateCmd.interval(200);
}
else{
cmdSpeed = 0;
if(disErr < -10) Heading = 0;
else Heading = 255;
BackRun = true;
UpdateCmd.interval(64000);
}
/*
Serial.print(cmdSpeed);
Serial.print("\t");
Serial.println(Heading);
*/
}
void irReader()
{
static float IRdata[IrNumber];
for(int h=0;h<IrNumber;h++)
{
float volts = analogRead(h);
iRraw[h] = (6787 / (volts - 3)) - 4 + iRoffset[h];
if(iRraw[h] < 10) iRraw[h] = 80;
//if(h = 1) iR[h] -= 1;
iRraw[h] = min(iRraw[h],80);
iRraw[h] = max(iRraw[h],10);
}
for(int h=0;h<IrNumber;h++)
{
iR[h] = iRraw[h];
iR[h] = smooth(iR[h],0.2,IRdata[h]);
IRdata[h] = iR[h];
}
}
float smooth(float newdata, float filterVal, float smoothedVal)
{
if (filterVal > 1)
filterVal = .99;
else if (filterVal <= 0)
filterVal = 0;
smoothedVal = (newdata * (1 - filterVal)) + (smoothedVal * filterVal);
return smoothedVal;
}
void SensorData(){
int val = 0;
int timecount = 0;
digitalWrite(INIT, HIGH);//??????
delayMicroseconds(900);
digitalWrite(BINH, HIGH);//??????
do
{
val = digitalRead(ECHO);//????????????? if (timecount >= 200) break;
timecount ++;
delayMicroseconds(53);
}
while(val == LOW);
digitalWrite(INIT, LOW);
digitalWrite(BINH, LOW);
ultraValue = timecount + 10;//??????????? //Serial.println(ultraValue);//??€??????????
}
void MotorControl(){
analogWrite (E1,cmdSpeed); //PWM Speed Control cmdSpeed
digitalWrite(M1,HIGH);
analogWrite (E2,Heading); //Heading
digitalWrite(M2,HIGH);
}
long TimeAmp(int input){
return input * TimerAmp;
}
void setPwmFrequency(int pin, int divisor) {
byte mode;
if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {
switch(divisor) {
case 1:
mode = 0x01;
break;
case 8:
mode = 0x02;
break;
case 64:
mode = 0x03;
break;
case 256:
mode = 0x04;
break;
case 1024:
mode = 0x05;
break;
default:
return;
}
if(pin == 5 || pin == 6) {
TCCR0B = TCCR0B & 0b11111000 | mode;
}
else {
TCCR1B = TCCR1B & 0b11111000 | mode;
}
}
else if(pin == 3 || pin == 11) {
switch(divisor) {
case 1:
mode = 0x01;
break;
case 8:
mode = 0x02;
break;
case 32:
mode = 0x03;
break;
case 64:
mode = 0x04;
break;
case 128:
mode = 0x05;
break;
case 256:
mode = 0x06;
break;
case 1024:
mode = 0x7;
break;
default:
return;
}
TCCR2B = TCCR2B & 0b11111000 | mode;
}
}
[/code]

2012-09-25 01:21:36 Haha,
Yes, I think you could try it. And I used the cellbots before. And works with Bluetooth Bee/Romeo and xbee shield on 4WD properly.
[code]#include <Metro.h>//version 0.2
#define LF 0
#define RT 1
#define ECHO 8
#define INIT 9
#define BINH 10
#define TimerAmp 64
Metro MotorGap = Metro(TimeAmp(3),true);
Metro SensorGap = Metro(TimeAmp(50),true);
Metro UpdateCmd = Metro(TimeAmp(10),true);
Metro printGap = Metro(TimeAmp(100),true);
int E1 = 5; //M1 Speed Control
int E2 = 6; //M2 Speed Control
int M1 = 4; //M1 Direction Control
int M2 = 7; //M1 Direction Control
#define IrNumber 2
float iR[IrNumber];
float iRraw[IrNumber];
float iRoffset[IrNumber] = {
0,0};
int ultraValue = 0;
int cmdSpeed = 127;
int Heading = 120;
boolean RemoteMode = false;
void setup(){
int i;
for(i = 4;i <= 7;i++) pinMode(i, OUTPUT);
Serial.begin(9600); //Set Baud Rate
/********** Initialize URM05 **********/
pinMode(ECHO, INPUT);
pinMode(INIT, OUTPUT);
pinMode(BINH, OUTPUT);
digitalWrite(INIT, LOW);
digitalWrite(BINH, LOW);
setPwmFrequency(6,64);
}
void loop(){
if(SensorGap.check()){
setPwmFrequency(6, 64);
SensorData();
setPwmFrequency(6, 1);
}
if(MotorGap.check()){
setPwmFrequency(6, 1);
MotorControl();
}
//cmdSpeed = 0;
if(UpdateCmd.check() && !RemoteMode) DataProcessing();
//if(printGap.check()) DataPrinter();
AttachCmd();
}
int BluetoothCmd[15];
int BlankPos[5];
int BlankCount = 0;
int Endbyte = 0x0A;
void AttachCmd(){
if(Serial.available()){
unsigned long timer = millis();
int i = 0;
int RetryCounter = 0;
int num = 0;
boolean valid = true;
for(int j = 0; j<10; j++)
BluetoothCmd[j] = 0;
byte firstByte = Serial.read();
//Serial.println(input,BYTE);
if(firstByte >= 'a' && firstByte <= 'z')
{
//Serial.println("PassHeader");
switch(firstByte){
case 'w':
BlankCount = 0;
for(i = 0;i < 5; i++) BlankPos[i] = 0;
RemoteMode = true;
break;
case 's':
RemoteMode = true;
break;
default:
break;
}
}
BluetoothCmd[0] = firstByte;
i = 1;
while(true){
if(Serial.available()){
BluetoothCmd[i] = Serial.read();
//Serial.print(BluetoothCmd[i],HEX);
//Serial.print("\t");
if(BluetoothCmd[i] == 0x20){
BlankPos[BlankCount] = i;
BlankCount ++;
}
if(BluetoothCmd[i] == Endbyte){
BlankPos[BlankCount] = i;
break;
}
else if(i >= 14){
Serial.flush();
valid = false;
break;
}
i++;
}
else delayMicroseconds(100);
}
//Serial.println("");
if(valid){
if(BluetoothCmd[0] == 's' && BluetoothCmd[1] == 0x0A){
Heading = 120;
cmdSpeed = 127;
//Serial.println("Stop Command!");
}
if(BluetoothCmd[0] == 'w' && BluetoothCmd[i] == 0x0A){
/*
for(int j = 0; j <= BlankCount ; j++){
Serial.print(BlankPos[j]);
Serial.print("\t");
}
Serial.println("Running Command!");
*/
char cmd[BlankPos[1] - BlankPos[0]];
for(int j = 0; j < (BlankPos[1] - BlankPos[0]) ; j++){
cmd[j] = BluetoothCmd[j + 1 + BlankPos[0]];
}
char Scmd[BlankPos[2] - BlankPos[1]];
for(int j = 0; j < (BlankPos[2] - BlankPos[1]) ; j++){
Scmd[j] = BluetoothCmd[j + 1 + BlankPos[1]];
}
/*
Serial.print("cmd:\t");
Serial.print(atoi(cmd));
Serial.print("\t");
Serial.println(atoi(Scmd));
*/
int left = atoi(cmd);
int right = atoi(Scmd);
float para = float(left) / float(right);
if( para > 2 ){
Heading = 255;
cmdSpeed = map(left,-45,45,0,255);
//Serial.print(cmdSpeed);
//Serial.println("\tTurn right big");
}
else if( para > 1.2 ){
Heading = 240;
cmdSpeed = map(left,-45,45,0,255);
//Serial.print(cmdSpeed);
//Serial.println("\tTurn right small");
}
else if( para > 0.8 ){
Heading = 120;
cmdSpeed = map((left + right) / 2,-45,45,0,255);
//Serial.print(cmdSpeed);
// Serial.println("\tStraight");
}
else if( para > 0.5 ){
Heading = 15;
cmdSpeed = map(right,-45,45,0,255);
//Serial.print(cmdSpeed);
//Serial.println("\tTurn left small");
}
else{
Heading = 0;
cmdSpeed = map(right,-45,45,0,255);
//Serial.print(cmdSpeed);
//Serial.println("\tTurn left big");
}
cmdSpeed = constrain(cmdSpeed ,0 ,255);
}
//Serial.println("Pass");
//Serial.println(millis() - timer);
}
else Serial.println("Invalid");
}
else Serial.flush();
}
void DataPrinter(){
for(int i = 0;i < IrNumber; i++){
Serial.print(iR[i]);
Serial.print("\t");
}
Serial.println(ultraValue);
}
unsigned long stopTimer = 0;
int disErr = 0;
void DataProcessing(){
boolean BackRun = false;
irReader();
disErr = iR[0] - iR[1];
UpdateCmd.interval(TimeAmp(10));
if(ultraValue > 45){
cmdSpeed = 255;
Heading = 120;
if(iR[LF] < 30){
cmdSpeed = 160;
Heading = 240;
//UpdateCmd.interval(500);
}
if(iR[RT] < 30){
cmdSpeed = 160;
Heading = 15;
//UpdateCmd.interval(500);
}
}
else if(ultraValue > 35){
cmdSpeed = 240;
if(disErr < -10) Heading = 245;
else Heading = 10;
//UpdateCmd.interval(200);
}
else if(ultraValue > 25){
cmdSpeed = 230;
if(disErr < -10) Heading = 255;
else Heading = 0;
//UpdateCmd.interval(200);
}
else{
cmdSpeed = 0;
if(disErr < -10) Heading = 0;
else Heading = 255;
BackRun = true;
UpdateCmd.interval(64000);
}
/*
Serial.print(cmdSpeed);
Serial.print("\t");
Serial.println(Heading);
*/
}
void irReader()
{
static float IRdata[IrNumber];
for(int h=0;h<IrNumber;h++)
{
float volts = analogRead(h);
iRraw[h] = (6787 / (volts - 3)) - 4 + iRoffset[h];
if(iRraw[h] < 10) iRraw[h] = 80;
//if(h = 1) iR[h] -= 1;
iRraw[h] = min(iRraw[h],80);
iRraw[h] = max(iRraw[h],10);
}
for(int h=0;h<IrNumber;h++)
{
iR[h] = iRraw[h];
iR[h] = smooth(iR[h],0.2,IRdata[h]);
IRdata[h] = iR[h];
}
}
float smooth(float newdata, float filterVal, float smoothedVal)
{
if (filterVal > 1)
filterVal = .99;
else if (filterVal <= 0)
filterVal = 0;
smoothedVal = (newdata * (1 - filterVal)) + (smoothedVal * filterVal);
return smoothedVal;
}
void SensorData(){
int val = 0;
int timecount = 0;
digitalWrite(INIT, HIGH);//??????
delayMicroseconds(900);
digitalWrite(BINH, HIGH);//??????
do
{
val = digitalRead(ECHO);//????????????? if (timecount >= 200) break;
timecount ++;
delayMicroseconds(53);
}
while(val == LOW);
digitalWrite(INIT, LOW);
digitalWrite(BINH, LOW);
ultraValue = timecount + 10;//??????????? //Serial.println(ultraValue);//??€??????????
}
void MotorControl(){
analogWrite (E1,cmdSpeed); //PWM Speed Control cmdSpeed
digitalWrite(M1,HIGH);
analogWrite (E2,Heading); //Heading
digitalWrite(M2,HIGH);
}
long TimeAmp(int input){
return input * TimerAmp;
}
void setPwmFrequency(int pin, int divisor) {
byte mode;
if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {
switch(divisor) {
case 1:
mode = 0x01;
break;
case 8:
mode = 0x02;
break;
case 64:
mode = 0x03;
break;
case 256:
mode = 0x04;
break;
case 1024:
mode = 0x05;
break;
default:
return;
}
if(pin == 5 || pin == 6) {
TCCR0B = TCCR0B & 0b11111000 | mode;
}
else {
TCCR1B = TCCR1B & 0b11111000 | mode;
}
}
else if(pin == 3 || pin == 11) {
switch(divisor) {
case 1:
mode = 0x01;
break;
case 8:
mode = 0x02;
break;
case 32:
mode = 0x03;
break;
case 64:
mode = 0x04;
break;
case 128:
mode = 0x05;
break;
case 256:
mode = 0x06;
break;
case 1024:
mode = 0x7;
break;
default:
return;
}
TCCR2B = TCCR2B & 0b11111000 | mode;
}
}
[/code]
Lauren
Yes, I think you could try it. And I used the cellbots before. And works with Bluetooth Bee/Romeo and xbee shield on 4WD properly.
[code]#include <Metro.h>//version 0.2
#define LF 0
#define RT 1
#define ECHO 8
#define INIT 9
#define BINH 10
#define TimerAmp 64
Metro MotorGap = Metro(TimeAmp(3),true);
Metro SensorGap = Metro(TimeAmp(50),true);
Metro UpdateCmd = Metro(TimeAmp(10),true);
Metro printGap = Metro(TimeAmp(100),true);
int E1 = 5; //M1 Speed Control
int E2 = 6; //M2 Speed Control
int M1 = 4; //M1 Direction Control
int M2 = 7; //M1 Direction Control
#define IrNumber 2
float iR[IrNumber];
float iRraw[IrNumber];
float iRoffset[IrNumber] = {
0,0};
int ultraValue = 0;
int cmdSpeed = 127;
int Heading = 120;
boolean RemoteMode = false;
void setup(){
int i;
for(i = 4;i <= 7;i++) pinMode(i, OUTPUT);
Serial.begin(9600); //Set Baud Rate
/********** Initialize URM05 **********/
pinMode(ECHO, INPUT);
pinMode(INIT, OUTPUT);
pinMode(BINH, OUTPUT);
digitalWrite(INIT, LOW);
digitalWrite(BINH, LOW);
setPwmFrequency(6,64);
}
void loop(){
if(SensorGap.check()){
setPwmFrequency(6, 64);
SensorData();
setPwmFrequency(6, 1);
}
if(MotorGap.check()){
setPwmFrequency(6, 1);
MotorControl();
}
//cmdSpeed = 0;
if(UpdateCmd.check() && !RemoteMode) DataProcessing();
//if(printGap.check()) DataPrinter();
AttachCmd();
}
int BluetoothCmd[15];
int BlankPos[5];
int BlankCount = 0;
int Endbyte = 0x0A;
void AttachCmd(){
if(Serial.available()){
unsigned long timer = millis();
int i = 0;
int RetryCounter = 0;
int num = 0;
boolean valid = true;
for(int j = 0; j<10; j++)
BluetoothCmd[j] = 0;
byte firstByte = Serial.read();
//Serial.println(input,BYTE);
if(firstByte >= 'a' && firstByte <= 'z')
{
//Serial.println("PassHeader");
switch(firstByte){
case 'w':
BlankCount = 0;
for(i = 0;i < 5; i++) BlankPos[i] = 0;
RemoteMode = true;
break;
case 's':
RemoteMode = true;
break;
default:
break;
}
}
BluetoothCmd[0] = firstByte;
i = 1;
while(true){
if(Serial.available()){
BluetoothCmd[i] = Serial.read();
//Serial.print(BluetoothCmd[i],HEX);
//Serial.print("\t");
if(BluetoothCmd[i] == 0x20){
BlankPos[BlankCount] = i;
BlankCount ++;
}
if(BluetoothCmd[i] == Endbyte){
BlankPos[BlankCount] = i;
break;
}
else if(i >= 14){
Serial.flush();
valid = false;
break;
}
i++;
}
else delayMicroseconds(100);
}
//Serial.println("");
if(valid){
if(BluetoothCmd[0] == 's' && BluetoothCmd[1] == 0x0A){
Heading = 120;
cmdSpeed = 127;
//Serial.println("Stop Command!");
}
if(BluetoothCmd[0] == 'w' && BluetoothCmd[i] == 0x0A){
/*
for(int j = 0; j <= BlankCount ; j++){
Serial.print(BlankPos[j]);
Serial.print("\t");
}
Serial.println("Running Command!");
*/
char cmd[BlankPos[1] - BlankPos[0]];
for(int j = 0; j < (BlankPos[1] - BlankPos[0]) ; j++){
cmd[j] = BluetoothCmd[j + 1 + BlankPos[0]];
}
char Scmd[BlankPos[2] - BlankPos[1]];
for(int j = 0; j < (BlankPos[2] - BlankPos[1]) ; j++){
Scmd[j] = BluetoothCmd[j + 1 + BlankPos[1]];
}
/*
Serial.print("cmd:\t");
Serial.print(atoi(cmd));
Serial.print("\t");
Serial.println(atoi(Scmd));
*/
int left = atoi(cmd);
int right = atoi(Scmd);
float para = float(left) / float(right);
if( para > 2 ){
Heading = 255;
cmdSpeed = map(left,-45,45,0,255);
//Serial.print(cmdSpeed);
//Serial.println("\tTurn right big");
}
else if( para > 1.2 ){
Heading = 240;
cmdSpeed = map(left,-45,45,0,255);
//Serial.print(cmdSpeed);
//Serial.println("\tTurn right small");
}
else if( para > 0.8 ){
Heading = 120;
cmdSpeed = map((left + right) / 2,-45,45,0,255);
//Serial.print(cmdSpeed);
// Serial.println("\tStraight");
}
else if( para > 0.5 ){
Heading = 15;
cmdSpeed = map(right,-45,45,0,255);
//Serial.print(cmdSpeed);
//Serial.println("\tTurn left small");
}
else{
Heading = 0;
cmdSpeed = map(right,-45,45,0,255);
//Serial.print(cmdSpeed);
//Serial.println("\tTurn left big");
}
cmdSpeed = constrain(cmdSpeed ,0 ,255);
}
//Serial.println("Pass");
//Serial.println(millis() - timer);
}
else Serial.println("Invalid");
}
else Serial.flush();
}
void DataPrinter(){
for(int i = 0;i < IrNumber; i++){
Serial.print(iR[i]);
Serial.print("\t");
}
Serial.println(ultraValue);
}
unsigned long stopTimer = 0;
int disErr = 0;
void DataProcessing(){
boolean BackRun = false;
irReader();
disErr = iR[0] - iR[1];
UpdateCmd.interval(TimeAmp(10));
if(ultraValue > 45){
cmdSpeed = 255;
Heading = 120;
if(iR[LF] < 30){
cmdSpeed = 160;
Heading = 240;
//UpdateCmd.interval(500);
}
if(iR[RT] < 30){
cmdSpeed = 160;
Heading = 15;
//UpdateCmd.interval(500);
}
}
else if(ultraValue > 35){
cmdSpeed = 240;
if(disErr < -10) Heading = 245;
else Heading = 10;
//UpdateCmd.interval(200);
}
else if(ultraValue > 25){
cmdSpeed = 230;
if(disErr < -10) Heading = 255;
else Heading = 0;
//UpdateCmd.interval(200);
}
else{
cmdSpeed = 0;
if(disErr < -10) Heading = 0;
else Heading = 255;
BackRun = true;
UpdateCmd.interval(64000);
}
/*
Serial.print(cmdSpeed);
Serial.print("\t");
Serial.println(Heading);
*/
}
void irReader()
{
static float IRdata[IrNumber];
for(int h=0;h<IrNumber;h++)
{
float volts = analogRead(h);
iRraw[h] = (6787 / (volts - 3)) - 4 + iRoffset[h];
if(iRraw[h] < 10) iRraw[h] = 80;
//if(h = 1) iR[h] -= 1;
iRraw[h] = min(iRraw[h],80);
iRraw[h] = max(iRraw[h],10);
}
for(int h=0;h<IrNumber;h++)
{
iR[h] = iRraw[h];
iR[h] = smooth(iR[h],0.2,IRdata[h]);
IRdata[h] = iR[h];
}
}
float smooth(float newdata, float filterVal, float smoothedVal)
{
if (filterVal > 1)
filterVal = .99;
else if (filterVal <= 0)
filterVal = 0;
smoothedVal = (newdata * (1 - filterVal)) + (smoothedVal * filterVal);
return smoothedVal;
}
void SensorData(){
int val = 0;
int timecount = 0;
digitalWrite(INIT, HIGH);//??????
delayMicroseconds(900);
digitalWrite(BINH, HIGH);//??????
do
{
val = digitalRead(ECHO);//????????????? if (timecount >= 200) break;
timecount ++;
delayMicroseconds(53);
}
while(val == LOW);
digitalWrite(INIT, LOW);
digitalWrite(BINH, LOW);
ultraValue = timecount + 10;//??????????? //Serial.println(ultraValue);//??€??????????
}
void MotorControl(){
analogWrite (E1,cmdSpeed); //PWM Speed Control cmdSpeed
digitalWrite(M1,HIGH);
analogWrite (E2,Heading); //Heading
digitalWrite(M2,HIGH);
}
long TimeAmp(int input){
return input * TimerAmp;
}
void setPwmFrequency(int pin, int divisor) {
byte mode;
if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {
switch(divisor) {
case 1:
mode = 0x01;
break;
case 8:
mode = 0x02;
break;
case 64:
mode = 0x03;
break;
case 256:
mode = 0x04;
break;
case 1024:
mode = 0x05;
break;
default:
return;
}
if(pin == 5 || pin == 6) {
TCCR0B = TCCR0B & 0b11111000 | mode;
}
else {
TCCR1B = TCCR1B & 0b11111000 | mode;
}
}
else if(pin == 3 || pin == 11) {
switch(divisor) {
case 1:
mode = 0x01;
break;
case 8:
mode = 0x02;
break;
case 32:
mode = 0x03;
break;
case 64:
mode = 0x04;
break;
case 128:
mode = 0x05;
break;
case 256:
mode = 0x06;
break;
case 1024:
mode = 0x7;
break;
default:
return;
}
TCCR2B = TCCR2B & 0b11111000 | mode;
}
}
[/code]

2012-09-25 01:12:40 I use this andriod app: https://play.google.com/store/apps/details?id=es.mobot.**ar
I have not made it my self. Connected to the bluetooth mate gold. Maybe I should try to put the bluetooth bee on the car and try again?
The arduino code is nothing else than some functions, that is called when recieving a char. I do not have the code on this computer right now. I can post it later today if needed.
The Crusher
I have not made it my self. Connected to the bluetooth mate gold. Maybe I should try to put the bluetooth bee on the car and try again?
The arduino code is nothing else than some functions, that is called when recieving a char. I do not have the code on this computer right now. I can post it later today if needed.

2012-09-25 01:12:40 I use this andriod app: https://play.google.com/store/apps/details?id=es.mobot.**ar
I have not made it my self. Connected to the bluetooth mate gold. Maybe I should try to put the bluetooth bee on the car and try again?
The arduino code is nothing else than some functions, that is called when recieving a char. I do not have the code on this computer right now. I can post it later today if needed.
The Crusher
I have not made it my self. Connected to the bluetooth mate gold. Maybe I should try to put the bluetooth bee on the car and try again?
The arduino code is nothing else than some functions, that is called when recieving a char. I do not have the code on this computer right now. I can post it later today if needed.

2012-09-25 01:01:58 1. Yes. I tried to use a pair of bluetooth bee before, and they could pair automatically without setting any configuration.
2. Could please tell me more details about the system of your phone and the software used. Actually I programmed a Android prototyping software before for communicating with my vehicle by using Bluetooth bee.
Lauren
2. Could please tell me more details about the system of your phone and the software used. Actually I programmed a Android prototyping software before for communicating with my vehicle by using Bluetooth bee.

2012-09-25 01:01:58 1. Yes. I tried to use a pair of bluetooth bee before, and they could pair automatically without setting any configuration.
2. Could please tell me more details about the system of your phone and the software used. Actually I programmed a Android prototyping software before for communicating with my vehicle by using Bluetooth bee.
Lauren
2. Could please tell me more details about the system of your phone and the software used. Actually I programmed a Android prototyping software before for communicating with my vehicle by using Bluetooth bee.

2012-09-25 00:53:48 So, it will be easier with 2x Bluetooth bee or 2x bluetooth mate gold? If so, I just order another bluetooth bee and xbee explorer.
I have tried to communicate from a phone to the bluetooth mate gold witch is on the arduino, and it is not doing anything. Looks like nothing gets recieved.
The Crusher
I have tried to communicate from a phone to the bluetooth mate gold witch is on the arduino, and it is not doing anything. Looks like nothing gets recieved.

2012-09-25 00:53:48 So, it will be easier with 2x Bluetooth bee or 2x bluetooth mate gold? If so, I just order another bluetooth bee and xbee explorer.
I have tried to communicate from a phone to the bluetooth mate gold witch is on the arduino, and it is not doing anything. Looks like nothing gets recieved.
The Crusher
I have tried to communicate from a phone to the bluetooth mate gold witch is on the arduino, and it is not doing anything. Looks like nothing gets recieved.

2012-09-25 00:00:46 What I know is that when you connect two Bluetooth module together, they will contact each other for transferring the pairing information. And they will assign each other to one slave and one master.
One of your Bluetooth module is Bluetooth mate gold and the other is the Bluetooth bee from DFRobot. And these two module are using different embedded Bluetooth chip. So you may need to configure two module for pairing.
Here's the Bluetooth chip datasheet.
Bluetooth mate gold:http://www.sparkfun.com/datasheets/Wireless/Bluetooth/rn-bluetooth-um.pdf
Bluetooth Bee:https://www.dfrobot.com/image/data/TEL0026/TEL0026_Datasheet.pdf
This is the main problem I could image. So for me, there is a simple way to finish a Bluetooth communication.Just use a couple of the Bluetooth mate gold or Bluetooth Bee. Generally speaking the compatibility will be much better than using two brand module. Also It could help to eliminate unnecessary issues later.
Just my own opinion~
;D
Lauren
One of your Bluetooth module is Bluetooth mate gold and the other is the Bluetooth bee from DFRobot. And these two module are using different embedded Bluetooth chip. So you may need to configure two module for pairing.
Here's the Bluetooth chip datasheet.
Bluetooth mate gold:http://www.sparkfun.com/datasheets/Wireless/Bluetooth/rn-bluetooth-um.pdf
Bluetooth Bee:https://www.dfrobot.com/image/data/TEL0026/TEL0026_Datasheet.pdf
This is the main problem I could image. So for me, there is a simple way to finish a Bluetooth communication.Just use a couple of the Bluetooth mate gold or Bluetooth Bee. Generally speaking the compatibility will be much better than using two brand module. Also It could help to eliminate unnecessary issues later.
Just my own opinion~
;D

2012-09-25 00:00:46 What I know is that when you connect two Bluetooth module together, they will contact each other for transferring the pairing information. And they will assign each other to one slave and one master.
One of your Bluetooth module is Bluetooth mate gold and the other is the Bluetooth bee from DFRobot. And these two module are using different embedded Bluetooth chip. So you may need to configure two module for pairing.
Here's the Bluetooth chip datasheet.
Bluetooth mate gold:http://www.sparkfun.com/datasheets/Wireless/Bluetooth/rn-bluetooth-um.pdf
Bluetooth Bee:https://www.dfrobot.com/image/data/TEL0026/TEL0026_Datasheet.pdf
This is the main problem I could image. So for me, there is a simple way to finish a Bluetooth communication.Just use a couple of the Bluetooth mate gold or Bluetooth Bee. Generally speaking the compatibility will be much better than using two brand module. Also It could help to eliminate unnecessary issues later.
Just my own opinion~
;D
Lauren
One of your Bluetooth module is Bluetooth mate gold and the other is the Bluetooth bee from DFRobot. And these two module are using different embedded Bluetooth chip. So you may need to configure two module for pairing.
Here's the Bluetooth chip datasheet.
Bluetooth mate gold:http://www.sparkfun.com/datasheets/Wireless/Bluetooth/rn-bluetooth-um.pdf
Bluetooth Bee:https://www.dfrobot.com/image/data/TEL0026/TEL0026_Datasheet.pdf
This is the main problem I could image. So for me, there is a simple way to finish a Bluetooth communication.Just use a couple of the Bluetooth mate gold or Bluetooth Bee. Generally speaking the compatibility will be much better than using two brand module. Also It could help to eliminate unnecessary issues later.
Just my own opinion~
;D

2012-09-24 23:25:08 Hi Lauren,
So far, I have got them linked, but nothing happens whatever I try to send trough serial monitor. I think I can not get contact with my bluetooth bee. It is connected trough a FTDI cable.
So, my problem is that I can not communicate, since I do not know where the error is. I am controlling a radio controlled car.
So any help to test it and make it work would help me, so I hope I can get some help here
The Crusher
So far, I have got them linked, but nothing happens whatever I try to send trough serial monitor. I think I can not get contact with my bluetooth bee. It is connected trough a FTDI cable.
So, my problem is that I can not communicate, since I do not know where the error is. I am controlling a radio controlled car.
So any help to test it and make it work would help me, so I hope I can get some help here

2012-09-24 23:25:08 Hi Lauren,
So far, I have got them linked, but nothing happens whatever I try to send trough serial monitor. I think I can not get contact with my bluetooth bee. It is connected trough a FTDI cable.
So, my problem is that I can not communicate, since I do not know where the error is. I am controlling a radio controlled car.
So any help to test it and make it work would help me, so I hope I can get some help here
The Crusher
So far, I have got them linked, but nothing happens whatever I try to send trough serial monitor. I think I can not get contact with my bluetooth bee. It is connected trough a FTDI cable.
So, my problem is that I can not communicate, since I do not know where the error is. I am controlling a radio controlled car.
So any help to test it and make it work would help me, so I hope I can get some help here

2012-09-24 23:21:33 Hi crusher,
I think it should work fine. What do you think will cause some problems?
Lauren
I think it should work fine. What do you think will cause some problems?

2012-09-24 23:21:33 Hi crusher,
I think it should work fine. What do you think will cause some problems?
Lauren
I think it should work fine. What do you think will cause some problems?

2012-09-24 03:28:40 Hello,
I have a bluetooth bee, an xbee explorer, an ardouin pro and a bluetooth mate gold. I was woundering if I can use the bluetooth bee as an usb adapter for my pc trough the xbee explorer and send serial data to my arduino witch has the bluetooth mate gold on it? Is that possible at all, or does it not work?
The Crusher
I have a bluetooth bee, an xbee explorer, an ardouin pro and a bluetooth mate gold. I was woundering if I can use the bluetooth bee as an usb adapter for my pc trough the xbee explorer and send serial data to my arduino witch has the bluetooth mate gold on it? Is that possible at all, or does it not work?
