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?
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).
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))
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);
}