0

NEOPIXEL LED Strip, NRF52, Android BLE Control
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

NEOPIXEL LED Strip, NRF52, Android BLE Control

by delawarehunter on Sun Jan 28, 2018 11:27 pm

Good evening,
Just a forewarning... I'm very new to Arduino and some of what I am attempting may be wrong. However, I wanted to run a couple of things by you all and make sure I have my thinking right...

I am trying to create a bluetooth controlled light for my sons that will let them change the color whenever they want. I've purchased the ADAFRUIT NRF52 Bluefruit LE, 1 meter of the 60 LED Neopixel strip, and the PermaProto 1/2 sized breadboard.

I have wired everything up correctly, I believe... I know that I need 5v to drive the LEDs. Using a multimeter, I found the USB port provided me 5v ( approx 4.95 - 4.98 depending on the power supply). I'm using a smartphone power adapter that provides 5v at 2a output.

My current setup, pictured below, is just a temporary setup to make sure everything is working before I finalize and solder the LED's into place in the lamp.

Image

Image

Image

Here is my problem: When I use the Bluefruit LE Connect app on my Ipad and connect to the setup, I can control the LED's from the NeoPixel mode, but not from the Color Picker Controller mode. From the Neopixel mode, I can set the color to anything that I want for the most part. Again, from the Color Picker controller mode, I get no response from the LEDs at all.

From my Android phone, I can't control the LED's at all. As soon as I connect to the setup and choose Neopixel mode, then connect to the setup in the Neopixel mode screen, it turns all of my LEDs white. I can't change the color at all... The ColorPicker Controller mode doesn't respond to my Android phone either, just like my Ipad.

So, what I am looking for help with is this:

1. Why isn't the Colorpicker Controller mode working? I'd have to guess that has something to do with the sketch that I uploaded to the NRF52?
2. Why isn't the Bluefruit LE Android app controlling the NeoPixel in Neopixel mode? In the settings for the NeoPixel mode, I can only choose between 2 different "Pixel Types"... GRB 800khz and GRBW 800khz. I've tried both and neither make a difference. By the way, there are ALOT more to choose from in the ipad app... The only other thing in the Android app is a Pixel Config Register decimal value that I can set manually... I haven't changed it manually and I can't find anything online that explains what this should be set to or how to determine what it is..

Here is the code I am using also, just in case something needs to be tweaked in here:

Code: Select all | TOGGLE FULL SIZE
/*********************************************************************
 This is an example for our nRF52 based Bluefruit LE modules

 Pick one up today in the adafruit shop!

 Adafruit invests time and resources providing this open source code,
 please support Adafruit and open-source hardware by purchasing
 products from Adafruit!

 MIT license, check LICENSE for more information
 All text above, and the splash screen below must be included in
 any redistribution
*********************************************************************/

// This sketch is intended to be used with the NeoPixel control
// surface in Adafruit's Bluefruit LE Connect mobile application.
//
// - Compile and flash this sketch to the nRF52 Feather
// - Open the Bluefruit LE Connect app
// - Switch to the NeoPixel utility
// - Click the 'connect' button to establish a connection and
//   send the meta-data about the pixel layout
// - Use the NeoPixel utility to update the pixels on your device

/* NOTE: This sketch required at least version 1.1.0 of Adafruit_Neopixel !!! */

#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#include <bluefruit.h>

#define NEOPIXEL_VERSION_STRING "Neopixel v2.0"
#define PIN                     15   /* Pin used to drive the NeoPixels */

#define MAXCOMPONENTS  4
uint8_t *pixelBuffer = NULL;
uint8_t width = 0;
uint8_t height = 0;
uint8_t stride;
uint8_t componentsValue;
bool is400Hz;
uint8_t components = 3;     // only 3 and 4 are valid values

Adafruit_NeoPixel neopixel = Adafruit_NeoPixel();

// BLE Service
BLEDis  bledis;
BLEUart bleuart;

