Controlling 2x Thermal Printers with 1x ESP32

Hi community,

I am fairly new to arduino (and electronics in general) and need some help with buying parts.

Right now, I am using a Fire Beetle ESP32 to control a small Thermal Printer. All is working well.

However, I want to communicate with 2x thermal printers from one ESP32 board. I believe I need two sets of TX/RX pins to do this, but the Fire Beetle only has the one pairing. Please correct me if I’m wrong!

Could you please suggest a board that has at least 2x TX/RX pairings?

I also want to power this board from a power point (as opposed to a laptop or a LiPo battery). Do I need something special to do this, or can I just use the USB cable that comes with the board and a USB to power point adapter?

Thanks for your help!

Liam

2 Likes

Hey Liam,

That’s a great question! Some ESP32 boards do have dual UART like the Beetle ESP32 - C3. This should enable you to use 2 thermal printers at once.

As for the power, you can use a standard wall adapter plug to power it as long as it can supply significant current and voltage (try and use the shortest cable you can get away).

Cheers,
Blayden

1 Like

Thanks, Blayden! I did some research and found this ESP-VROOM-32 that fit the specs I was after. If that doesn’t work I will check out the Beetle.

I’ll take your advice with powering from a wall socket.

Regards,
Liam

Hi Liam (Nice name :smiley: )

Sounds like a sick project!!

The board you have actually features three sets of TX/RX pins!
Though the pairings are more commonly called UART - or serial.

It just depends on the board definition that DFRobot use - would it be possible to get a copy of your code?

We’ll be able to make suggestions based on what modules you’ve already used.

(The ESP32 base module has 3 UART peripherals available, usually one is tapped into for USB-UART, leaving two for users, it wont matter which pins are used thanks to the ESP32’s bus matrix (letting peripherals get used to almost any pin))

Liam

1 Like

Hey @Liam (you have a cool name too!),

Sorry I had delete my reply because I forgot to hide some personal information (wifi passwords, API keys, etc. lol).

Anyway, for context, I’m doing this for an art installation. I want to have two (or more) printers “speaking” with one another.

// Include AdaFruit Thermal Printer library
#include <Adafruit_Thermal.h>

// Include Wifi, JSON, and ChatGPT libraries
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
#include <ChatGPT.hpp>

// Connect the printer to the ESP32 Fire Beetle board
#define RX_PIN 3 // yellow
#define TX_PIN 1 // green

// for printer2 (ignore this)
// #define RX_PIN 10 // yellow
// #define TX_PIN 9 // green

// Create an instance of the Adafruit_Thermal class
Adafruit_Thermal printer(&Serial2);

// Create constants for wifi
static const char *ssid = redacted;
static const char *password = redacted;

// Use API key to connect to ChatGPT 
WiFiClientSecure client;
ChatGPT<WiFiClientSecure> chat_gpt(&client, "v1", redacted);

// Create initial command
static const char *command = "INSERT PROMPT HERE";

String result;

int iteration = 0;

void setup() {

  //have to connect to Serial 1 first for some reason (IDK WHY)
  Serial.begin(19200);

  // Connect to Wifi Network
  Serial.print("Connecting to WiFi network: ");
  Serial.print(ssid);
  Serial.println("'...");
  WiFi.begin(ssid, password);

  // Print "connected!" once in
  while (WiFi.status() != WL_CONNECTED) {
    Serial.println("Connecting...");
    delay(500);
  }
  Serial.println("Connected!");

  // Ignore SSL certificate validation
  client.setInsecure();

  // Initialize the serial port for communication with the printer
  Serial2.begin(115200, SERIAL_8N1, RX_PIN, TX_PIN);
  
  // Initialize the printer
  printer.begin();

}

