KB2040 not working with Thermal Printer Lib

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jjjjkem
 
Posts: 15
Joined: Tue May 10, 2022 6:25 pm

KB2040 not working with Thermal Printer Lib

Post by jjjjkem »

Is there some fundamental reason why the KB2040 will not work with the Adafruit Thermal Printer library?
I am trying to run the Adafruit thermal printer example sketch and it complies and loads just fine but no luck getting the printer to output anything. I have run other Ardunino code on the KD2040 with i2c rotary encoder and seven segment display works just fine. Then tried running the unchanged example sketch from the Thermal printer library and it is not working . Tried various UART pin settings with mySerial or hardware serial and can't seem to get the UART to send anything to the printer. I have it wired to TX on GPIO0 pin. I have tested the printer with a Feather M0 hardware UART and it works fine.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: KB2040 not working with Thermal Printer Lib

Post by mikeysklar »

Seems like this should work.

Can you post the code you are trying to run and a photo of your setup?

RP2040 code usually just needs a slight mode for UART. Let's make sure you are doing that.

Code: Select all

import board
import busio

uart = busio.UART(tx=board.GP4, rx=board.GP5)

User avatar
jjjjkem
 
Posts: 15
Joined: Tue May 10, 2022 6:25 pm

Re: KB2040 not working with Thermal Printer Lib

Post by jjjjkem »

Thank you for your help.
I'm using the Adafruit example sketch for Thermal printer. KB2040 is powered from USB, Printer is power from 9VDC supply, ground wire connect between them. Printer has been tested and works fine when connected to Feather M0 connected to D1 (UART TX) and running the Adafruit Thermal Printer example sketch, using with hardware serial1. KB2040 works with Rotary Encoder example sketch just fine. So KB2040 is working and I know printer works. Printer was purchased from Adafruit.

Photo shows connection to KB2040 pin GPIO0 wired to printer RX. An extra wire is ready to be connected to the RTS mod wire that is added to the printer, but I'm not using this yet until I get printer basic operation. My other tests with printer using Feather M0 work well with the RTS feature. It really improves printer speed.

I have tried using Software Serial (see pin # edited in the commented out code) but still not luck.

I did notice one thing. Apparently the Adafruit code is based upon code done by some bildr-org source https://github.com/bildr-org/Thermal-Printer . In that code example it makes clear in the example sketch that it is for ARDUNIO ONLY!! Not sure why?

Here's the Adafruit example sketch, with my edits.

/*------------------------------------------------------------------------
Example sketch for Adafruit Thermal Printer library for Arduino.
Demonstrates a few text styles & layouts, bitmap printing, etc.

IMPORTANT: DECLARATIONS DIFFER FROM PRIOR VERSIONS OF THIS LIBRARY.
This is to support newer & more board types, especially ones that don't
support SoftwareSerial (e.g. Arduino Due). You can pass any Stream
(e.g. Serial1) to the printer constructor. See notes below.
------------------------------------------------------------------------*/
#include <SoftwareSerial.h>
#include "Adafruit_Thermal.h"
#include "adalogo.h"
#include "adaqrcode.h"

// Here's the new syntax when using SoftwareSerial (e.g. Arduino Uno) ----
// If using hardware serial instead, comment out or remove these lines:
//
//#include "SoftwareSerial.h"
//#define TX_PIN 0 // Arduino transmit YELLOW WIRE labeled RX on printer
//#define RX_PIN 1 // Arduino receive GREEN WIRE labeled TX on printer
//
//SoftwareSerial mySerial(RX_PIN, TX_PIN); // Declare SoftwareSerial obj first
//Adafruit_Thermal printer(&mySerial); // Pass addr to printer constructor
// Then see setup() function regarding serial & printer begin() calls.

// Here's the syntax for hardware serial (e.g. Arduino Due) --------------
// Un-comment the following line if using hardware serial:

Adafruit_Thermal printer(&Serial1); // Or Serial2, Serial3, etc.

// -----------------------------------------------------------------------

void setup() {

// This line is for compatibility with the Adafruit IotP project pack,
// which uses pin 7 as a spare grounding point. You only need this if
// wired up the same way (w/3-pin header into pins 5/6/7):
pinMode(7, OUTPUT); digitalWrite(7, LOW);

// NOTE: SOME PRINTERS NEED 9600 BAUD instead of 19200, check test page.
// mySerial.begin(19200); // Initialize SoftwareSerial
Serial1.begin(19200); // Use this instead if using hardware serial
printer.begin(); // Init printer (same regardless of serial type)

// The following calls are in setup(), but don't *need* to be. Use them
// anywhere! They're just here so they run one time and are not printed
// over and over (which would happen if they were in loop() instead).
// Some functions will feed a line when called, this is normal.

// Font options
printer.setFont('B');
printer.println("FontB");
printer.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
printer.setFont('A');
printer.println("FontA (default)");
printer.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ");

// Test inverse on & off
printer.inverseOn();
printer.println(F("Inverse ON"));
printer.inverseOff();

// Test character double-height on & off
printer.doubleHeightOn();
printer.println(F("Double Height ON"));
printer.doubleHeightOff();

// Set text justification (right, center, left) -- accepts 'L', 'C', 'R'
printer.justify('R');
printer.println(F("Right justified"));
printer.justify('C');
printer.println(F("Center justified"));
printer.justify('L');
printer.println(F("Left justified"));

// Test more styles
printer.boldOn();
printer.println(F("Bold text"));
printer.boldOff();

printer.underlineOn();
printer.println(F("Underlined text"));
printer.underlineOff();

printer.setSize('L'); // Set type size, accepts 'S', 'M', 'L'
printer.println(F("Large"));
printer.setSize('M');
printer.println(F("Medium"));
printer.setSize('S');
printer.println(F("Small"));

printer.justify('C');
printer.println(F("normal\nline\nspacing"));
printer.setLineHeight(50);
printer.println(F("Taller\nline\nspacing"));
printer.setLineHeight(); // Reset to default
printer.justify('L');

// Barcode examples:
// CODE39 is the most common alphanumeric barcode:
printer.printBarcode("ADAFRUT", CODE39);
printer.setBarcodeHeight(100);
// Print UPC line on product barcodes:
printer.printBarcode("123456789123", UPC_A);

// Print the 75x75 pixel logo in adalogo.h:
printer.printBitmap(adalogo_width, adalogo_height, adalogo_data);

// Print the 135x135 pixel QR code in adaqrcode.h:
printer.printBitmap(adaqrcode_width, adaqrcode_height, adaqrcode_data);
printer.println(F("Adafruit!"));
printer.feed(2);

printer.sleep(); // Tell printer to sleep
delay(3000L); // Sleep for 3 seconds
printer.wake(); // MUST wake() before printing again, even if reset
printer.setDefault(); // Restore printer to defaults
}

void loop() {
}
Attachments
KN2040setup.jpeg
KN2040setup.jpeg (89.76 KiB) Viewed 103 times

User avatar
jjjjkem
 
Posts: 15
Joined: Tue May 10, 2022 6:25 pm

Re: KB2040 not working with Thermal Printer Lib

Post by jjjjkem »

Photo shows red wire used for ground. I ran out of black with and the electron do seem to mind. ;-)

User avatar
jjjjkem
 
Posts: 15
Joined: Tue May 10, 2022 6:25 pm

Re: KB2040 not working with Thermal Printer Lib

Post by jjjjkem »

My apologies to the Forum.
Problem was broken connection on TX pin from KB2040.
All working fine now.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: KB2040 not working with Thermal Printer Lib

Post by mikeysklar »

Thank you for the followup. Glad you got it working.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”