What's the missing piece of getting the M280, control servo command to work?

I have my MPCNC up and running! (mostly).

Now I want to be able to control a servo with the M280 G-code command: https://reprap.org/wiki/G-code#M280:_Set_servo_position

I found this thread: Foam Cutter, how to control ESC

in which the guy said that you have to uncomment the #define NUM_SERVOS line in Configuration.h of the firmware. Before doing this, sending the M280 command in Repetier Host (RH) gave back an “unknown command”. After making the change to that file, and reflashing the firmware, it doesn’t give the unknown command echo!

However, it doesn’t work, either. I have one of these dinky sg90 servos:

plugged into the first servo position. To be explicit, it’s the first column on the left here, in the box labeled “servos”: https://www.reprap.org/mediawiki/images/c/ca/Arduinomega1-4connectors.png

(so the D11, 5V, GND column.)

I tried a couple of these servos just in case one didn’t work, same for all.

At this point I have two guesses: 1) Not enough power, I’ve heard the 5V there is from the Arduino, and has a low current limit, or 2) in that thread above, the guy mentions some other pins, something with pins in the pins_RAMBO.h file.

For 1), I guess it’s possible, but these are really dinky servos, and under no load right now (just trying to move them).

For 2), I don’t know what he means. And why would I have to do that when there are already a row of pins for servos on the board??

Any advice is appreciated, thanks!

I like the Marlin documentation better:

M280 P0 S50
M280 P0 S200

Something like that should work.

The 5V is really crappy on the clone megas. The regulator can die and then you need to be plugged into USB all the time to make it do anything.

Is the servo powered on at least? Doing its little holding and twitching?

I understood it was advisable to supply the servo power independently from the Mega board. Using an old PC psu one can get a stable 5V from it. See this:-

1 Like

Ah yeah, I was sending commands like M280 P0 S40, etc, but nothing.

I figured it out though! Well…it works, anyway.

I didn’t think to check if it was providing resistance (ie, powered), so thanks for reminding me. I also checked the voltages around the board. It’s…confusing.

the 5V there should be between the servo 5V and GND pins, it’s…fluctuating? but almost always <1V. It hovers around 200mV…

There are also those 3 (GND, 5V, VCC) pins to the lower right of the D2 diode in the schematic above. Strangely, neither the 5V or VCC measure any voltage with respect to its GND pin, but the VCC DOES measured 5V with respect to the servo’s GND pin!

So I’m not sure if that means a regulator is shot or something. But, if I use the servo GND, the VCC from the (GND, 5V, VCC) pins, and the servo signal… it works! The M280 command sends.

thank you again!!

Wow, that’s a really helpful resource, thanks!

1 Like

Sounds like it is just floating.

1 Like

Yeah, I’ll have to take a closer look at this after work… look at the traces/etc for the board. Nothing looks burnt out.

Did u get this to work? I run a servo on my cnc.