Go Down

Topic: Serial example does not compile (Read 2693 times) previous topic - next topic

gbosch

This example from the Arduino website returns following error.
/*
  Software serial multple serial test

Receives from the hardware serial, sends to software serial.
Receives from software serial, sends to hardware serial.

The circuit:
* RX is digital pin 2 (connect to TX of other device)
* TX is digital pin 3 (connect to RX of other device)

created back in the mists of time
by Tom Igoe
based on Mikal Hart's example

This example code is in the public domain.

*/
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

void setup() 
{
  Serial.begin(57600);
  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
  mySerial.println("Hello, world?");
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

Here the error:

In file included from test_serial.cpp:18:
/Users/gbosch/Documents/Arduino/libraries/SoftwareSerial/SoftwareSerial.h:95: error: conflicting return type specified for 'virtual void SoftwareSerial::write(uint8_t)'
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Print.h:48: error:   overriding 'virtual size_t Print::write(uint8_t)'

What to do?

PaulS

Quote
What to do?

Spend some time reading the messages. They tell you exactly what the problem is. If needed, spend some time searching for those errors which have posted far too many times this year.

gbosch

Where can I find these messages?

PaulS

Quote
Where can I find these messages?

At the bottom of your post!

gbosch

Ok, Paul. You are right. Well I did. But I don't see the conflict and how to solve it. The error refers to line 18 in my code, saying #include <SoftwareSerial.h>, telling me that the problem is between system libraries SoftwareSerial and Print. Should I change them? I have no idea how to go on with this. Hope you can help.
I would appreciate if the reference section of the Arduino website was more informative.

PaulS

What version of the IDE are you using?

Why do you have a SoftwareSerial library in your libraries folder? The SoftwareSerial library has always been part of the Arduino core.

gbosch

Since I'm using 1.0-rc2 I experience a lot of similar problems. So far I could tackle them.
While porting a Arduino_22 sketch to 1.0 I ran into this problem, and found out that even examples bundled with Arduino 1.0 have the same problem, so these code examples don't give any support on this.

Ok, my original sketch used NewSoftSerial. This library is still in my libraries folder. NewSoftSerial website says: To port your code to 1.0, simply change all NewSoftSerial references to SoftwareSerial. Which I did. Result, see above.
With Arduino_23 the sketch compiles with no problem. Any ideas?

gbosch

Quote
Why do you have a SoftwareSerial library in your libraries folder?


Paul, thanks for your hint. I overlooked there was a 'stray' library in my folder. Removed it and that solved the problem!

davefer

Please excuse my naivte, but I'm new to Arduino.

I'm having this exact same problem and I understand the errors perfectly and can find the locations of the faults and see the reason.

Here's what confuses me:
- How is SoftwareSerial part of Arduino core? If I delete the 3rd party (?) library I installed, then the #include won't resolve. I'm using Arduino 1.6.4 (that installed from Intel) and I don't see any SoftwareSerial in the stock libraries NOR in the core files -- not in file names, nor in file content.

I see that other people have a default (stock) library called SoftwareSerial, but I do not. Why is that? That adds to my confusion. Indeed the Arduino reference page lists SoftwareSerial as a core library. But I don't have it (except for the one I installed that took me 50 years of Googling to find).

Also, when I download the .ZIP installation files for a more recent version of Arduino, that archive DOES NOT contain any SoftwareSerial library either.

- So if I delete this rogue SoftwareSerial library from my documents folder, What will the compiler do? Should I also delete the #include and let the compiler treat SoftwareSerial as sort of a native object?

Any help greatly appreciated. THANK YOU!

PaulS

Quote
- How is SoftwareSerial part of Arduino core?
Starting with Arduino 1.0, all versions of the IDE have delivered SoftwareSerial.

Quote
If I delete the 3rd party (?) library I installed, then the #include won't resolve.
That you installed where? Where is the IDE installed? Where are your sketches stored?

Quote
I'm using Arduino 1.6.4 (that installed from Intel) and I don't see any SoftwareSerial in the stock libraries NOR in the core files -- not in file names, nor in file content.
For me, with 160, I have:
Quote
C:\Users\pjs9486\Documents\Arduino_160\hardware\arduino\avr\libraries
that has a SoftwareSerial folder. The is on Win7, and C:\Users\pjs9486\Documents\ is where I installed the IDE.

Quote
I see that other people have a default (stock) library called SoftwareSerial, but I do not. Why is that? That adds to my confusion. Indeed the Arduino reference page lists SoftwareSerial as a core library. But I don't have it (except for the one I installed that took me 50 years of Googling to find).
Tell me where you installed the IDE, and I'll install 164 the same way, and look for it, if you really don't have it in the (relative) location I described above.


davefer

Hi Paul -

I'll try to answer all your questions as best as possible. Sorry in advance if I miss something.

I'm on Windows 8.1 and my version of Arduino IDE is 1.6.4 which installed as part of the Intel package for the Intel Edison module.

It is installed at:  C:\Intel\Arduino-1.6.4

When I add libraries, they automatically go to: C:\Users\Dave Ferreira\Documents\Arduino\libraries

Sketches are stored here:  C:\Users\Dave Ferreira\Documents\Arduino\

I have no other versions of Arduino installed on this machine.

Trying to get my Ublox GPS working, I imported a library called TinyGPSPlus-0.94b using the Arduino .zip library import (Sketch > Include Library > Add .Zip library)

Using the DeviceExample from the TinyGPSPlus lib, I got compile errors -- conflicts with another Write() method in print.h.

Did some reading and learned that SoftwareSerial is supposed to be in the Arduino CORE library set and about how NewSoftwareSerial had suplanted SoftwareSerial in versions 1.0+, etc. Great.

But I don't see any SoftwareSerial library anywhere on my machine.

There WAS one that I hunted around the Internet for about 40 minutes and installed (again, using the Arduino .zip lib import). It went into my same personal library folder:  C:\Users\Dave Ferreira\Documents\Arduino\libraries. I've since deleted it and still get errors.

(I've since learned that I shouldn't have to search for some extraneous SoftwareSerial library out on the Internet and that those might be rogue, 3rd party versions that might interfere with other things.)

So I'm still stuck. And I hope I've answered all the material question that will give you enough info.

BTW, I also downloaded the most recent Arduino offering from the Arduino website (without installing it) and inside the .zip file I do not see any SoftwareSerial libraries or files. Hence my question, "How is SoftwareSerial part of CORE?" I wasn't trying to be snyde ... I honestly was wondering HOW is it carried along with the installation of Arduino? In a library folder called "SoftwareSerial"? In a SoftwareSerial.h file? In some code snippet within another library with a different name?

Thanks!

   - DaveFer

PaulS

Quote
for the Intel Edison module.
Aha. THAT explains a lot.

I don't know anything about the Edison, or whether SoftwareSerial works on it. I have my doubts, of course.

davefer

Ok, yes, I just confirmed from a post on the Intel Edison community forum that SoftwareSerial is NOT supported by the Intel Edison at this time.

Now ... How can I make the GPS (Ublox) work that I just got?

A Mr. MSuzuki posted this example on Instructables.com: http://www.instructables.com/id/Arduino-Ublox-GPS/

It is exactly the right example for me, except that the Arduino same code uses SoftwareSerial.

I wonder if there is some way to modify the example to work around this problem. (As I'm asking the question, the clouds are separating and I'm thinking, "No SoftwareSerial => no way to read serial input except with human eyes.")

If anyone is inclined to advise further, that would be GREATLY appreciated.

   - Dave F.

PaulS

Quote
I'm thinking, "No SoftwareSerial => no way to read serial input except with human eyes.")
There IS the hardware serial port. You could be the one to make SoftwareSerial work with the Edison.

davefer


And I would like to work on that.

But I wonder if I'd be better off trying to make the Eclipse dev environment work and perhaps that solves the problem.

PaulS are you involved in the development of the Arduino IDE or libraries? Perhaps I could ping you privately with my e-mail to get some insights into where to begin this process.

Thanks,

   - DaveFer

Go Up