Control Mote Lights Using JavaScript


#1

Hi,

I’m fairly new here… But I’m running a little app which gathers some cycling performance stats and lights stuff up based on percentage figures. I’ve got it running with the DisplayOTron HAT, but I’m looking to use Mote lights instead on the Pi, or also on a PC/Mac using the Mote host board.

I need to use javascript as that’s what the API I’m doing all the work with uses, so I ‘just’ need to light up the appropriate number of lights on the strips.

Is there a node.js API for mote? I’m trying to work a python call to make it work, but that’s messy as hell, and beginning to get out of my experience :)

EDIT: Can’t seem to delete the request… I’ve worked out how to kick off a python script in the background and pass JSON to it, so not urgent, but would still be much neater with node.js API.


#2

Mote or Mote pHAT? In either case it should be trivial to write one.


#3

Actually both :)

I wish my skill level was at ‘trivial’ for that kind of thing lol. I have managed to get it working using JSON calls to a python script, but as you can guess, it’s a bit messy and clunky for what is essentially a couple of procedure calls. I’d maybe have a bash, but I definitely wouldn’t be able to commit the time to keeping it in sync or updating it afterwards.


#4

As far as I’m aware, there’s a Node.js library for APA102 pixels- which is a good start for the Mote pHAT. Possibly this one: https://www.npmjs.com/package/hooloovoo

The Mote pHAT has 4 pins for selecting which channel to control, and they could be tricky to wrestle control of from the SPI interface though.

This example just uses regular SPI and its own Apa102spi class to control 7 LEDs (for Rainbow HAT): https://github.com/cyberflohr/node-red-contrib-rainbow-hat/blob/master/nodes/rainbow.js

Mote is a little bit trickier, or maybe easier, depending on how you look at it. It communicates over Serial so you could use something like: https://www.npmjs.com/package/serialport

It’s somewhat documented by the library, but the code isn’t easy to follow unless you already know what’s going on: https://github.com/pimoroni/mote/blob/master/python/library/mote/init.py

Any command sent via serial to Mote should start with mote, then there are to commands:

  • c to configure a channel- which should have one byte denoting the channel, and one byte denoting the number of LEDs connected to that channel (usually 16) and one final byte of flags of which there are currently only one: 0b00000001 to indicate gamma correction.

  • o to output the LED data. This is just followed by 3 bytes per pixel of colour data in the order: Blue, Green Red.

You should give it a go ;) I’m always here to field questions.


#5

Sounds doable :) If you hear a pop, a sizzle, and smell smoke, I’ve done it wrong lol

Thanks for the pointers. I’ll see what I can bodge this week!