Serial code trouble (Pololu Qik 2s12v10 + Breakout module + Linear actuator)


I’m kind of stuck. I’m trying to use a pololu motor controller (can’t use the GHI motor driver cause my linear actuator draws 9A) with some code I found from a robot gadgeteer project.
But, this project is old, and the interfaces seems to have changed/been updated, and I don’t know how to rewrite it (I have tried, see below the original code). (Using .NETMF 4.3)

I’m using a breakout module between pololu and fez hydra (didn’t have the extender module as seen in the robot, but I’ve ordered it just in case).

So, will someone help me update the code below? Or does anyone know of a recent driver for the pololu controller that works similarly to the ghi motor driver interface?

Original motor code from

public class DualMotor : GTM.Module
        public GTI.Serial serial;
        GTI.DigitalOutput resetkey;
        // Note: A constructor summary is auto-generated by the doc builder.
        /// <summary></summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public DualMotor(int socketNumber)
            Socket socket = Socket.GetSocket(socketNumber, true, this, null);
            //I think this uses pin 5. 
            serial = new GTI.Serial(socket, 115200, GTI.Serial.SerialParity.None, GTI.Serial.SerialStopBits.One, 8, GTI.Serial.HardwareFlowControl.NotRequired, this);

             resetkey = new GTI.DigitalOutput(socket, Socket.Pin.Three, false, this);

            byte tx = 0; ;
            byte rx = 0; ;
            serial.ReadTimeout = 50;
            byte[] rx_byte = new byte[80];
            byte i = 50;
            //char[] chars;
            while (serial.IsOpen)
                if (i >= 128)
                    i = 50;
                i += 5;
                tx = 136;
             //   Thread.Sleep(500);
                tx = i;
                int read_count = 0;

                 tx = 141;
                 tx = 0x7F;


What I’ve got so far. I can’t figure out how to write to output, so I’m probably doing it wrong :confused:

GT.Socket socket = breakout.Socket;
            var serial = socket.SerialIndirector;
            var digiOut = socket.DigitalOutputIndirector;
            object[] @ object = new object[] { "test" };

            AsyncCallback callbackSerial = new AsyncCallback(SerialIn);
            serial.BeginInvoke(socket, 115200, GTI.SerialParity.None, GTI.SerialStopBits.One, 8, GTI.HardwareFlowControl.NotRequired, null, callbackSerial, @ object);
            AsyncCallback callbackOut = new AsyncCallback(DigitalOut);
            digiOut.BeginInvoke(socket, GT.Socket.Pin.Three, false, null, callbackOut, null);


I just posted a digitalinputfactory snippet for someone in another thread, sounds like you need that for the IO pin aspect. Not sure how to handle serial, but just find another driver source for 4.3 of a device that uses serial and see how they set up the connection. is the driver for the old Bluetooth module that uses serial so might be a good target - seems like:

Socket socket = Socket.GetSocket(socketNumber, true, this, null);
this.reset = GTI.DigitalOutputFactory.Create(socket, Socket.Pin.Six, false, this);
this.statusInt = GTI.InterruptInputFactory.Create(socket, Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.Disabled, GTI.InterruptMode.RisingAndFallingEdge, this);
this.serialPort = GTI.SerialFactory.Create(socket, 38400, GTI.SerialParity.None, GTI.SerialStopBits.One, 8, GTI.HardwareFlowControl.NotRequired, this);

is how you’d do it :slight_smile: .

@ Brett - Thanks! My problem was mainly a missing reference: Gadgeteer.Serial + that it’s probably best to inherit from GTM.Module :wink: