Install Adafruit Code

Connect the power cable to boot the system. Negotiating a wireless connection will take a moment, so wait about a minute before trying to access the system using SSH.

Once logged in, install the Adafruit thermal printer library and example code:

git clone https://github.com/adafruit/Python-Thermal-Printer

Make sure a roll of paper is installed in the printer and the top is securely latched. Then we’ll test all the basic functionality:

cd Python-Thermal-Printer
python printertest.py

This should progress through different text sizes, styles and formats, as well as barcodes and images.

If this does not work, the most likely culprits are:
  • One of the prerequisite Python libraries is not installed (serial, imaging, unidecode) — explained in Raspberry Pi Setup Part 2 of 3.
  • The serial port has not been properly disengaged for application use — also explained in Raspberry Pi Setup Part 2 of 3.
  • Wrong connection between printer and Raspberry Pi — explained in Assembly.
The first two will likely give an informative error response. The latter will just produce no results.

Configure the Weather Scripts

Before running the weather scripts, you must create another developer account in order to use the DarkSky weather API.

Go to https://darksky.net/dev/ and sign up for an account.

Get your API secret key, and go ahead and modify the following line in forecast.py and timetemp.py

API_KEY = "YOUR_API_KEY"

Save the changes, then run the script again:

python forecast.py

This should now print the current weather and the forecast for NYC, the default location. Change the latitude and longitude variables too to reflect the location you'd like to get the weather for. I use NASA's site

If this works, also edit the file timetemp.py and make the same change there. This is a different script that prints the current time and local weather conditions.

Configure the Twitter Script

As written, the sketch will search for Tweets originating from Adafruit, but you can change this to any search string supported by the Twitter SearchAPI. FIrst step though is to set up authentication…

      nano twitter.py
    

Look for this section of code:

# Twitter application credentials -- see notes above -- DO NOT SHARE.
consumer_key    = 'PUT_YOUR_CONSUMER_KEY_HERE'
consumer_secret = 'PUT_YOUR_CONSUMER_SECRET_HERE'
Copy the Consumer key and Consumer secret strings from the Twitter application page into the corresponding spots, keeping the quotes around them.

Just below this is the search term. You can change Adafruit to any other valid Twitter account.
queryString = 'from:Adafruit'
Different search types are possible, such as by tag. Refer to the SEARCH OPERATORS section of the Twitter Developers Documentation for guidance.

Any search string used by the “Gutenbird” sketch for the original Internet of Things Printer can also be used here.

Test the Main Script

The “main” script starts by printing a greeting image, performs once-daily actions (weather forecast and Sudoku puzzle), then goes into Twitter-monitoring mode.

sudo python main.py

The “main” script must be run as root (i.e. using “sudo”) because it directly accesses hardware — the GPIO pins for the button and LED.

It may take a few minutes to run!

Each morning at 6:30 am, the once-daily actions are performed again. You can change this time (or the actions) by editing the main.py script.
Press control+C to stop the program. We’ll set it up to run automatically when the printer is turned on…

Configure Auto-Start

With the software now tested “manually,” let’s make it start automatically upon booting:

sudo nano /etc/rc.local

Before the final “exit 0” line, add these two lines:

cd /home/pi/Python-Thermal-Printer
python main.py &

If you downloaded or otherwise placed the printer software in a different location, the first line should be changed accordingly. “sudo” isn’t necessary here because the rc.local script is already run as root.

Reboot the system to test the startup function:

sudo reboot

After 30 seconds to a minute, you should see the status light come on. After another 30 seconds, the greeting image should be printed, then the “once daily” functions. After that, the printer will go into Twitter-monitoring mode.

Regular Operation

When the printer is idle, tap the button for the current time and local weather conditions.

Hold the button down to initiate an orderly shutdown. This is always a good idea — you don’t want to just pull the plug on most Linux systems. There may be many files open at any given time, and this gives the system a chance to put things in order.

This guide was first published on Apr 12, 2013. It was last updated on Jan 02, 2013.

This page (Raspberry Pi Setup: 3 of 3) was last updated on Feb 18, 2013.

Text editor powered by tinymce.