FPC RGB+W LEDs

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

FPC RGB+W LEDs

Zaaphod
I'm thinking about making a controller for SK6812 Individually addressable RGB+W Led strips, perhaps something I can run on a Raspberry Pi.  I'm curious if anyone has any example routines that do the output timing for Individually addressable LED strips?

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FPC RGB+W LEDs

Christo Crause
A user space library written in C: https://github.com/jgarff/rpi_ws281x

On Thu, Oct 24, 2019 at 3:54 PM James Richters <[hidden email]> wrote:
I'm thinking about making a controller for SK6812 Individually addressable RGB+W Led strips, perhaps something I can run on a Raspberry Pi.  I'm curious if anyone has any example routines that do the output timing for Individually addressable LED strips?

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FPC RGB+W LEDs

Jean SUZINEAU
In reply to this post by Zaaphod
May be it's not exactly what you are search for, but two years ago I used an Arduino with an Ethernet shield to control this kind of LED Strip.

I join below the content of the main file, just 111 lines.  It's very easy to control the led strip from arduino. Contrary to the comments , it seems I modified the code to use Adafruit DotStar library instead of NeoPixel library. I made the arduino part and the system was used for a show through the software Madmapper on Apple, connected to the arduino through the Artnet protocol other Ethernet. I took my last version of the code, I'm relatively confident it's the good one.

================

#include <Adafruit_DotStar.h>

/*
This example will receive multiple universes via Artnet and control a strip of ws2811 leds via
Adafruit's NeoPixel library: https://github.com/adafruit/Adafruit_NeoPixel
This example may be copied under the terms of the MIT license, see the LICENSE file for details
*/

#include <Artnet.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>

// Neopixel settings
const int numLeds = 60; // change for your setup
const int numberOfChannels = numLeds * 3; // Total number of channels you want to receive (1 led = 3 channels)
#define DATAPIN    4
#define CLOCKPIN   5
Adafruit_DotStar leds = Adafruit_DotStar(numLeds, DATAPIN, CLOCKPIN, DOTSTAR_BRG);

// Artnet settings
Artnet artnet;
const int startUniverse = 1; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0.

// Check if we got all universes
const int maxUniverses = numberOfChannels / 512 + ((numberOfChannels % 512) ? 1 : 0);
bool universesReceived[maxUniverses];
bool sendFrame = 1;
int previousDataLength = 0;

// Change ip and mac address for your setup
byte ip[] = {192, 168, 1, 57};
byte mac[] = {0x04, 0xE9, 0xE5, 0x00, 0x69, 0xEC};
byte broadcast[] = {10, 0, 1, 255};
void setup()
{
  //Serial.begin(115200);
  artnet.begin(mac, ip);
  leds.begin();
  artnet.setBroadcast(broadcast);
  initTest();

  // this will be called for each packet received
  artnet.setArtDmxCallback(onDmxFrame);
}

void loop()
{
  // we call the read function inside the loop
  artnet.read();
}

void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data, IPAddress remoteIP)
{
  sendFrame = 1;
  // set brightness of the whole strip
  if (universe == 15)
  {
    leds.setBrightness(data[0]);
    leds.show();
  }

  // Store which universe has got in
  if ((universe - startUniverse) < maxUniverses)
    universesReceived[universe - startUniverse] = 1;

  for (int i = 0 ; i < maxUniverses ; i++)
  {
    if (universesReceived[i] == 0)
    {
      //Serial.println("Broke");
      sendFrame = 0;
      break;
    }
  }

  // read universe and put into the right part of the display buffer
  for (int i = 0; i < length / 3; i++)
  {
    int led = i + (universe - startUniverse) * (previousDataLength / 3);
    if (led < numLeds)
      leds.setPixelColor(led, data[i * 3], data[i * 3 + 1], data[i * 3 + 2]);
  }
  previousDataLength = length;

  if (sendFrame)
  {
    leds.show();
    // Reset universeReceived to 0
    memset(universesReceived, 0, maxUniverses);
  }
}

void initTest()
{
  for (int i = 0 ; i < numLeds ; i++)
    leds.setPixelColor(i, 127, 0, 0);
  leds.show();
  delay(500);
  for (int i = 0 ; i < numLeds ; i++)
    leds.setPixelColor(i, 0, 127, 0);
  leds.show();
  delay(500);
  for (int i = 0 ; i < numLeds ; i++)
    leds.setPixelColor(i, 0, 0, 127);
  leds.show();
  delay(500);
  for (int i = 0 ; i < numLeds ; i++)
    leds.setPixelColor(i, 0, 0, 0);
  leds.show();
}

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FPC RGB+W LEDs

Zaaphod
In reply to this post by Christo Crause

I got my Raspberry pi working with the user space library written in C: at  https://github.com/jgarff/rpi_ws281x with python and got my LED strip to light up with the examples.  I also have FPC 3.0.4 installed on the pi.   I would really like to be able to use the C library with FPC.   I have some other C libraries that I’ve managed to use with FPC, but those were .dlls, but this doesn’t have .dlls.  Would accessing this from FPC even be possible?  And if so does anyone have an example of some C library that doesn’t have .dlls being accessed from FPC?

 

 

James

 

From: fpc-pascal <[hidden email]> On Behalf Of Christo Crause
Sent: Thursday, October 24, 2019 11:25 AM
To: James Richters <[hidden email]>
Cc: FPC-Pascal users discussions <[hidden email]>
Subject: Re: [fpc-pascal] FPC RGB+W LEDs

 

>A user space library written in C: https://github.com/jgarff/rpi_ws281x

 

On Thu, Oct 24, 2019 at 3:54 PM James Richters <[hidden email]> wrote:

I'm thinking about making a controller for SK6812 Individually addressable RGB+W Led strips, perhaps something I can run on a Raspberry Pi.  I'm curious if anyone has any example routines that do the output timing for Individually addressable LED strips?


_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FPC RGB+W LEDs

Jean SUZINEAU
It's possible but I've done it many years ago, I don't remember all the details .


From what I see from main.c, I think you'll have to convert the following headers:
#include "clk.h"
#include "gpio.h"
#include "dma.h"
#include "pwm.h"
#include "version.h"
#include "ws2811.h"
And I guess you'll have to add something like {$linklib libws2811.a}  (after looking at https://github.com/rpi-ws281x/rpi-ws281x-python/blob/master/library/Makefile )

May be too if you have object files *.o you can link them with something like {$L ws2811.o}

A tutorial showing how to use object-code and libraries created in C (I found it from https://wiki.lazarus.freepascal.org/Creating_bindings_for_C_libraries )

Le 31/10/2019 à 20:32, James Richters a écrit :

I got my Raspberry pi working with the user space library written in C: at  https://github.com/jgarff/rpi_ws281x with python and got my LED strip to light up with the examples.  I also have FPC 3.0.4 installed on the pi.   I would really like to be able to use the C library with FPC.   I have some other C libraries that I’ve managed to use with FPC, but those were .dlls, but this doesn’t have .dlls.  Would accessing this from FPC even be possible?  And if so does anyone have an example of some C library that doesn’t have .dlls being accessed from FPC?



_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal