# Rc\_channels\_override\_send() takes from 11 to 12 positional arguments but 21 were given

**URL:** <https://discuss.bluerobotics.com/t/rc-channels-override-send-takes-from-11-to-12-positional-arguments-but-21-were-given/10071>\
**Category:** Blue Robotics Software\
**Tags:** ardusub, pymavlink\
**Created:** [July 2, 2021, 6:28am UTC](https://discuss.bluerobotics.com/t/rc-channels-override-send-takes-from-11-to-12-positional-arguments-but-21-were-given/10071 "2021-07-02T06:28:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivanchen](https://avatars.discourse-cdn.com/v4/letter/i/e9c0ed/32.png) [@ivanchen](https://discuss.bluerobotics.com/u/ivanchen)\
**Post date:** [July 2, 2021, 6:28am UTC](https://discuss.bluerobotics.com/t/rc-channels-override-send-takes-from-11-to-12-positional-arguments-but-21-were-given/10071/1 "2021-07-02T06:28:25Z")

</div>

```
rc_channel_values = [65535 for _ in range(18)]
rc_channel_values[channel_id - 1] = pwm
master.mav.rc_channels_override_send(
    master.target_system, # target_system
    master.target_component, # target_component
    *rc_channel_values)

```

It makes an error that “rc\_channels\_override\_send() takes from 11 to 12 positional arguments but 21 were given”  
does it mean it only have 8 channels? I want to makes the light on through mavlink.

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [July 2, 2021, 9:33am UTC](https://discuss.bluerobotics.com/t/rc-channels-override-send-takes-from-11-to-12-positional-arguments-but-21-were-given/10071/2 "2021-07-02T09:33:57Z")

</div>

Hi @ivanchen, welcome to the forum 🙂

The error occurs because your mavlink thinks it needs to communicate using the mavlink 1 protocol (pymavlink default), but ardusub actually uses mavlink 2 (newer and improved), so our documentation is tailored to mavlink 2 examples. If you run `master.wait_heartbeat()` right after you create the mavlink connection then it will detect that the autopilot is using mavlink 2 and will switch to the correct function.

More generally, for turning on the lights I’d recommend instead using the `set_servo` function (e.g. `master.set_servo(output_channel_number, pwm)`) - it’s simpler since you directly set by the [output servo channel rather than the input channel](https://www.ardusub.com/developers/rc-input-and-output.html), and is less to type. We’re currently in the process of revamping our pymavlink docs, so that should be available in an example soon 🙂

For now, note that the output servo channels are directly based on the pixhawk outputs. The ‘Lights’ input channel (for controlling via QGC and `rc_channels_override`) is 9 but can be assigned to various output ports depending on your preference/setup. By default the lumens are plugged in to port AUX 2, which servo output 10 (8 MAIN, +2 AUX), so for turning on the lights there you would use

```python
import time
from pymavlink import mavutil

# assuming connecting from surface computer
master = mavutil.mavlink_connection('udpin:0.0.0.0:14550')

# wait a heartbeat to confirm connection and determine mavlink
# protocol version 
master.wait_heartbeat()

# turn on the lights (servo output 10, AUX 2) to half (1500us pwm)
master.set_servo(10, 1500)
time.sleep(5) # leave them on for 5 seconds
master.set_servo(10, 1100) # turn them off again

```

---

<div class="post-metadata">

**Author:** ![ivanchen](https://avatars.discourse-cdn.com/v4/letter/i/e9c0ed/32.png) [@ivanchen](https://discuss.bluerobotics.com/u/ivanchen)\
**Post date:** [July 2, 2021, 2:28pm UTC](https://discuss.bluerobotics.com/t/rc-channels-override-send-takes-from-11-to-12-positional-arguments-but-21-were-given/10071/3 "2021-07-02T14:28:02Z")

</div>

Thank you for your reply! : )  
The light still doesn’t work via your thought.  
Should I set the environment variables in advance? I used to think it’s not necessary to set the environment after install pymavlink via pip.

---

<div class="post-metadata">

**Author:** ![ivanchen](https://avatars.discourse-cdn.com/v4/letter/i/e9c0ed/32.png) [@ivanchen](https://discuss.bluerobotics.com/u/ivanchen)\
**Post date:** [July 2, 2021, 2:55pm UTC](https://discuss.bluerobotics.com/t/rc-channels-override-send-takes-from-11-to-12-positional-arguments-but-21-were-given/10071/4 "2021-07-02T14:55:49Z")

</div>

When I run the py, the process stuck at the “master.wait\_heartbeat()”, why it happend?

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [July 3, 2021, 6:58am UTC](https://discuss.bluerobotics.com/t/rc-channels-override-send-takes-from-11-to-12-positional-arguments-but-21-were-given/10071/5 "2021-07-03T06:58:48Z")

</div>

> [@ivanchen](#):
>
> The light still doesn’t work via your thought.

Have you checked which pixhawk port your light is plugged into? It’s possible it’s in a different port than the one in my example.

> [@ivanchen](#):
>
> Should I set the environment variables in advance? I used to think it’s not necessary to set the environment after install pymavlink via pip.

You can, but it shouldn’t be required. Once the heartbeat is successfully detected from an autopilot that’s running mavlink 2, pymavlink should automatically detect that and change to using mavlink 2 as well.

> [@ivanchen](#):
>
> the process stuck at the “master.wait\_heartbeat()”, why it happend?

That means you don’t have a valid connection to your autopilot. There are multiple possible causes of that, but they depend on your setup. Assuming you’re trying to connect to your pixhawk from your surface computer, via the udp endpoint provided by the companion computer, then you’ll need to make sure your program has access to udp streams. If you’ve set up your [network settings](https://bluerobotics.com/learn/bluerov2-software-setup/#windows-network-setup) correctly (e.g. QGroundControl works as expected) then it’s possible you just need to allow python through your [firewall](https://bluerobotics.com/learn/bluerov2-software-setup/#firewall), in the same way that you did for QGroundControl.

---

<div class="post-metadata">

**Author:** ![ivanchen](https://avatars.discourse-cdn.com/v4/letter/i/e9c0ed/32.png) [@ivanchen](https://discuss.bluerobotics.com/u/ivanchen)\
**Post date:** [July 3, 2021, 10:19am UTC](https://discuss.bluerobotics.com/t/rc-channels-override-send-takes-from-11-to-12-positional-arguments-but-21-were-given/10071/6 "2021-07-03T10:19:42Z")

</div>

Thank you for your reply and your patience!  
I’m sure that the light plugged into the AUX2, but that doesn’t work. In addition to, I tried set\_servo(, ) from 1 to 8, pwm from 1100 to 1900 but all the motors on it doesn’t run at all. However, I still can control the motors via RC\_Channels and MAV\_CMD\_DO\_MOTOR\_TEST. Why the set\_servo doesn’t work?

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [July 5, 2021, 11:03am UTC](https://discuss.bluerobotics.com/t/rc-channels-override-send-takes-from-11-to-12-positional-arguments-but-21-were-given/10071/7 "2021-07-05T11:03:19Z")

</div>

Have you confirmed that the `wait_heartbeat()` call is completing? If you don’t have a valid connection with the autopilot then no commands you send will work as expected.

> [@ivanchen](#):
>
> I tried set\_servo(, ) from 1 to 8, pwm from 1100 to 1900 but all the motors on it doesn’t run at all. However, I still can control the motors via RC\_Channels and MAV\_CMD\_DO\_MOTOR\_TEST.

The `set_servo` functionality is intended to work for non-motion outputs (ones that aren’t being used for control of the ROV’s movement), whereas the `rc_channels` commands are simulating pilot input (so can control ROV movement) and `MAV_CMD_DO_MOTOR_TEST` commands are set up specifically to control individual motors, so can also control motors. It may be possible to get the `set_servo` functionality controlling motors, but I’m not sure what settings/parameters need to be set for that to work.

If you’ve confirmed that the `wait_heartbeat` message is completing and returning a heartbeat message, but `set_servo` still isn’t working to turn on your lights, could you send a photo showing the pixhawk ports, to confirm which port the lights are plugged into? 🙂

---

<div class="post-metadata">

**Author:** ![ivanchen](https://avatars.discourse-cdn.com/v4/letter/i/e9c0ed/32.png) [@ivanchen](https://discuss.bluerobotics.com/u/ivanchen)\
**Post date:** [July 5, 2021, 9:02pm UTC](https://discuss.bluerobotics.com/t/rc-channels-override-send-takes-from-11-to-12-positional-arguments-but-21-were-given/10071/8 "2021-07-05T21:02:31Z")

</div>

Thank you! I’ve solve the problem by pluggng into the Rpi GPIO rather than the pixhawk. Another question come out that sometimes the Pi or my PC cannot receive the heartbeat from the pixhawk via USB connections(the process stuck at the “master.wait\_heartbeat()”). I connect them with a USB-MicroUSB wire. Sometimes I reboot or replug the pixhawk the heartbeat comes, so strange. Do you know how can I deal with it?

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [July 6, 2021, 12:20am UTC](https://discuss.bluerobotics.com/t/rc-channels-override-send-takes-from-11-to-12-positional-arguments-but-21-were-given/10071/9 "2021-07-06T00:20:44Z")

</div>

> [@ivanchen](#):
>
> I’ve solve the problem by pluggng into the Rpi GPIO rather than the pixhawk.

That sounds like a workaround rather than actually solving the issue with your pymavlink connection, but if that’s sufficient for your purposes then ok.

> [@ivanchen](#):
>
> sometimes the Pi or my PC cannot receive the heartbeat from the pixhawk via USB connections(the process stuck at the “master.wait\_heartbeat()”). I connect them with a USB-MicroUSB wire. Sometimes I reboot or replug the pixhawk the heartbeat comes, so strange. Do you know how can I deal with it?

It’s a bit hard to say without knowing the code you’re running when you’re connecting in the different configurations. The `master.wait_heartbeat()` call is blocking, and if you don’t have a valid connection then it will wait forever. As I mentioned two comments ago,

> [@EliotBR](#):
>
> There are multiple possible causes of that, but they depend on your setup. Assuming you’re trying to connect to your pixhawk from your surface computer, via the udp endpoint provided by the companion computer, then you’ll need to make sure your program has access to udp streams. If you’ve set up your [network settings](https://bluerobotics.com/learn/bluerov2-software-setup/#windows-network-setup) correctly (e.g. QGroundControl works as expected) then it’s possible you just need to allow python through your [firewall](https://bluerobotics.com/learn/bluerov2-software-setup/#firewall), in the same way that you did for QGroundControl.

I would suggest creating the mavlink connection in pymavlink **after** the relevant physical connections are set up between your electronics, if you’re not already doing that.
