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);
>
> }