Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1:
- from gpiozero import LED, Button
- from signal import pause
- from time import sleep
- button = Button(6, False)
- led1 = LED(13)
- button.when_pressed = led1.on
- button.when_released = led1.off
- pause()
- 2 GPIO:
- from gpiozero import LED, Button
- from signal import pause
- from time import sleep
- button = Button(6, False)
- led1 = LED(13)
- button.when_pressed = led1.on
- button.when_released = led1.off
- pause()
- 3 I2C:
- import smbus2
- import bme280
- port = 1
- address = 0x77
- bus = smbus2.SMBus(port)
- calibration_params = bme280.load_calibration_params(bus, address)
- # the sample method will take a single reading and return a
- # compensated_reading object
- data = bme280.sample(bus, address, calibration_params)
- # the compensated_reading class has the following attributes
- print(data.id)
- print(data.timestamp)
- print(data.temperature)
- print(data.pressure)
- print(data.humidity)
- # there is a handy string representation too
- print(data)
- 4 i2c-2:
- import time
- import board
- import adafruit_tsl2591
- # Create sensor object, communicating over the board's default I2C bus
- i2c = board.I2C() # uses board.SCL and board.SDA
- # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
- # Initialize the sensor.
- sensor = adafruit_tsl2591.TSL2591(i2c)
- # You can optionally change the gain and integration time:
- # sensor.gain = adafruit_tsl2591.GAIN_LOW (1x gain)
- # sensor.gain = adafruit_tsl2591.GAIN_MED (25x gain, the default)
- # sensor.gain = adafruit_tsl2591.GAIN_HIGH (428x gain)
- # sensor.gain = adafruit_tsl2591.GAIN_MAX (9876x gain)
- # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_100MS (100ms, default)
- # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_200MS (200ms)
- # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_300MS (300ms)
- # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_400MS (400ms)
- # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_500MS (500ms)
- # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_600MS (600ms)
- # Read the total lux, IR, and visible light levels and print it every second.
- while True:
- # Read and calculate the light level in lux.
- lux = sensor.lux
- print("Total light: {0}lux".format(lux))
- # You can also read the raw infrared and visible light levels.
- # These are unsigned, the higher the number the more light of that type.
- # There are no units like lux.
- # Infrared levels range from 0-65535 (16-bit)
- infrared = sensor.infrared
- print("Infrared light: {0}".format(infrared))
- # Visible-only levels range from 0-2147483647 (32-bit)
- visible = sensor.visible
- print("Visible light: {0}".format(visible))
- # Full spectrum (visible + IR) also range from 0-2147483647 (32-bit)
- full_spectrum = sensor.full_spectrum
- print("Full spectrum (IR + visible) light: {0}".format(full_spectrum))
- time.sleep(1.0)
- 5 camera:
- import arducam_mipicamera as arducam
- import v4l2
- import time
- import cv2
- import copy
- def align_down(size, align):
- return (size & ~((align)-1))
- def align_up(size, align):
- return align_down(size + align - 1, align)
- def set_controls(camera):
- try:
- camera.software_auto_exposure(enable = False)
- camera.software_auto_white_balance(enable = True)
- camera.set_control(v4l2.V4L2_CID_EXPOSURE, 15000)
- camera.set_control(v4l2.V4L2_CID_FOCUS_ABSOLUTE, 150)
- camera.manual_set_awb_compensation(20,150)
- except Exception as e:
- print(e)
- # TODO: haarcascades file path
- xml_file = "/home/rpi/Desktop/labs rpi/haarcascades/haarcascade_frontalface_alt2.xml"
- bodzenta = cv2.imread("/home/rpi/Desktop/labs rpi/bodzenta.png")
- classifier = cv2.CascadeClassifier(xml_file)
- camera = arducam.mipi_camera()
- camera.init_camera()
- fmt = camera.set_resolution(1920, 1080)
- print("Current resolution is {}".format(fmt))
- set_controls(camera)
- started = True
- while started:
- frame = camera.capture(encoding = 'i420')
- height = int(align_up(fmt[1], 16))
- width = int(align_up(fmt[0], 32))
- image = frame.as_array.reshape(int(height * 1.5), width)
- image = cv2.cvtColor(image, cv2.COLOR_YUV2BGR_I420)
- image = cv2.resize(image, (1280, 720))
- faces = classifier.detectMultiScale(image)
- image2 = copy.copy(image)
- # TODO: Add rectangle / image drawing
- for (x, y, w, h) in faces:
- cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
- bodzenta2 = cv2.resize(bodzenta, (w,h))
- image2[y: y+h, x: x+w] = bodzenta2
- cv2.imshow("Faces", image2)
- key = cv2.waitKey(1) & 0xFF
- if key == ord("q"):
- started = False
- camera.close_camera()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement