Esempio n. 1
0
        /// <summary>
        /// Main entry point
        /// </summary>
        /// <param name="args">Unused</param>
        public static void Main(string[] args)
        {
            Console.WriteLine($"Let's go!");
            using (Uln2003 motor = new Uln2003(BluePin, PinkPin, YellowPin, OrangePin))
            {
                Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs eventArgs) =>
                {
                    motor.Dispose();
                };

                while (true)
                {
                    // Set the motor speed to 15 revolutions per minute.
                    motor.RPM = 15;
                    // Set the motor mode.
                    motor.Mode = StepperMode.HalfStep;
                    // The motor rotate 2048 steps clockwise (180 degrees for HalfStep mode).
                    motor.Step(2048);

                    motor.Mode = StepperMode.FullStepDualPhase;
                    motor.RPM  = 8;
                    // The motor rotate 2048 steps counterclockwise (360 degrees for FullStepDualPhase mode).
                    motor.Step(-2048);

                    motor.Mode = StepperMode.HalfStep;
                    motor.RPM  = 1;
                    motor.Step(4096);
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine($"Let's go!");
            using (Uln2003 motor = new Uln2003(bluePin, pinkPin, yellowPin, orangePin))
            {
                while (true)
                {
                    // Set the motor speed to 15 revolutions per minute.
                    motor.RPM = 15;
                    // Set the motor mode.
                    motor.Mode = StepperMode.HalfStep;
                    // The motor rotate 2048 steps clockwise (180 degrees for HalfStep mode).
                    motor.Step(2048);

                    motor.Mode = StepperMode.FullStepDualPhase;
                    motor.RPM  = 8;
                    // The motor rotate 2048 steps counterclockwise (360 degrees for FullStepDualPhase mode).
                    motor.Step(-2048);

                    motor.Mode = StepperMode.HalfStep;
                    motor.RPM  = 1;
                    motor.Step(4096);
                }
            }
        }
Esempio n. 3
0
        public MeadowApp()
        {
            stepperController = new Uln2003(
                device: Device,
                pin1: Device.Pins.D01,
                pin2: Device.Pins.D02,
                pin3: Device.Pins.D03,
                pin4: Device.Pins.D04);

            stepperController.Step(1024);

            /*   for (int i = 0; i < 100; i++)
             * {
             *     Console.WriteLine($"Step forward {i}");
             *     stepperController.Step(50);
             *     Thread.Sleep(10);
             * }
             *
             * for (int i = 0; i < 100; i++)
             * {
             *     Console.WriteLine($"Step backwards {i}");
             *     stepperController.Step(-50);
             *     Thread.Sleep(10);
             * } */
        }
Esempio n. 4
0
        static void Step()
        {
            const int bluePin   = 4;
            const int pinkPin   = 17;
            const int yellowPin = 27;
            const int orangePin = 22;

            using (Uln2003 motor = new Uln2003(bluePin, pinkPin, yellowPin, orangePin))
            {
                // Set the motor speed to 15 revolutions per minute.
                motor.RPM = 12;
                // Set the motor mode.
                motor.Mode = StepperMode.HalfStep;
                // The motor rotate 2048 steps clockwise (180 degrees for HalfStep mode).
                motor.Step(4096 / 8);
                // motor.Mode = StepperMode.FullStepDualPhase;
                // motor.RPM = 8;
                // // The motor rotate 2048 steps counterclockwise (360 degrees for FullStepDualPhase mode).
                // motor.Step(-2048);

                // motor.Mode = StepperMode.HalfStep;
                // motor.RPM = 1;
                // motor.Step(4096);

                // motor.RPM = 1;
                // motor.Step(4);
            }
        }
Esempio n. 5
0
        public static void Main()
        {
            Debug.WriteLine("ULN2003 demonstration");

            var stepper = new Uln2003(IN1, IN2, IN3, IN4);

            // var stepper = new Uln2003(IN1, IN2, IN3, IN4, new Esp32HiresStopwatch());

            stepper.Mode = StepperMode.FullStepSinglePhase;

            stepper.SpeedAsDegPerSec = 80;

            // Blocking operation
            Debug.WriteLine("Rotate and block");
            stepper.StepAndWait(-4069);

            // Non blocking operation
            #region // Cycles between forward and reverse
            int totalSteps = 4069;
            Debug.WriteLine("Rotate in positive direction");
            stepper.StepNoWait(totalSteps);

            while (true)
            {
                if (stepper.IsTargetPositionReached())
                {
                    totalSteps = -totalSteps;
                    Debug.WriteLine("Rotate in negative direction");
                    stepper.StepNoWait(totalSteps);
                }
                stepper.Run();
            }
            #endregion
        }
Esempio n. 6
0
        protected void InitializePeripherals()
        {
            Console.WriteLine("Initialize the stepperController.");

            stepperController = new Uln2003(
                device: Device,
                pin1: Device.Pins.D01,
                pin2: Device.Pins.D02,
                pin3: Device.Pins.D03,
                pin4: Device.Pins.D04);
        }
        static void Main(string[] args)
        {
            // Pinout for Raspberry Pi 3
            const int pin1            = 17;
            const int pin2            = 27;
            const int pin3            = 22;
            const int pin4            = 10;
            int       degreesToRotate = 0;
            bool      parsable        = Int32.TryParse(args[0], out degreesToRotate);

            int[] parsedArgs = Array.ConvertAll(args, int.Parse);

            using (Uln2003 motor = new Uln2003(pin1, pin2, pin3, pin4))
            {
                Console.WriteLine($"The number of args is {args.Length}.");

                foreach (var parsedArg in parsedArgs)
                {
                    Console.WriteLine(parsedArg);
                }
                try
                {
                    motor.RPM  = 15;
                    motor.Mode = StepperMode.HalfStep;
                    foreach (int rotationArg in parsedArgs)
                    {
                        motor.Step(rotationArg * 4096);

                        Thread.Sleep(1000 * rotationArg);
                    }



                    //int i = 0;
                    //while (i<1)
                    //{
                    //    // Set the motor speed to 15 revolutions per minute.
                    //    motor.RPM = 15;
                    //    // Set the motor mode.
                    //    motor.Mode = StepperMode.HalfStep;
                    //    // The motor rotate 2048 steps clockwise (180 degrees for HalfStep mode).
                    //    motor.Step(2048);

                    //    motor.Mode = StepperMode.FullStepDualPhase;
                    //    motor.RPM = 8;
                    //    // The motor rotate 2048 steps counterclockwise (360 degrees for FullStepDualPhase mode).
                    //    motor.Step(-2048);

                    //    motor.Mode = StepperMode.HalfStep;
                    //    motor.RPM = 1;
                    //    motor.Step(4096);
                    //    i++;
                    //}
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    //motor.Stop();
                    //motor.Dispose();
                }
            }
        }