Page 1 of 1

How do i know my Bluno is connected?

Unread postPosted:Sat Mar 21, 2015 1:37 pm
by djh_83
Hi,

I connect to the bluno with my iphone app over blue tooth. When I connect, a little led turns on, on the board and I can now send and receive bytes over Bluetooth. I'd like to know from within the bluno program that I am now connected with a device. The reason being is to only start sending serial data after a successful connection with the smart phone.

Thanks

Re: How do i know my Bluno is connected?

Unread postPosted:Tue Mar 24, 2015 4:08 am
by Leff
Hi,

http://www.dfrobot.com/image/data/DFR02 ... %20Sch.pdf
I found the led which turning on when connected with a ble devices is connected to CC2540 pin8, so you could read the pin state(HIGH OR LOW ) through IIC interface. ;)

Re: How do i know my Bluno is connected?

Unread postPosted:Thu Apr 23, 2015 3:58 pm
by tiojoca
How do you do that? I'm a complete beginner and I've been looking for a solution like this for months (viewtopic.php?f=8&t=1350 ) and this seems like it could be it!

What's the IIC interface and how do you read pin8 from CC2540?

Thanks in advance!

Re: How do i know my Bluno is connected?

Unread postPosted:Thu Apr 30, 2015 11:38 am
by tiojoca
I ended up solving this using a totally different approach. I set the board to AT mode and use the AT+RSSI=? command to get the RSSI which will always be -000 if Bluno is not connected to a BT device. An example implementation of this solution:

Code: Select all
const int ledBLE = 13;
typedef enum {START, WAIT_AT, WAIT_RSSI, WAIT_EXIT, NORM_MODE, _TMP} state_type;
state_type state = START;
char chr;
String buffer, rssi, data;
bool reading = false;

void setup() {
   Serial.begin(115200);      //Initiate the Serial comm
   pinMode(ledBLE, OUTPUT);
   state = START;
 }

void loop() {
   if (state == START) {
      start();
   } else if (state == WAIT_AT) {
      wait_at();
   } else if (state == WAIT_RSSI) {
      wait_rssi();
   } else if (state == WAIT_EXIT) {
      wait_exit();
   } else if (state == NORM_MODE) {
      norm_mode();
   }
}

void start() {
   delay(10);
   Serial.print("+");
   Serial.print("+");
   Serial.print("+");
   data = "";
   state = WAIT_AT;
}

void wait_at() {
   while (Serial.available() > 0) {
      chr = Serial.read();
      if (chr == 'E') {
         reading = true;
         buffer = "";
      }
      if (reading) {
         buffer += chr;
      } else {
         data += chr;
      }
      if (reading && buffer == "Enter AT Mode\r\n") {
         Serial.println("AT+RSSI=?");
         reading = false;
         state = WAIT_RSSI;
      } else if (data == "led_on") {
         digitalWrite(ledBLE, HIGH);
         data = "";
      } else if (data == "led_off") {
         digitalWrite(ledBLE, LOW);
         data = "";
      }
   }
}

void wait_rssi() {
   while (Serial.available() > 0) {
      chr = Serial.read();
      if (chr == '-') {
         reading = true;
         buffer = "";
      }
      if (reading) {
         buffer += chr;
      }
      if (buffer.length() == 4) {
         rssi = buffer;
         Serial.println("AT+EXIT");
         reading = false;
         state = WAIT_EXIT;
         if (rssi == "-000") {
            digitalWrite(ledBLE, LOW);
         }
      }
   }
}

void wait_exit() {
   while (Serial.available() > 0) {
      chr = Serial.read();
      if (chr == 'O') {
         reading = true;
         buffer = "";
      }
      if (reading) {
         buffer += chr;
      }
      if (buffer == "OK\r\n") {
         reading = false;
         state = NORM_MODE;
      }
   }
}

void norm_mode() {
   Serial.println("\r\n<<<");
   Serial.println(rssi);
   Serial.println(">>>\r\n");
   Serial.flush();
   state = START;
}


Not sure this is the best way to do it, though. I'm not very comfortable with using Serial for all the different inputs/outputs of different sources: executing AT commands and getting their results, getting data from BT, and outputting data back to USB.

Does anyone have a better suggestion on how to do this?

Re: How do i know my Bluno is connected?

Unread postPosted:Tue Jun 23, 2015 8:58 am
by Leff
brilliant´╝ü

Re: How do i know my Bluno is connected?

Unread postPosted:Thu Jul 14, 2016 12:08 pm
by timjanwall
I think Leff ment i2c and i looking for the same solution as tiojoca, i will try dig in to how to get to the CC2540 with i2c. If you find enything usefull post here or pm :)

Re: How do i know my Bluno is connected?

Unread postPosted:Mon Jul 18, 2016 6:59 am
by Leff
Hi timjanwall,

Sorry my bad, I didn't check the IIC interface of CC2540 before. Just now, I had a look at its datasheet, it seems that CC2540 only supports SPI interface but not IIC. http://www.ti.com/lit/ds/symlink/cc2540.pdf