Members | Sign In
All Forums > Development
avatar

DMX controller code

posted Sep 17, 2012 16:36:45 by ThomRobertson
I found the ENTTEC box, bought it, and got it working with Artemis:
http://www.enttec.com/index.php?main_menu=Products&pn=70303&show=description

But clearly I'm just using a serial driver to send messages to the device, and I wanted to share the specifics of what I'm doing.

First, I'm linking against a library and .H file called FTD2XX.

Second, here's two very important functions I mostly copied from example code:




//*******************************************************************************
DWORD WINAPI ArtemisDMXSendFunction(LPVOID args)
{
int i;
ULONG bytesWritten;

// set RS485 for sendin
FT_W32_EscapeCommFunction(ArtemisDMX::ftHandle,CLRRTS);

while (!ArtemisDMX::terminated) {

FT_W32_SetCommBreak(ArtemisDMX::ftHandle);
FT_W32_ClearCommBreak(ArtemisDMX::ftHandle);


FT_W32_WriteFile(ArtemisDMX::ftHandle, &ArtemisDMX::StartCode, 1, &bytesWritten, NULL);
FT_W32_WriteFile(ArtemisDMX::ftHandle, ArtemisDMX::DMXData, 512, &bytesWritten, NULL);

Sleep(ArtemisDMX::inter_frame_delay);
ArtemisDMX::NbFramesSent++;
}

return 0;
}

//*******************************************************************************
void ArtemisDMX::MakeConnections(void)
{
FT_STATUS ftStatus;
char Buf[64];

connected = FALSE;

ftStatus = FT_ListDevices(0,Buf,FT_LIST_BY_INDEX|FT_OPEN_BY_DESCRIPTION);

ftHandle = FT_W32_CreateFile((LPCTSTR)Buf,GENERIC_READ|GENERIC_WRITE,0,0,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL | FT_OPEN_BY_DESCRIPTION,0);

// connect to first device
if (ftHandle == INVALID_HANDLE_VALUE) {
// Application->MessageBoxA("No device","Error",MB_OK);
return;
}

FTDCB ftDCB;
if (FT_W32_GetCommState(ftHandle,&ftDCB)) {
// FT_W32_GetCommState ok, device state is in ftDCB
ftDCB.BaudRate = 250000;
ftDCB.Parity = FT_PARITY_NONE;
ftDCB.StopBits = FT_STOP_BITS_2;
ftDCB.ByteSize = FT_BITS_8;
ftDCB.fOutX = false;
ftDCB.fInX = false;
ftDCB.fErrorChar = false;
ftDCB.fBinary = true;
ftDCB.fRtsControl = false;
ftDCB.fAbortOnError = false;

if (!FT_W32_SetCommState(ftHandle,&ftDCB)) {
// Application->MessageBoxA("Set baud rate error","Error",MB_OK);
return;
}
}

FT_W32_PurgeComm(ftHandle,FT_PURGE_TX | FT_PURGE_RX);

Sleep(1000L);
inter_frame_delay = 30;

DWORD threadId;
CreateThread(NULL, 0, ArtemisDMXSendFunction, 0, 0, &threadId);

eventsRunning = FALSE;
InitEventHandlers();
}



Creator of Artemis
page   1
8 replies
avatar
TomWyatt said Sep 18, 2012 14:46:00
fantastic! Cheers Thom

Looking at the driver code on the Future website it looks like this is driving the FTDI chips directly rather than setting up a Virtual COM port within windows.

I'll have to tinker with it tonight but theres a possibility this might just work with the FTDI chips on the older arduinos. If the chip is being nice and just passing rx/tx out of its pins then its fine, if it doesnt then I'm not sure.
I've got an FTDI232 based serial port adapter that uses the same chipset as the entec, if I can get that to work theres hope for the arduinos etc.

It might be possible to alter the firmware on a Leonardo to work in direct mode as well. I'll post what I find here



avatar
TomWyatt said Sep 23, 2012 15:32:49
Righty! I've had a chance to play with artemis and the USB stuff and theres good news all round!

