Hi @hughqelliott,
If you’d like to set up Pixelblaze for use with a matrix, it can totally do that (let me know). But I’ll cover the output expander with an Arduino UNO here.
The driver was written for an esp8266, but it should work on your Uno with a little work. The key thing is to swap out Serial1
references with your Serial
instance.
You can swap out the serial instances with a hack like this near the top of the PBDriverAdapter.cpp
file:
#define Serial1 Serial
Or you can search and replace the instances in the code.
Now the Uno has a single hardware serial port called Serial
that is also connected to the USB serial bridge that is used for the monitor and programming. Thats OK, but if you want to use it for the output expander, the baud rate has to be set to 2000000
(which is covered in the driver code), which is just within the capabilities of your Arduino. If you connect the monitor it will show mostly garbage generated by the driver, but aside from that it should work, and when you reprogram your Arduino, the output expander will ignore what it sees so you shouldn’t have to disconnect anything.
OK, on to setting up the driver.
The driver works on a list (the vector
type) of channels. It uses some fancy C++ stuff to handle pointers automatically. To make a new vector of channels, say for just 1 of them, and configure the first channel, do something like this:
const int count = 1;
std::unique_ptr<std::vector<PBChannel>> channelsPointer(new std::vector<PBChannel>(count));
auto vector = *channelsPointer;
vector[0].channelId = 0; //which ID is this talking about? For multiple expander boards, the boardId * 8 is added
vector[0].startIndex = 0; //first pixel index to render (used in the callback)
vector[0].header.numElements = 3; //RGB=3, RGBW=4
vector[0].header.redi = 0; //red first
vector[0].header.greeni = 1; //green
vector[0].header.bluei = 2; //blue last
vector[0].header.pixels = 100;
pbDriverAdapter.begin();
pbDriverAdapter.configureChannels(std::move(channelsPointer));
Now that the driver is configured, we can render some pixels. This will run a callback function for each pixel, and when done it will send it to the output expander. When all pixels on all channels are done, it will issue the draw command, and all channels on all expanders will send data to the LEDs.
The show
function is the same as the other drivers, so I’m going to borrow an example for an APA102 driver only slightly modified:
void loop() {
for (int counter = 0; counter < NUM_PIXELS; counter++) {
pbDriverAdapter.show(NUM_PIXELS, [counter](uint16_t index, uint8_t rgbv[]) {
//if color order is set right, this should show a bright red pixel on dim green background
if (counter == index) {
rgbv[0] = 255;
} else {
rgbv[1] = 1;
}
});
delay(100);
}
}
The callback passed to show()
above is going to draw a red pixel and chase that along the length of the strip. If you had a buffer that had pixel data in it, you could simply copy from it there instead.