0

Hi, I am a pretty novice coder and I am getting this error consistently with a library I have installed. Here is the code I am trying to run:

#include <Wire.h>
#include <SonarSRF02.h>
#include <SonarSRF08.h>

#define leftAddress ( 0xF2 >> 1)
#define rightAddress ( 0xE0 >> 1)
#define mainAddress ( 0xF8 >> 1)
SonarSRF02 LeftSonar;
SonarSRF02 RightSonar;
SonarSRF08 MainSonar;

char unit = 'c'; // 'i' for inches, 'c' for centimeters, 'm' for micro-seconds

void setup() {
    Serial.begin(115200);

    LeftSonar.connect(leftAddress);
    Serial.println("Left SRF02 US-Sensor ");
    Serial.println(LeftSonar.getSoft());

    RightSonar.connect(rightAddress);
    Serial.println("Right SRF02 US-Sensor ");
    Serial.println(RightSonar.getSoft());

    MainSonar.connect(mainAddress);
    Serial.println("Main SRF08 US-Sensor ");
    Serial.println(MainSonar.getSoft());
}

void loop() {
    float sensorReading = 0;

    sensorReading = LeftSonar.getRange(unit);
    // print out distance
    Serial.print("Distance from left: ");
    Serial.print(sensorReading);
    Serial.print(" ");
    Serial.print(unit);
    Serial.println();

    sensorReading = RightSonar.getRange(unit);
    // print out distance
    Serial.print("Distance from right: ");
    Serial.print(sensorReading);
    Serial.print(" ");
    Serial.print(unit);
    Serial.println();

    sensorReading = MainSonar.getRange(unit);
    // print out distance
    Serial.print("Distance from main: ");
    Serial.print(sensorReading);
    Serial.print(" ");
    Serial.print(unit);
    Serial.println();
}

My project is using an SRF08 sensor with an Arduino Mega 2560

1 Answer 1

3

Please note that I did not try to run your code on my Mega because I don't have SRFs

However, here is what I tried to recreate your error:

  • I went to the arduino homepage and downloaded the 1.0.5 version.

  • I downloaded the zipped library from this page SRF08 Ultra Sonic Range Finder

  • I imported the library into the arduino IDE. For this, I had to unpack the .zip and rename the folder of the library because arduino complained about non-ascii characters. I just called the enclosing folder "arduinoSRFmaster" without dashes. After that it let me import the library the usual way:

    How to Install a Library

  • After that I copied your code into a new sketch and hit Ctrl + R to compile and verify. It compiled just fine:

    Successfull compiling

(Picture updated for compiling against MEGA)

Please provide more information, like yor OS, Arduino Version, where you got the SRF Library from etc. if that didn't help.

4
  • It seems you have compiled for UNO, maybe the problem is specific to Mega?
    – jfpoilpret
    May 30, 2014 at 10:56
  • There should not be anything specific to the UNO in the code, therefore that should not be any issue. I updated my answer anyway.
    – Dave
    May 31, 2014 at 15:51
  • Sometimes OS might be a problem. When I used BLE library from Redbearlabs. And compile it I got an error message on Ubuntu. But when I did the same procedure with windows I was able to compile my sketch.
    – Handoko
    Jun 1, 2014 at 1:33
  • I'll try it on Ubuntu and Mac and update my answer
    – Dave
    Jun 2, 2014 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.