Help! arduino+mini6+ttl+compact != movement

Hi there,

I must be missing something !! I’ve an arduino connected to a mini maestro 6 serially, and am trying to use the compact protocol as described in the docs, everything seems right (the M6’s light’s blink properly, I can reset it at will, I seem to be reading and writing from/to it) - but the servo won’t turn ! I only have a Mac so I’ve not used the usb controller app to confirm that the mini can actually drive this servo, (I’ve tried two different ones…) I’ve driven these servo’s fine directly from the arduino already. I’m going to describe the wiring, and then post the code. I am perfectly happy to use another protocol if that would make the difference. I will eventually be driving 5 micros w/5 servo’s per micro from the arduino, managing each one on a separate serial connection.

Hardware: Arduino Mega, Micro 6 controller, 1 volume Pot, 1 DGY-D1290P servo

for this test: all power is from the USB connection to the Arduino, the M6 is fully wired to the Mega (as is the pot), the servo is fully wired only to the M6 (channel 1)

Wiring: (without listing power & grounds)
volume pot <-> A7 [analog]
servo <-> M6Chan1Sig
M6Tx <-> A10, M6Rx <-> A11, M6Reset <-> A31 [all digital on the Arduino]

code:

#include <SoftwareSerial.h>

#define MaestroTx 10
#define MaestroRx 11
#define MaestroReset 31
#define MaestroInverseLogic false

#define servo_0 byte(0x00)

// compact protocol
#define M6BaudRate() write(0xAA) 
#define M6SetTarget() write(0x84)
#define M6SetSpeed() write(0x87)
#define M6SetAccel() write(0x89)
#define M6GetPosition() write(0x90)
#define M6GetMoving() write(0x93)
#define M6GetErrors() write(0xA1)
#define M6GoHome() write(0xA2)

#define M6StopScript() write(0xA4) 
#define M6RestartScript() write(0xA7) 
#define M6RestartScriptParam() write(0xA8) 
#define M6GetScriptStatus() write(0xAE) 


class MaestroMini6 : public SoftwareSerial {

	private:
	
		int baudRate;
		int resetPin;

	public:
		MaestroMini6 ( int _b, int _r, int _rx, int _tx, bool _inv ) : SoftwareSerial(_rx, _tx, _inv) { 
			baudRate = _b; 
			resetPin = _r; 
		} 
		
		byte poll () { 
			return read(); 
		}
		
		void command ( byte _b ) { 
			write(_b); 
		}
		
		void command ( int _i ) { 
			write(byte(_i & 0x7F)); 
			write(byte((_i >> 7) & 0x7F)); 
		}
		
		void reset () { 
			pinMode(resetPin,OUTPUT); 
			digitalWrite(resetPin,LOW); delay(10);
			digitalWrite(resetPin,HIGH); delay(3000);
			M6BaudRate();
		}
		
		void setup () {
			begin(baudRate);
			reset();
		}
		
		void setTarget ( byte channel, int target ) {
			M6SetTarget();
			command(channel);
			command(target);
		}
		
		void setSpeed ( byte channel, int speed ) {
			M6SetSpeed();
			command(channel);
			command(speed);
		}
		
		void setAccel ( byte channel, int accel ) {
			M6SetAccel();
			command(channel);
			command(accel);
		}
		
		int getPosition ( byte channel ) {
			M6GetPosition();
			command(channel);
			byte low = poll();
			byte hi = poll();
			return ((hi << 8) & low);
		}
		
		bool getMoving () {
			M6GetMoving();
			return (0 != poll());
		}
		
		int getErrors () {
			M6GetErrors();
			byte low = poll();
			byte hi = poll();
			return ((hi << 8) & low);
		}
		
		void goHome () {
			M6GoHome();
		}

		
		void stopScript () {
			M6StopScript();
		}
		
		void restartScript ( byte subNo ) {
			M6RestartScript();
			command(subNo);
		}
		
		void restartScriptParam ( byte subNo, int param ) {
			M6RestartScriptParam();
			command(subNo);
			command(param);
		}
		
		void getScriptStatus () {
			M6GetScriptStatus();
		}
};

MaestroMini6 maestro(9600, MaestroReset, MaestroTx, MaestroRx, MaestroInverseLogic);

void setup ( void ) {
	Serial.begin(9600); delay(250);
	Serial.println("Startup");
	
	pinMode(7,INPUT); // pot
	
	maestro.setup();
	
	Serial.println("Ready");
}

int lastVal = 0;

void loop ( void ) {
	
	if (maestro.available()) { // read anything the M6 sends when I'm not looking for it
		int inByte = maestro.read();
		Serial.println(byte(inByte));
	}
	
	int raw = analogRead(7);
	if (abs(lastVal - raw) > 10) { // for now, limiting the change to 10 so I can touch the pot
		int val = map(raw, 0, 1023, 600, 2400) * 4; // full range plus polou target multiplier
		maestro.setTarget(1,val);
		lastVal = raw;
	} 
	
	
	if (Serial.available() > 0) {
		int inByte = Serial.read();
		
		switch (char(inByte)) {
		
			case 'r': { 
				maestro.reset();
				break;
			}
			
			case 'p': {
				Serial.println(maestro.getPosition(1));
				break;
			}
			
			case 'e': {
				Serial.println(maestro.getErrors());
				break;
			}
			
			case 'h': {
				maestro.goHome();
				break;
			}
		}
	}
}

Hello,

I haven’t looked over your code carefully yet, but just to check, how are you providing servo power to the Maestro? (Please note that the servo power is separate from the logic power, as explained in section 1.a of the user’s guide.)

Could you please post a picture of your setup showing how you have everything connected?

- Kevin

THANK YOU !!!

I will be supplying power to the servo from the Arduino as well (for this test)

I was hoping it was going to be something silly !!

(can’t get much simpler than power :slight_smile:

thanks!

al;

I’m glad you figured out the problem.

It sounds like you will be using the Arduino’s 5V output for the servo. Please note that the regulator on the Arduino can supply less than 1 A of current, so you might be fine powering a single small servo with it, but you should use a separate power source to supply servo power for anything more than that.

- Kevin

thanks,

I totally will be using an external power source, I’m going to have 25+ servos and 5+ lasers and a camera in the full prototype – I know the Arduino won’t be able to handle anywhere near that.

all is well,

al;