Pages: [1]   Go Down
Author Topic: Error creating library: 'SoftwareSerial' does not name a type  (Read 5025 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 1
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi there everybody
i'm new to the Arduino world and I think i am missing some basical stuff to make things working well..
I used to code a lot in c/c++,java etc, now in Arduino I have some problems with the language and the coding standards..

I am trying to write a simple library for an Arduino UNO using Arduino  IDE 1.0.1 on windows 7 x64.

I wrote these files:

serial2.h
Code:
#ifndef serial2_h
#define serial2_h
#include <Arduino.h>
 
class serial2
{
 public:
     serial2();
 private:
};

#endif


serial2.cpp
Code:
#include "Arduino.h"
#include "serial2.h"
#include <SoftwareSerial.h>

SoftwareSerial Serial_2(2, 3);

serial2::serial2(){
  
}

Uno.ino
Code:
#include <serial2.h>

void setup(){
}

void loop(){
}

but I am getting this error:

Code:
serial2.cpp:4: error: 'SoftwareSerial' does not name a type

I used SoftwareSerial in another skech and it worked well, but i cannot figure out why in this library is not recognized.
Am I writing the library in a wrong way?
Thanks everybody
« Last Edit: July 18, 2012, 03:56:02 am by CyberFox » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50924
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are trying to hide the use of a library from the sketch. You can not do that. You must do what everyone else does, and tell the sketch that you are using SoftwareSerial, but #including it's header file.
Logged

0
Offline Offline
Newbie
*
Karma: 1
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for the reply, so  i have to specifically include the library also in the main file?
I modified the files in this way, but i'm still getting the same error

serial2.h
Code:
#ifndef serial2_h
#define serial2_h
#include <Arduino.h>


class serial2
{
 public:
     serial2();
 private:
      SoftwareSerial Serial_2(2, 3);
};

#endif

serial2.cpp
Code:
#include "Arduino.h"
#include "serial2.h"


serial2::serial2(){
}

Uno.ino
Code:
#include <serial2.h>

#include <SoftwareSerial.h>

void setup(){
}

void loop(){
}
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50924
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your header file references the SoftwareSerial class. You need to #include SoftwareSerial.h in your header file, not in your source file.

Then. you will have other errors. The private member Serial_2 is defined AND INITIALIZED in the header. That is not allowed. You need to define it, only:

Code:
      SoftwareSerial Serial_2;

Then, in the source file, you need to initialize it:
Code:
serial2::serial2():Serial_2(2,3)
Logged

Pages: [1]   Go Up
Jump to: