How to Install Thermal Printer on Raspberry Pi

How to Install Thermal Printer on Raspberry Pi

We show you how to connect a Raspberry Pi to a thermal printer and schedule it to print useful data on a routine basis, including 7-day weather reports.

BUILD TIME: two HOURS
DIFFICULTY RATING: Intermediate

Press from the Raspberry Pi is definitely no new thing, however, it is an oftentimes overlooked output medium for maker projects. While traditional printers can be quite impractical for projects due to their size and ink cartridge/toner requirements, thermal printers overcome many of these issues.

THE BROAD OVERVIEW

This project started every bit an experiment to operate a cheap thermal receipt printer from a Raspberry Pi, and to go them working with a few basic scripts to print out useful information like weather condition, news, etc, on a recurring footing.

The event is a fully-performance Raspberry Pi controlled printer that can be ready to print a weather forecast, the news headlines, or hashtags that trend on Twitter, thanks to freely available APIs. At that place is plenty of scope to have it print other things equally well.

Our build uses a HOIN HOP-H58 Thermal Printer and Raspberry Pi 4, however, you lot could suit the projection to suit a different printer or RPi board.

We evidence you how to set the APIs, and how to code the Pi using various Python scripts.

Thermal Printers

Thermal printers are a proven technology which accept been deployed across the earth in cash registers, ATMs, etc. They require specialised thermal paper impregnated with a solid-land mixture of dye and matrix. When the paper is heated by the printhead, the dye reacts with the matrix and permanently becomes coloured. This setup eliminates the need for any external ink or toner but limits the available colours to just the dice and the base paper. This works well for printing text and icons but not good for intricate or coloured objects.

Thermal printers consist of iii primary components: the thermal head, platen, and leap. The thermal head contains heating elements that tin be controlled with an electrical current, the rut from these elements then activates the paper’s thermochromic layer exposing the dye. Modern thermal printers can include over 1000 individual heating elements assuasive for print resolutions upward to 1200 DPI. The platen is a motorised rubber roller that is used to feed the thermal newspaper under the thermal head with a leap to tension the paper for best results.


How to Install Thermal Printer on Raspberry Pi
CREDIT:
Mitsubishi HiTec Newspaper

This compact blueprint allows thermal printers to print much faster than dot-matrix printers while likewise existence smaller, lighter, and less ability-hungry. The thermal paper rolls can also be rapidly replaced, reducing turn-effectually times. Nosotros exercise need to consider the limited longevity of thermally printed content with the printed textile being more susceptible to heat, abrasion, friction, calorie-free, and water. In a domestic environment, nosotros can safely assume our content will remain legible for l days. This is perfectly fine for our project as we won’t be printing any important information, withal, if you were looking to deploy a similar setup in an industrial setting, it would be an important consideration.

Digital thermal printers feature an onboard processor that handles the conversion of our digital file to commands for the printhead and roller. While most thermal printers will come with a Windows driver, very few come with one that is uniform with the Raspberry Pi. While few official drivers exist, in that location are open up-source drivers derived from the original drivers bachelor for the virtually pop models.




We will be using the inexpensive HOIN HOP-H58 Thermal Printer, which can exist found for purchase online. The printer accepts common 58mm thermal paper and can exist connected via USB, or Bluetooth. This guide should work with other thermal printers, providing you are handy with Linux and can find working drivers.

Nosotros decided to create some Python scripts that we could apply to demonstrate the usefulness of a thermal printer for maker projects. We decided on three programs that could fetch useful data from free online sources and print the output. The programs can provide u.s.a. with a diversity of interesting and useful information such equally the atmospheric condition forecast for our location, news headlines, and the top tweets for a sure search term.

These scripts serve every bit a fantastic starting place for your very own thermal printer projection. The scripts can hands exist modified to suit your personal needs and requirements with a little bit of Python cognition.




Setup:



Raspberry Pi four mounted inside the Argon NEO case

We volition be using the Raspberry Pi 4 Model B 2GB for this project, yet, any modernistic Raspberry Pi with net connectivity should work. We besides paired our Raspberry Pi 4 with the Argon NEO passive case to ensure the Pi remained cool under 24/vii operation.

Read:  Cara Menginstal Printer Hp Deskjet Ink Advantage 2060

Nosotros decided to get with a passive case to reduce racket, withal, a variety of actively cooled cases are also available. You can use any mod microSD card with at to the lowest degree 16GB chapters and form ten speeds. Some cards come with firmware pre-installed, yet, we will be installing ours from scratch to ensure we go the latest version.

Parts Required: Jaycar Altronics Cadre Electronics
i x Raspberry Pi four Model B (2GB or 4GB) XC9102 Z6302G CE06424
1 x Raspberry Pi four Ability Supply XC9120 M8821 CE06427
1 10 16GB+ microSD Card XC4989 D0313A CE00279
1 x Argon NEO Raspberry Pi four Case^ XC9112 H8952 CE06587

^ Our projection uses the Argon NEO from Core Electronics. The alternatives from Jaycar and Altronics are unlike cases.

Nosotros will exist installing Raspberry Pi Os with desktop to our microSD card using Raspberry Pi Imager. We can download Raspberry Pi Imager for Windows, macOS, or Ubuntu from
https://www.raspberrypi.org/software/




One time nosotros accept installed Raspberry Pi Imager, select the Operating Arrangement, and the recommended Raspberry Pi Os (32-chip). Insert the microSD card into your host figurer and select the device in Raspberry Pi Imager. In one case you lot accept selected the microSD carte du jour you can click write and the OS volition exist installed.




We need to configure Raspberry Pi OS to operate in headless mode so that nosotros can control information technology remotely without the need to adhere a monitor and keyboard. To do this, we will configure our WiFi details and enable SSH, which volition allow us to remotely connect with our Raspberry Pi over our home network. If you are connecting your Raspberry Pi to the cyberspace with ethernet you can skip the WiFi configuration.

To configure the WiFi settings, y’all will need to create a wpa_supplicant.conf file. Open up Notepad or a like text editor and copy the following file, replacing ssid and psk with your WiFi network proper noun and password. Save this file as wpa_supplicant.conf past setting the file blazon to all files in Notepad. The wpa_supplicant.conf file tin can also be downloaded from our website and edited for employ with your network.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
land=AU
network={
  ssid="<Name of your wireless LAN>"
  psk="<Password for your wireless LAN>"
}

Copy the wpa_supplicant.conf file to the microSD card home directory. This file will allow the Raspberry Pi to connect to your home WiFi network, only we nevertheless need to enable ssh so that it can be accessed remotely. In the aforementioned directory, right-click and select New > Text Document. Proper name the file SSH and delete the .txt extension. If you tin not see file extensions, enable the option under the Windows explorer view tab.




Eject the microSD menu from the reckoner and insert information technology into your Raspberry Pi. If you purchased a case for your Raspberry Pi, now would be a good time to get together and install information technology. When you connect the power supply, the device should kicking and connect to your WiFi network. Next, detect the IP address of the Raspberry Pi so that y’all tin can connect to it via SSH.

If you lot take a mod WiFi system, you may have a mobile app that will requite you the IP addresses of connected devices. Otherwise, apply a free application similar Fing to scan your network for devices. Expect for a device called Raspberry Pi. Once you accept located the IP address for the Pi, you lot can connect to information technology.

We will be using the PuTTY SSH client to connect to the Raspberry Pi.You can download and install the latest version pf PuTTY from
https://www.chiark.greenend.org.u.k./~sgtatham/putty/latest.html. Next, enter your Raspberry Pi’south IP address in the Host Proper name field and select Open to constitute a connectedness.




If you receive a PuTTY Security Warning, select Yeah to establish the connection.




PuTTY will now open a control-line connection to the Raspberry Pi.

Log into the Os every bit admin with username pi and password raspberry (annotation that the password will not be visible in the console). This default login should exist changed to reduce the security gamble using the passwd control.




Nosotros are at present set up to configure the thermal printer for use with the Raspberry Pi.

We will be using the Common UNIX Printing Organisation (CUPS) to handle our print jobs and interface with the printer. CUPS will demand to be configured to requite the default user administrative rights so that we can successfully access the printer.

Read:  Cara Mengatasi No Printer Installed Windows 10

In the last, enter the following two commands to install and grant administrative rights:

