WS2812

Artnet, WS2812 and ESP8266 (Arduino IDE)

Posted on Updated on

From my previous post I have updated the program to be compiled from Arduino IDE.

#include 
#include 
#include 

#define WSout 5                                     // Pin D1
#define ARTNET_PORT 6454

#define PIXELCOUNT 100

byte hData[318];

const int number_of_channels=300; //512 for 512 channels

const char* ssid     = "SSID";
const char* password = "PASSWORD";

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(PIXELCOUNT,WSout,NEO_GRB+NEO_KHZ800);

WiFiUDP udp;


IPAddress local_ip(192, 168, 1, 190);
IPAddress gateway_ip(192, 168, 1, 1);
IPAddress subnet_ip(255, 255, 255, 0);

void setup() {
  
  Serial.begin(115200);
  delay(100);
  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());


pixels.begin();

  for(byte i=0;i<PIXELCOUNT;i++){
    pixels.setPixelColor(i, Color(0,0,0));
  }
  pixels.show();
  
}

void loop() {
  if (udp.parsePacket()) {
    udp.read(hData, 318);
    for ( int n=0; n<100; n++){   
     pixels.setPixelColor(n, Color(hData[(n * 3) + 19], hData[(n *3)+20],hData[(n *3)+21]));
    }
   pixels.show();
  }
}

uint32_t Color(byte r, byte g, byte b){
  uint32_t c;
  c = r;
  c <<=8;
  c |= g;
  c <<= 8;
  c |= b;
  return c;
}

The WS2812 data line is connected to D1 from the NODEMCU board.

NODEMCU_D1

Config of the Arduino IDE

config_arduino_1

It looks like it work better than the code in Lua.

This comes from a similar program I did few years ago to run 10 matrices of 10 x 10 pixels. I was using WS2801 led stripes, arduino UNO and ethernet shield.

Everything still runs smooth untill now.

Some photos of matrix installed and the controller running JINX.

Advertisements

ESP8266: Artnet receiver

Posted on Updated on

The other I was playing with a matrix of led. The matrix is made of a stripe of WS2801.

So, here is what I have done.

  1. I flash a new lua based firmware in the ESP8266 using Marcel’s NodeMCU custom build cloud service.
    Add WS2801 and / or WS2812 modules
  2. Wait and download the compiled firmware
  3. Flash it using the tool ESPtool
  4. I use ESPlorer to program the ESP
    1. Create a new ini.lua
    2. Copy the following lines of code.
      This is for a matrix 10×10 “snakelines”

      wifi.setmode(wifi.STATION)
      wifi.sta.config("******","******",1)
      tmr.delay(5000000)   -- wait 1,000,000 us = 1 second
      
      ws2801.init(0, 2)
      tmr.delay(1000000)
      
      ws2801.write(string.char(0,0,0):rep(100))
      
      s=net.createServer(net.UDP)
      s:on("receive",function(s,c) ws2801.write(string.sub (c, 19, 318)) end)
      s:listen(6454)
  5. Use Jinx or Glediator (I prefer Jinx) to drive the matrix and send the Artnet commands to the ESP8266

It works very well.
The code is simple and works well. I haven’t tried on large matrix but I think for larger matrix a fast wifi connection would be needed.