The driver that the old Arduino Deicemilias use supports artemis! I'm working on a firmware for them now that'll actually *do* something but I can see DMX data hitting their FTDI chips.

I'll post code on my blog and github accounts when i have something more useful
avatar
TomWyatt said Sep 23, 2012 17:17:51
I now have an LED on the arduino that responds to the shield status of the ship :)

Essentially what I've done is set up an arduino sketch that:

1) opens the serial port at 250000 bps
2) continually reads for data

The data comes through as a stream of RGB values from the DMXCommands.xml file, its a bit of a pain t keep track of the stream and know which byte is Red etc

What I've done is remove all of the current event colours and replace the Red values with a unique number while also clearing the GB values. The arduino is then triggering things based on the Red value.

For example

<event type="PLAYER_SHIELDS_ON" continuous="yes">

<!-- steady blue light -->
<timeblock mseconds="1000">
<setvalue index="0" value="2" change="0"/>

the arduino then sets an LED whenever a "2" is received.

avatar
alan.noltensmeyer said Oct 02, 2012 01:23:02
Tom,

Could I have a look at your arduino sketch? I want to see if I can get it working on my arduino Uno.

Thanks,
Alan
avatar
TomWyatt said Nov 05, 2012 14:48:02
Alan: you wont be able to, the Uno uses a reprogrammable Atmega chip for USB comms whereas the older arduinos use the same FTDI chip that the DMX devices do. From Artemis's point of view the Old arduinos are just a DMX device.


In any case I've given up with DMX interface in its current form. Its too limited for what were trying to do!

I've gone back to breaking the network protocol instead as (even without help or documentation) i've managed to pull more of the information I need
avatar
KiranShila said Dec 28, 2012 15:17:33
Can you still post the code? It would be ever helpful.
avatar
onwijzebackup said Jan 31, 2013 20:11:01
The following code does what is mentioned by TomWyatt on a MC-Nove:
int incomingByte = 0;

void setup() {
// initialize serial communication at 250000 bits per second:
Serial.begin(250000);
}

// the loop routine runs over and over again forever:
void loop() {
// read the serial input
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();

if (incomingByte == 2){
// set pin 13 to high if a 1 is received
digitalWrite(13, HIGH);
}

}
}
[Last edited Jan 31, 2013 20:11:50]
avatar
Catscradler said Feb 21, 2013 04:25:51
I spent a few hours getting Artemis to light up some LEDs through my Arduino this past weekend, and it turned out to be pretty straightforward. Here's the process:

  • Unzip the Arduino DMX library found here:
    http://www.mathertel.de/Arduino/DMXSerial.aspx
    to your Arduino libraries folder.
  • Upload the example DmxSerialRecv sketch to your Arduino.
  • Connect red, green and blue LEDs (and appropriate resistors) to pins 9, 6 and 5.
  • That's it. Start Artemis and you've got a basic RGB indicator.

Okay, it was almost that straightforward for me. I have an Uno R3. In recent Arduinos, they dropped the FTDI USB to serial chip in favour of a ATmega16U2. The USB to serial library Thom uses seems to look for any FTDI chip to use as a serial bridge, so I used an FTDI breakout board:
https://www.sparkfun.com/products/9716

The process with that goes:
  • Upload the sketch over the Arduino's USB.
  • Disconnect the Arduino's USB.
  • Connect the FTDI board's TX pin to the Arduino's RX pin, and the FTDI board's RX to the Arduino's TX.
  • Connect the FTDI board's USB to the computer.
  • Power up the Arduino using an external power supply or battery.
  • Start Artemis.

For any further programming of the Arduino, disconnect its RX pin and hook it back up to the computer via USB.


But hey, why stop at getting the basics working? I wanted the red alert to flash. I wanted seperate indicator lights for the various systems. I wanted...actually that's about it for now.
Arduino sketch
DMXcommands.xml
[Last edited Feb 21, 2013 04:30:04]
Login below to reply: