Go Down

Topic: Multiple SRF08 sonar sensor (Read 447 times) previous topic - next topic

NeoStark

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: [Select]


#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?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy