Skip to content

Instantly share code, notes, and snippets.

@combs
Created December 11, 2020 00:35
Show Gist options
  • Save combs/df63d26bada47ad94f5b197dbbe60b36 to your computer and use it in GitHub Desktop.
Save combs/df63d26bada47ad94f5b197dbbe60b36 to your computer and use it in GitHub Desktop.
import serial
import RPi.GPIO as GPIO
import time
import pygame
import pygame.camera
pygame.camera.init()
camera = pygame.camera.Camera("/dev/video0", (1024,768))
camera.start()
surf = camera.get_image()
GPIO.setmode(GPIO.BCM)
for bslabel, bs in {"EIGHTBITS": serial.EIGHTBITS, "SEVENBITS": serial.SEVENBITS }.items():
# , "SIXBITS": serial.SIXBITS, "FIVEBITS": serial.FIVEBITS
for parlabel, par in {"NONE": serial.PARITY_NONE, "ODD": serial.PARITY_ODD, "EVEN": serial.PARITY_EVEN,
"MARK": serial.PARITY_MARK, "SPACE": serial.PARITY_SPACE}.items():
for stlabel, stop in {"ONE": serial.STOPBITS_ONE, "1.5": serial.STOPBITS_ONE_POINT_FIVE,
"TWO": serial.STOPBITS_TWO}.items():
for bps in [8000, 8400, 8600, 8800, 9000, 9200, 9300, 9400, 9450, 9500, 9550, 9600, 9650, 9700, 9800, 10000]:
# sub your own BPS values here. I was wondering about an aging crystal, hence strange values
for xonxoff in (True, False):
# I have attached GPIO 7 to a transistor controlling the device's power
# it is powered by a boost converter w/ big caps, which takes a while to drain
# you could shorten these delays w/o that.
GPIO.setup(7, GPIO.OUT)
GPIO.output(7, 0)
time.sleep(.5)
GPIO.output(7, 1)
time.sleep(2.5)
fn = str(bps) + bslabel + parlabel + stlabel + str(xonxoff) + ".jpg"
print(str(bps),bslabel, parlabel, stlabel, str(xonxoff))
with serial.Serial("/dev/ttyAMA0", bps, bytesize=bs, parity=par, inter_byte_timeout=0.1,
stopbits=stop, xonxoff=xonxoff, timeout=1) as sph:
sph.write(("\n\rhello there\n\rok how's it going\n" + str(bps) +
bslabel + parlabel + stlabel + str(xonxoff)).encode('utf-8'))
time.sleep(2)
surf = camera.get_image()
pygame.image.save(surf, fn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment