Three js - Raspberry pi GPIO control

Hi all,
I am struggling to find an example where I can run 3js on raspberry pi or windows and use RPi’s GPIO pins to make changes on 3js. For example use joystick inputs to rotate, translate an object in 3js. I have seen an example of Arduino interfacing with Blender/python using serial comms. I was wondering if this can be done on RPi.

What I remember -from my physical computing days- is that usually the other way around of communications has received a lot more atention, that is controlling boards like RPi by using javascript. Johnny Five is the go to framework for this, here it is the demo for blinking a led with a js script.

For simple things -within Windows- like use of joystick I’d recommend giving Gamepad API a try.

I think I can retrieve some scripts from an old external disc in regards to RPi. But keep in mind that the more complex the logic the more latency you would get.

2 Likes

The problem with running tjs environments in this way has been physical hardware limitations so it really depends which pi you have… vram on rpi<5 is heavily limited, your best bet using velocity / orientation / positional inputs from a rpi would be web sockets, essentially you’d build a minimal socket.io server on the pi that would relay simple click / move / rotate matrix value updates on a vector based scene, interperatable and consumable by three hosted on a capable client device, rather than host a full client side 3D app on the pi… You’d want to look at socket.io sessions

2 Likes

Thank you Antonio. You are spot on, it is hardware limitation. I will play around Johnny Five and Gamepad API, lets see how it goes.

Fair point. I have never thought about VRAM. In fact I don’t know a lot about VRAM. Cheers Lawrence.