Skip to content

Instantly share code, notes, and snippets.

@goldsamantha
Created April 17, 2020 14:10
Show Gist options
  • Save goldsamantha/38c494e283aed3f87e124e93012d9e61 to your computer and use it in GitHub Desktop.
Save goldsamantha/38c494e283aed3f87e124e93012d9e61 to your computer and use it in GitHub Desktop.
import time
import serial
import RPi.GPIO as GPIO
# Set up gpio for button push
PIN_NUM = 7
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
# Set up printer
ser = serial.Serial('/dev/serial0', 19200)
# To write to serial port do:
# ser.write(b'Your text here\n\n')
GPIO.setup(PIN_NUM, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def main():
while True:
if GPIO.input(PIN_NUM) == GPIO.HIGH:
ser.write(b'button pushed!\n\n')
time.sleep(.5)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment