Forum >Replies by tiojoca
userhead tiojoca
Replies (7)
  • You Reply:

    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!

  • You Reply:

    您是如何做到的?我完全是个初学者,几个月来我一直在寻找这样的解决方案(viewtopic.php?f=8&t=1350),这似乎就是解决方案!@@什么是 IIC 接口,您如何从 CC2540 读取 pin8?@@提前致谢!

  • You Reply: After testing with 2 differents computers, more than 2 Bluno boards of different versions and 3 USB cables, turns out the issue were the cables themselves.
  • You Reply: 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?
  • You Reply: 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?
  • You Reply: Solved it! I was powering Bluno through the USB connection and didn't realise it was not enough for the 7v to 12v power supply that the Relay Shield needs. I've connected the Bluno to a 9v power source and the relays are now working fine!

    You have no idea the amount of hours I've wasted on this silly problem. My faith in electronics is restored.
  • You Reply: That's true, I could buy a cheap Android por personal projects with Bluno but I need it for a project with non-tech users who use iPhones.