Servo in meadow lab v3

I am using the code bellow to test a Grove Servo in Meadow Lab V3.

using Meadow;
using Meadow.Devices;
using Meadow.Foundation.Grove.Servos;
using Meadow.Units;
using Meadow.Foundation;
using Meadow.Foundation.Leds;
using Meadow.Peripherals.Leds;
using System;
using System.Threading;
using System.Threading.Tasks;
using AU = Meadow.Units.Angle.UnitType;

namespace ServoTest
{
    // Change F7CoreComputeV2 to F7FeatherV2 (or F7FeatherV1) for Feather boards
    public class MeadowApp : App<F7CoreComputeV2>
    {
        Servo servo;

        public override async Task Run()
        {
            await servo.RotateTo(new Angle(servo.Config.MinimumAngle.Degrees, AU.Degrees));

            while (true)
            {
                for (int i = 0; i <= servo.Config.MaximumAngle.Degrees; i++)
                {
                    await servo.RotateTo(new Angle(i, AU.Degrees));
                    Console.WriteLine($"Rotating to {i}");
                    await Task.Delay(40);
                }

                await Task.Delay(2000);

                for (int i = 180; i >= servo.Config.MinimumAngle.Degrees; i--)
                {
                    await servo.RotateTo(new Angle(i, AU.Degrees));
                    Console.WriteLine($"Rotating to {i}");
                    await Task.Delay(40);
                }

                await Task.Delay(2000);
            }

        }

        public override Task Initialize()
        {
            Resolver.Log.Info("Initialize...");
            servo = new Servo(Device.Pins.D00);
            return base.Initialize();
        }
    }
}

I tried connecting the servo in the Grove UART port (D00), but it is not working. What PIN should I use? Thanks, in advance.

Hi @montoya.juanc ,

You’re sample look very close to working, but you’re missing an important step:

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");
    projectLab = ProjectLab.Create();
    servo = new Servo(projectLab.MikroBus1.Pins.PWM);
    return base.Initialize();
}

Since you’re using a ProjectLab, you need create a ProjectLab object first, and then use the connectors API to access the exposed pins. If you use Device.Pins you’re accessing the pins on the Meadow Core-Compute Module, which is wired with a bunch of things on the project lab.

If you look at the ProjectLab pinout, you can see that we expose PWM pins on the mikrobus connectors, so if you wire your servo like my photo below and run your sample with the correction above, you’ll see the servo rotating back and forth.

Hope this helps,
Jorge

I will give it a try, but I am using a grove servo. I connected it in the middle grove port and set the pin D00 is that correct?

Thank you for your response.

I tried a servo in projectLab.MikroBus1.Pins.PWM and it worked.

But I would like to know what is the code for a grove servo.

Image of my setup bellow:

I tried a grove buzzer but did not work either: Code bellow

    public class MeadowApp : App<F7CoreComputeV2>
    {
        private IProjectLabHardware projectLab;
        Buzzer buzzer;

        public override Task Initialize()
        {
            Resolver.Log.Info("Initialize...");
            projectLab = ProjectLab.Create();
            buzzer = new Buzzer(projectLab.GroveAnalog.Pins.D0); //Not sure about this one
            return base.Initialize();
        }

        public override async Task Run()
        {
            Resolver.Log.Info("Run...");

            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine("Playing A major triad starting at A4");
                await buzzer.PlayTone(new Frequency(440, Frequency.UnitType.Hertz), TimeSpan.FromMilliseconds(500)); //A
                await buzzer.PlayTone(new Frequency(554.37f, Frequency.UnitType.Hertz), TimeSpan.FromMilliseconds(500)); //C#
                await buzzer.PlayTone(new Frequency(659.25f, Frequency.UnitType.Hertz), TimeSpan.FromMilliseconds(500)); //E

                await Task.Delay(2500);
            }

        }

    }