louie - 2018-04-28

here is a video of my program at work:
https://www.youtube.com/watch?v=VOzxqHe4tm8
using MotoGeek's code as seen here: https://sourceforge.net/p/gcbasic/discussion/projects%26guides/thread/899e5a0b/
and modified for the weenie Mega2560 board.

dmxing a LED floodlite


' DMX transmitter for weenie and the MAX485 chip
' this program is written for the arduino mega board
' and the Conceptinetics DMX shield which is based on the
' MAX485 signalling chip
' see the setup specifics at the end of the code below

#chip mega2560, 16
#include <maths.h>

'************************ COMM SETTINGS *******************************

#define USART_BAUD_RATE 250000  ' Initializes USART port to 250000 baud
#define USART_TX_BLOCKING       ' wait for tx register to finish

#define DMXout PORTE.1          ' Pin E.1, TX - out to MAX481 DMX driver
dir DMXout out                  ' Set pin directions
set DMXout on                   ' DMX MARK condition (DMX idle)

#define DE PORTE.4              ' on the shield i'm using, this is for
dir DE out                      ' Pin E.4, MAX485 output enable
set DE on

#define LED PORTB.7            ' Pin B.7 - LED
dir LED out
set LED off

UCSR0C = 0b00001111            ' Async, 8N2
TXEN0 = 0                      ' disable TX

'************************ FUNCTION SETTINGS ***************************

#define MaxChan 10
dim DMXCHAN(MaxChan)           ' Create DMX array

dim xx as word
dim yy as byte

'**************************** EXECUTION *****************************

'****************************** SETUP *******************************

ClrAll                          ' Clear DMX array

' load buffer with two values
SendChan(1, 6)    ' enable floodlite
SendChan(4, 255)   ' enable dumb control of colors

for xx = 1 to 10               ' Blink "I'm alive" LED
pulseout LED, 60 ms
wait 60 ms
next xx

'***************************** RUN **********************************
do

' this routine sends a symetric sawtooth stream of values to
' the green channel of a floodlite to make the green LEDs 
' slowly fade up and down
xx = xx + 1
direction = (xx / 256) % 2
green = ((xx % 256) * direction) + (256 - (xx % 256)) * (1 - direction)
SendChan(6, power((green/16), 2))
wait 2 ms

loop

'************************ SUBS by MotoGeek ************************
sub SendChan(Chan, Value) ' update single channel
DMXCHAN(Chan) = Value
TransDMX
end sub

sub SendAll(Value)        ' update all channels
for xx = 1 to MaxChan
DMXCHAN(xx) = Value
next xx
TransDMX
end sub

sub ClrAll                ' clear all channels
for xx = 1 to MaxChan
DMXCHAN(xx) = 0
next xx
TransDMX
end sub

'****************** TRANSMIT DMX Channels *************
' this sub transmits (MaxChan) of the DMX array
sub TransDMX
set LED on                    'Show DMX activity on LED
set DMXout off
wait 100 us                   'BREAK
set DMXout on
wait 6 us                     'MARK AFTER BREAK (MAB)
TXEN0 = 1                     'enable TX
HSerSend 0                    'STARTCODE (always 0)
'set DMXout on
'wait 100 ms                   'Mark Time Between Frames (MTBF)
'set DMXout off
for yy = 1 to MaxChan         'Channel 1 - (MaxChan)
HSerSend DMXCHAN(yy)
next yy
TXEN0 = 0                     ' disable TX
set DMXout on                 'DMX MARK condition (DMX idle)
set LED off
end sub

' SPECS
' written on SynWrite 6.22.2290 on Windows 7 - 64
' tested on the weenie mega 2560 r3
' using a dmx shield, the Conceptinetics CTC-DRA-10-R2
' the shield takes serial data on mega pins D0(rx), D1(tx), D2(enable)
' which is serial0 on the atmega2560
' the shield has an option to take rx and tx from pins D3 and D4
' this routine sends dmx data to a cheap no-name LED floodlite
' as seen here: https://www.youtube.com/watch?v=9wAr2UX-c5A
' google: 8CH 12 LED color Par Light
' all it does is continuously fade the green up and down

' CREDITS
' i took the code written by MotoGeek
' (https://sourceforge.net/p/gcbasic/discussion/projects&guides/thread/899e5a0b/?page=0)
' and modified it for the 2560
' thanks to him, to Anobium and particularly to Mike
' (https://sourceforge.net/u/mmotte/profile/) for thier assistance
 

Last edit: louie 2018-04-29