Controlling G2 24v12 via Arduino with DMX

hello

i am trying to make my G2 motor controller work via DMX and trying to do this using an Arduino Uno and a DMX shield ( https://sourceforge.net/projects/dmxlibraryforar/ ) I have got the motor controller working via Arduino just using the simple command examples found in the G2 user guide… However when I try and control it via DMX the signal constantly pulses the motor rather than just keep it on… So for example if I send it a top speed command via DMX - i can see in the Pololu config utlity tha tthe speed is oscilatting between 0% & 100%… Has anyone had much experience with this? Here is the code I am using …

Any help would be greatly appreciated.

> #include <Conceptinetics.h>
> #include <SoftwareSerial.h>
> #define rxPin 3  // pin 3 connects to smcSerial TX  (not used in this example)
> #define txPin 4  // pin 4 connects to smcSerial RX
> SoftwareSerial smcSerial = SoftwareSerial(rxPin, txPin);
> 
> #define DMX_SLAVE_CHANNELS   1
> 
> 
> //    Arduino digital pin 4 to Simple Motor Controller RX
> //    Arduino GND to Simple Motor Controller GND
> 
> //
> // Pin number to change read or write mode on the shield
> // Uncomment the following line if you choose to control 
> // read and write via a pin
> //
> // On the CTC-DRA-13-1 shield this will always be pin 2,
> // if you are using other shields you should look it up 
> // yourself
> //
> ///// #define RXEN_PIN                2
> 
> 
> // Configure a DMX slave controller
> DMX_Slave dmx_slave ( DMX_SLAVE_CHANNELS );
> 
> // If you are using an IO pin to control the shields RXEN
> // the use the following line instead
> ///// DMX_Slave dmx_slave ( DMX_SLAVE_CHANNELS , RXEN_PIN );
> // required to allow motors to move
> // must be called when controller restarts and after any error
> void exitSafeStart()
> {
>   smcSerial.write(0x83);
> }
> 
> // speed should be a number from -3200 to 3200
> void setMotorSpeed(int speed)
> {
>   if (speed < 0)
>   {
>     smcSerial.write(0x86);  // motor reverse command
>     speed = -speed;  // make speed positive
>   }
>   else
>   {
>     smcSerial.write(0x85);  // motor forward command
>   }
>   smcSerial.write(speed & 0x1F);
>   smcSerial.write(speed >> 5 & 0x7F);
> }
> 
> 
> // the setup routine runs once when you press reset:
> void setup() {             
>   
>   // Enable DMX slave interface and start recording
>   // DMX data
>   dmx_slave.enable ();  
>   
>   // Set start address to 1, this is also the default setting
>   // You can change this address at any time during the program
>   dmx_slave.setStartAddress (1);
>     // Initialize software serial object with baud rate of 19.2 kbps.
>   smcSerial.begin(19200);
>   // The Simple Motor Controller must be running for at least 1 ms
>   // before we try to send serial data, so we delay here for 5 ms.
>   delay(5);
>  
>   // If the Simple Motor Controller has automatic baud detection
>   // enabled, we first need to send it the byte 0xAA (170 in decimal)
>   // so that it can learn the baud rate.
>   //smcSerial.write(0xAA);
>  
>   // Next we need to send the Exit Safe Start command, which
>   // clears the safe-start violation and lets the motor run.
>   exitSafeStart();
> }
> 
> // the loop routine runs over and over again forever:
> void loop() 
> {
> 
>  int val = dmx_slave.getChannelValue (1);
>    val = map(val, 0, 255, 0, 3200);
>    setMotorSpeed(val);
> 
> }

Hello.

I am not very familiar with that particular DMX shield or library, but from your description of the problem it might be helpful to print out the value you are getting from dmx_slave.getChannelValue(1) to the Serial Monitor, preferably before it gets mapped, to see if it is what you expect it to be.

When you run your code and monitor the Simple Motor Control Center G2 software, do you see any errors being triggered (i.e. the “Count” value going up for any errors)?

Brandon

hi brandon - thanks for your suggestion. the serial stream from the dmx_slave.getChannelValue(1) is actually pretty noisy … lots of ??? and extra characters besides the actual valid INT values i was expecting. Must be a fault with the DMX library itself… I added a delay to the code and it actually has fixed the problem - i mean the stream is still noisy but the motor driver works fine… seems that the Pololu board is able to filter out the noise… woudl you recommend a better method for driving the Pololu over DMX? I was just using that board because i had it lying around… but would love to know if there is a better method… thanks

If the DMX shield is like the interface I built, then it’s using the rx/tx lines to talk to the line driver. That might explain the noise?

right - that’s why i was using softserial library to create another instance of the RX/TX in order to re-route the data to the Pololu driver… I tried to parse the integers to get rid of any random characters and only keep valid integers - but i couldn’t make it work… it works… which is great. but its not the perfect solution… I thought it would be a useful solution for the wider community in terms of a relatively cheap DMX integration… maybe someone else who is better at arduino will come up with a more robust solution!

I do not have any specific suggestions for alternative methods for controlling the G2 24v12 from DMX signals. As I mentioned, I am not very familiar with that DMX library, but if you are getting valid values in between the “noise”, it might be that there is more information getting transmitted than you are expecting, so you might be able to parse it better to separate the extra data from your intended values.

Brandon