For those who might be curious, here is how i wired up the Arduino and Dice Roller:
First, as I posted here
, I ordered a $10 battery (2xAA) powered dice spinner from Amazon. You push a button and the base spins for a second or so, throwing the dice out to the edge where it tumbles against a sloped incline; the friction of the base and the angle of the edge seems to do quite a good job of randomly spinning dice of various shapes.
Next, I got an Arduino (R3) and a Sainsmart single channel Relay
. A relay is a switch that allows an external source of power through it when it is closed.
I soldered an additional (parallel) connection from battery to motor through the relay -- basically acting as a parallel way to complete the circuit that the existing button on the device provides. Now you can push the button to spin the dice, OR activate the relay.
Next a tiny script(sketch) was written for the Arduino, which just loops and listens to serial (usb) connection for a simple signal telling it to spin the die for a certain amount of time. When the signal arrives, it turns on the relay (a simple command to the pin on the Arduino that drives the relay) briefly, and then turns it off.
Next, my python dice control code uses the PySerial library to send the signal to the Arduino when it wants the dice rolled. The script already has code that notices when the dice are moving, and waits until they settle before performing another cycle of processing, so everything proceeds automatically once they die settles.
It can perform a roll and visual processing of a die about once every 1.5 seconds.
The only real complication I've had is that the Arduino seems to sometimes loose connection with the serial communication. So my code has to check that the Arduino confirms it has received the command, and if not, occasionally disconnect and reconnect. This works most of the time but occasionally the Arduino just won't wake up and requires a hardware reset. This would not be acceptable for a setup that required a high-level of uptime, but for this project it's not a show stopper.