5
\$\begingroup\$

I have NewSoftSerial.h and NewSoftSerial.cpp in the same folder as my sketch.

The sketch is thus.

#include <NewSoftSerial.h>

int incomingByte = 0;   // for incoming serial data
NewSoftSerial bluetooth(2, 3);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);   // opens serial port, sets data rate to 9600 bps
  Serial.flush();
  //enter command mode
  Serial.println("$$$");
}

void loop() {
  // send data only when you receive data:
  if (Serial.available() > 0) {
    //read the incoming byte:
    incomingByte = Serial.read();

    //say what you got:
    Serial.print("I received: ");
    Serial.println(incomingByte, BYTE);
  }
}

What am I doing wrong that I get these errors?

trainremotesketch.cpp:1:27: error: NewSoftSerial.h: No such file or directory trainremotesketch:3: error: 'NewSoftSerial' does not name a type

\$\endgroup\$
1

2 Answers 2

7
\$\begingroup\$

The short answer is that library files go in the libraries folder in the Arduino root folder. A library should be in a sub-folder named for the class, and should contain a c++ implementation and header file.

-Arduino
  |
  +--libraries  
       |
       +--NewSoftSerial
           |
           +--NewSoftSerial.cpp
           |
           +--NewSoftSerial.h           
\$\endgroup\$
15
\$\begingroup\$

A longer answer is that if you want to include a header file which isn't in the library path, you use double quotes, instead of angle brackets:

#include "NewSoftSerial.h"
\$\endgroup\$
1
  • 6
    \$\begingroup\$ This answer is actually shorter \$\endgroup\$ Commented Jul 8, 2014 at 16:11

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.