sudo apt-become install cups
sudo usermod -a -G lpadmin pi

We can at present install the drivers for the thermal printer.

Note: The following instructions are for the HOIN HOP-H58 printer You may need to arrange your install based on the printer you are using.

In our case, we volition use the custom drivers created past Okkar Min, which have been modified to work correctly on the Raspberry Pi.

The showtime step is to ability on our printer and connect it to the Raspberry Pi via USB. Once the printer is continued we can download and install the drivers with the following commands:

git clone https://github.com/
OkkarMin/HOP-H58-RaspberryPi-Driver
cd HOP-H58-RaspberryPi-Driver
chmod +x ./install_H58_driver.sh
./install_H58_driver.sh

The thermal printer should now be configured to work on the Raspberry Pi with CUPS, which will allow us to send print jobs and configure the printer.

To simplify the setup, we take also created an automatic script that volition perform the steps to a higher place, along with installing the Python scripts we will be using and their necessary modules. To run the script, you will need the HOIN HOP-H58 thermal printer attached and powered on. Running the following commands volition download and run the installer script.

git clone https://github.com/
LukePrior/Raspberry-Pi-Thermal-Printer
cd Raspberry-Pi-Thermal-Printer
sudo chmod +x ./installer.sh
sudo ./installer.sh

The Python scripts require a program to export the result to a file CUPS could send to the printer. We decided to apply the paps text to PostScript converter which takes a text file and converts information technology to the printer-friendly PostScript file. To install paps, employ the post-obit command (paps will already exist installed if yous used our installation script):

sudo apt-go install paps

The terminal stride is to install the necessary Python modules then that our custom scripts tin can interact with the APIs they use to fetch the required data. We used pip3 to install the iii packages nosotros needed, which were pyowm, tweepy, and requests.

The post-obit command will install them (these modules will already be installed if yous used our installation script):

pip3 install pyowm tweepy requests

Python Scripts

With all our prerequisites installed and the thermal printer configured, we are ready to create our custom Python scripts. We decided to create three scripts that would impress the weather forecast for the upcoming days at a specific location, show the tiptop news headlines, and showcase recent popular tweets for a certain topic. We chose these options considering they offered a wide range of options and had existing Python API implementations that we could apply.

Weather Forecast




The conditions script uses the costless Weather condition API from the OpenWeatherMap to fetch the 7-day forecast for a set location provided by latitude and longitude coordinates. To use the script, we need to create an OpenWeatherMap account here:
https://home.openweathermap.org/users/sign_up

The account confirmation e-mail volition comprise your unique API cardinal (APPID). You lot will likewise need to find the coordinates for your chosen location using a service such equally
https://www.latlong.net/.




To run the weather script, download the weather.py file. If you used our automatic installer, the scripts volition already exist installed in Raspberry-Pi-Thermal-Printer/code. The scripts can also be downloaded from our website.

To use the programme, navigate to the program folder using:

cd ~Raspberry-Pi-Thermal-Printer/code

We can now run our script using the python3 command. We volition also need to send arguments to the program with our API central, and location. The but mandatory argument is –api which takes our OpenWeatherMap API key. We take three optional arguments for latitude, longitude, and the number of days to return. Latitude is provided as a bladder with N positive and South negative, for longitude East is positive and Due west is negative. You can choose to return ane to seven days of a weather condition forecast.

To view all available arguments and their functions we tin use:

python3 weather.py --help

The program will default to Sydney (-33.8688, 151.2093) as its location and three days as the forecast to return if no arguments are provided. With our printer powered on and connected to the Raspberry Pi, we can phone call the plan using:

python3 weather.py --api API_KEY --lat -XX.XXXX --lon 20.XXXX --days X

This will fetch the weather forecast for the provided location and create a file that can be interpreted past our printer.




The plan tin be modified to provide more than weather information or brandish the forecast differently. The documentation for the Once Phone call OpenWeatherAPI nosotros used can be found here:
https://openweathermap.org/api/i-call-api

News Headlines




The news headlines script uses the News API to fetch the top headlines from all major publications in Australia. We will need to sign upward for a free developer account to get an API access key, by going to https://newsapi.org/register.

