sonar sensor srf08 error compiling code

hi hoping someone can help. i'd like to incorporate a sonar sensor into one of my projects and had a srf08 laying about. I found this setup instruction in the playground http://www.arduino.cc/playground/Main/SonarSrf08

however after downloading the library from that page and after trying to verify the code (also unchanged from that page) i got this error compiling message

/Applications/Arduino.app/Contents/Resources/Java/libraries/Sonar_srf08/Sonar_srf08.cpp:49: error: case label does not reduce to an integer constant

I found another post about a similar problem however no solutions. http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1261230637/5

I'm using mac OSX 10.5.8 and using arduino 0018 if this helps.

any help would be much appreciated

void Sonar_srf08::setUnit(int commandRegister, int address, char units){
  switch(units) {
        case [glow]"[/glow]i[glow]"[/glow]: ;
  Sonar_srf08::sendCommand(commandRegister, address, 0x50);
  break;
        case [glow]"[/glow]c[glow]"[/glow]: ;
  Sonar_srf08::sendCommand(commandRegister, address, 0x51);
  break;
  default:
  Serial.print("Invalid Units Entered...");
  Serial.println();
  }
}

Highlighted should be single quotes.

a similar problem however no solutions.

In reply #5:

If you change the "switch" in "setUnit" to use single quotes, it should compile.

ahh in the .cpp file... got you. Thanks for that

as for

Quote: a similar problem however no solutions. In reply #5: Quote: If you change the "switch" in "setUnit" to use single quotes, it should compile.

I didn't quite understand what this meant or where it was... I do now ... thanks again.

Sorry, I re-read the other thread, and I think I can see why you thought it was unresolved, but I think the OP must have had other issues with their sketch, but didn't follow them up (or post their sketch). Hope it's working now.

well got I the code to work.... I think the sensor might be bust though... I cant get a distance reading off it, keeps returning a 0 inch reading... Ill try and have a look at it later....

any ideas on how I can test the sensor??

Without an oscilloscope, no not really. Unless 40kHz will annoy your cat/dog. Does the SRF08 have an LED, and does it flash when you take a reading? Could you post your code as it is now? (please use the # button on the editor's toolbar)

It has a small led on the back that flashes,
the code I’m using to see if i can get it to work is

#include <Wire.h>
#include <Sonar_srf08.h>

Sonar_srf08 MySonar;

#define CommandRegister 0x00
int New_Address = 248; //0xF8
#define ResultRegister  0x02

int DEBUG = 1;
char unit = 'i'; // 'i' for inches , 'c' for centimeters
float sensorReading =0;


void setup()
{
 MySonar.connect();  
 MySonar.changeAddress(CommandRegister, New_Address);
 if (DEBUG){
   Serial.begin(9600);
 }
 New_Address += 4; 
//offset address not sure why this is but it works for this address
}

void loop()
{
// set units for reading out distance
  MySonar.setUnit(CommandRegister, New_Address, unit);
//pause
  delay(70);
// set register for reading
  MySonar.setRegister(New_Address, ResultRegister);
// read data from result register
  sensorReading = MySonar.readData(New_Address, 2);
//print out distance
  Serial.print("Distance: ");
  Serial.print(sensorReading);
  Serial.print(" inches");
  Serial.println();
//pause
  delay(70);
}

as in the playground example.

I have wired up everything as in the diagram except for the 1.8 kOhm pullup resistor.
I don’t have one so I did the best I could with what i have and I’m getting 1.84 kOhm through 3 resistors.
However I’ve been talking to the guy I got the sensor off and he reckons it should have a 4.7kOhm resistors which I tried, and again i dont have one so I’m getting 4.72kOhm trough 6 resistors this time
and I’m getting the same result.

Distance: 0.00 inches

Is the .04 or .02kOhm going to cause a problem??

Is +/- 20 or 40 ohms causing a problem?
No. Not at all.

Does the LED flash repeatedly, or only at power on?

If it flashes repeatedly, this suggests that I2C is working correctly, so the problem lies elsewhere.

If it only flashes once, this may suggest that you still have some I2C issues.

If you have a scope, you could probe the back of the transmit transducer, and check that the pulses (8 @ 25us each, IIRC) are going out.