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

Hey,

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 gadgeteerrobot.codeplex.com

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);
            resetkey.Write(true);

            byte tx = 0; ;
            byte rx = 0; ;
            serial.ReadTimeout = 50;
            serial.Open();
            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);
               serial.WriteLine("L=22");
                tx = i;
 
              Thread.Sleep(500);
                int read_count = 0;
                 

                //Debug.Print(serial.ReadByte().ToString());
                Thread.Sleep(500);
                 tx = 141;
                 Thread.Sleep(500);
                 serial.Write(tx);
                 tx = 0x7F;
                serial.Write(tx);
 
            }

        }
    }

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

Boards:

https://www.ghielectronics.com/catalog/product/405

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. https://bitbucket.org/ghi_elect/gadgeteer/src/86e246d051bf5e78ec1923b173410c5e47591bf8/Modules/GHIElectronics/Bluetooth/Bluetooth_43/Bluetooth_43.cs?at=master 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: