DMX - Arduino and Processing 2 channel output

edited March 2017 in Arduino

Hi all, I have an Ardunio with a DMX breakout connected to a dimmer pack. From this pack there are 2 different light outputs on different DMX channels. The Arduino is connected to my laptop so that through Processing it can read csv files that contain the data that each light will react to. My problem is that I have got this working for outputting to one DMX channel from one csv file, but I can not get it to output to 2 DMX channels from 2 different csv files, and I do not know where I am going wrong. The code is as follows: For Arduino:

#include <DmxSimple.h>
byte brightness1;
byte brightness2;

void setup() {
 Serial.begin(9600);

 DmxSimple.usePin(3);
 DmxSimple.maxChannel(4);
}

void loop() {

  if (Serial.available()) {
    brightness1 = Serial.read();
    brightness2 = Serial.read();
    // set the brightness of DMX1
    DmxSimple.write(1, brightness1);
    // set the brightness of DMX2
    DmxSimple.write(2, brightness2);
  }
}

For Processing: import processing.serial.*; Serial port;

Table table1;
TableRow row1;
float fData1;
Table table2;
TableRow row2;
float fData2;

PFont font;
int index = 0;
int i = 0;
int x = 0;
int mapMin = 0;
int mapMax = 7000;

float lerpFdata1;
float lerpFdata2;
int timer = 0;
int timerDelay = 1000; 
float lerpEase = 0.01;
byte brightness1;
float fPast1;
byte brightness2;
float fPast2;


 void setup() {
 size(500, 100);
 background(255);
  font = createFont("Arial", 14, true);
  table1 = loadTable("04.07.2016 lux.csv", "header");// info DMX Channel 1
  table2 = loadTable("lux test spikes.csv", "header");// infor DMX Channel 2
  frameRate(60); 
  println("Available serial ports:");
  printArray(Serial.list());
  port = new Serial(this,  Serial.list()[2], 9600);

 }

 void draw() {
  background(0);

  if (millis() >= timer) {
    timer = millis() + timerDelay;
    row1 = table1.getRow(i); 
    row2 = table2.getRow(x); 
    fData1 = map(row1.getInt("lux"), mapMin, mapMax, 0, 255); 
    fData2 = map(row2.getInt("lux"), mapMin, mapMax, 0, 255);

    i++;
    x++;
    //  check to see if at end of data
    if (i == table1.getRowCount()) {
      i = 0;//if so, loop back to first row
    } 
     if (x == table2.getRowCount()) {
      x = 0;//if so, loop back to first row
    } 
 }

  fPast1 = map(fData1,0, 255, 0,120);
  brightness1 = byte(fPast1);
  port.write(brightness1);
  println("1: "+fPast1);
  println("Brightness1: "+brightness1); 

  fPast2 = map(fData2,0, 255, 0,120);
  brightness2 = byte(fPast2);
  port.write(brightness2);
  println("2: "+fPast2);
   println("Brightness2: "+brightness2);

  // draw text
  fill(100,100,100);
  textFont(font);
  textAlign(LEFT);
  text("Brightness1: "+brightness1, 10, 10);
  text("Day: "+(row1.getString("date")) + " Time: "+row1.getString("time") + " Lux: "+row1.getInt("lux"), 10, 30); 
  text("Brightness2: "+brightness2, 10, 50);
  text("Day: "+(row2.getString("date")) + " Time: "+row2.getString("time") + " Lux: "+row2.getInt("lux"), 10, 70); 

 }

I am a newbie with Processing and coding in general so if anyone has any suggestions, or can point me in the direction of my mistake it would be greatly appreciated. Many thanks!

Answers

  • The code as it is right now, only works for one LED? or does it work for both?

    Kf

  • As it is right now, it works for just one light, the other (channel 2) is on but unresponsive.

  • Are you sure channel 2 is working? You might write a simple Arduino sketch to write to both channels to make sure both are working with the Arduino sketch.

  • edited March 2017

    Ok, so basically reduce it down to just Arduino with 2 LEDs and make sure it works there, before I progress it to DMX? Is this because you think the problem is there and the Processing code is ok? I'll get onto it and see what happens. Thanks!

  • Yes, write a simple Arduino sketch and give it a try.

  • It could be your processing/arduino code or your DMX. One easy check is to swap the connections on your arduino board using your original code. This will demonstrate that your second DMX works.

    Kf

  • Kfrajer, I am not sure I understand. There is only one Arduino with a DMX breakout, I am not sure what connections you refer to that should be swapped.

  • I have been busy but now I have some time to try and figure this out. In order to get 2 different light sensors both needing SCL/SDA to communicate to the same board I'm going to need to order a bi-directional level shifter and this will take some time to try out without the DMX.

Sign In or Register to comment.