Read:  Cara Membersihkan Tinta Printer Hp Deskjet 2135

Once you accept registered for an individual account, you can find your API fundamental on the account page.

Notation: This program is also packaged with our automated installer or alternatively can be institute on our website.

The program merely requires a single argument with our API key. There is also an optional argument to specify the number of headlines to return, which defaults to three.

To view all bachelor arguments and their functions, we can use:

The program will print the superlative Australian headlines from a multifariousness of publications.

With the thermal printer continued and powered on, we can run the script using the post-obit command:

python3 news.py --api API_KEY --headlines 10

The News API is very powerful and tin easily be configured to render headlines for a different land or from only certain institutions by modifying our script. The complete documentation for the News API can be found here:
https://newsapi.org/docs/endpoints/top-headlines.




Trending Tweets




The trending tweets script uses the Tweepy Twitter API to fetch the trending tweets for a sure search term or hashtag.

To gain access to the Twitter API you will need a Twitter account and apply for standard hobbyist access at:
https://developer.twitter.com/en/apply-for-admission.

One time you lot have been granted access to the API, navigate to the Twitter Developer Dashboard and create a new standalone application. Once you have created the app, re-create the API key, and API cloak-and-dagger key.




The programme requires ii arguments with our API fundamental and API clandestine to authenticate with Twitter and fetch the results. The program too includes two optional arguments for the search term and the number of tweets to return. These default to “Raspberry Pi” and three tweets.

To view all bachelor arguments and their functions, we can use:

The programme will search Twitter in extended style for pop tweets which encounter the search criteria.

With the thermal printer connected and powered on, run the script using the following control:

python3 tweets.py --key API_KEY --underground API_SECRET --query Thirty --tweets X

The Tweepy Twitter API is very customisable and could hands be modified to display different Tweet information or content. The consummate Tweepy api documentation can be found hither:
https://docs.tweepy.org/en/v3.10.0/api.html




Automatic Running

The steps we accept only described just allow the states to run our scripts once when we are remotely continued to our RPi via SSH and can send commands. Nosotros can prepare up the RPi to automatically run our scripts at a ready time using cron. Cron is a tool used for scheduling commands and scripts on UNIX systems. All cron entries are fabricated up of the same 6 components: minute, hour, mean solar day of the month, month of the year, day of the week, and the command to exist executed.



CREDIT:
Raspberry Pi Foundation

We tin use cron to create scheduled tasks for our scripts.

To create a new entry, edit crontab using the post-obit command:

When asked to select an edit, choose nano by pressing enter. Navigate to the bottom of the file with the downwardly key. Y’all can now enter a cron task on a new line. For example, if you lot wanted to run the weather program each morning at 7:00 am, use the post-obit entry:

0 0 7 ane/1 * python3 /dwelling/pi/Raspberry-Pi-Thermal-Printer/code/weather.py --api API_KEY




You can use an online tool similar CronMaker to easily generate cron expressions to run the program at any fourth dimension y’all prefer.

Simply select how often you want the script to run and CronMaker volition generate the commencement 5 parts of the cron expression. Simply add the script at the end.




WHERE TO FROM HERE?

Due to limited time and telescopic for this projection, we could simply describe iii api methods. When planning this project, we had brainstormed many other possibilities for real-world uses of this printer and data service configuration.

These included printing shopping lists, stock/crypto prices, weekly tides, inspirational quotes, fun facts, etc. Y’all may find a completely different purpose for connecting a RPI to a thermal printer.

GETTING FUNKY

At that place’south also something fun you can do with thermal printers without much additional work from this fundamental build. Modify the media!

At that place are about limitless options for what a thermal printer can print on. Stickers or labels, merely yous’re not limited to white. There’s as well a huge assortment of coloured options besides!




So don’t be afraid to push button the envelope – there’s plenty of fun opportunities with this fundamental thought! Compatibility volition just depend on the printer you utilize.

How to Install Thermal Printer on Raspberry Pi

Check Also

Ampun Reset Kedap Kedip Pada Printer Epson L350

Ampun Reset Kedap Kedip Pada Printer Epson L350

Ampun Reset Kedap Kedip Pada Printer Epson L350 Seperti yang kita ketahui, penggunaan printer tentunya …