Shop OBEX P1 Docs P2 Docs Learn Events
Javelin Stamp with Devantech SRF02 Sensor — Parallax Forums

Javelin Stamp with Devantech SRF02 Sensor

josh_ozjosh_oz Posts: 9
edited 2008-03-13 21:41 in General Discussion
I am having trouble interfacing with the SRF02 sensor. If someone has some experience with this sensor, I would like to know what kind of code I should use to test it.

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-03-13 21:41
    I have confirmation that the following code works:

    // Code for testing SRF02 sensor

    import stamp.core.*;
    public class test
    {
    · static final int pinTX = CPU.pin0;
    · static final int pinRX = CPU.pin1;
    · static Uart srfTX = new Uart(Uart.dirTransmit,pinTX,Uart.invert,Uart.speed9600,Uart.stop2);
    · static Uart srfRX = new Uart(Uart.dirReceive,pinRX,Uart.invert,Uart.speed9600,Uart.stop2);

    · public static void main()
    · {
    ··· int data;


    ··· srfTX.sendByte(0x00); //address
    ····srfTX.sendByte(0x50); //command Real Ranging Mode (result in inches)
    ··· while(true)
    ··· {
    ······· CPU.delay(10500); //wait 1 second
    ······· srfTX.sendByte(0x00); //address
    ······· srfTX.sendByte(0x5E); //command Get Range, returns 2 bytes
    ······· data = srfRX.receiveByte() << 8; //receive MSB
    ······· data += srfRX.receiveByte();·· //receive LSB
    ······· System.out.println(data);
    ···· }
    · }
    }


    regards peter
Sign In or Register to comment.