Hi,
I have a problem with a SRF08 Supersonic-Sensor on an Arduino UNO. I don't know the I2C address because somebody changed it. When the sensor gets power it blinks two times at all what should mean that the address is E2 but I don't get it to change the standardcode the right way:
#include <Wire.h>
#include <SoftwareSerial.h>
#define rxPin 2 // Software serial pin for rx
#define txPin 3 // Software serial pin for tx
#define srfAddress 0x07 // Address of the SRF08
#define cmdByte 0x00 // Command byte
#define lightByte 0x01 // Byte to read light sensor
#define rangeByte 0x02 // Byte for start of ranging data
byte highByte = 0x00; // Stores high byte from ranging
byte lowByte = 0x00; // Stored low byte from ranging
void setup(){
Serial.begin(9600); // Begins serial port for Serial
Wire.begin();
delay(100); // Waits to make sure everything is powered up before sending or receiving data
}
void loop(){
Serial.print("Range = ");
int rangeData = getRange(); // Calls a function to get range
Serial.println(rangeData, DEC); // Print rangeData to LCD03
delay(100); // Wait before looping
}
int getRange(){ // This function gets a ranging from the SRF08
int range = 0;
Wire.beginTransmission(srfAddress); // Start communticating with SRF08
Wire.send(cmdByte); // Send Command Byte
Wire.send(0x51); // Send 0x51 to start a ranging
Wire.endTransmission();
delay(100); // Wait for ranging to be complete
Wire.beginTransmission(srfAddress); // start communicating with SRFmodule
Wire.send(rangeByte); // Call the register for start of ranging data
Wire.endTransmission();
Wire.requestFrom(srfAddress, 2); // Request 2 bytes from SRF module
while(Wire.available() < 2); // Wait for data to arrive
highByte = Wire.receive(); // Get high byte
lowByte = Wire.receive(); // Get low byte
range = (highByte << 8) + lowByte; // Put them together
return(range); // Returns Range
}
I'm not sure which parameter I must change and everything I tried didn't work.
Toby
(Sorry for my English. I'm from Germany)