This is a simple example mostly lifted directly from the rppal hardware PWM example. I just ran into a few setup issues and wanted to document how I got it working (mostly for when I inevitably forget a step).
Standard setup for rpi is here and works fine for this, except for possibly the error below. Don't bother with the fix unless you're getting the error.
Set up ssh access to the pi (see here for details). I also assigned a static IP to the pi in my router so I could just alias the connect and mount commands, but you could also just look them up each time by running hostname -I
on the pi.
If, when running cargo run
(or running the built artifact), you're getting Error: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })
, then try adding the following line to the end of your /boot/config.txt
file:
dtoverlay=pwm,pin=18,func=2
(thanks @drauschenbach for the fix here)
Install sshfs (and fuse if you're on Mac) on your local machine (one tutorial here).
After some experimentation I settled on the following for connecting and mounting the pi (sshfs is a bit flaky, and I found that the reconnect
and workaround=all
options helped but ymmv):
alias connect_pi="ssh [email protected]"
alias mount_pi="diskutil umount force ~/rpi/; sshfs -C -o reconnect -o workaround=all -o IdentityFile=/path/to/ssh/private/key [email protected]:/home/pi /Users/bws/rpi"
NB: For cross compiling with cross
you need Docker running.
# run on your macbook to generate the cross compiled binary for the rpi
# if you're on the rpi you can just run `cargo build`
cargo install cross
cross build --target armv7-unknown-linux-gnueabihf # or specify the target in your .cargo/config