Jump to content
Sign in to follow this  
rickysinho

I2C - SRF10 and Stellaris

Recommended Posts

I still can not use SRF10 with stellaris, had already done the same library on MSP430 and worked, what can be?

The SRF10 simply does not send signal, to measure the distance.

 

My code is:

/*
Pins:
SDA ------ PB_3
SCL ------ PB_2
*/

#include <Wire.h>

void setup()
{
  Wire.begin();            
  Serial.begin(9600); 
}

int reading = 0;

void loop()
{
  Wire.beginTransmission(120);                              
  Wire.write(byte(0x00));        
  Wire.write(byte(0x50));                                                               
  Wire.endTransmission();      
  delay(70);                 
  Wire.beginTransmission(120);
  Wire.write(byte(0x02));    
  Wire.endTransmission();    
  Wire.requestFrom(120, 2);    
  if(2 <= Wire.available())    
  {
    reading = Wire.read();  
    reading = reading << 8;   
    reading |= Wire.read(); 
    Serial.println(reading); 
  }

  delay(250);               
}

 

Share this post


Link to post
Share on other sites

This code worked for me (sligthly adapted from the examples provided).

 

Please note that my I2C-Adress is not the default one and that you have to convert the 8bit Sensor-adress to 7bit e.g shift by one bit.

 

I also had to use the I2C-Module 1, the others wouldn't work for me.

 



#include <Wire.h>

#define SENSOR_ADRESS 115

void setup()
{
  Wire.setModule(1); 
  Wire.begin();                // join i2c bus (address optional for master)
  Serial.begin(9600);          // start serial communication at 9600bps
}

int reading = 0;

void loop()
{
  Serial.println("begin transmission");
  // step 1: instruct sensor to read echoes
  Wire.beginTransmission(SENSOR_ADRESS); // 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.write(byte(0x00));      // sets register pointer to the command register (0x00)  
  Wire.write(byte(0x51));      // command sensor to measure in "inches" (0x50) 
                               // use 0x51 for centimeters
                               // 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(SENSOR_ADRESS); // transmit to device #112
  Wire.write(byte(0x02));      // sets register pointer to echo #1 register (0x02)
  Wire.endTransmission();      // stop transmitting

  // step 4: request reading from sensor
  Wire.requestFrom(SENSOR_ADRESS, 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.read();  // receive high byte (overwrites previous reading)
    reading = reading << 8;    // shift high byte to be high 8 bits
    reading |= Wire.read(); // receive low byte as lower 8 bits
    //Serial.println(reading);   // print the reading
  }

  //delay(250);                  // wait a bit since people have to read the output 
}


/*

// The following code changes the address of a Devantech Ultrasonic Range Finder (SRF10 or SRF08)
// usage: changeAddress(0x70, 0xE6);

void changeAddress(byte oldAddress, byte newAddress)
{
  Wire.beginTransmission(oldAddress);
  Wire.write(byte(0x00));
  Wire.write(byte(0xA0));
  Wire.endTransmission();

  Wire.beginTransmission(oldAddress);
  Wire.write(byte(0x00));
  Wire.write(byte(0xAA));
  Wire.endTransmission();

  Wire.beginTransmission(oldAddress);
  Wire.write(byte(0x00));
  Wire.write(byte(0xA5));
  Wire.endTransmission();

  Wire.beginTransmission(oldAddress);
  Wire.write(byte(0x00));
  Wire.write(newAddress);
  Wire.endTransmission();
}

*/

Share this post


Link to post
Share on other sites

Sorry for my late reply, I somehow expected to get an email if someones writing in this topic :/

 

I can't remember if I was able to get readings beyond 45cm but I know it's possible as I've done it using another microcontroller.

 

You might want to experiment with different Gain- and Range-Values (see Datasheet). The values, in the sensor I've tried with, were probably already changed from the default values. Good luck and report your findings here :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×