Neopixel and Firmata

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
AKSoapy29
 
Posts: 39
Joined: Sat Jan 07, 2012 6:56 pm

Neopixel and Firmata

Post by AKSoapy29 »

Hi. I have a project that uses an Arduino Uno and Firmata, and I was wondering if it is possible to modify Firmata to use the Adafruit Neopixel library, or if there is any way to use Neopixels without modifying. Has anyone ever done this before?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Neopixel and Firmata

Post by adafruit_support_rick »

You can't drive neopixels directly with Firmata. However, you could arrange a simple protocol. For example, you could use the Firmata sendSysex function to send a set of pixel colors. The Arduino would need a simple loop to assign the pixel colors.

AKSoapy29
 
Posts: 39
Joined: Sat Jan 07, 2012 6:56 pm

Re: Neopixel and Firmata

Post by AKSoapy29 »

Alright. I think I might be able to send the message, but how do I receive it in Firmata and do something with it?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Neopixel and Firmata

Post by adafruit_support_rick »

Please refer to the Firmata documentation:
http://arduino.cc/en/reference/firmata
sendSysex sends an arbitrary array of bytes. You implement a sysex callback function, and attach it to Firmata using the attach function:
attach(byte command, callbackFunction myFunction)
attach a function to an incoming message type
where "command" is "SYSEX_START" and "myFunction" is the name a function of the form
void sysexCallbackFunction(byte pin, byte byteCount, byte *arrayPointer);
In your loop function, call processInput to dispatch incoming messages to your callback function:

Code: Select all

    while(Firmata.available()) {
        Firmata.processInput();
    }
You format the data in the array any way you like. Simplest would be a series of r, g, b values, one for each NeoPixel. Then you can just loop through the array and write each set of r, g, b to each pixel in your system.

User avatar
christopherv
 
Posts: 32
Joined: Wed Jan 08, 2014 4:56 pm

Re: Neopixel and Firmata

Post by christopherv »

To get the WS2812's 800KHz timing right, the Adafruit_NeoPixel library resorts to assembly code. Has anyone actually implemented this in the context of the Firmata protocol? I'd like to have students program NeoPixel rings using Scratch (scratchx.org) and would prefer not to reinvent the wheel if it's already been done! Thanks.

User avatar
t_serkov
 
Posts: 7
Joined: Sat Jul 11, 2015 1:30 pm

Re: Neopixel and Firmata

Post by t_serkov »

Hello, I'm also trying to make some light over Firmata and Neopixel library.
Presently nothing works, what am I doing wrong?

Code: Select all

#include <Adafruit_NeoPixel.h>

#include <Firmata.h>

#define PIN            6
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      16
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

//void sysexCallbackFunction(byte pin, byte byteCount, byte *arrayPointer);

void sysexCallback(byte num, byte argc, byte *argv)
{
  pixels.begin();
  pixels.setPixelColor(num, pixels.Color(argc, argc, argv[1]));
}

void setup() {
  // put your setup code here, to run once:
  Firmata.attach(START_SYSEX, sysexCallback);
  Firmata.begin();
}

void loop() {
  // put your main code here, to run repeatedly:
  while (Firmata.available()) {
    Firmata.processInput();
  }
}

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Neopixel and Firmata

Post by adafruit_support_rick »

When you say, "nothing works", what exactly do you mean? Are you getting compilation errors? Does it compile and upload but the NeoPixels don't respond?

Your callback isn't right. argc is the argument count. And you want pixels.begin in setup, not in your callback. You should be doing this:

Code: Select all

void sysexCallback(byte num, byte argc, byte *argv)
{
  pixels.setPixelColor(num, pixels.Color(argv[0], argv[1], argv[2]));
}

void setup() {
  // put your setup code here, to run once:
  pixels.begin();
  Firmata.attach(START_SYSEX, sysexCallback);  //shouldn't this be SYSEX_START?
  Firmata.begin();
}


Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”