void setup()
{
  Serial.begin(115200);
  Serial.println("Adafruit Bluefruit Neopixel Test");
  Serial.println("--------------------------------");

  Serial.println();
  Serial.println("Please connect using the Bluefruit Connect LE application");
 
  // Config Neopixels
  neopixel.begin();

  // Init Bluefruit
  Bluefruit.begin();
  // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
  Bluefruit.setTxPower(4);
  Bluefruit.setName("Bluefruit52");
  Bluefruit.setConnectCallback(connect_callback);

  // Configure and Start Device Information Service
  bledis.setManufacturer("Adafruit Industries");
  bledis.setModel("Bluefruit Feather52");
  bledis.begin(); 

  // Configure and start BLE UART service
  bleuart.begin();

  // Set up and start advertising
  startAdv();
}

void startAdv(void)

  // Advertising packet
  Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
  Bluefruit.Advertising.addTxPower();
 
  // Include bleuart 128-bit uuid
  Bluefruit.Advertising.addService(bleuart);

  // Secondary Scan Response packet (optional)
  // Since there is no room for 'Name' in Advertising packet
  Bluefruit.ScanResponse.addName();
 
  /* Start Advertising
   * - Enable auto advertising if disconnected
   * - Interval:  fast mode = 20 ms, slow mode = 152.5 ms
   * - Timeout for fast mode is 30 seconds
   * - Start(timeout) with timeout = 0 will advertise forever (until connected)
   *
   * For recommended advertising interval
   * https://developer.apple.com/library/content/qa/qa1931/_index.html   
   */
  Bluefruit.Advertising.restartOnDisconnect(true);
  Bluefruit.Advertising.setInterval(32, 244);    // in unit of 0.625 ms
  Bluefruit.Advertising.setFastTimeout(30);      // number of seconds in fast mode
  Bluefruit.Advertising.start(0);                // 0 = Don't stop advertising after n seconds 
}

void connect_callback(uint16_t conn_handle)
{
  char central_name[32] = { 0 };
  Bluefruit.Gap.getPeerName(conn_handle, central_name, sizeof(central_name));

  Serial.print("Connected to ");
  Serial.println(central_name);

  Serial.println("Please select the 'Neopixels' tab, click 'Connect' and have fun");
}

void loop()
{
  // Echo received data
  if ( Bluefruit.connected() && bleuart.notifyEnabled() )
  {
    int command = bleuart.read();

    switch (command) {
      case 'V': {   // Get Version
          commandVersion();
          break;
        }
 
      case 'S': {   // Setup dimensions, components, stride...
          commandSetup();
          break;
       }

      case 'C': {   // Clear with color
          commandClearColor();
          break;
      }

      case 'B': {   // Set Brightness
          commandSetBrightness();
          break;
      }
           
      case 'P': {   // Set Pixel
          commandSetPixel();
          break;
      }
 
      case 'I': {   // Receive new image
          commandImage();
          break;
       }

    }
  }
}

void swapBuffers()
{
  uint8_t *base_addr = pixelBuffer;
  int pixelIndex = 0;
  for (int j = 0; j < height; j++)
  {
    for (int i = 0; i < width; i++) {
      if (components == 3) {
        neopixel.setPixelColor(pixelIndex, neopixel.Color(*base_addr, *(base_addr+1), *(base_addr+2)));
      }
      else {
        neopixel.setPixelColor(pixelIndex, neopixel.Color(*base_addr, *(base_addr+1), *(base_addr+2), *(base_addr+3) ));
      }
      base_addr+=components;
      pixelIndex++;
    }
    pixelIndex += stride - width;   // Move pixelIndex to the next row (take into account the stride)
  }
  neopixel.show();

}

void commandVersion() {
  Serial.println(F("Command: Version check"));
  sendResponse(NEOPIXEL_VERSION_STRING);
}

void commandSetup() {
  Serial.println(F("Command: Setup"));

  width = bleuart.read();
  height = bleuart.read();
  stride = bleuart.read();
  componentsValue = bleuart.read();
  is400Hz = bleuart.read();

  neoPixelType pixelType;
  pixelType = componentsValue + (is400Hz ? NEO_KHZ400 : NEO_KHZ800);

  components = (componentsValue == NEO_RGB || componentsValue == NEO_RBG || componentsValue == NEO_GRB || componentsValue == NEO_GBR || componentsValue == NEO_BRG || componentsValue == NEO_BGR) ? 3:4;
 
  Serial.printf("\tsize: %dx%d\n", width, height);
  Serial.printf("\tstride: %d\n", stride);
  Serial.printf("\tpixelType %d\n", pixelType);
  Serial.printf("\tcomponents: %d\n", components);

  if (pixelBuffer != NULL) {
      delete[] pixelBuffer;
  }

  uint32_t size = width*height;
  pixelBuffer = new uint8_t[size*components];
  neopixel.updateLength(size);
  neopixel.updateType(pixelType);
  neopixel.setPin(PIN);

  // Done
  sendResponse("OK");
}

void commandSetBrightness() {
  Serial.println(F("Command: SetBrightness"));

   // Read value
  uint8_t brightness = bleuart.read();

  // Set brightness
  neopixel.setBrightness(brightness);

  // Refresh pixels
  swapBuffers();

  // Done
  sendResponse("OK");
}

void commandClearColor() {
  Serial.println(F("Command: ClearColor"));

  // Read color
  uint8_t color[MAXCOMPONENTS];
  for (int j = 0; j < components;) {
    if (bleuart.available()) {
      color[j] = bleuart.read();
      j++;
    }
  }

  // Set all leds to color
  int size = width * height;
  uint8_t *base_addr = pixelBuffer;
  for (int i = 0; i < size; i++) {
    for (int j = 0; j < components; j++) {
      *base_addr = color[j];
      base_addr++;
    }
  }

  // Swap buffers
  Serial.println(F("ClearColor completed"));
  swapBuffers();


  if (components == 3) {
    Serial.printf("\tclear (%d, %d, %d)\n", color[0], color[1], color[2] );
  }
  else {
    Serial.printf("\tclear (%d, %d, %d, %d)\n", color[0], color[1], color[2], color[3] );
  }
 
  // Done
  sendResponse("OK");
}

void commandSetPixel() {
  Serial.println(F("Command: SetPixel"));

  // Read position
  uint8_t x = bleuart.read();
  uint8_t y = bleuart.read();

  // Read colors
  uint32_t pixelOffset = y*width+x;
  uint32_t pixelDataOffset = pixelOffset*components;
  uint8_t *base_addr = pixelBuffer+pixelDataOffset;
  for (int j = 0; j < components;) {
    if (bleuart.available()) {
      *base_addr = bleuart.read();
      base_addr++;
      j++;
    }
  }

  // Set colors
  uint32_t neopixelIndex = y*stride+x;
  uint8_t *pixelBufferPointer = pixelBuffer + pixelDataOffset;
  uint32_t color;
  if (components == 3) {
    color = neopixel.Color( *pixelBufferPointer, *(pixelBufferPointer+1), *(pixelBufferPointer+2) );
    Serial.printf("\tcolor (%d, %d, %d)\n",*pixelBufferPointer, *(pixelBufferPointer+1), *(pixelBufferPointer+2) );
  }
  else {
    color = neopixel.Color( *pixelBufferPointer, *(pixelBufferPointer+1), *(pixelBufferPointer+2), *(pixelBufferPointer+3) );
    Serial.printf("\tcolor (%d, %d, %d, %d)\n", *pixelBufferPointer, *(pixelBufferPointer+1), *(pixelBufferPointer+2), *(pixelBufferPointer+3) );   
  }
  neopixel.setPixelColor(neopixelIndex, color);
  neopixel.show();

  // Done
  sendResponse("OK");
}

void commandImage() {
  Serial.printf("Command: Image %dx%d, %d, %d\n", width, height, components, stride);
 
  // Receive new pixel buffer
  int size = width * height;
  uint8_t *base_addr = pixelBuffer;
  for (int i = 0; i < size; i++) {
    for (int j = 0; j < components;) {
      if (bleuart.available()) {
        *base_addr = bleuart.read();
        base_addr++;
        j++;
      }
    }

/*
    if (components == 3) {
      uint32_t index = i*components;
      Serial.printf("\tp%d (%d, %d, %d)\n", i, pixelBuffer[index], pixelBuffer[index+1], pixelBuffer[index+2] );
    }
    */
  }

  // Swap buffers
  Serial.println(F("Image received"));
  swapBuffers();

  // Done
  sendResponse("OK");
}

void sendResponse(char const *response) {
    Serial.printf("Send Response: %s\n", response);
    bleuart.write(response, strlen(response)*sizeof(char));
}


EDIT: I did want to mention that i mimicked my wiring after the NRF52 page where it shows the NeoPixel ring being controlled by an Iphone. The only difference is that I'm not using the BAT post like is shown on the NRF52 webpage image. When I attempted that, I got some really wierd flashing and dimming/brightening effect when changing the colors via my Ipad through the NeoPixel mode. So I switched back to the USB post.

delawarehunter
 
Posts: 9
Joined: Sun Jan 28, 2018 10:47 pm

Re: NEOPIXEL LED Strip, NRF52, Android BLE Control

by delawarehunter on Sun Jan 28, 2018 11:39 pm

An Update:

The code that I posted was the NeoPixel example that is in the Arduino IDE under the Adafruit BLE libraries for Bluefruit52. I just tried the controller example under that same library and it didn't work either.

delawarehunter
 
Posts: 9
Joined: Sun Jan 28, 2018 10:47 pm

Re: NEOPIXEL LED Strip, NRF52, Android BLE Control

by kcl1s on Mon Jan 29, 2018 12:00 am

Your wiring looks good. Can't see the soldering so hope that is good also. I would break this down and see what is working. If you have not already load the regular Neopixel strandtest to see if it works. File/Examples/Adafruit NeoPixel/strandtest That will confirm if the Neopixels and soldering are OK. Then you can move on to troubleshooting the BLE.

Let us know how it goes.

Fellow Hobbyist
Keith
Bridgeville DE

kcl1s
 
Posts: 603
Joined: Tue Aug 30, 2016 12:06 pm

Re: NEOPIXEL LED Strip, NRF52, Android BLE Control

by kcl1s on Mon Jan 29, 2018 12:08 am

I can control the LED's from the NeoPixel mode, but not from the Color Picker Controller mode.

Sorry. Missed that part. Ignore above. Not sure why the colorpicker is not working for you. The Adafruit support guys should weigh in tomorrow.

Keith

kcl1s
 
Posts: 603
Joined: Tue Aug 30, 2016 12:06 pm

Re: NEOPIXEL LED Strip, NRF52, Android BLE Control

by delawarehunter on Mon Jan 29, 2018 12:20 am

Thanks for the quick reply Keith. Hard to believe of all the people that would read and reply to my post one of them might be from Delaware too.

Anyway, I did try the strandtest and it's working as expected. I also switched back to the BAT post and am powering through my computer USB now and I am able to get the ColorPicker controller working, but only through my Ipad. So, I'm thinking the 5v wall adapter I was using was over driving the LEDs? I still get no response on my Android through the ColorPicker Controller mode. Through the NeoPixel mode, I can now change colors through my Android, however it doesn't change it to the color that I want. Also, what happens is really odd... if I click the red and then tap the button that changes all leds to that color, nothing happens. However, if I tap the "change all" button a few times in a row, it will flash between white and green... again, trying to set the LEDs to red...

