9 years, 9 months ago.

UART input

Hei,

I am doing a project that uses multiple buffers. I am feeding UART8 bit input=> DMX512. So from packet 2 bits represent RED intensity and others are spread out for Blue and Green. So effectively UART packets are stored in an array. The bitmapping array is shifting the bits as the WS2812 expects it 24bit, but there comes my big question. What would be the most efficient way to link the DMX buffer with the PixelArray library?

And what would be the most efficient way to link the pointer of an array to a specific LED? My lecturer suggested me placing the serial interrupts on the counter of the packets, but is it the most useful way?

DMX color mappingt

#include "pixelArray.h"


"int ColorMap(int color) {
    uint32_t green;
    uint32_t red;
    uint32_t blue;
   // NeoColor RGB; //type NeoColor now making variable RGB
    
    red   = (11000000 & color) <<8;
    blue  = (00111000 & color) << 2;
    green = (00000111 & color) << 21;
    
   unit32_t rgb = red+blue+green;
   return rgb;
   " 

Buffering the colors

#include "mbed.h"
#include "NeoStrip.h"
#include "DMX.h"

//**
 dmx.start();
 while(1) {
        
        for( i=0 ; i<512 ; i++ ){   //now from address 0 of DMX put in buffer address 0 and so on
             DMXBufRX[i]= dmx.get(i); //indexing array and making = to return value function
             RGBBuf[i] = ColorMap(DMXBufRX[i]);
              //setPixels(DMXBufRX[i]); //returns the RGB color of the function ColorMap read from DMXBuf
             
             //RGBBuf[i]  = ColorMap(dmx.get(i)); shorter way    
    
    // void get (unsigned char *buf, int addr = 0, int len = DMX_SIZE);
//**
    BufferedSerial buf;
    buf.BufferedSerial(DMXTx, DMXRx, UART8RX, UART8TX);

Question relating to:

Control an array or chain of NeoPixel-compatible RGB LEDs. "NeoPixel" is Adafruit's name for WS2812- and WS2811-based addressable RGB LEDs. This library should work with any WS2811- or WS2812-based devices. … NeoPixel, NeoPixels, WS2811, WS2812, WS2812B

1 Answer

9 years, 9 months ago.

The most efficient way would probably be to modify the PixelArray library so that in place of taking 24 bit values it takes 8 bit values and then have the sendPixel function expand that into the 24 bits that the LED needs when it transmits the value. That way you aren't using up any more memory than you need to.

However if you don't want to play with the library then the pixelArray library doesn't use uint_32 for holding 24 bit colours. It uses the PixelInfo structure so your colour map function should return one of those (or ideally a pointer to one) e.g.

void colourMap(pixelInfo *pixel, uint8_t serialByte) {
pixel->red     = serialByte & 0xc0; // 1100 0000 in binary
pixel->green = serialByte & 0x38; // 0011 1000
pixel->blue   = serialByte  & 0x07; // 0000 0111
}

pixelInfo pixelBuffer[10];
main() {
...
count = 0;
while (count < 10) {  // read 10 bytes from serial and store in buffer.
  if (port.readable()) {
    colourMap(&pixelBuffer[count++],port.getc());
  }
}

}

The above waits until it's got 10 bytes of serial data converting them and storing the result in an array as they arrive. I've not put in anything for reading the serial port on an interrupt, there are lots of examples around for using interrupts to reading a uart and storing the results in a buffer.

Accepted Answer