OK, it's time for the first code here. As I wrote, I'm using the
DFRobot I/O Expansion shield V4, and it requires some hardware setup
to get it to work:
- of the three 'RS485' jumpers, set the leftmost ones (the two closest
to the word DIGITAL to the upper position, so they should cap the
middle pin and the pin in the DIGITAL 485 row. BUT NOT the rightmost
one (close to the '485' text) as this is the receiver pin. You don't
need that, and it will screw up your USB connection.
- You have to test out your DMX wiring. Some equipment talks about '+'
and '-', which is not correct. The shield is labeled 'a' and 'b', but
what is '-' and what '+', is something you have to find out yourself.
I checked this using a Duemilanove 328 at 16MHz, the DFRduino I/O
expansion shield V4 DFR0014 by DFRobot, and the setup controlled a
four channel dimmer pack, Showtec Multidim MKII.
Now for the code: where the DMX shields have the 'send' mode
hardwired, this true RS485 converter has the enable pin attached to
Arduino pin 2. You need to set this to HIGH to enable transmission.
For the rest, the code is just a four channel version of 'fade up and
down'.
<code>
/* 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.
**
** 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.
*/
#include <DmxSimple.h>
const int DMXpin = 1;
const int RS_ENpin = 2;
void setup() {
/* 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(DMXpin);
/* 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(64);
pinMode(RS_ENpin, OUTPUT);
digitalWrite(RS_ENpin,HIGH);
}
void loop() {
// Cycle channel 1 to 3
for (int channel = 1; channel <4; channel++){
// increase brightness from zero to full
for(int brightness = 0; brightness<=255; brightness++) {
DmxSimple.write(channel, brightness);
delay (1);
}
// ... and back to zero
for(int brightness = 255; brightness>=0; brightness--) {
/* Update DMX channel 1 to new brightness */
DmxSimple.write(channel, brightness);
delay (1);
}
}
// channel 4 to 2
for (int channel = 4; channel >1; channel--){
// brightness from zero to full
for(int brightness = 0; brightness<=255; brightness++) {
DmxSimple.write(channel, brightness);
delay (1);
}
// and back to zero
for(int brightness = 255; brightness>=0; brightness--) {
DmxSimple.write(channel, brightness);
delay (1);
}
}
}
</code>
It works like a breeze, so now the next step: reading show data from
an SD card. I will be using this library: SdFatLib,
http://code.google.com/p/sdfatlib/
to read the SD card, and will put like 8 or so files on there, 1 for
each show... more on that in my next post!