Open DMX

 
 

/* This program allows you to set DMX channels over the serial port.

**

** After uploading to Arduino, switch to Serial Monitor and set the baud rate

** to 9600. You can then set DMX channels using these commands:

**

** <number>c : Select DMX channel

** <number>v : Set DMX channel to new value

**

** These can be combined. For example:

** 100c355w : Set channel 100 to value 255.

**

** For more details, and compatible Processing sketch,

** visit http://code.google.com/p/tinkerit/wiki/SerialToDmx

**

** Help and support: http://groups.google.com/group/dmxsimple       */


#include <DmxSimple.h>



String inputString = "";         // a string to hold incoming data

String inputAString = "";         // a string to hold incoming channel

String inputBString = "";         // a string to hold incoming value

boolean stringComplete = false;  // whether the string is complete

int value = 0;

int channel;

int positionC;



void setup() {

       Serial.begin(115200);

//  Serial.begin(57600);

//    Serial.begin(9600);

  Serial.println("SerialToDmx ready");

  Serial.println();

  Serial.println("Syntax:");

  Serial.println(" 123c : use DMX channel 123");

  Serial.println(" 45w  : set current channel to value 45");


      /* The most common pin for DMX output is pin 3, which DmxSimple

  ** uses by default. If you need to change that, do it here. */

  DmxSimple.usePin(3);


  /* DMX devices typically need to receive a complete set of channels

  ** even if you only need to adjust the first channel. You can

  ** easily change the number of channels sent here. If you don't

  ** do this, DmxSimple will set the maximum channel number to the

  ** highest channel you DmxSimple.write() to. */

//  DmxSimple.maxChannel(4);

 

 

}




/*

  SerialEvent occurs whenever a new data comes in the

hardware serial RX.  This routine is run between each

time loop() runs, so using delay inside loop can delay

response.  Multiple bytes of data may be available.

*/

void serialEvent() {

  while (Serial.available()) {

    // get the new byte:

    char inChar = (char)Serial.read();

    // add it to the inputString:

    inputString += inChar;

    // if the incoming character is a newline, set a flag

    // so the main loop can do something about it:

//    if (inChar == '\n') {

          if (inChar == '\r') {

      stringComplete = true;

    }

  }

}




  int inputCString(String inputXString) {

  int RX;

  int i;


  int X0, X1, X2;

  String inputYString="a";

  char mostSignificantDigit;

 

  positionC = inputXString.indexOf('c');

//  Serial.println(positionC);

 

 

  switch (positionC)  {

    case 0:

      return channel;

    break;



     case 1: 

      mostSignificantDigit = inputXString.charAt(0);

      inputYString.setCharAt(0, mostSignificantDigit);

  //    Serial.println(inputYString);

      X0 = inputYString.toInt();

      RX=X0;

    break;


    case 2:

      mostSignificantDigit = inputXString.charAt(0);

      inputYString.setCharAt(0, mostSignificantDigit);

//     Serial.println(inputYString);

      X0 = inputYString.toInt();

      mostSignificantDigit = inputXString.charAt(1);

      inputYString.setCharAt(0, mostSignificantDigit);

  //    Serial.println(inputYString);

      X1 = inputYString.toInt();

      RX=(X0*10)+X1;

     break; 


    case 3:

      mostSignificantDigit = inputXString.charAt(0);

      inputYString.setCharAt(0, mostSignificantDigit);

      X0 = inputYString.toInt();

      mostSignificantDigit = inputXString.charAt(1);

      inputYString.setCharAt(0, mostSignificantDigit);

      X1 = inputYString.toInt();

      mostSignificantDigit = inputXString.charAt(2);

      inputYString.setCharAt(0, mostSignificantDigit);

      X2 = inputYString.toInt();

      RX=(X0*100)+(X1*10)+X2;

     break; 


   

  }

 

 


 

  return  RX;

 

}




   int inputWString(String inputXString) {

  int RX;

  int i;

  int positionW;

  int X0, X1, X2;

  String inputYString="a";

  char mostSignificantDigit;

 

  positionW = inputXString.indexOf('w');

//  Serial.println(positionW);

  positionW = positionW-positionC-1;

 

 

  switch (positionW)  {

    case 0:

      return channel;

    break;




     case 1: 

      mostSignificantDigit = inputXString.charAt(0+positionC+1);

      inputYString.setCharAt(0, mostSignificantDigit);

      X0 = inputYString.toInt();

      RX=X0;

    break;


    case 2:

      mostSignificantDigit = inputXString.charAt(0+positionC+1);

      inputYString.setCharAt(0, mostSignificantDigit);

      X0 = inputYString.toInt();

      mostSignificantDigit = inputXString.charAt(1+positionC+1);

      inputYString.setCharAt(0, mostSignificantDigit);

      X1 = inputYString.toInt();

      RX=(X0*10)+X1;

     break; 


    case 3:

      mostSignificantDigit = inputXString.charAt(0+positionC+1);

      inputYString.setCharAt(0, mostSignificantDigit);

      X0 = inputYString.toInt();

      mostSignificantDigit = inputXString.charAt(1+positionC+1);

      inputYString.setCharAt(0, mostSignificantDigit);

      X1 = inputYString.toInt();

      mostSignificantDigit = inputXString.charAt(2+positionC+1);

      inputYString.setCharAt(0, mostSignificantDigit);

      X2 = inputYString.toInt();

      RX=(X0*100)+(X1*10)+X2;

     break; 


   

  }

 

 


 

  return  RX;

 

}




void loop() {

  int c;

String string1;

String string2;

String stringOut;



     // print the string when a newline arrives:

  if (stringComplete) {

  //    Serial.println(inputString);

   

    channel=inputCString(inputString);

    value=inputWString(inputString);

   

    DmxSimple.write(channel, value);

   

    string1 = String(channel);

        string2 = String(value);

    stringOut=String(string1 + "c" + string2 + "w");

   

//    Serial.println(stringOut);

  //    Serial.println();

   

    // clear the string:

    inputString = "";

        inputAString = "";

            inputBString = "";

    stringComplete = false;

  }

 

  

}


================================

DMX library for Arduino

http://tinkerit.googlecode.com



https://github.com/Cathedrow/DmxSimple



need to modify include file as following from GitHub downloaded file : DmxSimple.cpp


/**

* DmxSimple - A simple interface to DMX.

*

* Copyright (c) 2008-2009 Peter Knight, Tinker.it! All rights reserved.

*/

#include <avr/io.h>

#include <avr/interrupt.h>

#include <util/delay.h>

#include "pins_arduino.h"


// #include "wiring.h"

#include "Arduino.h"

#include "DmxSimple.h"



===================================


circuit :

differential bus/line transceiver IC. SN 75176 also can use LTC1485, etc.

IC DI need to connect Arduino PIN 3 : D3, in case set Arduino program

DmxSimple.usePin(3);

at Setup ().


this construction used Arduino BT.

also you can use Arduino UNO with Bluetooth serial interface, works same way.

this photo is Bluetooth open DMX hardware interface.

you can make without wireless, just use USB cable with Arduino UNO.


https://pictures.lytro.com/mkahata/pictures/716243


https://pictures.lytro.com/mkahata/pictures/716244


https://pictures.lytro.com/mkahata/pictures/716245

 

Open DMX with Arduino