Changing the Mode of the Micro Maestro in C# to Output


I’ve got a problem. By the time i’m programming a program in C# for the Micro Maestro. And all seems very well, because till now, I’ve only programmed with servos. Now I want to control an extern LED on channel 6. I don’t know what I have to do to configure the Maestro from “servo” to “output”? All this has to be placed in the C# Code, because I’m programming an interaktiv programm with a formular.

It would be great if someone could help me with al little example how to configure the Maestro and how to set the state of the LED after that.

Anton Train

I’m not sure what a “interaktiv programm with a formular” is. Is there some reason that you can’t simply use the Meastro Control Center or UscCmd to configure the channel as an output before you run your program?

If you need to change the settings of the Maestro from C# using the Pololu USB SDK, you should create a UscSettings object and then apply it to the Maestro using the setUscSettings method. If you need more details, please read the source code and comments in the SDK, and ask here if you have any more specific questions.


Thanks for the answer.
I tried to the following:

usc = new Usc(d);

UscSettings settings = new UscSettings();
settings.channelSettings[5].mode = ChannelMode.Output;

usc.setUscSettings(settings, false);

But this doesn’t work. If I Debug the script, at this line settings.channelSettings[5].mode = ChannelMode.Output; the debugger tells me that there is a NullReferenceException. In the help they say that I have to create an object but I can’t imagine what object they mean. I had created an “UscSettings”-object.

I wrote this down because I didn’t want that anyone comes and sais that I should use the Scriptlanguage in the Controlcenter.

No. I didn’t know that the Maestro saves these settings while being initialized by different Programs. On this way it works! Great.

But it would be great if you could help me in spite of this with the problem on the top.

Antony Train

The changes you make in the Maestro Control Center will be saved permanently on the device when you click Apply Settings (except your changes in the Status tab and the Script tab).

Regarding the NullReferenceException for settings.channelSettings[5].mode, there are many things that could be causing it:

  • settings might be null (you ruled that out)
  • settings.channelSettings might be null
  • settings.channelSettings[5] might be null

You should learn how to use the Immediate window in the Visual Studio debugger to evaluate those expressions to figure out which one is null.

But I’ll also tell you the answer: the channelSettings list starts off empty, so you need to create 6 (or more if you had a different Maestro) ChannelSetting objects and add them to the list using settings.channelSettings.add().