Author Topic: rfduino crashes when enable BLE  (Read 1515 times)

jackyslim55

  • RFduino Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
rfduino crashes when enable BLE
« on: January 12, 2015, 09:16:01 AM »
https://gist.github.com/anonymous/249b613b38299b2b80e9
This is my code. Basicaly it works fine but when i start RFduinoBLE.begin();
the rfduino will crash within about 150sec or more.
It happens even without sending signals from my cell phone.
The crash will disable the connection between my cell phone and rfduino, and will be cured by clicking the serial monitor.
Can someone heip me correct my code plz?
or is it possible to use RFduino_systemReset() or things like that to prevent the crash by resetting the rfduino every 100sec (just before the crash happens)

I'm currently using usb to uart connecting my mac with rfduino
I'm using
Tolson's adafruit neopixel library
Rfduino 2.0.3
arduino 1.5.6 r2

Code: [Select]
#include <RFduinoBLE.h> //RFduino support
#include <Adafruit_NeoPixel.h>
#define PIN0 6
#define PIN1 4

Adafruit_NeoPixel strip0 = Adafruit_NeoPixel(11, PIN0, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(4, PIN1, NEO_GRB + NEO_KHZ800);

void setup() {
  strip0.begin();
  strip0.show(); // Initialize all pixels to 'off'
  strip1.begin();
  strip1.show(); // Initialize all pixels to 'off'
  Serial.begin(9600);
  RFduinoBLE.advertisementData = "rgb";
  RFduinoBLE.begin();
  //Serial.println("setup");
}
int mode = 4;
//int m = 0;
int steps = 0;
void RFduinoBLE_onReceive(char *data, int len) {
  uint8_t myByte = data[0]; // store first char in array to myByte
  Serial.println(data); // print myByte via serial
  if (myByte == '1') {
    //colorWipe0(strip0.Color(255, 0, 0), 10); // Red
    //colorWipe1(strip1.Color(0, 255, 0), 10); // Green
  }
  if (myByte == '0') {
    //colorWipe1(strip1.Color(255, 0, 0), 10); // Red
    //colorWipe0(strip0.Color(0, 255, 0), 10); // Green
  }
  if (myByte == '2') {
    mode = 1;
  }
  if (myByte == '4') {
    mode = 4;
  }

  //RFduino_systemReset(SECONDS(1));
}
void loop() {
 

 
 

//m += 25; if (m > 255) m = 0;

  if (mode == 4)
  {
   
    for ( int i = 0 ; i < 12; i++)
    {
            strip0.setPixelColor(i, 0, 0, 0);
            strip1.setPixelColor(i, 0, 0, 0);

    }
    if (steps == 0) {
      //for (int i = 0 ; i < 12 ; i++)  strip0.setPixelColor(i, 0, 0, 0);
      //for (int i = 0 ; i < 4 ; i++)  strip1.setPixelColor(i, 0, 0, 0);
      strip0.setPixelColor(5, 0, 120, 255);
     
    }
    if (steps == 1) {
      strip0.setPixelColor(4, 0, 120, 255);
      strip0.setPixelColor(6, 0, 120, 255);
      strip0.setPixelColor(5, 0, 60, 125);
    }
    if (steps == 2) {
      strip0.setPixelColor(4, 0, 60, 125);
      strip0.setPixelColor(6, 0, 60, 125);
      strip0.setPixelColor(2, 0, 120, 255);
      strip0.setPixelColor(8, 0, 120, 255);
      strip0.setPixelColor(5, 0, 30, 65);
      strip1.setPixelColor(0, 0, 30, 65);
      strip1.setPixelColor(1, 0, 30, 65);
      strip1.setPixelColor(2, 0, 30, 65);
      strip1.setPixelColor(3, 0, 30, 65);
    }
    if (steps == 3) {
      strip0.setPixelColor(4, 0, 30, 65);
      strip0.setPixelColor(6, 0, 30, 65);
      strip0.setPixelColor(2, 0, 60, 125);
      strip0.setPixelColor(8, 0, 60, 125);
      strip0.setPixelColor(0, 0, 60, 125);
      strip0.setPixelColor(10, 0, 60, 125);
      strip0.setPixelColor(5, 0, 0, 0);

      strip1.setPixelColor(0, 0, 60, 125);
      strip1.setPixelColor(1, 0, 60, 125);
      strip1.setPixelColor(2, 0, 60, 125);
      strip1.setPixelColor(3, 0, 60, 125);
    }
    if (steps == 4) {
      strip0.setPixelColor(4, 0, 0, 0);
      strip0.setPixelColor(6, 0, 0, 0);
      strip0.setPixelColor(2, 0, 30, 65);
      strip0.setPixelColor(8, 0, 30, 65);
      strip0.setPixelColor(0, 0, 120, 225);
      strip0.setPixelColor(10, 0, 120, 225);

      strip1.setPixelColor(0, 0, 30, 65);
      strip1.setPixelColor(1, 0, 30, 65);
      strip1.setPixelColor(2, 0, 30, 65);
      strip1.setPixelColor(3, 0, 30, 65);   
    }
        if (steps == 5) {
      strip0.setPixelColor(4, 0, 0, 0);
      strip0.setPixelColor(6, 0, 0, 0);
      strip0.setPixelColor(2, 0, 0, 0);
      strip0.setPixelColor(8, 0, 0, 0);
      strip0.setPixelColor(0, 0, 50, 125);
      strip0.setPixelColor(10, 0, 50, 125);

      strip1.setPixelColor(0, 0, 0, 0);
      strip1.setPixelColor(1, 0, 0, 0);
      strip1.setPixelColor(2, 0, 0, 0);
      strip1.setPixelColor(3, 0, 0, 0);   
   

    }
        if (steps == 6) {
      strip0.setPixelColor(4, 0, 0, 0);
      strip0.setPixelColor(6, 0, 0, 0);
      strip0.setPixelColor(2, 0, 0, 0);
      strip0.setPixelColor(8, 0, 0, 0);
      strip0.setPixelColor(0, 0, 0, 0);
      strip0.setPixelColor(10, 0, 0, 0);

      strip1.setPixelColor(0, 0, 0, 0);
      strip1.setPixelColor(1, 0, 0, 0);
      strip1.setPixelColor(2, 0, 0, 0);
      strip1.setPixelColor(3, 0, 0, 0);   
    }
 
   // (RFduinoBLE.radioActive);
    strip0.show();
    strip1.show();
    delay(800);
  steps++;
  if (steps > 6) steps = 0;
   

  }
  //steps++;
  //if (steps > 6) steps = 0;
  if (mode == 0) {

    //for ( int i = 0 ; i < 12; i++)
    {
      //strip0.setPixelColor(i, 0, 0, 255);
    }
    //strip0.show();

  }

  if (mode == 1) {

    for ( int i = 0 ; i < 12; i++)
    {
            strip0.setPixelColor(i, 0, 0, 0);
            strip1.setPixelColor(i, 0, 0, 0);

    }

    strip0.setPixelColor(int(random(12)), 0, 170, 120);
    strip0.setPixelColor(int(random(12)), 0, 120, 150);
    strip1.setPixelColor(int(random(4)), 0, 150, 100);

   //(RFduinoBLE.radioActive);
    strip0.show();
    strip1.show();
    delay(0.5);

    /*
        for ( int i = 0 ; i < 12; i++)
        {
          strip0.setPixelColor(i, 0, 0, 0);
        }
        strip0.show();
        delay(1 00);
        */

  }
  //Serial.println("ok");
  Serial.println(millis());
  //delay(1000);
  RFduino_ULPDelay(SECONDS(1));
}




edorphy

  • RFduino Full Member
  • ***
  • Posts: 86
  • Karma: +0/-0
    • View Profile
Re: rfduino crashes when enable BLE
« Reply #1 on: March 30, 2015, 10:46:46 PM »
I had similar issues making an on connect light up my room app.

The neo pixel is VERY dependent on timing working. An interrupt on BLE and its callback would likely break the one wire protocol being used by neopixels. There is a new pixel that Adafruit sells that uses two pins, one for a variable clock, and the other for data. Completely independent of a specific clock frequency.

Not idea, however you could save your color data, disconnect, stop advertising, stop ble and then do your color wipe. Once complete ble begin etc. I haven't tested this, but if it is indeed a timing issue and you're getting lost in no ops, perhaps this would resolve that issue?

 

anything