Go Down

Topic: SMS printer with gsm shield and Sparkfun thermal printer (Read 3647 times) previous topic - next topic

chris_van_roey

I'm trying to make an sms printer using the Arduino/telefonica gsm shield and the Sparkfun thermal printer.
I've used the Arduino example code for receiving sms and it works.
I've used the example code for printing on the thermal printer and it works.
When combining both, I receive a compiler error.

As far as I can interpret the compiler error code, I assume there is a conflict between the gsm library and the software serial library.
Digital pins 0 and 1 are used by USB.
The gsm shield uses digital pins 2 and 3 for serial comm.
Therefore I used software serial to put the printer on port 4 and 5.

Enclosed the code.
Has someone an idea how to solve this?

Here is the error message:

[font=Verdana]
SoftwareSerial/SoftwareSerial.cpp.o: In function `__vector_3':
/Applications/Arduino.app/Contents/Resources/Java/libraries/SoftwareSerial/SoftwareSerial.cpp:305: multiple definition of `__vector_3'
GSM/GSM3SoftSerial.cpp.o:/Applications/Arduino.app/Contents/Resources/Java/libraries/GSM/GSM3SoftSerial.cpp:511: first defined here
SoftwareSerial/SoftwareSerial.cpp.o: In function `__vector_4':
/Applications/Arduino.app/Contents/Resources/Java/libraries/SoftwareSerial/SoftwareSerial.cpp:312: multiple definition of `__vector_4'
GSM/GSM3SoftSerial.cpp.o:/Applications/Arduino.app/Contents/Resources/Java/libraries/GSM/GSM3SoftSerial.cpp:518: first defined here
SoftwareSerial/SoftwareSerial.cpp.o: In function `__vector_5':
/Applications/Arduino.app/Contents/Resources/Java/libraries/SoftwareSerial/SoftwareSerial.cpp:319: multiple definition of `__vector_5'
GSM/GSM3SoftSerial.cpp.o:/Applications/Arduino.app/Contents/Resources/Java/libraries/GSM/GSM3SoftSerial.cpp:525: first defined here
[/font]


And here is the code:

Code: [Select]


/* project #5 SMS printer
versie a.0.01
15 augustus 2014
Chris Van Roey
© The Lab, a division of The House */

/* hardware
Arduino Uno Rev3
GSM shield Telefonica
Sparkfun Thermal Printer */

// INITIALISATIE
// bibliotheken
#include <GSM.h> // gsm bib
#include <SoftwareSerial.h> // softwareserial voor printer
SoftwareSerial Thermal(5, 4); // Tx=dPin 5, Rx= dPin 4
int heatTime = 80;
int heatInterval = 255;
char printDensity = 15;
char printBreakTime = 15;

#define PINNUMBER "1111" // PIN nummer SIM

// Initialiseer gsm bib
GSM gsmAccess;
GSM_SMS sms;

// array voor het nummer van de sms zender
char senderNumber[20]; 


// SETUP
void setup()
{
  // initialize serial communications and wait for port to open:
  Serial.begin(9600); // voor debug
  Thermal.begin(19200); // om naar printer te schrijven
  initPrinter();

  Serial.println("SMS Messages Receiver");

  // connection state
  boolean notConnected = true;

  // Start GSM connection
  while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");
}


// PROGRAMMA
void loop()
{
  char c;

  // If there are any SMSs available() 
  if (sms.available())
  {
    Serial.println("Message received from:");

    // Get remote number
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);
    Thermal.print("SMS van ");
    Thermal.println(senderNumber);

    // Read message bytes and print them
    while(c=sms.read())
      Serial.print(c);
    Thermal.print(c);

    Serial.println("\nEND OF MESSAGE");
    Thermal.write(10); // Line feed printer
    Thermal.write(10);  // Line feed printer

    // Delete message from modem memory
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }

  delay(1000);

}

// FUNCTIE PRINTERINITIALISATIE
void initPrinter()
{
  //Modify the print speed and heat
  Thermal.write(27);
  Thermal.write(55);
  Thermal.write(7); //Default 64 dots = 8*('7'+1)
  Thermal.write(heatTime); //Default 80 or 800us
  Thermal.write(heatInterval); //Default 2 or 20us
  //Modify the print density and timeout
  Thermal.write(18);
  Thermal.write(35);
  int printSetting = (printDensity<<4) | printBreakTime;
  Thermal.write(printSetting); //Combination of printDensity and printBreakTime
  Serial.println();
  Serial.println("Printer ready");
}


larskrachen

Hey Chris. I have the same problem. Have you fixed it?

robtillaart

#2
Sep 30, 2014, 06:24 pm Last Edit: Sep 30, 2014, 06:27 pm by robtillaart Reason: 1
don't have experience here or the solution

a quick look into the GSM lib code shows GSM has a GSM3SOftSerial class.

might be the cause of the conflict...

update: solution might be to use ALtSoftSerial 
see - https://github.com/mainehackerclub/open_vehicle_tracker/issues/28 -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

larskrachen

Thank you. I have used this trick and have comment some lines. http://purposefulscience.blogspot.de/2013/06/arduino-gsm-shield-tips.html. Now it is working and I can upload the sketch to the board. But when I send a sms, the printer only prints out the sendernumber. But not the sms text. When I delete "while" and only have c=sms.read(); the printer prints out the first letter of the sms. Does anyone have a solution?
Code: [Select]
// Read message bytes and print them
    while(c=sms.read())
      Serial.print(c);
    Thermal.print(c);

robtillaart

you might need to add a small delay between characters, Serial is asynchronous and takes time...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

larskrachen

I have found the solution. The printer is printing the sms without an error.
The problem was in the code. (missing  {} )

Code: [Select]
while(c=sms.read())
     {
Serial.print(c);
Thermal.print(c);
}

Go Up