Mini Thermal Receipt Printer + GSM

Hi,

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 :

    // 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 :

    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?

Thx.

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.

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.

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

#ifndef Thermal_h
#define Thermal_h

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

// 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);
#else
  #define SERIAL_IMPL      NewSoftSerial
  #define PRINTER_PRINT(a) _printer->print(a, BYTE);
#endif

class Adafruit_Thermal : public Print {

 public:

  Adafruit_Thermal(int RX_Pin, int TX_Pin);

  void
    begin(int heatTime=200),
    reset(),
    setDefault(),
    test(),
    testPage(),

    normal(),
    inverseOn(),
    inverseOff(),
    upsideDownOn(),
    upsideDownOff(),
    doubleHeightOn(),
    doubleHeightOff(),
    doubleWidthOn(),
    doubleWidthOff(),
    boldOn(),
    boldOff(),
    underlineOn(uint8_t weight=1),
    underlineOff(),
    strikeOn(),
    strikeOff(),

    justify(char value),
    feed(uint8_t x=1),
    feedRows(uint8_t),
    flush(),
    online(),
    offline(),
    sleep(),
    sleepAfter(uint8_t seconds),
    wake(),
    listen(),

    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),
    timeoutWait(),
    setTimes(unsigned long, unsigned long),

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

  bool hasPaper();

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

 protected:

  SERIAL_IMPL
    *_printer;
  uint8_t
    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
  int
    printMode,
    _RX_Pin,
    _TX_Pin;
  void
    setPrintMode(uint8_t mask),
    unsetPrintMode(uint8_t mask),
    writePrintMode(),
    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

and Adafruit_Thermal.cpp

I have an arduino UNO Rev3 and mega ADK.

Sorry for my english, I'm french!

Thx

Adafruit_Thermal.cpp (15.4 KB)

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:

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

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


void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);

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

void loop()
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());

}

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: AltSoftSerial Library, for an extra serial port.