Git Product home page Git Product logo

usbprinter_uhs2's Introduction

USBPrinter driver for USB Host Shield 2.0 Library

This driver is designed to work for small USB thermal printers. Do not expect this to work for laser or inkjet printers because they require complex software support.

This has been tested with USB Host Shield Library 2.0 with one required patch and the ESC POS Printer library on a Uno.

https://github.com/felis/USB_Host_Shield_2.0

Required patch not merged yet

felis/USB_Host_Shield_2.0#473

https://github.com/gdsports/ESC_POS_Printer

Sample program that prints "Hello Printer" in large letters.

#include "USBPrinter.h"         // https://github.com/gdsports/USBPrinter_uhs2
#include "ESC_POS_Printer.h"    // https://github.com/gdsports/ESC_POS_Printer

class PrinterOper : public USBPrinterAsyncOper
{
  public:
    uint8_t OnInit(USBPrinter *pPrinter);
};

uint8_t PrinterOper::OnInit(USBPrinter *pPrinter)
{
  Serial.println(F("USB Printer OnInit"));
  Serial.print(F("Bidirectional="));
  Serial.println(pPrinter->isBidirectional());
  return 0;
}

USB myusb;
PrinterOper AsyncOper;
USBPrinter uprinter(&myusb, &AsyncOper);
ESC_POS_Printer printer(&uprinter);

void setup() {
  Serial.begin(115200);
  while (!Serial && millis() < 3000) delay(1);

  if (myusb.Init()) {
    Serial.println(F("USB host failed to initialize"));
    while (1) delay(1);
  }

  Serial.println(F("USB Host init OK"));
}

void loop() {
  myusb.Task();

  // Make sure USB printer found and ready
  if (uprinter.isReady()) {
    printer.begin();
    Serial.println(F("Init ESC POS printer"));

    printer.setSize('L');   // L for large
    printer.println(F("Hello Printer"));
    printer.feed(2);

    // Do this one time to avoid wasting paper
    while (1) delay(1);
  }
}

The ESC POS library send printer ESC/POS commands for different font sizes, graphics mode, etc. It is based on the Adafruit Thermal printer library but modified to work with USB thermal receipt printers. Note different thermal printers from even if from the same manufacturers implement different subsets of the ESC POS commands. You will have to find the ones that work on your printer.

Related

The following driver works on SAMD board with USB OTG ports such as Arduino Zero and MKR family.

https://github.com/gdsports/USBPrinter_uhls

The following driver works on Teensy 3.6 boards.

https://github.com/gdsports/USBPrinter_t36

usbprinter_uhs2's People

Contributors

gdsports avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

ezhangle lgv2018

usbprinter_uhs2's Issues

Thermal Barcode Printer is not responding to Arduino Mega ADK

Hello,

Firstly, thank you for providing this library. Currently, I am trying to drive a thermal barcode printer from Arduino Mega ADK via USB. I have used this library and examples. What I have found is command issue is successful, but the printer is not responding.
Is it like the library compatible only with Arduino UNO+USB Host Shield and not with Arduino Mega ADK? Could you please help me in resolving this issue?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.