I2C???
import stamp.core.*;
import stamp.peripheral.io.I2C;
public class SRF02{
· static I2C i2cBus = new I2C(CPU.pin0, CPU.pin1);
· static int Distance=0;
· static int Light=0;
· static int DataHigh = 0;
· static int DataLow = 0;
· public static void main() {
··· while (true) {
····· Distance = getSRF08Data ();
····· System.out.print("Distance(cm) is ");
····· System.out.println(Distance + "\n");
····· CPU.delay(20000);
··· }
· }
· public static int getSRF08Data(){
··· System.out.print("Reading SRF08 Data ");
··· System.out.print(".....");
··· i2cBus.start();
··· i2cBus.write(0x0);
··· CPU.delay(1);
··· i2cBus.write(0x51);
··· DataHigh = i2cBus.read(0);
··· DataLow = i2cBus.read(1);
··· i2cBus.stop();
··· System.out.println("Done");
··· return(DataHigh+DataLow);
· }
}
Hi,
I used the following code to make an I2C connection between the Javelin and an ultrasonic sensor.
However, it seems to return 510 all the time. I'm not sure if something is wrong with the commands.. (There's no compile-time error).
Can someone help me out?
The list of commands are found in: http://www.robot-electronics.co.uk/htm/srf02tech.htm
import stamp.peripheral.io.I2C;
public class SRF02{
· static I2C i2cBus = new I2C(CPU.pin0, CPU.pin1);
· static int Distance=0;
· static int Light=0;
· static int DataHigh = 0;
· static int DataLow = 0;
· public static void main() {
··· while (true) {
····· Distance = getSRF08Data ();
····· System.out.print("Distance(cm) is ");
····· System.out.println(Distance + "\n");
····· CPU.delay(20000);
··· }
· }
· public static int getSRF08Data(){
··· System.out.print("Reading SRF08 Data ");
··· System.out.print(".....");
··· i2cBus.start();
··· i2cBus.write(0x0);
··· CPU.delay(1);
··· i2cBus.write(0x51);
··· DataHigh = i2cBus.read(0);
··· DataLow = i2cBus.read(1);
··· i2cBus.stop();
··· System.out.println("Done");
··· return(DataHigh+DataLow);
· }
}
Hi,
I used the following code to make an I2C connection between the Javelin and an ultrasonic sensor.
However, it seems to return 510 all the time. I'm not sure if something is wrong with the commands.. (There's no compile-time error).
Can someone help me out?
The list of commands are found in: http://www.robot-electronics.co.uk/htm/srf02tech.htm
Comments
so try this
··· i2cBus.start();
··· i2cBus.write(0xE0); //device address
··· i2cBus.write(0x00);·//register
··· i2cBus.write(0x51); //range cm
··· CPU.delay(700); //wait 65 msec
··· DataHigh = i2cBus.read(2);
··· DataLow = i2cBus.read(3);
··· i2cBus.stop();
regards peter
·Hi, Thank you for your response, but I don't seem to get the correct range... I'm still getting 510.
Is there something wrong with either my sensor or my Javelin???
whereas your read method is called getSRF08Data().
So which device do you have, because the SRF02 has both a serial and I2C interface.
If you have the SRF02 make sure the I2C interface is selected.
Also,·do you have 4.7k pullup resistors on javelin I/O pins 0 and 1?
regards peter