I have been working with a MEGA2560, a GSMshield and a data logger shield. I have written some code that works but when I first complie it it give me an error, with the include statement #include "SoftwareSerial.h" commented out. The basic code is set up for using an Uno and uses SoftwareSerial to talk to the GSMshield. I shouldn't need the SoftwareSerial library when using the Mega2560 board, it uses another hardware serial port for GSM communication. I have adjusted the supporting files so when Mega2560 is selected, it excludes SoftwareSerial.h and includes HWserial.h
When I include SoftwareSerial in my code, it compiles ok. Then immediately after that I comment out the SoftwareSerial.h and recompile and it compiles ok again. It is baffling me. Does anyone know of any issuse with the SoftwareSerial and using it with the Mega2560? Also, I cannot get the SoftwareSerial example to compile with the Mega2560.
Also, SoftwareSerial example compiles OK on all the boards listed except the Mega2560
StanK:
When I include SoftwareSerial in my code, it compiles ok. Then immediately after that I comment out the SoftwareSerial.h and recompile and it compiles ok again.
I am baffled by the fact that I have to run the compiler with SoftwareSerial included to get it to compile the first time. Then I exclude SoftwareSerial and run the compiler and it compiles OK with out it and the code size is reduce. But If I include SoftwareSerial the first time through compiling it will not compile.
It is a bit confusing. As I said I don't need the SoftwareSerial library with the MEGA.
Mmmm... there is something about the scratch directory used to store intermediate compile files. WIthout more details, I am guessing a bit here. Possibly the first compiles leaves an object file of software serial in the scratch directory that resolves some global variable/function during the final link phase. Whenever the IDE is restarted it starts on a new scratch directory (well so it did last time I was deepdivin behind the IDEs back).
Do a "verbose compile", (setup in preference in newer IDE) and then look at the files generated/included.
There was a bug about that a while back, which I reported. Removing a tab from your project didn't delete the file from the scratch directory, which has been fixed. However this doesn't sound exactly the same. Msquare might be right though, it is similar.
Hello, I am back, sorry I didn't reply sooner. I have the error listing from compiling my code, first run without SoftwareSerial included It calls WideTextFinder. First I have to say I have searched all the files in the libraries associated with this sketch for SoftwareSerial inclusions and I can't finds any. This where I get the error, no such file, which what I would expect except I can't find any place where Software Serial is included.
-IC:\arduino-1.0.4\libraries\GSMSHIELD\utility C:\arduino-1.0.4\libraries\GSMSHIELD\WideTextFinder.cpp -o C:\DOCUME~1\Stan\LOCALS~1\Temp\build2519806572797515030.tmp\GSMSHIELD\WideTextFinder.cpp.o
In file included from C:\arduino-1.0.4\libraries\GSMSHIELD\WideTextFinder.cpp:1:
C:\arduino-1.0.4\libraries\GSMSHIELD\/WideTextFinder.h:6:28: warning: SoftwareSerial.h: No such file or directory
In file included from C:\arduino-1.0.4\libraries\GSMSHIELD\WideTextFinder.cpp:1:
C:\arduino-1.0.4\libraries\GSMSHIELD\/WideTextFinder.h:11: error: ISO C++ forbids declaration of 'SoftwareSerial' with no type
C:\arduino-1.0.4\libraries\GSMSHIELD\/WideTextFinder.h:11: error: expected ';' before '*' token
C:\arduino-1.0.4\libraries\GSMSHIELD\/WideTextFinder.h:22: error: expected `)' before '&' token
C:\arduino-1.0.4\libraries\GSMSHIELD\WideTextFinder.cpp: In member function 'char WideTextFinder::read()':
C:\arduino-1.0.4\libraries\GSMSHIELD\WideTextFinder.cpp:11: error: 'nSerialStream' was not declared in this scope
C:\arduino-1.0.4\libraries\GSMSHIELD\WideTextFinder.cpp: At global scope:
C:\arduino-1.0.4\libraries\GSMSHIELD\WideTextFinder.cpp:30: error: expected `)' before '&' token
C:\arduino-1.0.4\libraries\GSMSHIELD\WideTextFinder.cpp: In member function 'float WideTextFinder::getFloat()':
C:\arduino-1.0.4\libraries\GSMSHIELD\WideTextFinder.cpp:156: warning: no return statement in function returning non-void
C:\arduino-1.0.4\libraries\GSMSHIELD\WideTextFinder.cpp: In member function 'float WideTextFinder::getFloat(char)':
C:\arduino-1.0.4\libraries\GSMSHIELD\WideTextFinder.cpp:164: warning: unused variable 'fValue'
This following code is the first part of the file GSMSHIELD.H
#ifndef GSM_H
#define GSM_H
//#define UNO
#define MEGA
#ifdef UNO
#include <SoftwareSerial.h>//comment for MEGA
#include "WideTextFinder.h" //Comment out if using MEGA and HWSerial.h
#endif
#include <inttypes.h>
#define ctrlz 26 //Ascii character for ctr+z. End of a SMS.
#define cr 13 //Ascii character for carriage return.
#define lf 10 //Ascii character for line feed.
#define ctrlz 26 //Ascii character for ctr+z. End of a SMS.
#define cr 13 //Ascii character for carriage return.
#define lf 10 //Ascii character for line feed.
#define GSM_LIB_VERSION 308 // library version X.YY (e.g. 1.00)
//#define DEBUG_ON
#ifdef MEGA
#include "HWSerial.h"
#endif
Now with the SoftwareSerial incuded in my sketch I get no compilation errors.
Then I exclude SoftWareSerial from my sketch and compile, no errors. The compiler says, Using previously compiled, often.
Here is the top of my sketch where I include or exclude SoftwareSerial with comment //'s
//#include "Arduino.h"
//#define MEGA
//#include <stdlib.h>
#include <SoftwareSerial.h>
#include "HWSerial.h"
#include "sms.h"
//#include "GSM.h"
//#include "SIM900.h"
SMSGSM sms;
#include <SD.h>
boolean gsmStarted=false;
const byte phoneNumberLength = 20;
const byte messageLength = 161;
const int serialBaud = 57600;
char smsbuffer[messageLength];
char number[] = "BLANK NUMBER";
char lastPhoneNumberToCall[phoneNumberLength] = "Last Phone number";
byte last_successful_msg = 0;
String inputString = ""; // a string to hold incoming data
const int chipSelect = 53;//MegaADK
volatile int ringFlag = LOW;
File dataFile;
Anyhow, the top part of the GSMSHIELD.h the comment says to exclude the serial stuff if a mega... (depending on how the comment is interpreted) seems like a bug/confsuion in the ifdef structure if uno/mega etc. (Hey - I havn't studied this in detail, just glancing at it for least-effort-bugfix)
Just comment out this block
#ifdef UNO
#include <SoftwareSerial.h>//comment for MEGA
#include "WideTextFinder.h" //Comment out if using MEGA and HWSerial.h
#endif
Yes, make a modification to the library file. You can always save the original ".orig"
More smarter - if you want it to be flexible for all your different boards is
#ifdef UNO
#ifndef MEGA
#include <SoftwareSerial.h>//comment for MEGA
#include "WideTextFinder.h" //Comment out if using MEGA and HWSerial.h
#endif
#endif
(Code not tested, may not work in your enviroment, warranty void if used above sealevel)
I think I found my problem. One of the modules SIM900 calls a function in WideTextFinder.cpp which is part of the GSMSHIELD library. WideTextFinder calls includes SoftwareSerial in its header. So it looks for the function and can't find SoftwareSerial and errors out. When I include SoftwareSerial it works. I don't know if that explains it but that is the best I can do for now. if you need a better explanation reply to me. I suppose the code could be better written for differentiating the two different processors, UNO and Mega, but it looks like the Mega was an after thought. I think Msquare had it right early on.