DIY 3D Controller

 by kylemcdonald
Contest WinnerFeatured

Step 7: Do Something Cool!

If you look at the serial window in the Arduino environment, you'll notice it's spitting out raw 3D coordinates at 115200 baud, at approximately 10 Hz = 60Hz / (2 full cycles * 3 sensors). The code takes measurements as many times as possible on each sensor over the period of two cycles of the mains power frequency (which is suprisingly stable) in order to cancel out any coupling.

The first thing I did with this was make a simple 3D Tic Tac Toe Interface. If you want to start with a working demo, the code is available here, just drop the folder "TicTacToe3D" in your Processing sketches folder.

Three helpful things that the Tic Tac Toe code demonstrates:

  • Linearizes the raw data. The charge time actually follows a power law relative to distance, so you have to take the square root of one over the time (i.e., distance ~= sqrt(1/time))
  • Normalizes the data. When you start up the sketch, hold the left mouse button down while moving your hand around to define the boundaries of the space you want to work with.
  • Adding "momentum" to the data to smooth out any jitters.

In practice, using this setup with aluminum foil I can get a range of the largest dimension of foil (the biggest piece I've tested is 1.5 square feet).
 
Remove these adsRemove these ads by Signing Up
hornedCapybara says: Apr 23, 2013. 4:24 PM
Hi,
I'm trying to make this work, and it isn't working.
I loaded the code to arduino, and i load the processing code and run it, and all i get is a blank white screen. Please tell me what im doing wrong!
TomB22 says: Mar 15, 2013. 4:54 AM
Hi
I installed processing and arduino software. I upload sketch to arduino and copied Tic Tac Toe 3D to sketch folder in processing. I'm running processing and I can see window with dimensions of 7x7cm, however I don't see any any points inside the square and I'm not sure how to initialize it. Could you pls help me out? Am I missing something? Thanks a lot for any help!
royshearer says: Dec 21, 2012. 4:37 AM
Does the serial port numbering array work in the same way in mac OSX?
I have

[0] "/dev/tty.usbmodemfa131"
[1] "/dev/cu.usbmodemfa131"
[2] "/dev/tty.Bluetooth-PDA-Sync"
[3] "/dev/cu.Bluetooth-PDA-Sync"
[4] "/dev/tty.Bluetooth-Modem"
[5] "/dev/cu.Bluetooth-Modem"

from Processing.
I upload to /dev/tty.usbmodemfa131 in Arduino successfully and get good numbers out of the serial monitor there.
When I use a [0] variable for the serial port in Processing however, I get a lot of interference on the serial monitor - not gobbledygook, just weird strings of numbers if varying lengths. I just see the grey cube and nothing else happens.
When I use a [1] variable i get the following error:
RXTX Warning: Removing stale lock file. /var/lock/LK.012.018.043
gnu.io.PortInUseException: Unknown Application
and lots more.

Am I doing anything wrong?
royshearer in reply to royshearerDec 21, 2012. 4:58 AM
I switched to the earlier v1.5 of Processing and that seemed to fix my problem. Greta fun now!
royshearer in reply to royshearerDec 21, 2012. 4:58 AM
I can use either [0] or [1] as serial port variables
phammer says: Sep 10, 2012. 9:45 AM
Hi I have got the thing up and running with the problem that when running the processor the gray box appears instead of the cubes and when I move my hand the grey box moves with my hand instead. Any solution for this?
avillanueva1 says: May 20, 2011. 5:10 PM
I had problems with the code, the processing tell me that i have an error ArrayIndexOutOfBoundsException 2, am i doing something wrong?
jimmy dean in reply to avillanueva1Jun 11, 2011. 8:47 AM
I am also getting the same error. It is pointing to this line in setup:

serial = new Serial(this, Serial.list()[serialPort], 115200);

Has anyone solved this yet?
jimmy dean in reply to jimmy deanJun 11, 2011. 9:11 AM
Ok, I figured it out.

If you were getting that error from the serial line, you have to make sure that the serial variable at the top is the correct serial port. If you look above the error, it should show the serial port that you are using. Mine was com4 so it showed:
[0] "COM4"
Therefore in my situation I had to change the serial variable to 0.

I also got that error randomly sometimes when I would run the program. I think that came from the board sending data before the program starts receiving it and then the program starting halfway through a line. To fix this I just made sure to hit the reset button at the same time I hit run on the processing code and it solved my problem.

Hope that helped :)
Account1212 in reply to jimmy deanMay 21, 2012. 11:07 PM
Hey, i know it's been awhile, but i am having a related issue, and i thought you might know how to fix it. See i switched the variable to 0, and it works, but 0 is for com1, and my arduino is plugged into com3. Com3 is 1, but whenever i change the variable to 1, the code doesn't run.
TopherT1 in reply to Account1212Aug 11, 2012. 3:45 PM
if you have 3 ports: COM1, COM2, COM3 and your Arduino is on COM2 you should set this to '1' - since the array is 0 based. In your case COM3 is "2".
samblam says: May 2, 2012. 6:14 AM
Hi there,
I just made the 3d controller and im now trying to make it work. Im new to processing so when I tried to 'just drop the folder TicTacToe3D' in the folder I found under sketch->show sketch folder it wasnt opening. so i just dragged the 3 .pde files on the screen and pressed Run.

