Loading...
Pages: [1]   Go Down
Author Topic: srfo8 and wire. anything  (Read 271 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Has anyone used a srf08 range finder with an arduino. I have found code for literally every other controller except arduino. I used the wiring library for i2c communication and found this code, (see below)  but it won't compile in arduino. When I try I get a ton of syntax errors and then it says it can't determine file size. Im using the analogue ports 4,5 for the data send/receive line and the master clock, has anyone used these ports for slaving/controlling other IC's, is this info real,  where am I, who said that….. ?
Any help would be great'
john

//- SRF08 code-------------------
 
#include <TwoWire.h>
 
void setup()  
{  
  Wire.begin();                // join i2c bus (address optional for master)  
  Serial.begin(19200);          // start serial communication at 19200bps  
}  
 int reading = 0;  
 void loop()  
{  
  // step 1: instruct sensor to read echoes  
  Wire.beginTransmission(112); // transmit to device #112 (0x70)  
  // the address specified in the datasheet is 224 (0xE0)  
  // but i2c adressing uses the high 7 bits so it's 112  
  Wire.send(0x00);             // sets register pointer to the command register (0x00)  
  Wire.send(0x51);             // command sensor to measure in cm (0x51)  
  // use 0x52 for ping microseconds  
  Wire.endTransmission();      // stop transmitting  
 
  // step 2: wait for readings to happen  
  delay(70);                   // datasheet suggests at least 65 milliseconds  
 
  // step 3: instruct sensor to return a particular echo reading  
  Wire.beginTransmission(112); // transmit to device #112  
  Wire.send(0x02);             // sets register pointer to echo #1 register (0x02)  
  Wire.endTransmission();      // stop transmitting  
 
  // step 4: request reading from sensor  
  Wire.requestFrom(112, 2);    // request 2 bytes from slave device #112  
 
    // step 5: receive reading from sensor  
  if(2 <= Wire.available())    // if two bytes were received  
  {  
    reading = Wire.receive();  // receive high byte (overwrites previous reading)  
    reading = reading << 8;    // shift high byte to be high 8 bits  
    reading |= Wire.receive(); // receive low byte as lower 8 bits  
    Serial.println(reading);   // print the reading  
  }  
 
  delay(250);                  // wait 250ms
}
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

got it working. no worries smiley
Logged

Daniel
Guest
 Bigger Bigger  Smaller Smaller  Reset Reset

excellent-- did you see that the code above in included in Arduino 006, along with the Arduino verison of the Wire library, but now called "wire.h"?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@john henry:

i've tried to use a srf08 too but failed...

first you've postet you've got syntax errors but you got it to work later... can you post the working code please...
and a photo of your hardwaresetup would be nice too... so people can the the wiring and extraparts... would be nice...
thx
peter
Logged

Pages: [1]   Go Up
Print
 
Jump to: