Go Down

Topic: ArtNet to WS2812 Pixel LED driver : Using Wemos D1 (arduino-esp8266) (Read 7695 times) previous topic - next topic

mcnobby

Hi Tom,
I am currently up to 32 universes of SPI driven LEDs in one continuous line
I have tested 16 universes (split on 4 ports) at 25Hz refresh and there is no glitching
I make these up into finished products which people buy off me
Good Luck
Bob
http://www.youtube.com/user/Recovered
http://www.smartshow.lighting

DanBendavid

@ mcnobby

Hello and thank you for this great code.

I am using Jinx with ESP8266-01 with a frame of 10x10 WS2812 and the ArnetArduino (It works fine).

I am also using the McLighting with another ESP (https://github.com/toblum/McLighting) wich is a very nice webserver including more than 50 effects.

My goal is to combine both features, i.e., using 1 ESP  with McLighting Webserver (websocket), plus  a switching link to allow me to activate the Artnet (For Jinx, using UDP)

I now that websocket and UDP are difficult to manage together ... 

Any idea ?

Thank you very much for your help

Dan



 

mcnobby

I also use UDP and HTTP in the same program, but never at the same time (kind of...)

I use a 0.5 sec timer that only times-out when artnet UDP has stopped running.
Once timed-out I then check for HTTP requests.
If during the time-out an artNet UDP packet arrives, the timer is reset and HTTP requests are ignored until the the artnet stops again
http://www.youtube.com/user/Recovered
http://www.smartshow.lighting

mcnobby

Project has now been expanded to handle 32 universes of Pixel data from Jinx, splitting the output over 8 pins (4 consecutive universes per pin)
http://www.youtube.com/user/Recovered
http://www.smartshow.lighting

camilozk

ey mcnobby!

I am trying out your amazing code, and it is working nicely, but there are 2 weirds things going on:

The first pixel is always displaying some degree of green, regardless what I send  there is always a little bit of green. I tried different strips and I always get the same result.

Also, specially in the first pixel but not exclusively, there is some flickering. I trid with and without a 470Ohm resistor and it flickers both ways.

I copy the code as I am using it here:

Code: [Select]

/*
  SmartShow AirPixel ONE - Single Universe ArtNet to WS2812 Driver - For Wemos D1
  You can set the Device IP, and universe number below
  Works perfectly with Jinx LED software
*/

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

#define WSout 5  // Pin D1
#define WSbit (1<<WSout)

// ARTNET CODES
#define ARTNET_DATA 0x50
#define ARTNET_POLL 0x20
#define ARTNET_POLL_REPLY 0x21
#define ARTNET_PORT 6454
#define ARTNET_HEADER 17

WiFiUDP udp;

uint8_t uniData[514];
uint16_t uniSize;
uint8_t hData[ARTNET_HEADER + 1];
uint8_t net = 0;
uint8_t universe = 0;
uint8_t subnet = 0;

const char* ssid     = "ARTNET_LINK";
const char* password = "M-Tork144";

IPAddress local_ip(2, 0, 0, 22);
IPAddress gateway_ip(2, 0, 0, 1);
IPAddress subnet_ip(255, 0, 0, 0);

void setup() {
  Serial.begin(115200);
  delay(10);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);
  WiFi.config(local_ip, gateway_ip, subnet_ip);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  udp.begin(ARTNET_PORT); // Open ArtNet port

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  pinMode(WSout, OUTPUT);
}



void ICACHE_FLASH_ATTR sendWS() {
  uint32_t writeBits;
  uint8_t  bitMask, time;
  os_intr_lock();
  for (uint16_t t = 0; t < uniSize; t++) { // outer loop counting bytes
    bitMask = 0x80;
    while (bitMask) {
      // time=0ns : start by setting bit on
      time = 4;
      while (time--) {
        WRITE_PERI_REG( 0x60000304, WSbit );  // do ON bits // T=0
      }
      if ( uniData[t] & bitMask ) {
        writeBits = 0;  // if this is a '1' keep the on time on for longer, so dont write an off bit
      }
      else {
        writeBits = WSbit;  // else it must be a zero, so write the off bit !
      }
      time = 4;
      while (time--) {
        WRITE_PERI_REG( 0x60000308, writeBits );  // do OFF bits // T='0' time 350ns
      }
      time = 6;
      while (time--) {
        WRITE_PERI_REG( 0x60000308, WSbit );  // switch all bits off  T='1' time 700ns
      }
      // end of bite write time=1250ns
      bitMask >>= 1;
    }
  }
  os_intr_unlock();
}

void loop() {
  if (udp.parsePacket()) {
    udp.read(hData, ARTNET_HEADER + 1);
    if ( hData[0] == 'A' && hData[1] == 'r' && hData[2] == 't' && hData[3] == '-' && hData[4] == 'N' && hData[5] == 'e' && hData[6] == 't') {
      if ( hData[8] == 0x00 && hData[9] == ARTNET_DATA && hData[15] == net ) {
        if ( hData[14] == (subnet << 4) + universe ) { // UNIVERSE
          uniSize = (hData[16] << 8) + (hData[17]);
          udp.read(uniData, uniSize);
          //Serial.print("ArtNet packet RX Uni 0 - size:");
          //Serial.println(uniSize);
          sendWS();
        }
      } // if Artnet Data
    }
  }
}


