Pages: [1]   Go Down
Author Topic: Multiple SRF08 sonar sensor  (Read 363 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have two SRF08 sensors that have different addresses (e.g. 0xF8, 0xE0) but I can't get separate readings from them.
this is the code I am using(modified example):
Code:

#include <Wire.h>
#include <SonarSRF08.h>

SonarSRF08 sonar1;
SonarSRF08 sonar2;

#define CommandRegister 0x00
int sonar1address = 248; // 0xF8
int sonar2address = (int)0xE0;
#define ResultRegister  0x02
#define GainRegister 0x00 // Setup Analogue Gain -- http://www.robot-electronics.co.uk/htm/srf08tech.html section "Analogue Gain"
#define RangeLocation 0xFF // Setup Range Location -- http://www.robot-electronics.co.uk/htm/srf08tech.html section "Changing the Range"

int DEBUG = 1;
char unit = 'c'; // 'i' for inches, 'c' for centimeters, 'm' for micro-seconds
float sensorReading = 0;
int time = 70;


void setup()
{
  Wire.begin();
  if (DEBUG){
    Serial.begin(9600);
  }
  sonar1address += 4;
  // offset address not sure why this is but it works for this address
}

void loop()
{
  // set units, gain, and range location for reading out distance
  sonar1.setUnit(CommandRegister, sonar1address, unit, GainRegister, RangeLocation);
  // pause
  delay(time);
  // set register for reading
  sonar1.setRegister(sonar1address, ResultRegister);
  // read data from result register
  sensorReading = sonar1.readData(sonar1address, 2);
  // print out distance
  Serial.print("Distance1: ");
  Serial.print(sensorReading);
  Serial.print(" units");
  Serial.println();
  // pause
  delay(time);
 
  // set units, gain, and range location for reading out distance
  sonar2.setUnit(CommandRegister, sonar2address, unit, GainRegister, RangeLocation);
  // pause
  delay(time);
  // set register for reading
  sonar2.setRegister(sonar2address, ResultRegister);
  // read data from result register
  sensorReading = sonar2.readData(0xe0, 2);
  // print out distance
  Serial.print("Distance2: ");
  Serial.print(sensorReading);
  Serial.print(" units");
  Serial.println();
  // pause
  delay(time);
}


the original code can  be found at:  http://www.arduino.cc/playground/Main/SonarSrf08

how do I get the separate SRF08 readings?
Logged

Pages: [1]   Go Up
Jump to: