Using non-standard external hardware with Panda3D

Does anyone know how to use non-standard external hardware with Panda 3D? For instance, if for a game I want it to activate a small electrical motor, or turn on an LED light when something happens?

What interface do you have to your hardware? Is there a C library that you need to call, or a serial port that you need to write to, or a TCP/IP socket you need to send a message to, or a command-line program you need to run, or what?

In any case, it’s probably more of a Python question than a Panda3D question. But the exact answer depends on the nature of your interface to the hardware.


i’ve build a number of custom input/output devices and used some of them in combination. basically you can do whatever you want as long as you can easily read/write using python.

in my case i used atmega8 microcontrollers which connect to the pc using a good old serial connection (using usb2serial adapter). if you know how to handle those microcontrollers you can esily use digital and analog input, and digital output. switching led’s or motors, or reading values is no problem this way.

the hardware usualy can be assembled from a few very cheap parts. usualy less than 10$.

Here are some code snippets from a piece where I’m controlling vintage telegraph equipment synced with animation in Panda.

I use an Arduino as the interface, though many other micros would work well too.

First, you import the python serial library and set up your serial port. /dev/ttyUSB0 is the port name on linux, it’ll be other names on Win and OSX of course.

import serial
self.ser = serial.Serial ('/dev/ttyUSB0', 9600)

I play dots and dashes like this:

dashseq = Parallel (actor.actorInterval("dash"),tgraph.actorInterval("dash"),Func(self.sendToArduino,'-'))

“actor” and “tgraph” here are a character and his/her telegraph key in my scene, so this plays the two anim clips and calls sendToArduino() with a “dash” or a “dot”

	def sendToArduino(self,c):

the code on the arduino takes a - or . and converts that to the timing to activate the sounders. pretty easy.

following up on the arduino…would an atmega328 with 4 momentary buttons attached work? a little bit like the jam-o-drum…i have a physical device with 4 buttons that i need to identify individually and trigger accordingly in the virtual world!!

Thanks :smiley:

if it is only 4 buttons you could even rape an old keyboard controller for that job.

atmega on a serial port would work,too.