Arduino Setup
Plug in your Arduino Uno or Metro 328 to your computer over a known good USB cable.
Before going any further, make sure you have a basic understanding of how to program and use an Arduino. Thankfully, we have a lot of great tutorials on how this whole thing works. Click here to get started with Arduino, and then come back to this guide to continue.
Additional Boards Manager URLs
To use the Metro board in Arduino, check the Arduino IDE Tools > Board list and select Adafruit Metro. Note: if you don't see the Metro on that list, add this URL to your Arduino > Preferences > Additional Boards Manager URLs:
https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
Install Adafruit AVR
Then, go to the Arduino > Tools > Board > Boards Manager... and type 'metro' in the search, then install the Adafruit AVR Boards package.
DMXSimple Library
Next, you'll add the DMXSimple library by clicking on Tools > Manage Libraries... and then entering 'dmxsimple' in the search box.
Click the Install button.
You can find out more about this library here.
/* 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>
void setup() {
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");
}
int value = 0;
int channel;
void loop() {
int c;
while(!Serial.available());
c = Serial.read();
if ((c>='0') && (c<='9')) {
value = 10*value + c - '0';
} else {
if (c=='c') channel = value;
else if (c=='w') {
DmxSimple.write(channel, value);
Serial.println();
}
value = 0;
}
}
Modifications
We'll make a few small changes to use this example with the Conceptnetics DMX shield.
Pin definitions
First, we'll define the pins for transmitting and mode selection. Add these two lines after the #include line:
const byte dmxTransmitPin = 4; // conceptinetics transmit pin 4 const byte modeSelectPin = 2; // conceptinetics mode pin
Setup
Next, in the setup() loop we'll set the mode select pin to OUTPUT with a HIGH value, placing the shield in sender mode.
You'll also tell DmxSimple to use the pre-defined transmit pin, and set the max channel value to 512 so that a full-length message is sent every time (some fixtures don't like receiving a shorter message).
pinMode(modeSelectPin, OUTPUT); digitalWrite(modeSelectPin, HIGH); // set to sender mode (low for receiver mode) DmxSimple.usePin(dmxTransmitPin); DmxSimple.maxChannel(512);
Here's the final code, you can copy this and paste it into your Arduino IDE to upload to the Metro.
/* This program allows you to set DMX channels over the serial port.
**
** John Park update for Conceptinetics DMX shield for this example
** 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:
** 100c355v : 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 */
/*
________
EN -- •
SL • --
TX -- •
RX -- •
________
*/
#include <DmxSimple.h>
//Constants
const byte dmxTransmitPin = 4; // conceptinetics transmit pin 4 or use TX(1) with jumper to the right
const byte modeSelectPin = 2; // conceptinetics mode pin
void setup() {
pinMode(modeSelectPin, OUTPUT);
digitalWrite(modeSelectPin, HIGH); // set to sender mode (low for receiver mode)
/* 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(dmxTransmitPin);
DmxSimple.maxChannel(512);
Serial.begin(9600);
Serial.println("SerialToDmx ready");
Serial.println();
Serial.println("Syntax:");
Serial.println(" 123c : use DMX channel 123");
Serial.println(" 45v : set current channel to value 45");
//set initial values
DmxSimple.write(1, 255); // ch1 is brightness on first fixture
DmxSimple.write(3, 150); // ch3 is green on first fixture
DmxSimple.write(17, 255); // ch17 is brightness on second fixture
DmxSimple.write(20, 200); // ch20 is red on second fixture
}
int value = 0;
int channel;
void loop() {
int c;
while(!Serial.available());
c = Serial.read();
if ((c>='0') && (c<='9')) {
value = 10*value + c - '0';
} else {
if (c=='c') channel = value;
else if (c=='v') {
DmxSimple.write(channel, value);
Serial.println();
}
value = 0;
}
}
DMX Fade Up
Let's check out another example -- this will fade up the values on one channel.
Click on File > Examples > DMXSimple > SerialtoDMX to open the example file.
We'll make a few adjustments to suit the Conceptinetics shield, and add a second fixture:
/* Welcome to DmxSimple. This library allows you to control DMX stage and
** architectural lighting and visual effects easily from Arduino. DmxSimple
** is compatible with the Tinker.it! DMX shield and all known DIY Arduino
** DMX control circuits.
** John Park update for Conceptinetics DMX shield for this example
**
** DmxSimple is available from: http://code.google.com/p/tinkerit/
** Help and support: http://groups.google.com/group/dmxsimple */
/* To use DmxSimple, you will need the following line. Arduino will
** auto-insert it if you select Sketch > Import Library > DmxSimple. */
/*
________
EN -- •
SL • --
TX -- •
RX -- •
________
*/
#include <DmxSimple.h>
//Constants
const byte dmxTransmitPin = 4; // conceptinetics transmit pin 4 or use TX(1) with jumper to the right
const byte modeSelectPin = 2; // conceptinetics mode pin
void setup() {
pinMode(modeSelectPin, OUTPUT);
digitalWrite(modeSelectPin, HIGH); // set to sender mode (low for receiver mode)
DmxSimple.usePin(dmxTransmitPin);
DmxSimple.maxChannel(512);
// first fixture
DmxSimple.write(1, 0); // set brightness
// set R,G,B
DmxSimple.write(2, 0);
DmxSimple.write(3, 0);
DmxSimple.write(4, 150);
// second fixture
DmxSimple.write(17, 0); // set brightness
// set R,G,B
DmxSimple.write(18, 0);
DmxSimple.write(19, 150);
DmxSimple.write(20, 0);
}
void loop() {
// fade loop:
int brightness;
/* Simple loop to ramp up brightness */
for (brightness = 0; brightness <= 255; brightness++) {
/* Update DMX channel 1 and 17 to new brightness */
DmxSimple.write(1, brightness);
DmxSimple.write(17, brightness);
/* Small delay to slow down the ramping */
delay(7);
}
delay(1000);
DmxSimple.write(1, 0); // set brightness to 0
DmxSimple.write(17,0);
delay(1000);
}
Page last edited December 11, 2024
Text editor powered by tinymce.