Close

Bluetooth Low Energy controlled Neopixel Matrix

A project log for Oneoffs

Small, quick, oneoff projects

parasquidparasquid 08/09/2020 at 07:070 Comments

I accidentally lifted the pads off of my Ebyte nrf52832 bare module (affiliate link: https://psqd.pw/ebyte-bare ) and that means I won't be able to use it as a development and test board anymore.

That also does mean I can use it on a more permanent fixture, so that's what I did.

I've been looking to have my neopixel matrix more autonomous by connecting it with a wireless microcontroller and having that as a single unit. This ebyte module is perfect to integrate with the matrix, giving me the ability to control it remotely via Bluetooth Low Energy.

I've already installed Espruino on the module, so all I needed was some sticky tack and wires (and a 3v3 regulator I salvaged from another project that didn't quite go as planned).

I added the button because Espruino supports DFU updates and you do that by holding BTN1 (which in this firmware was P14) during bootup.

Here's the javascript program for the BLE control:

const neopixel = require("neopixel");

const rows = 8;
const cols = 8;
const bpp = 24;
const ledCount = 64;
const pin = 25;
const leds = Graphics.createArrayBuffer(
  rows,
  cols,
  bpp,
  {
    zigzag:true,
    color_order: 'gbr'
  }
);
leds.flip = () => { neopixel.write(pin, leds.buffer); };


const scale = (num) => num / 0xFF;

NRF.setTxPower(4);
NRF.setServices({
  "0x181C": {
    "0x2A3D": {
      value: [0,0,0,0,0],
      writable : true,
      description: "sets the value of a pixel: [r, g, b, x, y]",
      onWrite : function(e) {
        const data = new Uint8Array(e.data);
        leds.setColor(scale(data[0]), scale(data[1]), scale(data[2]));
        leds.setPixel(data[3], data[4]);
        leds.flip();
      }
    }
  }
}, { advertise: ['181C'] });


NRF.on('disconnect', function() {
  leds.clear(true);
  leds.flip();
});

E.on('init', function() {
  NRF.setConnectionInterval(7.5);
  console.log("Hello World!");
  leds.clear(true);
  leds.flip();
});

 If you write a byte array of [r, g, b, x, y] to the 0x2A3D characteristic, that particular pixel in the matrix will light up. Disconnecting will clear the whole matrix.

The whole thing was done at the back, so all that really shows up in front is the power cable.

Discussions