Hi
I am running a test project with SRF08 library.. the sensor works but never seems to return a distance great that 1.2-1.6 M
I have set the gain register to 0x31 and the location register to 0x8C but that has made no difference.
Has anyone got any ideas?
Many Thanks
Mike
#include <SonarSRF.h>
#include <SonarSRF02.h>
#include <SonarSRF08.h>
#include <Wire.h>
#define MAIN_08_ADDRESS (0x70)
SonarSRF08 MainSonar;
// Setup Analogue Gain
// http://www.robot-electronics.co.uk/htm/srf08tech.html section "Analogue Gain"
#define GAIN_REGISTER 0x31
// Setup Range Location
// http://www.robot-electronics.co.uk/htm/srf08tech.html section "Changing the Range"
#define LOCATION_REGISTER 0x8C
char unit = 'c'; // 'i' for inches, 'c' for centimeters, 'm' for micro-seconds
void setup() {
Serial.begin(9600);
MainSonar.connect(MAIN_08_ADDRESS, GAIN_REGISTER, LOCATION_REGISTER);
// isConnected("SRF08", MainSonar.getSoft());
}
void loop() {
float sensorReading = 0;
sensorReading = MainSonar.getRange(unit);
distance("sensor", sensorReading);
}
// Print out distance
void distance(String reference, int sensorReading) {
Serial.print("Distance from " + reference + ": ");
Serial.print(sensorReading);
Serial.println(unit);
}
// Print out distance
void isConnected(String reference, int sensorSoft) {
if (sensorSoft >= 0)
{
Serial.print("Sensor " + reference + " connected (");
Serial.print(sensorSoft);
Serial.println(")");
}
else
{
Serial.println("Sensor " + reference + " not detected");
}
}