That tells me there has to be something wrong with the code... I think? Especially since this is ONLY happening when connected through the BLE Control app on my Android. The Ipad BLE Control App is working perfectly fine...

delawarehunter
 
Posts: 9
Joined: Sun Jan 28, 2018 10:47 pm

Re: NEOPIXEL LED Strip, NRF52, Android BLE Control

by delawarehunter on Mon Jan 29, 2018 8:32 am

Another update: After changing back to the BAT post to power the LEDs, I'm getting some weird effects when changing colors. Sometimes the strip will turn off, sometimes it will only light 6 of the 7 LEDs... So, when I get home this afternoon, I am going to switch back the USB post since I didn't seem to be having any issues at all, at least from my Ipad.

I'm still wondering whether my issue from an android device has something to do with that Pixel Config Register field, or some piece of code that is missing or needs modified in the Neopixel example sketch that I am using.

Also, I mentioned that the Color Picker mode was working from my Ipad. The only way I am able to get that working is if I go into the Neopixel mode first and connect, then back out and go to the Color Picker mode. I can't even try from this method since it seems to me like you have to completely reset the BT connection in order to change modes in the Android app.

delawarehunter
 
Posts: 9
Joined: Sun Jan 28, 2018 10:47 pm

Re: NEOPIXEL LED Strip, NRF52, Android BLE Control

by natewin on Mon Jan 29, 2018 3:01 pm

I'm having a similar problem using the NeoPixel Featherwing 4x8
iPhone app controls the colors just fine using the color picker in the Neopixel tab. No issues with iPhone app at all.
Android results in full white from all LEDs with strange behavior if I pick different colors or brightness. I'm using Android Oreo 8 on a Pixel 2 XL to try and control this.
Serial output using the Android and iPhone apps looks the same. The only thing I can think of that is causing a problem could be the way that Android maintains the bluetooth connection vs iPhone.

natewin
 
Posts: 2
Joined: Mon Jan 29, 2018 10:03 am

Re: NEOPIXEL LED Strip, NRF52, Android BLE Control

by delawarehunter on Mon Jan 29, 2018 3:07 pm

Interestingly enough, I am also using a Pixel 2 XL. However, I am also seeing the issue with my son's Samsung Galaxy Tab 10.1 running Nougat (not sure what version exactly?).

delawarehunter
 
Posts: 9
Joined: Sun Jan 28, 2018 10:47 pm

Re: NEOPIXEL LED Strip, NRF52, Android BLE Control

by delawarehunter on Mon Jan 29, 2018 8:32 pm

After connecting back to the USB post, everything seems to be working fine from my Ipad through the BLE Connect app. I still get random or no response from the Android BLE Connect app.

Just to mention as well, I followed the instructions in the help of the Neopixel mode and exported the sketch, emailed it to myself, and tried to compile it in the Arduino IDE. However, I am getting an error:

Code: Select all | TOGGLE FULL SIZE
Arduino: 1.8.5 (Windows 10), Board: "Adafruit Bluefruit nRF52 Feather, 0.5.0 dual, S132 2.0.1, Level 0 (Release)"

D:\Arduino\Neopixel\Neopixel.ino:12:26: fatal error: Adafruit_BLE.h: No such file or directory

compilation terminated.

exit status 1
Error compiling for board Adafruit Bluefruit nRF52 Feather.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


So, I am not able to do what the app says until I can figure out why it's error on that line...

delawarehunter
 
Posts: 9
Joined: Sun Jan 28, 2018 10:47 pm

Re: NEOPIXEL LED Strip, NRF52, Android BLE Control

by natewin on Tue Jan 30, 2018 12:51 pm

delawarehunter wrote:
Just to mention as well, I followed the instructions in the help of the Neopixel mode and exported the sketch, emailed it to myself, and tried to compile it in the Arduino IDE. However, I am getting an error:



