Go Down

Topic: Mini Thermal Receipt Printer + GSM (Read 3162 times) previous topic - next topic



I want to use the Mini thermal Receipt Printer with the new official GSM shield of Arduino.
I have a conflict with the two libraries : Gsm & ArdunioThermal

Just try to compile this :

Code: [Select]
    // include the GSM library
    #include <GSM.h>

    // PIN Number for the SIM
    #define PINNUMBER "1234"

    #include <SoftwareSerial.h>

    #include "Adafruit_Thermal.h"

    int printer_RX_Pin = 5;  // This is the green wire
    int printer_TX_Pin = 6;  // This is the yellow wire

    Adafruit_Thermal printer(printer_RX_Pin, printer_TX_Pin);

    // initialize the library instances
    GSM gsmAccess;
    GSM_SMS sms;
    GSM_SMS send_sms;

and I have this message :

Code: [Select]
    SoftwareSerial\SoftwareSerial.cpp.o: In function `__vector_3':
    C:\Users\Nicolas\Desktop\Arduino\libraries\SoftwareSerial/SoftwareSerial.cpp:302: multiple definition of `__vector_3'
    GSM\GSM3SoftSerial.cpp.o:C:\Users\Nicolas\Desktop\Arduino\libraries\GSM/GSM3SoftSerial.cpp:511: first defined here
    SoftwareSerial\SoftwareSerial.cpp.o: In function `__vector_4':
    C:\Users\Nicolas\Desktop\Arduino\libraries\SoftwareSerial/SoftwareSerial.cpp:309: multiple definition of `__vector_4'
    GSM\GSM3SoftSerial.cpp.o:C:\Users\Nicolas\Desktop\Arduino\libraries\GSM/GSM3SoftSerial.cpp:518: first defined here
    SoftwareSerial\SoftwareSerial.cpp.o: In function `__vector_5':
    C:\Users\Nicolas\Desktop\Arduino\libraries\SoftwareSerial/SoftwareSerial.cpp:316: multiple definition of `__vector_5'
    GSM\GSM3SoftSerial.cpp.o:C:\Users\Nicolas\Desktop\Arduino\libraries\GSM/GSM3SoftSerial.cpp:525: first defined here

Anybody can help me?



You won't be able to use GSMSoftSerial and SoftwareSerial in the same sketch.

You'll need to rework Adafruit_Thermal.h to use a hardware serial port, and sacrifice whatever you are using the hardware serial port for now.

I haven't dig into why the GSM library seemed to feel it necessary to re-invent the SoftwareSerial class, but, having done so it prevents other classes that use SoftwareSerial from working.

I suspect a Mega may be in your future.
The art of getting good answers lies in asking good questions.


I'm sorry but I'm don't understand what I will change at the Adafruit Class !
Can you please help me to understand ?


I'm sorry but I'm don't understand what I will change at the Adafruit Class !
Can you please help me to understand ?

The Adafruit_Thermal expects to use SoftwareSerial to talk to the thermal printer. The GSM library makes that impossible.

You need to modify Adafruit_Thermal.h and Adafruit_Thermal.cpp to not use SoftwareSerial or whatever instance it creates of SoftwareSerial. Instead, the Adafruit_Thermal class needs to use the HardwareSerial class (and one of its instances - Serial, Serial1, Serial2, or Serial3, depending on which Arduino you have) to talk to the printer.
The art of getting good answers lies in asking good questions.


I understand the problem but i don't know how to fix it.
What can I do with theses files :

Code: [Select]

#ifndef Thermal_h
#define Thermal_h

#if ARDUINO >= 100
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "WProgram.h"
#include "WConstants.h"
#include "NewSoftSerial.h"

// Barcode types
#define UPC_A   0
#define UPC_E   1
#define EAN13   2
#define EAN8    3
#define CODE39  4
#define I25     5
#define CODEBAR 6
#define CODE93  7
#define CODE128 8
#define CODE11  9
#define MSI    10

#if ARDUINO >= 100
 #define SERIAL_IMPL      SoftwareSerial
 #define PRINTER_PRINT(a) _printer->write(a);
 #define SERIAL_IMPL      NewSoftSerial
 #define PRINTER_PRINT(a) _printer->print(a, BYTE);

class Adafruit_Thermal : public Print {


 Adafruit_Thermal(int RX_Pin, int TX_Pin);

   begin(int heatTime=200),

   underlineOn(uint8_t weight=1),

   justify(char value),
   feed(uint8_t x=1),
   sleepAfter(uint8_t seconds),

   setSize(char value),
   setLineHeight(int val=32),

   printBarcode(char * text, uint8_t type),
   setBarcodeHeight(int val=50),

   printBitmap(int w, int h, const uint8_t *bitmap, bool fromProgMem = true),
   printBitmap(int w, int h, Stream *stream),
   printBitmap(Stream *stream),

   timeoutSet(unsigned long),
   setTimes(unsigned long, unsigned long),

   setCharSpacing(int spacing), // Not working
   tab();                       // Not working

 bool hasPaper();

#if ARDUINO >= 100
 size_t write(uint8_t c);
 void   write(uint8_t c);


   prevByte,      // Last character issued to printer
   column,        // Last horizontal column printed
   maxColumn,     // Page width (output 'wraps' at this point)
   charHeight,    // Height of characters, in 'dots'
   lineSpacing,   // Inter-line spacing (not line height), in dots
   barcodeHeight; // Barcode height in dots, not including text
 unsigned long
   resumeTime,    // Wait until micros() exceeds this before sending byte
   dotPrintTime,  // Time to print a single dot line, in microseconds
   dotFeedTime;   // Time to feed a single dot line, in microseconds
   setPrintMode(uint8_t mask),
   unsetPrintMode(uint8_t mask),
   writeBytes(uint8_t a),
   writeBytes(uint8_t a, uint8_t b),
   writeBytes(uint8_t a, uint8_t b, uint8_t c),
   writeBytes(uint8_t a, uint8_t b, uint8_t c, uint8_t d);

#endif // Thermal_h


Code: [Select]

I have an arduino UNO Rev3 and mega ADK.

Sorry for my english, I'm french!



Actually I think the conflict is between the <GSM.h> and <SoftwareSerial.h> libraries (as well?). I have the same exact issue with the following simple sketch:

Code: [Select]

#include <SoftwareSerial.h>
#include <GSM.h>

GSM gsmAccess(false);
GSMSoftSerial mySerial(2,3); // RX, TX on GSM shield

void setup()

  // connection state
  boolean notConnected = true;
    if(gsmAccess.begin() == GSM_READY) //Note: I do not require PIN #
      notConnected = false;
    else {
      Serial.println("Not connected, trying again");

void loop()
  if (mySerial.available())
  if (Serial.available())


With my limited knowledge, I believe the conflict is in the fact that the main Arduino shield and the GSM Shield use the software serial to communicate and somehow the 2 software serials conflict...

Any help greatly appreciated, I have the same issue...


GSMSoftSerial and SoftwareSerial conflict with each other because they use the same pin interrupts.  I got around this by using the AltSoftSerial library instead of SoftwareSerial.  It does not use pin interrupts, or at least not the same ones as GSMSoftSerial.  Serial communication with AltSoftSerial can only be used through two specific pins.  You can download it and see the documentation here: http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131