Notice: Undefined index: order_next_posts in /nas/content/live/gadgetmag/wp-content/plugins/smart-scroll-posts/smart-scroll-posts.php on line 194

Notice: Undefined index: post_link_target in /nas/content/live/gadgetmag/wp-content/plugins/smart-scroll-posts/smart-scroll-posts.php on line 195

Notice: Undefined index: posts_featured_size in /nas/content/live/gadgetmag/wp-content/plugins/smart-scroll-posts/smart-scroll-posts.php on line 196

DiceBot interview

Request a roll from the tweet-powered dice machine, made from the unlikely mix of Ruby, Python and Pi with an antique game

So where did the idea come from – was it a personal project?

I worked on it myself. I got a little help on the website from some others at Intridea, but we’ve been working as a company just exploring various interfaces and social machines – Internet of Things, things like that. So it’s kind of how this idea came about. We have a few projects that we’re working on at the moment that are in a similar vein but this is the first one we’ve published. So I came across this little dice roller and I thought ‘Hey, this would make a perfect internet- controlled device’. And it would be a fun project, using something old and retro.

This antique dice game originally had a push button on the side that was spring-loaded to spin the platform and roll the dice
This antique dice game originally had a push button on the side that was spring-loaded to spin the platform and roll the dice

The dice roller looks amazing – where did you find that thing?

I actually found it on eBay and supposedly it’s from the Twenties – it shows a lot of age and wear. It’s a little tin device and it used to have a tiny push button on the side with a little gear. You push that in and, as it was spring-loaded, you’d let go and it’d pop, and the little platform would spin with a couple of little dice in there.

So did you rig up some motors with the Raspberry Pi and get the original mechanism working then?

I pulled out the old mechanism and replaced it because it wasn’t very reliable, since it was quite old. So yeah, I connected a motor to it and connected that to a little motor controller, a servo controller, and that to the Raspberry Pi. Then, on the Raspberry Pi, I ran some software to control everything.

What method are you using to read the tweet feed, then?

I’m using a Ruby script that I wrote and I’m using a library called Tweetstream. It’s a Ruby library, so it’s basically listening on Twitter for any mention of @IntrideaDiceBot as well as the hashtag #RolltheDice. Every time it runs across that it queues a job, putting it into something called Firebase. From there there’s another script that’s running that listens for jobs on that queue, and whenever it finds one it picks it up and it does the rest. It spins the device through the GPIO pins on the Raspberry Pi, and that’s using a Python script. So, it calls the Python script to spin the device through the GPIO, and then it takes a picture using the raspistill command. Then it uploads that to Amazon AWS, to Amazon S3, and then it runs an OpenCV program I created that basically takes that image and runs a Canny on it, trying to figure out how many pips are visible. From there it takes the image, takes the results of the OpenCV output, and then it tweets back the result as well prints the results back into Firebase, so the website can display it in real-time.

How long did it take to make this?

It was actually pretty straightforward; it was just a weekend project to build the device and to write the scripts. The scripts are pretty straightforward and simple as well. I also had to build the platform that it sits on. It used to just be a bunch of loose parts – you know, the Raspberry Pi, the controller and the dice spinner. It’s kind of hard to set the camera to get the right angle of image over it, so I just built this little platform out of wood around it. It makes it quite portable, and I was able to put the camera into a fixed position so that it’s always getting the same angle and the same shot. That seemed to work quite well. So really it was just a weekend, and then probably another day or two for final assembly and polish, things like that.

Do you have any plans to make it interactive, so that people could play against the tweet feed?

Yeah we’ve had all sorts of thoughts about stuff like that, and the fun things we could do running and creating some simple games you could play over Twitter. We’ve thought about using different kinds of dice and doing image recognition for the number versus just the pips on the device, for when you get into higher- sided dice. So yeah, I think there are a lot of possibilities and we’re kind of thinking about those – and hopefully soon we can build some fun things around it. Another option is to create a simple API that people can use to get random numbers – so a physical random number generator that they could call via an API from another program or something.

…There – it’s spinning. I don’t know if you heard that but it’s driving me nuts, because I’m sitting next to it!