# Controlling PWM Values with Python

**URL:** <https://discuss.bluerobotics.com/t/controlling-pwm-values-with-python/12529>\
**Category:** Blue Robotics Software\
**Created:** [July 15, 2022, 10:44pm UTC](https://discuss.bluerobotics.com/t/controlling-pwm-values-with-python/12529 "2022-07-15T22:44:01Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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 28, 2022, 8:19am UTC](https://discuss.bluerobotics.com/t/controlling-pwm-values-with-python/12529/5 "2022-07-28T08:19:43Z")

</div>

> [@EliotBR](#):
>
> I’m not sure what’s going on there - I’ll need to look more into it.

Following up on this, because BlueOS has additional MAVLink components for the camera manager and some other systems, there are multiple heartbeats. Accordingly the first heartbeat received through the MAVLink connection is not necessarily a heartbeat from the vehicle, so it’s necessary to wait until a correct one has been found. That can be done with something like the following:

```python
from pymavlink import mavutil

... # create the connection

# wait for vehicle heartbeat before sending commands
ensure_autopilot_heartbeat = (
    f'HEARTBEAT.get_srcSystem() == {master.target_system} and '
    f'HEARTBEAT.get_srcComponent() == {mavutil.mavlink.MAV_COMP_ID_AUTOPILOT1}'
)
master.recv_match(type='HEARTBEAT', condition=ensure_autopilot_heartbeat, blocking=True)

... # rest of the program

```

---

_[View the full topic](https://discuss.bluerobotics.com/t/controlling-pwm-values-with-python/12529)._
