ios - Red Bear Lab BLE Shield isn't connecting to my iPhone -


i've purchased this: http://redbearlab.com/bleshield/

i've connected arduino , i'm trying run first test program tell me run ble controller sketch. i've connected , resolved original compile errors got, , upload. when upload it, iphone unresponsive shield. i'm trying figure out if problem in code or if it's problem shield itself. if it's code, how fix code? i'm relatively new arduino , new making work bluetooth. here's entire sketch guide told me download github.

blecontrollersketch.ino

/*  copyright (c) 2012, 2013 redbearlab  permission hereby granted, free of charge, person obtaining copy of software , associated documentation files (the "software"), deal in software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of software, , permit persons whom software furnished so, subject following conditions:  above copyright notice , permission notice shall included in copies or substantial portions of software.  software provided "as is", without warranty of kind, express or implied, including not limited warranties of merchantability, fitness particular purpose , noninfringement. in no event shall authors or copyright holders liable claim, damages or other liability, whether in action of contract, tort or otherwise, arising from, out of or in connection software or use or other dealings in software.  */  #include <servo.h> #include <spi.h> #include <eeprom.h> #include <boards.h> #include <rbl_nrf8001.h> #include "boards.h"  #define protocol_major_version   0 // #define protocol_minor_version   0 // #define protocol_bugfix_version  2 // bugfix  #define pin_capability_none      0x00 #define pin_capability_digital   0x01 #define pin_capability_analog    0x02 #define pin_capability_pwm       0x04 #define pin_capability_servo     0x08 #define pin_capability_i2c       0x10  // pin modes //#define input                 0x00 // defined in wiring.h //#define output                0x01 // defined in wiring.h #define analog                  0x02 // analog pin in analoginput mode #define pwm                     0x03 // digital pin in pwm output mode #define servo                   0x04 // digital pin in servo output mode  byte pin_mode[total_pins]; byte pin_state[total_pins]; byte pin_pwm[total_pins]; byte pin_servo[total_pins];  servo servos[max_servos];  void setup() {   serial.begin(57600);   serial.println("ble arduino slave");    /* default digital input */   (int pin = 0; pin < total_pins; pin++)   {     // set pin input internal pull     pinmode(pin, input);     digitalwrite(pin, high);      // save pin mode , state     pin_mode[pin] = input;     pin_state[pin] = low;   }    // default pins set 9 , 8 reqn , rdyn   // set reqn , rdyn here before ble_begin() if need   //ble_set_pins(3, 2);    // set ble shield name here, max. length 10   //ble_set_name("my name");    // init. , start ble library.   ble_begin(); }  static byte buf_len = 0;  void ble_write_string(byte *bytes, uint8_t len) {   if (buf_len + len > 20)   {     (int j = 0; j < 15000; j++)       ble_do_events();      buf_len = 0;   }    (int j = 0; j < len; j++)   {     ble_write(bytes[j]);     buf_len++;   }    if (buf_len == 20)   {     (int j = 0; j < 15000; j++)       ble_do_events();      buf_len = 0;   }   }  byte reportdigitalinput() {   if (!ble_connected())     return 0;    static byte pin = 0;   byte report = 0;    if (!is_pin_digital(pin))   {     pin++;     if (pin >= total_pins)       pin = 0;     return 0;   }    if (pin_mode[pin] == input)   {       byte current_state = digitalread(pin);        if (pin_state[pin] != current_state)       {         pin_state[pin] = current_state;         byte buf[] = {'g', pin, input, current_state};         ble_write_string(buf, 4);          report = 1;       }   }    pin++;   if (pin >= total_pins)     pin = 0;    return report; }  void reportpincapability(byte pin) {   byte buf[] = {'p', pin, 0x00};   byte pin_cap = 0;    if (is_pin_digital(pin))     pin_cap |= pin_capability_digital;    if (is_pin_analog(pin))     pin_cap |= pin_capability_analog;    if (is_pin_pwm(pin))     pin_cap |= pin_capability_pwm;    if (is_pin_servo(pin))     pin_cap |= pin_capability_servo;    buf[2] = pin_cap;   ble_write_string(buf, 3); }  void reportpinservodata(byte pin) { //  if (is_pin_servo(pin)) //    servos[pin_to_servo(pin)].write(value); //  pin_servo[pin] = value;    byte value = pin_servo[pin];   byte mode = pin_mode[pin];   byte buf[] = {'g', pin, mode, value};            ble_write_string(buf, 4); }  byte reportpinanalogdata() {   if (!ble_connected())     return 0;    static byte pin = 0;   byte report = 0;    if (!is_pin_digital(pin))   {     pin++;     if (pin >= total_pins)       pin = 0;     return 0;   }    if (pin_mode[pin] == analog)   {     uint16_t value = analogread(pin);     byte value_lo = value;     byte value_hi = value>>8;      byte mode = pin_mode[pin];     mode = (value_hi << 4) | mode;      byte buf[] = {'g', pin, mode, value_lo};              ble_write_string(buf, 4);   }    pin++;   if (pin >= total_pins)     pin = 0;    return report; }  void reportpindigitaldata(byte pin) {   byte state = digitalread(pin);   byte mode = pin_mode[pin];   byte buf[] = {'g', pin, mode, state};            ble_write_string(buf, 4); }  void reportpinpwmdata(byte pin) {   byte value = pin_pwm[pin];   byte mode = pin_mode[pin];   byte buf[] = {'g', pin, mode, value};            ble_write_string(buf, 4); }  void sendcustomdata(uint8_t *buf, uint8_t len) {   uint8_t data[20] = "z";   memcpy(&data[1], buf, len);   ble_write_string(data, len+1); }  byte querydone = false;  void loop() {   while(ble_available())   {     byte cmd;     cmd = ble_read();     serial.write(cmd);      // parse data here     switch (cmd)     {       case 'v': // query protocol version         {           byte buf[] = {'v', 0x00, 0x00, 0x01};           ble_write_string(buf, 4);         }         break;        case 'c': // query board total pin count         {           byte buf[2];           buf[0] = 'c';           buf[1] = total_pins;            ble_write_string(buf, 2);         }                 break;        case 'm': // query pin mode         {             byte pin = ble_read();           byte buf[] = {'m', pin, pin_mode[pin]}; // report pin mode           ble_write_string(buf, 3);         }           break;        case 's': // set pin mode         {           byte pin = ble_read();           byte mode = ble_read();            if (is_pin_servo(pin) && mode != servo && servos[pin_to_servo(pin)].attached())             servos[pin_to_servo(pin)].detach();            /* todo: check mode in capability or not */           /* assume ok */           if (mode != pin_mode[pin])           {                           pinmode(pin, mode);             pin_mode[pin] = mode;              if (mode == output)             {               digitalwrite(pin, low);               pin_state[pin] = low;             }             else if (mode == input)             {               digitalwrite(pin, high);               pin_state[pin] = high;             }             else if (mode == analog)             {               if (is_pin_analog(pin)) {                 if (is_pin_digital(pin)) {                   pinmode(pin_to_digital(pin), low);                 }               }             }             else if (mode == pwm)             {               if (is_pin_pwm(pin))               {                 pinmode(pin_to_pwm(pin), output);                 analogwrite(pin_to_pwm(pin), 0);                 pin_pwm[pin] = 0;                 pin_mode[pin] = pwm;               }             }             else if (mode == servo)             {               if (is_pin_servo(pin))               {                 pin_servo[pin] = 0;                 pin_mode[pin] = servo;                 if (!servos[pin_to_servo(pin)].attached())                   servos[pin_to_servo(pin)].attach(pin_to_digital(pin));               }             }           }    //        if (mode == analog)   //          reportpinanalogdata(pin);           if ( (mode == input) || (mode == output) )             reportpindigitaldata(pin);           else if (mode == pwm)             reportpinpwmdata(pin);           else if (mode == servo)             reportpinservodata(pin);         }         break;        case 'g': // query pin data         {           byte pin = ble_read();           reportpindigitaldata(pin);         }         break;        case 't': // set pin digital state         {           byte pin = ble_read();           byte state = ble_read();            digitalwrite(pin, state);           reportpindigitaldata(pin);         }         break;        case 'n': // set pwm         {           byte pin = ble_read();           byte value = ble_read();            analogwrite(pin_to_pwm(pin), value);           pin_pwm[pin] = value;           reportpinpwmdata(pin);         }         break;        case 'o': // set servo         {           byte pin = ble_read();           byte value = ble_read();            if (is_pin_servo(pin))             servos[pin_to_servo(pin)].write(value);           pin_servo[pin] = value;           reportpinservodata(pin);         }         break;        case 'a': // query pin status         (int pin = 0; pin < total_pins; pin++)         {           reportpincapability(pin);           if ( (pin_mode[pin] == input) || (pin_mode[pin] == output) )             reportpindigitaldata(pin);           else if (pin_mode[pin] == pwm)             reportpinpwmdata(pin);           else if (pin_mode[pin] == servo)             reportpinservodata(pin);           }          querydone = true;          {           uint8_t str[] = "abc";           sendcustomdata(str, 3);         }          break;        case 'p': // query pin capability         {           byte pin = ble_read();           reportpincapability(pin);         }         break;        case 'z':         {           byte len = ble_read();           byte buf[len];           (int i=0;i<len;i++)             buf[i] = ble_read();           serial.println("->");           serial.print("received: ");           serial.print(len);           serial.println(" byte(s)");           serial.print(" hex: ");           (int i=0;i<len;i++)             serial.print(buf[i], hex);           serial.println();         }     }      // send out outstanding data     ble_do_events();     buf_len = 0;      return; // task in loop   }    // process text data   if (serial.available())   {     byte d = 'z';     ble_write(d);      delay(5);     while(serial.available())     {       d = serial.read();       ble_write(d);     }      ble_do_events();     buf_len = 0;      return;       }    // no input data, no commands, process analog data   if (!ble_connected())     querydone = false; // reset query state    if (querydone) // report data after query state   {      byte input_data_pending = reportdigitalinput();       if (input_data_pending)     {       ble_do_events();       buf_len = 0;        return; // task in loop     }      reportpinanalogdata();      ble_do_events();     buf_len = 0;      return;     }    ble_do_events();   buf_len = 0; } 

any , appreciated.

i've been working these quite bit in last 8 months, i'll can help. don't have reputation comment , ask clarification on specific things, i'm gonna try cover can.

let's first lay out few things:

  • because sketch uploaded i'm assuming have added of necessary libraries arduino. if haven't, don't know why uploading, sure that.

  • the problem won't arduino code. i ran code provided, sketch provided rbl (red bear lab) on computer. i able connect iphone using both sketches.

i'm going lay out think potentially source of problem:

  • make sure of header pins (you should have bunch of headers sticking out of board in rows of 3 next digital pins) connected correctly, rbl shows in instructions. if want me provide picture of mine can that.

  • make sure white power light on on shield. if isn't, power isn't getting shield itself.

  • be sure have bluetooth enabled on phone.

  • you didn't mention downloaded app. sure (it called "ble controller" redbear), cannot connect iphone without app (apple's bluetooth menu not show ble shield).

  • if have downloaded app, sure have selected correct setting choices using button on top left of screen (3 lines on top of each other). sketch provided, should select ble controller.

if have tried , nothing else working, try 1 of other sketches provided rbl, such simplechat. uses serial monitor on arduino communicate , forth iphone. if doesn't work, upload picture of specific shield (the top of it) can take @ it. best of luck.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -