[SOLVED] How to get SoftwareSerial to work on the SerialGateway...?



  • Can't figure out how to get the SoftwareSerial to work on the SerialGateway. Have been using the GitHub master branch of MySensors and tried all described workarounds I have came over but to no avail - usually I get the long error codes referring to vectors....

    Then I saw a five days old message on GitHub that said that this behavior is fixed in the GitHub development branch. I installed that and now SoftwareSerial can be successfully compiled on nodes with no error.

    But on the SerialGateway I run into two different nonworking options,

    • if I don't #include <SoftwareSerial.h> in the sketch it recognizes SoftwareSerial when I type it and colors it orange - but when I run the sketch I get the following error SerialGateway.ino:46:1: error: 'SoftwareSerial' does not name a type

    • if I again #include <SoftwareSerial.h> in the sketch I get the usual long compile error - SoftwareSerial/SoftwareSerial.cpp.o: In function _vector_3:
      /Applications/Arduino 1.5.8.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:307: multiple definition of __vector_3' SerialGateway.cpp.o:/Users/sirrai/Documents/Arduino/libraries/PinChangeInt/PinChangeInt.h:563: first defined here SoftwareSerial/SoftwareSerial.cpp.o: In function __vector_5': /Applications/Arduino 1.5.8.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:322: multiple definition of __vector_5'
      SerialGateway.cpp.o:/Users/sirrai/Documents/Arduino/libraries/PinChangeInt/PinChangeInt.h:583: first defined here

    I have a Seeedstudio GPRS shield that uses SoftwareSerial on pins 7 and 8 that I intend to fit on the Arduino SerialGateway to send out alert messages.

    Can anyone help me to solve the problem...


  • Mod

    @ruxu arduino is using a bit stupid way of making files and this sometimes leads to stupid behavior

    try to place #include <SoftwareSerial.h> between or after other includes, top, bottom or middle
    or even try to include PinChangeInt.h: instead

    also check the content of SoftwareSerial.h, it should have #ifdef #endif at most top and most bottom of the file to avoid problem in case of multiple inclusions, etc, it is a common practice for any .H file



  • @axillent said:

    @ruxu arduino is using a bit stupid way of making files and this sometimes leads to stupid behavior

    try to place #include <SoftwareSerial.h> between or after other includes, top, bottom or middle
    or even try to include PinChangeInt.h: instead

    also check the content of SoftwareSerial.h, it should have #ifdef #endif at most top and most bottom of the file to avoid problem in case of multiple inclusions, etc, it is a common practice for any .H file

    Tried your suggestions and noticed that if I comment out #include PinChangeInt.h and one line related to that library then the code compiles fine with SoftwareSerial.h included. Still the code doesn't of course work because the inclusion is then disabled. Any new ideas...?



  • The following SerialGateway code works but inclusion is not possible as NO_PINCHANGE is set for all ports.

     #define NO_PORTB_PINCHANGES
     #define NO_PORTC_PINCHANGES
     #define NO_PORTD_PINCHANGES
    
     #include <SPI.h>  
     #include <MySensor.h>  
     #include <stdarg.h>
     #include <MsTimer2.h>
     #include <PinChangeInt.h>
     #include "GatewayUtil.h"
     #include <SoftwareSerial.h>
    
     #ifndef MYSENSORS_SERIAL_GATEWAY
     #error Please switch to MYSENSORS_SERIAL_GATEWAY in MyConfig.h
     #endif
    
     #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
     #define INCLUSION_MODE_PIN  3 // Digital pin used for inclusion mode button
     #define RADIO_ERROR_LED_PIN A3  // Error led pin
     #define RADIO_RX_LED_PIN    A5  // Receive led pin
     #define RADIO_TX_LED_PIN    A4  // the PCB, on board LED
    
     MySensor gw;
    
     SoftwareSerial SIM900(7, 8);
    
     char inputString[MAX_RECEIVE_LENGTH] = "";    // A string to hold incoming commands from serial/ethernet interface
     int inputPos = 0;
     boolean commandComplete = false;  // whether the string is complete
    
     void parseAndSend(char *commandBuffer);
    
     void output(const char *fmt, ... ) {
        va_list args;
        va_start (args, fmt );
        vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args);
        va_end (args);
        Serial.print(serialBuffer);
     }
    
    
     void setup()  
     { 
       gw.begin(incomingMessage, 0, true, 0);
    
       setupGateway(RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN, INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);  
    
       // Add led timer interrupt
       MsTimer2::set(300, ledTimersInterrupt);
       MsTimer2::start();
    
       // Add interrupt for inclusion button to pin
       PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING);
    
    
       // Send startup log message on serial
       serial(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"),  C_INTERNAL, I_GATEWAY_READY);
     }
    
     void loop()  
     { 
       gw.process();
    
       checkButtonTriggeredInclusion();
       checkInclusionFinished();
    
       if (commandComplete) {
         // A command wass issued from serial interface
         // We will now try to send it to the actuator
         parseAndSend(gw, inputString);
         commandComplete = false;  
         inputPos = 0;
       }
     }
    
    
     /*
      SerialEvent occurs whenever a new data comes in the
      hardware serial RX.  This routine is run between each
      time loop() runs, so using delay inside loop can delay
      response.  Multiple bytes of data may be available.
      */
     void serialEvent() {
       while (Serial.available()) {
         // get the new byte:
         char inChar = (char)Serial.read(); 
         // if the incoming character is a newline, set a flag
         // so the main loop can do something about it:
         if (inputPos<MAX_RECEIVE_LENGTH-1 && !commandComplete) { 
           if (inChar == '\n') {
             inputString[inputPos] = 0;
             commandComplete = true;
           } else {
             // add it to the inputString:
             inputString[inputPos] = inChar;
             inputPos++;
           }
         } else {
            // Incoming message too long. Throw away 
             inputPos = 0;
         }
       }
     }
    

    But as soon as i comment out any of the three #define NO_PORTx_PINCHANGES I get a compile error including the vector 3, 4 or 5 messages. If I am correct the #define NO_PORTD_PINCHANGES should be uncommented for the inclusion to work. Any ideas on how to fix this annoying problem?



  • Managed to find out a solution by myself.

    • removed the three #define NO_PORTx_PINCHANGES

    • removed the #include <PinChangeInt.h>

    • changed PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING); to
      attachInterrupt(1, startInclusionInterrupt, RISING);

    Now I am able to use the Seeedstudip GPRS shield pins 7 and 8 with SoftwareSerial.



Suggested Topics

  • 6
  • 72
  • 199
  • 14
  • 9
  • 10
  • 2

62
Online

11.4k
Users

11.1k
Topics

112.7k
Posts