Did you already posted the project that handles 32 universes?

Also, is there no way to control the rgb order in the sketch right? The order is not correct as we speak.


Thank you so much for this!

mcnobby

Hi cam...

I have a few improvements to get over the green flicker (you think you have flicker with only one universe ? I gets harder to remove with 32 universes !! lol) The green flicker is related to the very first bit of the first byte of the first pixel's data...

Firstly, you could try removing the ICACHE_FLASH_ATTR  from sendWS()

Alternatively, compile the code to run at at 160MHz and adjust the time= values within sendWS() (time=6 might work for all of them !)

or, remove a few of the conditional checks for "Art-Net" within the header


I found that this annoying flicker is when there doesnt seem to be enough time to 'get the job done' and the wifi rx code interrupts in places where it shouldnt

Have a try !
http://www.youtube.com/user/Recovered
http://www.smartshow.lighting

camilozk

thank you very much for answering!

I will check it out with a bit more detail, but I have to confess that at first time it doesnt seem to be something that I can handle with my level of knowledge. Nevertheless, I will give it a try and I would be very happy if you could share any progress yo do!

thanks again!

mcnobby

One line you could change is this...

instead of
Code: [Select]
uniSize = (hData[16] << 8) + (hData[17]);

use this
Code: [Select]
if (!uniSize) {
  uniSize = (hData[16] << 8) + (hData[17]);
}


This will only ever calculate the length of the universe once when the first one is received, this will cut down the number of calculations required per packet received and speed up the loop()  (if you ever happen to change the length of the universe (or number of pixels etc, then you will need to reboot the device)
http://www.youtube.com/user/Recovered
http://www.smartshow.lighting

kollimann

Sorry for my bad englich.

Has Anybody the Code from "mcnobby" expanded that i can drive 800 Pixels on 2 Pins and more Universe?

I understand the Answers not in the Posts.

Thanks Heiko

patdev

Hi Tom,
I am currently up to 32 universes of SPI driven LEDs in one continuous line
I have tested 16 universes (split on 4 ports) at 25Hz refresh and there is no glitching
I make these up into finished products which people buy off me
Good Luck
Bob
Hi Bob, thanks for sharing your knowledge and you current code running on a esp8266 module. I was wondering what you mean with "32 universes of SPI driven LEDSs in one continuous line?

I am trying to drive 1200 leds from jinx or glediator. I understand that i need 3600 channels over multiple universes.

Is it possible to sent all receveived information at once just to 1 port on D1 on which all the leds (in my case 1200) are connected as one string. And is it then able to achieve a refreshrate of 25 fps. Or do i need to split it over multliple strings connected to multiple ports.

I understand the trick of using multiple universes and storing in a 2-dimensional array. But i am puzzling with sending the information to the leds

Thanks Patrick


mcnobby

PatDev

there is a physical limit of sending NRZ data to WS2812 LEDs at 25Hz, you will get about 680 pixels refreshed in that time (which will take about 25ms), so splitting over multiple strings and doing both strings at the same time is the right approach, althought this gets complex !

Bob
http://www.youtube.com/user/Recovered
http://www.smartshow.lighting

patdev

Hi Bob,

Thanks for answering. I am currently able to write to 6 strips (6 x 120) using three ports. Someway i can't find any more available ports on the board. Other ports are not working somehow? Currently i am looking at expanding to 9 strips. But at the moment i am getting unstable results and looking how to speedup sending the nrz code.

Curious how you managed to sent 32 universes over 4 ports.

I am experimenting with asm code now.

mcnobby

I managed to send out 4 universes on each of 8 pins
I had to do this in parallel, by working out if each port is hi or lo at any instance, then once all bits are ready I wrote to the port. The big problem for me was writing it so that all universe can be a different length if required, so then I had to write a Universe Manager. I had to upgrade to 160Mhz and fine tune my code so that reading 32 uni and writing 32 uni do not conflict. It is as smooth as silk now :)
http://www.youtube.com/user/Recovered
http://www.smartshow.lighting

patdev

I managed to send out 4 universes on each of 8 pins
I had to do this in parallel, by working out if each port is hi or lo at any instance, then once all bits are ready I wrote to the port. The big problem for me was writing it so that all universe can be a different length if required, so then I had to write a Universe Manager. I had to upgrade to 160Mhz and fine tune my code so that reading 32 uni and writing 32 uni do not conflict. It is as smooth as silk now :)
Still need a lot of work and puzzling to do on my side. Do you need a betatester ;-)

mcnobby

Still need a lot of work and puzzling to do on my side. Do you need a betatester ;-)
I have several beta testers, and many of these running LED panels in various places round the world ;)
http://www.youtube.com/user/Recovered
http://www.smartshow.lighting

Go Up