Ultrasonic senor program won't compile


#1

Other example programs seem to compile fine, but the copy and pasted code won’t. I have also hand typed in the code with the same results.

Keep getting a status1 error.

Help would be appreciated

Thanks


#2

What version of arduino are you using? I had a problem with arduino compiling to but when i updated to a newer version it compiled the same code without any errors.


#3

Post the compiler output if you could, but I would check your includes for too many/overlapping/missing library


#4

Below is the code using version 1.6.7

#include<Makeblock.h>
#include<Arduino.h>
#include<SoftwareSerial.h>
#include<Wire.h>
#include “MeUltrasonicSensor.h”

MeUltrasonicSensor UltraSensor(PORT_6);
void setup()

{
Serial.begin(9600);
}

void loop()
{
Serial.print("Distance: ");
Serial.print(ultraSensor.distanceCm());
Serial.println(“cm”);
Serial.print(ultraSensor.distanceInch());
Serial.println(“inch”);
delay(100);
}


#5

OK, there are several errors in your code:

1.) Your includes: You need to include the library “MeOrion.h”, nothing else! This depends on the type of your board. Please read the ReadMe file, shipped with the library in order to see which of the board-libraries needs to be included for your board.

2.) Below the includes, you define the sensor as
MeUltrasonicSensor UltraSensor(PORT_6);
but in the loop, you call it ultraSensor.
That makes a huge difference to the compiler! you need to match the exact writing.

See below the original code of the UltrasonicSensorTest sketch:
(btw: When you want to paste code, select it and format it as “Preformatted Text”, then it looks better)

#include "MeOrion.h"

MeUltrasonicSensor ultraSensor(PORT_7); /* Ultrasonic module can ONLY be connected to port 3, 4, 6, 7, 8 of base shield. */

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

void loop()
{
  Serial.print("Distance : ");
  Serial.print(ultraSensor.distanceCm() );
  Serial.println(" cm");
  delay(100); /* the minimal measure interval is 100 milliseconds */
}

Check to name the correct port in the script, looks like you have connected the sensor to PORT_6

Hope this helps :slightly_smiling:
Stefan


#6

Actually, the compiler output is below the code window in Arduino, below is an example of what I wanted to see.

This program is from the examples, and appears to be the one you are using, but you maybe got a spell check or something on that typo.

Good catch on that typo @srothe , and the library thing. I’ve found most of those examples have the Makeblock library
which may be good on mBot but not Orion? Anyway, the program will compile with the libraries as written when the correct board is selected, so I wanted to be sure that is correct as well. (That doesn’t mean it will necessary run on Orion)

The program below compiles with the board selected as Arduino/Genuino Uno, but with the incorrect board selected, we have the Status 1 message.


#7

@Gort: This changed since library 3.0. Now you need to include the proper library for your board, as explained in thd ReadMe file, delivered with thw download of the library.
Cheers, Stefan


#8

Yes, this is an example of choosing the wrong board with the correct libraries, in case that is the issue. Choosing Arduino/Genuino Uno would be correct for these libraries.

Point being, many examples written use the Makeblock library along with Arduino, Wire, and Serial.

Are you saying the Orion lib covers/replaces all the mentioned libraries/functions and uses the same function syntax?


#9

No @Gort, I am saying that one needs to read the ReadMe file delivered with the library 3.X :slightly_smiling:
Taking the change for the correct board into account, the examples delivered with the library work pretty well.


#10

I appreciate the example you gave me, but it still won’t upload. I got it to finally compile, but while the software has identified com4 as being ready, it complains that it cannot communicate using it.


#11

Well, this sounds like a configuration problem at your computer. Double check which port your board is connected to, and that you selected the correct board type.


#12