This gave an error
in line 54: if(parts.length == sensors) {

'Cannot find anythin named "sensors"'

Does anyone know what is the problem and what is the solution?

Thanks,
kylemcdonald (author) in reply to samblamMay 20, 2012. 5:19 PM
yes, it looks like that's a bug with the code. i'm not sure how it got there, sorry!

change "sensors" to "sen" and it should run.
samblam in reply to kylemcdonaldJun 1, 2012. 4:44 AM
Thanks a lot, it's working now. Awesome!
pierceRom says: Jan 31, 2012. 10:29 PM
Hi there !!! im totally new at this whole electronics thing and I wanna try this project but i ran into a bit of problem.

I have built the board and everything but my problem is with the code. Where exactly is the code for the arduino ?? Or is the program " Processing" code suppose to upload the code into the arduino ?? Sorry if this question seems noob but im really new at this =(

Thank you soo much for any help !!
kylemcdonald (author) in reply to pierceRomJan 31, 2012. 11:09 PM
there is a link to the arduino code at the bottom of step 6. good luck!
pierceRom in reply to kylemcdonaldFeb 1, 2012. 7:48 AM
Thank you sooo much for the quicky reply !! So the interface code goes into the Arduino and the TicTacToe code goes into Processing ??

But shouldnt there be a camera in the code somewhere so i can interact with the TicTacToe game in 3d ??? Where would that code be ??

Sorry once again if my questions seems completely retarded , im really new at all this unfortunately =
kylemcdonald (author) in reply to pierceRomFeb 2, 2012. 2:19 PM
hey, you're welcome -- the delay in my response to a question is usually exponentially proportional to the complexity of the response, so the easy ones get answered fast :)

there is no camera involved here -- you just need to look at your hand :)

if you want to get a camera involved, you'll have to hack the processing sketch.

for the video i posted, i recorded the camera separately and composited them afterwards, just for demoing how things worked.
pierceRom in reply to kylemcdonaldFeb 2, 2012. 5:46 PM
Last question i promise !!

It seem that there were two files " Interface" and "Tic Tac Toe " in the download section .

So the interface code goes into the Arduino board and the TicTacToe code goes into Processing ??

Sorry but could you clarify that a little bit ??? Many many thanks for your help !!

Cheers

Pierce
rct1113 says: Jul 23, 2008. 5:55 PM
kylemcdonald (author) in reply to rct1113Jul 23, 2008. 6:14 PM
Thanks for the note -- I tried replying to some of the comments there, but they have yet to post my comment. Alas.
rct1113 in reply to kylemcdonaldJul 23, 2008. 7:36 PM
yeah, it can be hard to post on Gizmodo, they're all uptight on new posters, but I think that if you sent them a note saying that it's you're 'structible, then I think they'll let you in. Tell us what it's like on "the other side". ;)
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!