Jump to content
  • 0

Using A Teensy As Art-Net Device For Dof


Westworld

Question

My usage:
As the discussed controller is not available yet and I don't want to wait, I try creating my own. This mail describes the first steps, using a Teensy as controller for lamps, LEDs, etc.
 
 
Background:
A Teensy is similar to an Arduino a tiny, low cost microprocessor with many Input/Output Pins with digital (one/off) or analog (PWM) output.
 
Compared to Arduino it is more powerful - and more expensive.
While you get an Arduino clone for $5, a Teensy 3.1 is $20.
But you get plenty of features for that:
72 MHZ - fast enough to drive several long ledstrips
128 kb Flash, 16 kb Ram (compared to 2-8 kb of Arduino. 16kb is needed to handle 1000 LED's - array of 4 byte * 1000 = 4kb, too much for Arduino)
34 digital I/O Pins
And a fully controllable USB (acting as HID device to simulate keyboard, joystick, serial or raw, no driver needed)
Even smaller as an Arduino Nano/Micro, it still has more GPIOs (some not useable for breadboard, only soldered).
 
While I want to use it for Ledstrips only, it could also be used for other stuff, like lamps or motors (you need power driver or relay to handle that, the Teensy can handle only 3V with 60mA) or buttons (acting in parallel via USB and Ethernet).
 
 
This tutorial is covering to handle LED's as placeholder, just as prove of concept and help for others to do first steps.
 
To follow this steps, you need hardware:
- Teensy 3.1 (I purchased with header pins to avoid soldering)
- USB cable (Micro USB)
- Ethernet shield. I used one with ENC28J60. You can get one on ebay for < $5. Google for ENC28J60 and Arduino. This is cheaper as the standard Arduino shield (Using W5100). If you already have one based on W5100, you can of course also use this one. The ENC28J60 uses other libraries, you need to slightly modify the following code example.
- Breadboard + some wires
- 2 LED's (any color)
- 2 resistors, like 220 Ohm
 
Connect the stuff following the enclosed picture.
 
For Teensy<->ENC28J60:
GND 1 <-> GND
3.3V 24 - VCC
CS  10 <-> CS
DOut 11 <-> SF
DIn 12 <-> SO
SCK 13 <-> SCK
 
2 connectors of the ENC28J60 are not used.
 
For LED's:
The short leg goes to minus!
 
 
Now for the software:
Download Arduino development kit from 
Download Teensyduino
This goes as plugin in Arduino, allows to use the standard Arduino development tool, no need to learn something different.
 
If you are new to that, start with the tutorial on that page and do a LEDblink first:
 
 
To make the Teensy to act as Art-Net controller, we need two libraries:
- Ethernet 
- Artnet
 
If you are using a W5100 based Ethernet shield, you can use the standard library.
For ENC28J60 download:
arduino_uip
Click on Download Zip
Expand it, remove the word "-master", so the folder is named "arduino_uip"
Move that folder inside the library folder of your arduino documents.
On OS X that's a path like "/Users/Westworld/Documents/Arduino/libraries"
On Windows inside your documents folder.
 
For Artnet download:
Follow the description as above, rename the folder and move it into your Arduino/Libraries folder.
Now rename it Artnet_uip, as we need to modify it.
Note: if you use a W5100 based ethernet shield, you do not need to do this steps!
 
In Artnet.h replace:

#include <Arduino.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
 
with:

#include <Arduino.h>
#include <UIPEthernet.h>
//#include <EthernetUdp.h>
 
rename it from Artnet.h to UIPArtnet.h
 
In Artnet.cpp:
replace:
#include <Artnet.h>
 
with:
#include <UIPArtnet.h>
 
Save it as UIPArtnet.cpp
 
 
For any kind of ethernet shield, you need to modify Artnet.cpp or UIPArtnet.cpp to fix a bug:
 
Line 44:
      for (byte i = 0 ; i < 9 ; i++)
      
replace with: 
     
      for (byte i = 0 ; i < 7 ; i++)
 
 
Finally the sketch to run all that:

/*
This is a basic example that will print out the header and the content of an ArtDmx packet.
This example uses the read() function and the different getter functions to read the data.
This example may be copied under the terms of the MIT license, see the LICENSE file for details
*/


#include <UIPEthernet.h>
#include <UIPArtnet.h>
//#include <EthernetUdp.h>
#include <SPI.h>


Artnet artnet;


// Change ip for your setup - you can keep the MAC address or modify it
byte ip[] = {192, 168, 0, 200};
uint8_t mac[] = {0x04, 0xE9, 0xE5, 0x00, 0x69, 0xEC};


const int ledPin1 = 23;
const int ledPin2 = 22;


void setup()
{
  Serial.begin(115200);
  artnet.begin(mac, ip);
  Serial.println("start");
   pinMode(ledPin1, OUTPUT);
   pinMode(ledPin2, OUTPUT);


  digitalWrite(ledPin1, HIGH);   // set the LED on
  for(int i=0;i<256;i++) {
      analogWrite(ledPin2, i);
      delay(10);
  }


  digitalWrite(ledPin1, LOW);    // set the LED off
  analogWrite(ledPin2, 0);    // set the LED off


}


void loop()
{
  if (artnet.read() == ART_DMX)
  {
    // print out our data - debug only
    Serial.print("universe number = ");
    Serial.print(artnet.getUniverse());
    Serial.print("\tdata length = ");
    Serial.print(artnet.getLength());
    Serial.print("\tsequence n0. = ");
    Serial.println(artnet.getSequence());
    Serial.print("DMX data: ");
    for (int i = 0 ; i < artnet.getLength() ; i++)
    {
      Serial.print(artnet.getDmxFrame()[i]);
      Serial.print("  ");
    }
    Serial.println();
    Serial.println();
    
    if (artnet.getLength() > 1) {
      if (artnet.getDmxFrame()[0] > 0)
          digitalWrite(ledPin1, HIGH);   // set the LED on
      else
          digitalWrite(ledPin1, LOW);   // set the LED on


      analogWrite(ledPin2, artnet.getDmxFrame()[1]); 
    }


  }
}
 
 
Look for:
byte ip[] = {192, 168, 0, 200};
 
replace that with a free address in your local network.
 
Compile and transfer to your Teensy.
It will reboot, then one LED will be fully on, the second will slowly go from off to full y on - then both off.
 
Now either use your cabinet/Virtual Pinball and DOF to test it - or a Art-Net test application (like free DMX-ArtNET-controller from http://www.robe.cz/, for Mac or Windows)
 
Use any Universe, channel 1 and 2. Note: this simple code respond to any universe, it does not check it.
Channel 1 is off for 0, one for any other value
Channel 2 is covering 0-255 (analog).
 
In doubt use the serial monitor from the Arduino software.
This will give you a report for every received packet - with all values (all 512 values, not just the 2 we are using) - and for every universe.
Great for debugging...
 
As soon everything works, take the code and remove every Serial.xxxx line. This was just for debugging.
Also remove in Setup() the on/off code, which is there only for testing.
 
If you don't know how to use Art-Net in DOF, this beginners tutorial might help:

post-72-0-55899500-1442426711_thumb.png

post-72-0-22024500-1442426715_thumb.png

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

A simple setup as here, with just 8-16 lamps, works as well with Arduino. Even a Micro, no need for Mega.

You need any kind of Ethernet device, with either W5100 or ENC28J60 chip. (Use different version of library, as described in first mail).

 

In both cases, Arduino or Teensy, the power is not enough to drive lamps, only leds. You need a transistor to increase power. Mine are ordered, I'll write an update as soon I get them.

 

I choosed a Teensy because I want to connect ledstrips and the Teensy has so much more power than an Arduino, for just 5-10 Euro more...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
  • Create New...