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]