"_____ Does not name a type"

Hi there, I’m having trouble resolving an issue with compiling my code. I am extremely new at this so it could be a trivial issue.

I am using the CTC 101 kit with an Arduino UNO for tutorials with the education shield piece which can be added onto the top of the UNO, and I am on a OSX. From what I can tell this is a library issue but I am unsure on how to fix it.

The error i am getting is “Does not name a type”, here is an example from the 5.1 tutorial

exit status 1
'IMU' does not name a type

Here is the code provided by the tutorial on the website, however the issue is with defining the IMU with the 4th line “IMU imu;”

#include <EducationShield.h>


IMU imu; // the IMU

const int piezoPin = 8; //piezo

const int ledPin = 13;      // activity LED pin
boolean blinkState = false; // state of the LED


void setup() {
  // configure Arduino LED for activity indicator
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH); // turn on LED to show that the board has executed


  Serial.begin(9600); // initialize Serial communication
  while (!Serial);    // wait for the serial port to open


  imu.begin();
 



  // blink the LED again to show that the calibration is done
  blinkState = !blinkState;
  digitalWrite(ledPin, blinkState);

  pinMode(piezoPin, OUTPUT);
}

void loop() {
  // start the IMU read
  imu.run();

  // read raw gyro measurements from the IMU device
  int gx = imu.getGyroX();
  int gy = imu.getGyroY();

  // map the raw value to be on a smaller scale
  gx = map(gx, -36044 , 36043 , -360, 360);
  gy = map(gy, -36044 , 36043 , -360, 360);


  // print the measurements
  Serial.print(gx);
  Serial.print("\t");
  Serial.println(gy);



  //Computes the absolute value of the IMU read
  gx = abs(gx);
  gy = abs(gy);



  // add together the 2 values and use them for setting the frequency for the speaker to play
  int frequency = gx  + gy;
  frequency = frequency / 2;
  frequency = map(frequency, 0, 360, 0, 1000);

  // only play a sound if the frequency is not too low or the IMU is still
  if (frequency > 50) {
    tone(piezoPin, frequency);
  } else {
    noTone(piezoPin);// stop the sound
  }

  // blink LED to indicate activity
  blinkState = !blinkState;
  digitalWrite(ledPin, blinkState);
  delay(30);
}

From everything I’ve been able to find, this is an issue with the library it includes from, but i have the correct library provided and I believe it is in the correct folder (Documents/Arduino/libraries).

This is my first time posting. sorry if I missed anything.

That library also includes in the IMU library?

When you look in the Arduino/libraries directory you see a folder named “IMU”?

Yes I believe it does, but this is not the first time I have had this issue. Using VUMeter is another example of the same thing happening

So add in

#include <IMU>

And your belief system will know.

sorry, I think I misunderstood your first question, I mean to say that the IMU code is included within the Education Shield library, it doesnt have its own library in the folder.
when using

#include <IMU>

this is the result

exit status 1
IMU: No such file or directory

Here is the code from the IMU.cpp file itself, but it is within the Education shield library im trying to include from

#if defined(__arc__)

#include "EducationShield.h"
#include "Arduino.h"
#include "CurieIMU.h"
#include "CurieTimerOne.h"

#define RESTRICT_PITCH // Comment out to restrict roll to ±90deg instead - please read: http://www.freescale.com/files/sensors/doc/app_note/AN3461.pdf

long IMU::timer;
bool IMU::useISR=false;

int IMU::accRange,IMU::gyroRange;

int16_t IMU::ax,IMU::ay,IMU::az;
int16_t IMU::gx,IMU::gy,IMU::gz;

float IMU::pitch,IMU::roll;

IMU::IMU(){	
}

void staticRun(){
  IMU::run();
}

void IMU::begin(int accRange, int gyroRange){
  //Serial.println("Initializing IMU device...");
  CurieIMU.begin();

  CurieIMU.setAccelerometerRange(accRange);
  CurieIMU.setGyroRange(gyroRange);

  IMU::accRange=accRange;
  IMU::gyroRange=gyroRange;

  if(USE_ISR){
    CurieTimerOne.start(10,&staticRun);  
  }
}


void IMU::calibrate(){
  
  // verify connection
  Serial.println("Testing device connections...");
  if (CurieIMU.testConnection()) {
    Serial.println("CurieIMU connection successful");
  } else {
    Serial.println("CurieIMU connection failed");
  }

  // use the code below to calibrate accel/gyro offset values
  Serial.println("Internal sensor offsets BEFORE calibration...");
  Serial.print(CurieIMU.getXAccelOffset());
  Serial.print("\t"); // -76
  Serial.print(CurieIMU.getYAccelOffset());
  Serial.print("\t"); // -235
  Serial.print(CurieIMU.getZAccelOffset());
  Serial.print("\t"); // 168
  Serial.print(CurieIMU.getXGyroOffset());
  Serial.print("\t"); // 0
  Serial.print(CurieIMU.getYGyroOffset());
  Serial.print("\t"); // 0
  Serial.println(CurieIMU.getZGyroOffset());


  Serial.println("About to calibrate. Make sure your board is stable and upright");
  delay(5000);

  // The board must be resting in a horizontal position for
  // the following calibration procedure to work correctly!
  Serial.print("Starting Gyroscope calibration...");
  CurieIMU.autoCalibrateGyroOffset();
  Serial.println(" Done");
  Serial.print("Starting Acceleration calibration...");
  CurieIMU.autoCalibrateXAccelOffset(0);
  CurieIMU.autoCalibrateYAccelOffset(0);
  CurieIMU.autoCalibrateZAccelOffset(1);
  Serial.println(" Done");

  Serial.println("Internal sensor offsets AFTER calibration...");
  Serial.print(CurieIMU.getXAccelOffset());
  Serial.print("\t"); // -76
  Serial.print(CurieIMU.getYAccelOffset());
  Serial.print("\t"); // -2359
  Serial.print(CurieIMU.getZAccelOffset());
  Serial.print("\t"); // 1688
  Serial.print(CurieIMU.getXGyroOffset());
  Serial.print("\t"); // 0
  Serial.print(CurieIMU.getYGyroOffset());
  Serial.print("\t"); // 0
  Serial.println(CurieIMU.getZGyroOffset());

  Serial.println("Enabling Gyroscope/Acceleration offset compensation");
  CurieIMU.setGyroOffsetEnabled(true);
  CurieIMU.setAccelOffsetEnabled(true);

}

void IMU::detectShock(int shockThreashold, int shockDuration){
  /* Enable Shock Detection */
  CurieIMU.setDetectionThreshold(CURIE_IMU_SHOCK, 1500); // 1.5g
  CurieIMU.setDetectionDuration(CURIE_IMU_SHOCK, 11);   // 30ms
  CurieIMU.interrupts(CURIE_IMU_SHOCK);

  /* Enable Interrupts Notifications */
  //CurieIMU.setIntEnabled(true);
}
void IMU::attachCallback(void (*callback)(void)){
	  CurieIMU.attachInterrupt(callback);
}

void IMU::measureMotion(){
	// read raw accel/gyro measurements from device
	CurieIMU.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
}



void IMU::calculateRollPitch(){
	// Source: http://www.freescale.com/files/sensors/doc/app_note/AN3461.pdf eq. 25 and eq. 26
	// atan2 outputs the value of -π to π (radians) - see http://en.wikipedia.org/wiki/Atan2
	// It is then converted from radians to degrees
	#ifdef RESTRICT_PITCH // Eq. 25 and 26
	  roll  = atan2(ay, az) * RAD_TO_DEG;
	  pitch = atan(-ax / sqrt(ay * ay + az * az)) * RAD_TO_DEG;
	#else // Eq. 28 and 29
	  roll  = atan(ay / sqrt(ax * ax + az * az)) * RAD_TO_DEG;
	  pitch = atan2(-ax, az) * RAD_TO_DEG;
	#endif

}
void IMU::calculateComplementaryRollPitch(){
  /*long dt=millis()-timer;
  timer=millis();*/
  float dt=10;

  pitch=pitch-convertGyro_dps(gy)*(dt/1000.0);
  roll=roll+convertGyro_dps(gx)*(dt/1000.0);

  float pitchAcc=atan2(ax,az)*RAD_TO_DEG;
  float rollAcc=atan2(ay,az)*RAD_TO_DEG;

  pitch=pitch*0.98+pitchAcc*0.02;
  roll=roll*0.98+rollAcc*0.02;
}

void IMU::run(){
	if(USE_ISR)return;

  measureMotion();

  if(FILTER_TYPE==0){
    calculateRollPitch();
  }else if(FILTER_TYPE==1){
    calculateComplementaryRollPitch();
  }
}

int IMU::getPitch(){
	return (int)pitch;
}

int IMU::getRoll(){
	return (int)roll;
}

int IMU::getAccelerometerX(){
	return (int)ax;
}

int IMU::getAccelerometerY(){
	return (int)ay;
}

int IMU::getAccelerometerZ(){
	return (int)az;
}

int IMU::getGyroX(){
	return (int)gx;	
}

int IMU::getGyroY(){
	return (int)gy;	
}

int IMU::getGyroZ(){
	return (int)gz;	
}

float IMU::getAccelerometerX_g(){
  return convertAcclerometer_g(ax);
}

float IMU::getAccelerometerY_g(){
  return convertAcclerometer_g(ay);
}

float IMU::getAccelerometerZ_g(){
  return convertAcclerometer_g(az);
}

float IMU::getGyroX_dps(){
  return convertGyro_dps(gx);
}

float IMU::getGyroY_dps(){
  return convertGyro_dps(gy);
}

float IMU::getGyroZ_dps(){
  return convertGyro_dps(gz);
}

float IMU::convertAcclerometer_g(int16_t rawVal){
  return (float)rawVal*accRange/32768.0;
}
float IMU::convertGyro_dps(int16_t rawVal){
  return (float)rawVal*gyroRange/32768.0;

}


#endif

I do not have or use the Education Shield library. You might want to contact the author of the library with the issues you are having with the library they wrote.

Ok, I’m not sure who exactly to contact since this tutorial and library came from an educational tutorial by Arduino on the website. I’m pretty sure the issue isn’t with the code itself because it’s what they provided in the tutorial, but I figured I would include it anyway.

The IMU and BLE classes in the library work only on an Arduino 101.

Hey there, I was able to swap out the boards and change the board info to the right version in the tool window, however it still gives me the same error. Is there another setting I need to change?