Bluetooth & OSX - more issues

Hi All,

I have bluetooth working in OSX and I can connect at 115200, send commands and get responses via a terminal emulator and from my own program (not PoMoCo) (written in Processing) and I can send and recieve commands and move servos. The issue is that the bluetooth serial port has some latency/delay associated with it. For a basic round trip it takes <1ms for a character via USB to be echoed back and about 250ms for Bluetooth. Some simple test code below.

Has any one else had performance issues with bluetooth - particularly in OSX?

Regards, John.


import processing.serial.*;


Serial mp0;  // Create object from Serial class
Serial mp1;  // Create object from Serial class

void setup() {
  size(500, 500);
  
  String portName = Serial.list()[4];
  mp0 = new Serial(this, portName, 115200);
  portName = Serial.list()[6];
  mp1 = new Serial(this, portName, 115200);
 
}

void draw() {
  int m;
  
  m=millis();
  mp1.write("UUUUUUUUUUUUUU");
  delay(1);
  while (mp1.available()>0)
    print(char(mp1.read()));
  println(millis()-m);
  
  delay(5);
  
  m=millis();
  mp0.write("BBBBBBBBBBBBBB");
  delay(1);
  while (mp0.available()>0)
    print(char(mp0.read()));
  println(millis()-m);  
  
  delay(5);
  

}

[code]#include “TimerOne.h”
#include “SPI.h”

#define STATUS_LED 7

void setup() {
//setup pin modes
DDRF |= 0xF0; // sets pins F7 to F4 as outputs
DDRB = 0xFF; // sets pins B0 to B7 as outputs
pinMode(STATUS_LED,OUTPUT);
//setup PC serial port

// setup SPI port
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV2);

//start the servo-timing timer and associated interrupt
Timer1.initialize(10); // initialize timer1, and set a period of 10 uS
Timer1.attachInterrupt(callback); // attaches callback() as a timer overflow interrupt

Serial.begin(115200);
Serial1.begin(115200);
Serial1.print(“AT+BAUD8”); // Added this line to tell the module to change the baud rate to 9600
delay_new(2000);

}

long unsigned int us_counter = 0;
long unsigned int startTime = 0;
long unsigned int currentTime = 0;
long unsigned int last_update = 0;

long unsigned int micros_new(){
return us_counter;
}

long unsigned int millis_new(){
return us_counter/1000;
}

void delay_new(long unsigned int delay_time){
startTime = millis_new();
currentTime = millis_new() - startTime;
while(currentTime < delay_time){
delayMicroseconds(10);
currentTime = millis_new() - startTime;
}
}

void callback(){
cli();
us_counter += 10;
sei();
}

void loop() {
digitalWrite(STATUS_LED, HIGH);
delay_new(500);
digitalWrite(STATUS_LED, LOW);
delay_new(500);
digitalWrite(STATUS_LED, HIGH);
delay_new(500);
digitalWrite(STATUS_LED, LOW);
delay_new(500);

while(true) {
TIMSK0 &= ~(_BV(TOIE0)); // disables the arduino delay function, but also
// all but eliminates servo jitter
TIMSK2 &= ~(_BV(TOIE2)); // disable the arduino tone function, but also
// also helps eliminate some jitter
TIMSK3 &= ~(_BV(TOIE3)); // for good measure
TIMSK4 &= ~(_BV(TOIE4)); // for good measure

while(Serial1.available()) {
  char inChar = (char)Serial1.read();
  Serial1.println(inChar);  
}
while(Serial.available()) {
  char inChar = (char)Serial.read();
  Serial.println(inChar);  
}

}
}

[/code]

The Servotor 1.7 firmware now defaults to 9600 baud. You’ll need to re-program the Bluetooth module as discussed in this thread

Additional details may be found in the Hexy Wiki

I hope this helps.

Hi Luis,

I have reprogrammed the firmware for 115200 baud over both bluetooth and USB. It ‘feels’ like an OSX driver issue for the bluetooth serial connection allthough I cant confirm.

JF.

Hmm… I’m traveling for the next two weeks and don’t have access to my Hexy so I won’t be able to assist much on this front. Hopefully someone else might have some suggestions…

One thing to try is:

  1. Try loading the Servotor firmware onto the Hexy board.
  2. Use CoolTerm for Mac to connect to the board and type “V” followed by the return key into the terminal, the board should respond with “Servotor 1.7”.

That should help you find the cause of the troubles.

Hi All,

I am still have performance issues with MAC OSX and the bluetooth module.

Am using firmware 1.7. Can esatblish a blue tooth connection (115200 baud) but there still seems to be ~250ms of latency when sending a command to Hexy (compared to <1ms using USB).

I have two questions if any MAC OSX users can help:

  • do you have bluetooth up and running?
  • if so do you get the same performance as USB?

Thanks - JF.

JF -

Did you ever find a way to improve your latency issues?

I just got my hexy up and running on bluetooth using my mac. I get about 2-4 of the pre-programmed movements before he gets so backed up the movement freezes. Occasionally, I can select another movement and get one or two servo movements before all motion ceases.

Thanks,
Erica