Arduino BT datarate

Hi,
Ive just started messing with an arduino BT. I am trying to sample 2 analog Ins at different sampling rates. It seems I can only sample at up to 15hz. ANy faster and the hardware serial monitor in the ide throws up a load of errors when trying to access the serial port. As if the port isnt available anymore. Same thing in MAX. At 10Hz max serial happily opens the port and in comes the data. At higher sampling rate max says 'error cant open serial port bla bla bla'
Any ideas on where i could be going wrong?
I dont have the device here now but Im wondering is it that i am swamping the blugiga with too much data from the atmega168 side before it is properly connected to the computer/max?
Im going to try a long delay before i start sampling tomorrow to see if that helps but if anyone had example code that gives them a faster sampling rate Id be really grateful.
Will report back in the morning.
Thanks
Nicky

hi

What kind of Mac are you using? On my Macbook Pro, when I use Arduino2Max I get a sample rate of over 50Hz from the BT module, reading all the digital and analog pins each time. Opening the Arduino IDE tends to cause a wicked crash, as there seems to be too much negotiation going on between the computer and the BlueGiga module. Running the data through max works pretty flawlessly.

D

imac core 2 duo. Its really very oddd. havent looked at arduino2max as i really need > 500Hz sampling rate so im sending the 2 analogs in a 5 byte packet.
thanks
Nicky

hi
I really doubt you can get that speed over the BT, as even at 115200 bps the data rate is pretty slow!
I'd be interested to know if you can though...
D

not sure if its realistic but the iwap manual claims data rates of 600kbps. Thats roughly 60kBps. my packet (arduino side) is 5 bytes. So that should be 12000 packets a second. OF course im ignoring the overhead from the bluetooth which i have no idea about.

I can handle latency as long as i get my rate so i wonder can i set the packet size so the blue giga buffers a few 5 byte packets and sends them together?

At the atmega to bluegiga end of things i reckoned that
At 115,200bps => 11,520 Bytes per sec. at 5 bytes a sample => 2304 samples per sec.

I'll investigate and report back. ANy info from folks in the know opn this stuff would be great.

thanks
Nicky

yes it sounds like it will work in principle but my gut feeling is that it won't!
Massimo would know the answer really quickly, as he has designed the BT module with Gianluca.

D

hello

datarate over wireless connections i always a bit of a gamble but... let's try
theoretically it could work...

the only problem is when there is a lot of traffic in that band (Wifi, bluetooth, other 2.4GHz thingies)

another factor that might slow down your module is if somebody is doing a discovery of the bt devices in the area.
that tends to hog the bandwidth and CPU time of the modules... now if somebody would be running a lot
of discoveries they would kill your performance pretty fast.

you should try the Firmata protocol on PD as a test, it has a very compact protocol and it has been adapted to the BT board

find it here http://www.tinker.it/en/Teaching/Bluetooth

massimo

Hi,
Success! 6 channels at 500 samples per second 10bit resolution. I just put a delay of 30 seconds at the end of my setup. When max opens the serial connection there is no data for a few seconds and then it comes. It doesnt suffer from the problem i outlined with the ftdi serial here either http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1170939903/0

My firmware is based on firmata but smalller as im only reading the analog ins and with an interrupt (from the clock example changed slightly got atmega168) to time the sampling.

#include <avr/interrupt.h>
#include <avr/io.h>

#define INIT_TIMER_COUNT 6
#define RESET_TIMER2 TCNT2 = INIT_TIMER_COUNT


int int_counter = 0;
volatile int count = 149;
int oldcount = 0;



int analogPin = 0;
int analogInputsEnabled = 6;
int analogData;            // outgoing ADC value








// Arduino runs at 16 Mhz, so we have 1000 Overflows per second...
// 1/ ((16000000 / 64) / 256) = 1 / 1000
ISR(TIMER2_OVF_vect) {
  RESET_TIMER2;
  int_counter += 1;
  
  if (int_counter == 1) //set sampling frequency here 1 = 1kHz, 2 = 500Hz etc
  {
    if (count == 250){count = 149;}
    count+=1; 
    int_counter = 0;
  } 
};

void setup() {


  Serial.begin(115200);        // connect to the serial port

 
  //set up the timer 2 interrupt
  //Timer2 Settings: Timer Prescaler /64, 
  TCCR2A |= (1<<CS22);    
  TCCR2A &= ~((1<<CS21) | (1<<CS20));     
  // Use normal mode
  TCCR2A &= ~((1<<WGM21) | (1<<WGM20));  
  // Use internal clock - external clock not used in Arduino
  ASSR |= (0<<AS2);
  //Timer2 Overflow Interrupt Enable
  TIMSK2 |= (1<<TOIE2) | (0<<OCIE2A);  
  RESET_TIMER2;               
  sei();
   
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);          
delay(100);
digitalWrite(13, HIGH); 
delay(100);
digitalWrite(13, LOW); 
delay(10000); //big delay to give time to establish serial link with max/pd whatever
digitalWrite(13, HIGH);  

}

void loop() { 


             
  if (oldcount != count) {
   /* get analog in, for the number enabled */
      for(analogPin=0; analogPin<analogInputsEnabled; ++analogPin) 
      {
            analogData = analogRead(analogPin);
                Serial.print(analogData >> 7, BYTE); 
            Serial.print(analogData % 128, BYTE); 

      }

Serial.print(255, BYTE); // end of analogs signifier   
 oldcount = count;
  }
  
}

Great!

like I was saying, yes it sounds like it will work in principle but my gut feeling is that it won't!

:slight_smile:

D

yip, very happy with this. 4 channels at 1kHz too which is cool. The limitation on sampling rate now comes from my code for sample and send. It cant execute 6 analog reads and the serial sending in under a ms so i miss an interupt which drops me to 500hz. Any sugggestions on how i might stream line my code would be welcome. perhaps its time to go and learn some asm.