void loop() {

  // Set size of font to large or small
  // printer.setSize('L');
  printer.setSize('S');

  if (iteration < 1) {

    // New message incoming
    Serial.println("FIRST MESSAGE:");

    // If command returns a message, print the string (result)
    if (chat_gpt.simple_message("gpt-3.5-turbo-0301", "user", command, result)) {
      Serial.println("===OK===");
      Serial.println(result);
      // printer.setSize('L');
      printer.println(result);
    } else {
      Serial.println("===ERROR===");
      Serial.println(result);
      // printer.setSize('L');
      printer.println(result);
    }

    iteration = 1;

  } else {

    command = result.c_str();

    Serial.println(command);

    // New message incoming
    Serial.println("New message:");

    // If command returns a message, print the string (result)
    if (chat_gpt.simple_message("gpt-3.5-turbo-0301", "user", command, result)) {
      Serial.println("===OK===");
      Serial.println(result);
      // printer.setSize('L');
      printer.println(result);
    } else {
      Serial.println("===ERROR===");
      Serial.println(result);
      // printer.setSize('L');
      printer.println(result);
    }

  }

  // Advance the paper by 10 lines
  printer.feed(10);
  
  // Wait for 20 seconds
  delay(20000);
}

Let me know what you think. Thanks!

1 Like

Hi Liam,

Sorry for the delay!

Sounds awesome! We’d love to see some photos once its working :smiley:

Give this code a shot, it just initialises another printer, so you’ll have to add some more context around what it does:

// Include AdaFruit Thermal Printer library
#include <Adafruit_Thermal.h>

// Include Wifi, JSON, and ChatGPT libraries
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
#include <ChatGPT.hpp>

// Connect the printer to the ESP32 Fire Beetle board
#define RX_PIN 3 // yellow
#define TX_PIN 1 // green

// for printer2 - 
#define RX_1_PIN 10 // yellow
#define TX_1_PIN 9 // green

// Create an instance of the Adafruit_Thermal class
Adafruit_Thermal printer(&Serial2);
Adafruit_Thermal printer1(&Serial1);

// Create constants for wifi
static const char *ssid = redacted;
static const char *password = redacted;

// Use API key to connect to ChatGPT 
WiFiClientSecure client;
ChatGPT<WiFiClientSecure> chat_gpt(&client, "v1", redacted);

// Create initial command
static const char *command = "INSERT PROMPT HERE";

String result;

int iteration = 0;

void setup() {

  //have to connect to Serial 1 first for some reason (IDK WHY)
  Serial.begin(19200);

  // Connect to Wifi Network
  Serial.print("Connecting to WiFi network: ");
  Serial.print(ssid);
  Serial.println("'...");
  WiFi.begin(ssid, password);

  // Print "connected!" once in
  while (WiFi.status() != WL_CONNECTED) {
    Serial.println("Connecting...");
    delay(500);
  }
  Serial.println("Connected!");

  // Ignore SSL certificate validation
  client.setInsecure();

  // Initialize the serial ports for communication with the printer
  Serial2.begin(115200, SERIAL_8N1, RX_PIN, TX_PIN);
  Serial1.begin(115200, SERIAL_8N1, RX_1_PIN, TX_1_PIN);
  
  // Initialize the printers
  printer.begin();
  printer1.begin();

}

void loop() {

  // Set size of font to large or small
  // printer.setSize('L');
  printer.setSize('S');

  if (iteration < 1) {

    // New message incoming
    Serial.println("FIRST MESSAGE:");

    // If command returns a message, print the string (result)
    if (chat_gpt.simple_message("gpt-3.5-turbo-0301", "user", command, result)) {
      Serial.println("===OK===");
      Serial.println(result);
      // printer.setSize('L');
      printer.println(result);
    } else {
      Serial.println("===ERROR===");
      Serial.println(result);
      // printer.setSize('L');
      printer.println(result);
    }

    iteration = 1;

  } else {

    command = result.c_str();

    Serial.println(command);

    // New message incoming
    Serial.println("New message:");

    // If command returns a message, print the string (result)
    if (chat_gpt.simple_message("gpt-3.5-turbo-0301", "user", command, result)) {
      Serial.println("===OK===");
      Serial.println(result);
      // printer.setSize('L');
      printer.println(result);
    } else {
      Serial.println("===ERROR===");
      Serial.println(result);
      // printer.setSize('L');
      printer.println(result);
    }

  }

  // Advance the paper by 10 lines
  printer.feed(10);
  
  // Wait for 20 seconds
  delay(20000);
}

``

Liam