We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpElectronics,  Serial Library › I2C ultrasound sensor sourcecode
Page Index Toggle Pages: 1
I2C ultrasound sensor sourcecode (Read 858 times)
I2C ultrasound sensor sourcecode
Feb 13th, 2009, 12:47pm
 
I have been meaning to package this java file into a library but always seemed to stop myself in time, apart from weird jvm fights with eclipse crashing and so on. In the spirit of backups, which are most reliable if they are submitted to the community to keep, here is the raw source of my java file. Hopefully it will save someone some trouble.

The long and the short of it is this class when instantiated will makes a new thread, detect ultrasound sensors connected to the USB port with a Serial/USB/I2C converter hardware. It will then continuously probe each sensor in turn. The draw method can then ask the values when it likes.

Find the hardware at robot-electronics.co.uk.

Code tested on Windows XP professional SP2 and Ubuntu Hardy Heron and Intrepid Ibex. Unfortunately the last thorough test was done on the 0135 version of processing. For what its worth it doesn't crash on 1.0.1 though.

find the java here http://home.imaginet.co.za/maia/DistanceSensor.java

1. Drop the java file in your sketch
2. Instantiate the DistanceSensor class with the string which identifies your USB/Serial port on your system e.g."/dev/ttyUSB0" or "COM4"
3. call the getDistance method passing the sensor number starting from 0 and get the distance it sees something in cm.

Of course any comments&crits welcome




Page Index Toggle Pages: 1