kaack / elrs-joystick-control

Use USB joysticks to remote control a drone or airplane
Other
105 stars 15 forks source link

Raspberry PI? #1

Open Yith1 opened 1 year ago

Yith1 commented 1 year ago

Looks like a great project and one I will be trying out as I have all the hardware needed lying around.

I can see that a lot of work has gone into it!

How about support for use on a Raspberry PI? You could avoid usb or ftdi and just send the crsf signal down one of the gpio pins.

kaack commented 1 year ago

@Yith1 I tried cross-compiling it from with the Linux toolchain over to ARM, but ran into issues with the GoLang SDL2 library as it has dependencies on lower level C libraries, which were not available. I want to provide support for running it on a Pi 4, but I think I will need to actually go and buy one, and setup the toolchain there to compile it.

I don't have much experience with GPIO on Raspberry Pi. It might be possible to write directly to the CRSF pin. One thing I am not totally sure is if a UART from the Pi will work directly with the CRSF Pin (3.3V vs 5V TTL).

Aside from that, you would still need the USB library to read the gamepad stick positions. Another alternative is to use a wrapper around evdev on Linux, and use SDL2 only for windows.

Yith1 commented 1 year ago

I might be able to help. I have a range if PIs available, but really it'd be a PI 3 I'd be using not a 4.

Usb should be fine with the PI.

I have some experience with the gpio pins and I'm sure something could be made to work.

kaack commented 1 year ago

I was able to get a Pi 4 locally, and built the binary there.

Couple of caveats/issues I ran into:

  1. Must build on 32bit host - At first I tried building it with Raspbian 64bit, but the GoLang SDL2 library does not have ABI bindings for SDL2 in arm64. So, I ended up goin to Raspbian 32 bit, and got it to compile successfully there.

  2. Must build with dynamic library dependencies - I tried building the application with tags static to reduce the runtime dependencies, but got an error from the linker saying that libiconv.a was not available. I did not feel like building libiconv from source, so instead I went ahead and told Go to just build it with dynamic dependencies. I might try later this week to build it statically again.

  3. Use prebuilt webapp dist - Since the webapp is platform independent, there is no need to build it from source on the Pi. Instead I just created a tar-ball dist of the webapp that is already included in the github-page branch.

Here are some instructions:

cd $HOME

# Install SDL2
sudo apt install libsdl2-dev

# Download and Install GoLang
curl -sfL -o go.tar.gz https://dl.google.com/go/go1.20.7.linux-armv6l.tar.gz
tar -xzvf go.tar.gz
mv go go-sdk

export CC=gcc
export CGO_ENABLED=1
export GOPATH=$HOME/go
export GOROOT=$HOME/go-sdk
export GOARCH arm
export OOS=linux
export PATH="${PATH}:${HOME}/go-sdk/bin:${HOME}/go/bin"

# Clone the Repo
git clone https://github.com/kaack/elrs-joystick-control.git
cd elrs-joystick-control

# Grab the latest webapp from the github-pages branch
git checkout -b github-page origin/github-page
tar -czvf dist.tar.gz --transform 's/^docs/dist/' docs

# Switch to main branch to compile the application 
git checkout main

# Extract the webapp dist 
tar -xzvf dist.tar.gz -C webapp

# Generate version file (optional)
go generate pkg/server/version.go

# Compile binary
go build -trimpath --ldflags '-s -w' -o elrs-joystick-control ./cmd/elrs-joystick-control/.

Try these instructions on your Pi 3, and see if you are able to build it.

I have not tested flying with it yet, but the application starts without issues, and I can access the webapp and see USB devices.

Yith1 commented 1 year ago

Cool. I'll give it a go when I get chance. I have a lot on right now, so don't hold your breath!

kaack commented 1 year ago

I've created a new release https://github.com/kaack/elrs-joystick-control/releases/tag/v0.2.1 with a binary for armhf (ARM Hard Float).

I've tested it and flown with it on a Raspberry Pi 4 (running Raspberry Pi OS 32 bit).

I don't have a Pi 3 to test on. Please try this when you have a chance, and see if the binary works on Pi 3 as-is.

If not, then try using the new build-script https://github.com/kaack/elrs-joystick-control/blob/main/build-raspbian32-linux-armhf.sh

Yith1 commented 1 year ago

Sorry I've not had chance to look at this yet. So many other projects going on. It's still on my radar though!

sneakyferret07 commented 10 months ago

I have a Pi 3 I am trying to get this running on but man I suck with Linux based systems. I've ran your script, I run the elrs-joystick-control executable, its telling me http server started on [ : : ] : 3000 and the same for the gRPC server on 10000 yet when i go to the browser and open Https://localhost:3000 nothing is coming up.