Artnet multiple universe with Teensy 3 and octows2811 -part 1

EDIT:an error in pasting code in to the blog, whereby symbols were not showing has now been corrected, so it should work, let me know if not…
The setup used the Wiznet 5200 chip badged as 820io.

wiznet 820io module based on 5200 chip
wiznet 820io module based on 5200 chip

this module hooks up to the Teensy via SPI and uses the arduino ethernet library.

The manipulation of large lighting arrays can be enhanced by taking control of the DMX data stream in a more hands-on way. The Artnet protocol is used by a number of lighting software producers (some of them free, such as pixelcontroller, or hook it up to Max output) to package up lighting information in a tidy wrapper that can carry additional information such as commands for specific array sections, as well as the lighting information. The attached code lets you use the Teensy 3.0 and Teensy 3.1 micro controller to receive incoming artnet packages, process them, and send them to an led array.

Here is a forum discussion on the process: http://forum.pjrc.com/threads/24688-Artnet-to-OctoWS2811

artnet = http://en.wikipedia.org/wiki/Art-Net

In this instance the led array consists of cheap ws2811 led pixels controlled by the octows2811 software. This software has been specifically designed to work on the Teensy 3.x, and depending on your ethernet connection, you can get some very good data streaming going. My test was only 60*8 @30fps, but I had a report of much higher when not going through the router over the wireless connection from the laptop.

Here is a sketch to run that will check to see if your teensy is receiving artnet packages from your output software:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// libraries
#include "SPI.h"
#include "stdlib.h"    
#include "Ethernet.h"
#include "EthernetUdp.h"
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//this sketch is a cut down test for receiving Art-net packages via ethernet
// this sketch prints out universe number and frame sequence number to the serial monitor
// set your artnet output device to send to the IP address, use a valid MAC address
// and leave the port address as 6454 (the default port for artnet).
// the sketch should print out the universe number and sequence number
// of received artnet packages. This is confirmed to work with Artnet2 but may need a tweak for
//artnet3.
#define bytes_to_short(h,l) ( ((h << 8) & 0xff00) | (l & 0x00FF) );
 
byte mac[] = {
  0x90, 0xA2, 0xDA, 0x0D, 0x4C, 0x8C} 
; //the mac adress in HEX of ethernet shield or uno shield board
byte ip[] = {
  192, 168, 1, 10}; // the IP adress of your device, that should be in same universe of the network you are using
 
unsigned int localPort = 6454;      // artnet UDP port is by default 6454
 
//buffers
const int MAX_BUFFER_UDP = 768;
char packetBuffer[MAX_BUFFER_UDP]; //buffer to store incoming data
short incoming_universe=0;
EthernetUDP Udp;
 
void setup() {
  Serial.begin(115200);
  //setup ethernet and udp socket
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);
  delay(250);
    Serial.println("end of setup");
    Serial.println("waiting for incoming Artnet to start");
    //if nothing appears after this, then the loop is not receiving your
    //artnet package
}
 
void loop() {
  int packetSize = Udp.parsePacket();
  if(packetSize)
  { Serial.print("Received packet of size ");
    Serial.println(packetSize);
 
  Udp.read(packetBuffer,MAX_BUFFER_UDP);
  Serial.print(packetBuffer);
  Serial.print("  ");
   //-------read incoming universe and sequence number to check for data series-------------//
        incoming_universe=bytes_to_short(packetBuffer[15],packetBuffer[14])
        Serial.print("universe number = ");
        Serial.print(incoming_universe);
        byte sequence = packetBuffer[12];
        Serial.print("  ");
        Serial.print("sequence n0. = ");
        Serial.println(sequence);
  }
}