You are reading a single comment by @Jorgen and its replies. Click here to read the full conversation.
  • I have some trouble writing data to APA102 LED strip.
    In my example I just do the same as the documentation said.

    1. 4 bytes of 0x00 as a start frame.
    2. For each LED, a brightness byte (0xE0 + value), a blue value byte, a green value byte, and a red value byte.
    3. (N/2)/8 bytes of 0xFF as an end frame, where N is the number of LEDs.

    result is following source:

    SPI2.setup({mosi:B15, sck:B13, baud:4000000});
    
    var NumLEDs = 150;
    var leds = new Uint8Array(NumLEDs*4);
    
    function draw() {
      var millis = getTime();
    
      var r = Math.random()*255;
      var g = Math.random()*255;
      var b = Math.random()*255;
      for (var pixel = 0; pixel < leds.length; pixel+=4)
      {
        leds[pixel+0] = 0xE0 | 5;
        leds[pixel+1] = b;
        leds[pixel+2] = g;
        leds[pixel+3] = r;
      }
      write_leds(leds, NumLEDs);
    }
    
    function write_leds(leds, numLeds) {
      var halfLed = numLed/16 + 1; // compute end frame length
      var maxIndex = numLed * 4; // maximum leds row index;
      var index; 
      SPI2.write(0x00);
      SPI2.write(0x00);
      SPI2.write(0x00);
      SPI2.write(0x00);
      
      // LED Frame
      for (index = 0; index < maxIndex; index+=4) {
        SPI2.write(leds[index+0]);  // global brigthness 
        SPI2.write(leds[index+1]);  // B
        SPI2.write(leds[index+2]);  // G
        SPI2.write(leds[index+3]);  // R
      } // for all leds
    
      // End Frame
      for (index = 0; index < halfLed; index++) {
        SPI2.write(0xFF);
      } // for end frame
    } // write_leds()
    
    function onInit() {
      setInterval(draw, 50);
    }
    
    onInit();
    

    But it seems that the data I send is not the data I see.
    Also if I change the pixel data to show only red pixels; there is always a kind of random colors to see :/

    Hope someone can help me here to fix the problem.

About

Avatar for Jorgen @Jorgen started