Published © CC BY-NC-SA

Four Pies

We give you a quick overview and build a project to welcome the Raspberry Pi 4 to the world!

BeginnerFull instructions provided8 hours1,707

Things used in this project

Hardware components

Adafruit Mini Thermal Receipt Printer
×1
Felt
×1
Raspberry Pi 4 Model B
Raspberry Pi 4 Model B
×1

Software apps and online services

Raspbian
Raspberry Pi Raspbian

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Code

Code

Python
import os
import sys
import time
import re

# Setup our printer
def setup():
    os.system("stty -F /dev/serial0 19200")

# Calculate pi using the system
def calculatePi():
    os.system('echo "scale=2000;4*a(1)"|bc -l')

# Print them pies!
def printPies():
    
#     width of our paper. this many character fit on a single
    width = 32

# Barrier to print between every pie
    barrier = width * '*'

# Our asci art pie
    pi = (
            "                (               "
            "                 )              "
            "            __..---..__         "
            "        ,-=   \  |  /   =-.     "
            "       :--..___________..--;    "
            "        \.,_____________,./     "
        )

#   Command to print   
    os.system('echo "' + pi + '\\n" > /dev/serial0')

try:

    setup()

    while True:

        print('start')
        calculatePi()

        print('done')
        printPies()
        
        time.sleep(2)

except KeyboardInterrupt:
    sys.exit()

Credits

Comments