# Controlling pan and tilt servos from beaglebone

**URL:** https://discourse.julialang.org/t/controlling-pan-and-tilt-servos-from-beaglebone/60464
**Category:** Maker
**Tags:** question
**Created:** [May 3, 2021, 1:59pm UTC](https://discourse.julialang.org/t/controlling-pan-and-tilt-servos-from-beaglebone/60464 "2021-05-03T13:59:41Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [May 3, 2021, 1:59pm UTC](https://discourse.julialang.org/t/controlling-pan-and-tilt-servos-from-beaglebone/60464/1 "2021-05-03T13:59:41Z")

</div>

I want to control a [LynxMotion pan and tilt unit](https://www.robotshop.com/en/lynxmotion-pan-and-tilt-kit-aluminium2.html) from a BeagleBone using Julia, if possible. Ideally, I’d like to skip the use of a micro-controller altogether and communicate with the LynxMotion unit directly through the PWM ports of the BeagleBone (but maybe I need a [shield](https://openmv.io/products/pan-and-tilt-shield) in there). In fact, the reason I want to use a BeagleBone is because of its hardware PWM ports, which, if I understood correctly, are missing in a Raspberry Pi.

Is any of this possible?

---

<div class="post-metadata">

### Author: ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)
#### Post date: [May 3, 2021, 3:14pm UTC](https://discourse.julialang.org/t/controlling-pan-and-tilt-servos-from-beaglebone/60464/2 "2021-05-03T15:14:00Z")

</div>

seems like you can configure the Beaglebone’s PWM outputs by poking bits at a device in `/sys/` see how this bash program does it:  
[https://github.com/justinpearson/Beaglebone-motor-from-command-line](https://github.com/justinpearson/Beaglebone-motor-from-command-line)  
I guess you can use `write` + `open` to do that bit prodding from julia.  
idk if there is a package that has that kind of thing wrapped up or not.

Which I wish I had known a decade ago when I was doing motor control for a project, we had a beaglebone talking to a seperate microprocessor over serial to have that do PWM for motor control.

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [May 3, 2021, 3:33pm UTC](https://discourse.julialang.org/t/controlling-pan-and-tilt-servos-from-beaglebone/60464/3 "2021-05-03T15:33:54Z")

</div>

> [@oxinabox](#):
>
> had a beaglebone talking to a seperate microprocessor over serial to have that do PWM for motor control

This is exactly what I would like to avoid. I’ve had RPI talk through serial to an Arduino, and while it work etc etc, skipping a micro-controller altogether would be the dream.

> [@oxinabox](#):
>
> configure the Beaglebone’s PWM outputs by poking bits at a device in `/sys/`

Oof, I hope to avoid too much fiddling… Maybe I can avoid some of that with the shield, or things like [GitHub - ronisbr/BaremetalPi.jl: Julia library to access Raspberry Pi peripherals without requiring external libraries.](https://github.com/ronisbr/BaremetalPi.jl)

---

<div class="post-metadata">

### Author: ![mgkuhn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mgkuhn/32/6276_2.png) [@mgkuhn](https://discourse.julialang.org/u/mgkuhn)
#### Post date: [May 3, 2021, 5:25pm UTC](https://discourse.julialang.org/t/controlling-pan-and-tilt-servos-from-beaglebone/60464/4 "2021-05-03T17:25:31Z")

</div>

Hardware PWM is available of the Raspberry Pi computers on GPIO pins 12, 13, 18 and 19: [Raspberry Pi Documentation - Raspberry Pi OS](https://www.raspberrypi.org/documentation/usage/gpio/)

They are controlled via ioctl() to a character device. So the thing to do in Julia is to load a suitable C shared library ([libgpiod](https://kernel.googlesource.com/pub/scm/libs/libgpiod/libgpiod/+/v0.2.x/README.md) or [pigpio library](http://abyz.me.uk/rpi/pigpio/)) and then call it via [`@ccall`](https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/).

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [May 3, 2021, 5:29pm UTC](https://discourse.julialang.org/t/controlling-pan-and-tilt-servos-from-beaglebone/60464/5 "2021-05-03T17:29:21Z")

</div>

> [@mgkuhn](#):
>
> Hardware PWM is available of the Raspberry Pi computers on GPIO pins 12, 13, 18 and 19: [GPIO - Raspberry Pi Documentation](https://www.raspberrypi.org/documentation/usage/gpio/)

TIL! Thanks!

> [@mgkuhn](#):
>
> They are controlled via ioctl() to a character device. So the thing to do in Julia is to load a suitable C shared library ([libgpiod](https://kernel.googlesource.com/pub/scm/libs/libgpiod/libgpiod/+/v0.2.x/README.md) or [pigpio library](http://abyz.me.uk/rpi/pigpio/)) and then call it via [`@ccall`](https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/).

Maybe I can simply use [GitHub - JuliaBerry/PiGPIO.jl: Manage external hardware using GPIO pins on the Raspberry Pi](https://github.com/JuliaBerry/PiGPIO.jl)?

---

<div class="post-metadata">

### Author: ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)
#### Post date: [May 3, 2021, 5:31pm UTC](https://discourse.julialang.org/t/controlling-pan-and-tilt-servos-from-beaglebone/60464/6 "2021-05-03T17:31:21Z")

</div>

> [@yakir12](#):
>
> Oof, I hope to avoid too much fiddling…

It doesn’t look too fiddly to me.  
If the readme of the bash thing I link is correct.  
Looks like a one liner for each function:

```julia
set_pwm_period!(ns) = open(io->print(io, ns), "/sys/devices/ocp.3/pwm_test_P8_34.12/period") 
set_pwm_offduty!(ns) = open(io->print(io, ns), "/sys/devices/ocp.3/pwm_test_P8_34.12/duty")

```

might take a little looking around to find out the device name for your particular make.  
(Most of the bash script in that repo is just find the names for things)