Can you attach that export here? I can't even get it to export on my phone, the app crashes.
Strandtest_BLE also doesn't seem to let me pick a through i in UART mode on Android. iPhone works.

natewin
 
Posts: 2
Joined: Mon Jan 29, 2018 10:03 am

Re: NEOPIXEL LED Strip, NRF52, Android BLE Control

by delawarehunter on Tue Jan 30, 2018 8:12 pm

natewin wrote:
Can you attach that export here? I can't even get it to export on my phone, the app crashes.
Strandtest_BLE also doesn't seem to let me pick a through i in UART mode on Android. iPhone works.


Attached to this post.
Attachments
Neopixel_Arduino.zip
(5.04 KiB) Downloaded 6 times

delawarehunter
 
Posts: 9
Joined: Sun Jan 28, 2018 10:47 pm

Re: NEOPIXEL LED Strip, NRF52, Android BLE Control

by delawarehunter on Thu Feb 01, 2018 8:46 am

Good morning,
I just wanted to bump this and see if anyone has any suggestions or if Adafruit Support has anything I should look at? Did I post this in the wrong forum? Should it be in the Feather forum?

It's pretty frustrating that I can't get the project to work from the Android app but it works great from the IOS app. Any help is greatly appreciated.

delawarehunter
 
Posts: 9
Joined: Sun Jan 28, 2018 10:47 pm

Re: NEOPIXEL LED Strip, NRF52, Android BLE Control

by delawarehunter on Mon Feb 05, 2018 10:53 pm

Sorry to bump this again.. I am trying to be patient waiting for Adafruit support to see my post and offer some sort of help...

If there is a better forum for me to place this post, please let me know and I'll gladly post in the correct spot.

Thanks!

delawarehunter
 
Posts: 9
Joined: Sun Jan 28, 2018 10:47 pm

Re: NEOPIXEL LED Strip, NRF52, Android BLE Control

by sabhuku on Sat Feb 10, 2018 10:50 pm

Faced the same problem and I was able to control the NEOPIXEL LED strip using the Android
Controller app after making some additions to the controller sketch and uploading that onto my NRF52. I figured the changes by looking at the code of the neopixel test sketch.
If you edit the controller sketch, I recommend saving your edited version in a new place as mycontroller or something like that.

Code: Select all | TOGGLE FULL SIZE
//ADDITIONS TO FIX PIXELS NOT LIGHTING UP PART 1 OF 2: Paste under line #include <bluefruit.h>
#define PIN 16  //The pin to which your strip data in pin is connected
#define NUMPIXELS 12 //Edit this to match the number of pixels in your strip
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
//END ADDITIONS TO FIX PIXELS NOT LIGHTING UP PART 1 OF 2


Code: Select all | TOGGLE FULL SIZE
//ADDITIONS TO FIX PIXELS NOT LIGHTING UP PART 2 OF 2:  Must be in display loop. Paste immediately under line Serial.println(blue, HEX);
    for(int i=0;i<NUMPIXELS;i++) {  //loop through all pixels setting to selected color
     pixels.setPixelColor(i, pixels.Color(red, green, blue));
     pixels.show(); 
     }
 //END ADDITIONS TO FIX PIXELS NOT LIGHTING UP PART 2 OF 2

sabhuku
 
Posts: 2
Joined: Sat Feb 10, 2018 10:42 pm

Re: NEOPIXEL LED Strip, NRF52, Android BLE Control

by RossiFan46 on Mon Feb 12, 2018 11:43 pm

Thank you, sabhuku!

That additional code did the trick for me. It did not work at first, so I went into my Bluetooth settings on my Phone and unpaired my feather. Once I re-connected to the Feather using the app, and chose the color picker it then worked.

RossiFan46
 
Posts: 8
Joined: Mon Aug 28, 2017 10:44 pm

Please be positive and constructive with your questions and comments.