Pages: [1]   Go Down
Author Topic: Wizard reading from the SFR02 Ultrasonic range finder  (Read 2188 times)
0 Members and 1 Guest are viewing this topic.
Buenos Aires, Argentina
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I´m working with the SFR02 Ultrasonic Range Finder (Devantech). And is given me one real measurement and then repeat 16 cm fake measurement four or five times, and then another real measurement. So this fake measurement doesn´t allow me to get a continous real mesurement.

HOW CAN I ABOID THIS 16 CM  FAKE MEASUREMENT ?, ANY CLUE, THANKS.

SFR02 Spec.

Range detection 16 cm to 600 cm

I use this code
Code:
*/

// include Wire library to read and write I2C commands:

#include <Wire.h>

// the commands needed for the SRF sensors:

#define sensorAddress 0x70

#define readInches 0x50

// use these as alternatives if you want centimeters or microseconds:

#define readCentimeters 0x51

#define readMicroseconds 0x52

// this is the memory register in the sensor that contains the result:

#define resultRegister 0x02

void setup()

{

  // start the I2C bus

  Wire.begin();

  // open the serial port:

  Serial.begin(9600);

}

void loop()

{

  // send the command to read the result in inches:

  sendCommand(sensorAddress, readCentimeters);

  // wait at least 70 milliseconds for a result:

  delay(70);

  // set the register that you want to reas the result from:

  setRegister(sensorAddress, resultRegister);

// read the result:

  int sensorReading = readData(sensorAddress, 2);

  // print it:

  Serial.print("distance: ");

  Serial.print(sensorReading);

  Serial.println(" Centimeters");

  // wait before next reading:

  delay(70);

}

/*

  SendCommand() sends commands in the format that the SRF sensors expect

 */

void sendCommand (int address, int command) {

  // start I2C transmission:

  Wire.beginTransmission(address);

  // send command:

  Wire.send(0x00);

  Wire.send(command);

  // end I2C transmission:

  Wire.endTransmission();

}

/*

  setRegister() tells the SRF sensor to change the address pointer position

 */

void setRegister(int address, int thisRegister) {

  // start I2C transmission:

  Wire.beginTransmission(address);

  // send address to read from:

  Wire.send(thisRegister);

  // end I2C transmission:

  Wire.endTransmission();

}

/*

readData() returns a result from the SRF sensor

 */

int readData(int address, int numBytes) {

  int result = 0;        // the result is two bytes long

// send I2C request for data:

  Wire.requestFrom(address, numBytes);

  // wait for two bytes to return:

  while (Wire.available() < 2 )   {

    // wait for result

  }

  // read the two bytes, and combine them into one int:

  result = Wire.receive() * 256;

  result = result + Wire.receive();

  // return the result:

  return result;

}
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13896
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


how much time is there between the readings? you have a delay of 70 millis() but it could be more. NB  five time 70 + the sertial prints etc ==>  500 millis between good readings.

Most devices that need time to "recover" from measurements. Check the datasheet, what does it say?

Rob

(and please don't shout smiley-wink
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Buenos Aires, Argentina
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Rob, Thanks for the reply. I re checked the datasheet, the  complete measurement cycle is 65ms, and recommends 70 ms delay between readings. Also said that the SFR02 doesn´t response to any command  on the I2C bus whilst it is ranging, so I have no clue by is getting this 16cm false measurement.


About the shout, was a mistake. didn´t see it.

Any tip or advice to give it a try?

Logged

New Hampshire
Offline Offline
God Member
*****
Karma: 17
Posts: 781
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I would try it via serial comms and see if the behavior is the same.
Logged


Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13896
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Pitu,

The strange thing is that it is (seems) to be consequent.
How about the wiring?
What is the length of the I2C wire?

Do have you pull up resistors in place ? Depending on the length they must be smaller See - http://www.gammon.com.au/forum/?id=10896 - at the bottom.

Further no ideas yet,
Rob
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Buenos Aires, Argentina
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I´m being doing some tests and now is given me right values from 16 cm away until 27 cm, but as soon as I try beyond 27 cm, it´s begin to reply with the fake 16 cm measurament .

I´m using a 100uf cap in parallel with the range finder to smooth it's power supply. As is recomend in the SFR02 Sonic Range Finder Reader Tutorial. But it didn´t make a diference about de ranging.

( http://arduino.cc/en/Tutorial/SFRRangerReader ).

Rob, the length of the 12C wire is less than 10 cm, but I planed to use longer wiring, so I´ll test with the 4.7k to check if I could get better results.

If doesn´t  work, i´ll try via serial as jraskell suggest.

« Last Edit: June 09, 2011, 02:36:57 pm by Pitu » Logged

Pages: [1]   Go Up
Jump to: