"Does not name type" SwitecX25 library

I'm having an issue that I can't seem to find the answer for.

I am attempting to use Guy Carpenter's SwitecX25 library to run a stepper motor, eventually a couple, but crawl, then walk... GitHub - clearwater/SwitecX25: Arduino library for Switec X25.168 and friends

I installed the library using the guide here on the arduino.cc site. http://arduino.cc/en/Guide/Libraries

I tried installing the SwitecX25.cpp and .h files inside a folder called SwitecX25, (Location: My Documents/Arduino/libraries/SwitecX25) but that gave me some errors, such as: error: stray '\302' in program, which seems to be saying that there is a problem with the included libraries, from what I have been able to find out. I seem to have been able to get rid of these errors by installing the SwitecX25.cpp and .h files just in the My Documents/Arduino/libraries folder.

Now I am getting these errors:

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.4 (Windows 7), Board: "Arduino Uno"
sketch_may15a:23: error: 'SwitecX25' does not name a type
sketch_may15a.ino: In function 'void setup()':
sketch_may15a:28: error: 'motor1' was not declared in this scope
sketch_may15a.ino: In function 'void loop()':
sketch_may15a:42: error: 'motor1' was not declared in this scope

The full code I am using is straight from the Github examples.

//----------------------------------------------------------------------
// https://github.com/clearwater/SwitecX25
// 
// This is an example of using the SwitchX25 library.
// It zero's the motor, sets the position to mid-range
// and waits for serial input to indicate new motor positions.
// 
// Open the serial monitor and try entering values 
// between 0 and 944.
// 
// Note that the maximum speed of the motor will be determined
// by how frequently you call update().  If you put a big slow
// serial.println() call in the loop below, the motor will move
// very slowly!
//----------------------------------------------------------------------

#include <SwitecX25.h>

// standard X25.168 range 315 degrees at 1/3 degree steps
#define STEPS (315*3)

// For motors connected to pins 3,4,5,6
SwitecX25 motor1(STEPS,4,5,6,7);

void setup(void)
{
  // run the motor against the stops
  motor1.zero();
  // start moving towards the center of the range
  motor1.setPosition(STEPS/2);
  
  Serial.begin(9600);
  Serial.print("Enter a step position from 0 through ");
  Serial.print(STEPS-1);
  Serial.println(".");
}

void loop(void)
{
  static int nextPos = 0;
  // the motor only moves when you call update
  motor1.update();
  
  if (Serial.available()) {
    char c = Serial.read();
    if (c==10 || c==13) {
      motor1.setPosition(nextPos);
      nextPos = 0;
    } else if (c>='0' && c<='9') {
      nextPos = 10*nextPos + (c-'0');
    }
  }
}

Through some research I found this thread: Basic include questions - Programming Questions - Arduino Forum, that if I read that correctly, the #include <SwitecX25.h> must be at the top of the SwitecX25.cpp file as well as my sketch.

Looking at the github page for the SwitecX25.cpp file the #include <SwitecX25.h> is in the file.

I am assuming at this point that once I can get rid of the Does not name a type error, the motor1 not declared errors will also disappear.

What do I need to do to get this to work?

Thanks

The .cpp and .h files should be in the My Documents/Arduino/libraries/SwitecX25 folder as you originally had them or they will not be found by the #include, hence the errors that you now get. The problem with the stray '\302' type errors is usually because the files were copied and pasted from a web page into local files. On the github page try switching to the Raw view of the files before copying and pasting to your PC.

Thanks for the reply.

That makes sense, as far as having issues with the libraries not beiung found.

When I saved them I saved them as "Save taget as".

So how do I create the .cpp and .h files? I know I could use Visual Studio to do it, as I have for assignments in my college course, but is there an easier way to do it? I find Visual Studio to be cumbersome sometimes, and I would suspect there is an easier way, because not everyone will have Visual Studio to do this with.

I looked through the create a libraries tutorial and it doesn't mention how to save the code as .cpp or .h files.

I've tried creating a .txt file and then just adding the .cpp and .h extensions, but that didn't seem to work.

Off to do more searching...

I think I may have figured it out.

It seems that if a new tab is created, you can name the file foo.h and foo.cpp and they appear to be saved as .h and .cpp files.

I copied these files (SwitecX25.cpp and SwitecX25.h) to the My Documents/Arduino/libraries/SwitecX25 folder, started a new sketch with the original code and it compiled, so now to do some testing.

I used the raw format to grab the code as well.

Some success, The code compiles, and uploads (after having some com port issues :head->wall:), the motor is not reacting exactly as expected to serial monitor inputs, but, it's mostly working.

:smiley:

Thanks

Six_Shooter:
I've tried creating a .txt file and then just adding the .cpp and .h extensions, but that didn't seem to work.

You have to change the extension, not add it.

Arrch:

Six_Shooter:
I've tried creating a .txt file and then just adding the .cpp and .h extensions, but that didn't seem to work.

You have to change the extension, not add it.

:facepalm: It took me writing out this reply to remember that I have to "unhide" the file extensions to be able to manipulate them. I was looking through the file properties for a way to do it there. duh.

Thanks for giving me a kick in the brain. lol

I figured out how to create the files using the new tab feature of the Arduino IDE anyway.

Everything is working as it should. I just had a pinout issue, where the grounds, contrary to what has been written on the Guy Carpenters site are paired to the other connections.

Now I just need to figure out how to incorporate this into my final goal of making some custom gauges for my car, so that they are actually accurate and respond quickly. Bi-metal movements are so 1970's. lol

:facepalm: It took me writing out this reply to remember that I have to "unhide" the file extensions to be able to manipulate them

That has got to be, beyond a shadow of a doubt, the absolutely dumbest idea Microslop EVER had. No one else thinks that hiding extensions is even remotely close to a good idea.