IMAGE_FILE = "/sd/image.jpg"  # Full path to file name to save captured image.
# Will overwrite!

# Setup SPI bus (hardware SPI).
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Setup SD card and mount it in the filesystem.
sd_cs = digitalio.DigitalInOut(SD_CS_PIN)
sdcard = adafruit_sdcard.SDCard(spi, sd_cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")

# Create a serial connection for the VC0706 connection, speed is auto-detected.
uart = busio.UART(board.TX, board.RX)
# Setup VC0706 camera
vc0706 = adafruit_vc0706.VC0706(uart)

# Print the version string from the camera.
print("VC0706 version:")
print(vc0706.version)

# Set the baud rate to 115200 for fastest transfer (its the max speed)
vc0706.baudrate = 115200

# Set the image size.
vc0706.image_size = adafruit_vc0706.IMAGE_SIZE_640x480  # Or set IMAGE_SIZE_320x240 or
# IMAGE_SIZE_160x120
# Note you can also read the property and compare against those values to
# see the current size:
size = vc0706.image_size
if size == adafruit_vc0706.IMAGE_SIZE_640x480:
예제 #2
0
def takeimage():
    # Configuration:
    SD_CS_PIN = board.D10  # CS for SD card (SD_CS is for Feather Adalogger)
    IMAGE_FILE = '/sd/image.jpg'  # Full path to file name to save captured image.
    # Will overwrite!

    # Setup SPI bus (hardware SPI).
    spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

    # Setup SD card and mount it in the filesystem.
    sd_cs = digitalio.DigitalInOut(SD_CS_PIN)
    sdcard = adafruit_sdcard.SDCard(spi, sd_cs)
    vfs = storage.VfsFat(sdcard)
    storage.mount(vfs, '/sd')

    # Create a serial connection for the VC0706 connection, speed is auto-detected.
    uart = busio.UART(board.TX, board.RX, timeout=250)
    # Setup VC0706 camera
    vc0706 = adafruit_vc0706.VC0706(uart)

    # Print the version string from the camera.
    print('VC0706 version:')
    print(vc0706.version)

    # Set the baud rate to 115200 for fastest transfer (its the max speed)
    vc0706.baudrate = 115200

    # Set the image size.
    vc0706.image_size = adafruit_vc0706.IMAGE_SIZE_640x480  # Or set IMAGE_SIZE_320x240 or
    # IMAGE_SIZE_160x120
    # Note you can also read the property and compare against those values to
    # see the current size:
    # size = vc0706.image_size
    # if size == adafruit_vc0706.IMAGE_SIZE_640x480:
    #     print('Using 640x480 size image.')
    # elif size == adafruit_vc0706.IMAGE_SIZE_320x240:
    #     print('Using 320x240 size image.')
    # elif size == adafruit_vc0706.IMAGE_SIZE_160x120:
    #     print('Using 160x120 size image.')

    # Take a picture.
    print('Taking a picture in 3 seconds...')
    time.sleep(3)
    print('SNAP!')
    if not vc0706.take_picture():
        raise RuntimeError('Failed to take picture!')

    # Print size of picture in bytes.
    frame_length = vc0706.frame_length
    print('Picture size (bytes): {}'.format(frame_length))

    # Open a file for writing (overwriting it if necessary).
    # This will write 50 bytes at a time using a small buffer.
    # You MUST keep the buffer size under 100!
    print('Writing image: {}'.format(IMAGE_FILE), end='')
    with open(IMAGE_FILE, 'wb') as outfile:
        wcount = 0
        while frame_length > 0:
            # Compute how much data is left to read as the lesser of remaining bytes
            # or the copy buffer size (32 bytes at a time).  Buffer size MUST be
            # a multiple of 4 and under 100.  Stick with 32!
            to_read = min(frame_length, 32)
            copy_buffer = bytearray(to_read)
            # Read picture data into the copy buffer.
            if vc0706.read_picture_into(copy_buffer) == 0:
                raise RuntimeError('Failed to read picture frame data!')
            # Write the data to SD card file and decrement remaining bytes.
            outfile.write(copy_buffer)
            frame_length -= 32
            # Print a dot every 2k bytes to show progress.
            wcount += 1
            if wcount >= 64:
                print('.', end='')
                wcount = 0
    print("")
    print('Finished!')
예제 #3
0
RX_PIN = board.RX     # RX pin of board, connected to VC0706 TX
TX_PIN = board.TX     # TX pin of board, connected to VC0706 RX
IMAGE_FILE = '/sd/image.jpg'  # Full path to file name to save captured image.
                              # Will overwrite!

# Setup SPI bus (hardware SPI).
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Setup SD card and mount it in the filesystem.
sd_cs = digitalio.DigitalInOut(SD_CS_PIN)
sdcard = adafruit_sdcard.SDCard(spi, sd_cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, '/sd')

# Setup VC0706.
vc0706 = adafruit_vc0706.VC0706(RX_PIN, TX_PIN)

# Print the version string from the camera.
print('VC0706 version:')
print(vc0706.version)

# Set the image size.
vc0706.image_size = adafruit_vc0706.IMAGE_SIZE_640x480 # Or set IMAGE_SIZE_320x240 or
                                                       # IMAGE_SIZE_160x120
# Note you can also read the property and compare against those values to
# see the current size:
size = vc0706.image_size
if size == adafruit_vc0706.IMAGE_SIZE_640x480:
    print('Using 640x480 size image.')
elif size == adafruit_vc0706.IMAGE_SIZE_320x240:
    print('Using 320x240 size image.')
 def __init__(self):
     # Set up the camera
     uart = busio.UART(board.TX, board.RX, baudrate=BAUD_RATE, timeout=0.25)
     self._vc0706 = adafruit_vc0706.VC0706(uart)
     self._vc0706.baudrate = BAUD_RATE
     self._vc0706.image_size = adafruit_vc0706.IMAGE_SIZE_320x240
예제 #5
0
    def __init__(self):
        ### Configuration
        print('Configuration has begun.')

        ## I2C setup (Air quality and pressure sensors)
        self.i2c_bus = busio.I2C(board.SCL, board.SDA)
        self.ccs811 = adafruit_ccs811.CCS811(self.i2c_bus,
                                             Sensors.AIRQ_SENS_ADDRESS)
        self.presSensor = adafruit_mpl3115a2.MPL3115A2(
            self.i2c_bus, address=Sensors.PRES_SENS_ADDRESS)
        self.presSensor.sealevel_pressure = Sensors.SEA_LEVEL_PRES
        print('I2C has been configured.')

        ## Camera setup
        print('Configuring the camera.')
        # Setup the UART
        self.uart = serial.Serial(Sensors.UART_PORT,
                                  baudrate=Sensors.UART_BAUD_RATE,
                                  timeout=Sensors.UART_TIMEOUT)

        # Setup VC0706 camera
        self.vc0706 = adafruit_vc0706.VC0706(self.uart)

        # Print the version string from the camera.
        print('VC0706 version:')
        print(self.vc0706.version)

        # Set the image size.
        self.vc0706.image_size = adafruit_vc0706.IMAGE_SIZE_640x480

        # Note you can also read the property and compare against those values to see the current size:
        imageSize = self.vc0706.image_size
        if imageSize == adafruit_vc0706.IMAGE_SIZE_640x480:
            print('Using 640x480 size image.')
        elif imageSize == adafruit_vc0706.IMAGE_SIZE_320x240:
            print('Using 320x240 size image.')
        elif imageSize == adafruit_vc0706.IMAGE_SIZE_160x120:
            print('Using 160x120 size image.')
        print('Camera has been configured.')

        ## Ultrasonic sensor setup
        self.echoPin = gpiozero.DigitalInputDevice(Sensors.ULTRA_ECHO_PIN_NUM)
        self.trigPin = gpiozero.DigitalOutputDevice(Sensors.ULTRA_TRIG_PIN_NUM)

        self.trigPin.off()
        print('Ultrasonic sensor has been configured.')

        ## Humidity sensor setup
        self.humidSensor = Adafruit_DHT.DHT22
        self.humidPin = Sensors.HUMID_PIN_NUM
        print('Humidity sensor has been configured.')

        ## SPI setup
        # Sets up MCP3202 ADCs
        self.solarIrradADC = gpiozero.MCP3202(
            channel=0,
            differential=True,
            select_pin=Sensors.SOLAR_IRRAD_SEL_PIN_NUM)
        self.powerOutADC = gpiozero.MCP3202(
            channel=0,
            differential=True,
            select_pin=Sensors.POWER_OUT_SEL_PIN_NUM)
        self.surfTempADC0 = gpiozero.MCP3208(channel=0,
                                             differential=False,
                                             select_pin=13)
        self.surfTempADC1 = gpiozero.MCP3208(channel=1,
                                             differential=False,
                                             select_pin=13)
        self.surfTempADC2 = gpiozero.MCP3208(channel=2,
                                             differential=False,
                                             select_pin=13)
        self.surfTempADC3 = gpiozero.MCP3208(channel=3,
                                             differential=False,
                                             select_pin=13)
        self.surfTempADC4 = gpiozero.MCP3208(channel=4,
                                             differential=False,
                                             select_pin=13)
        self.surfTempADC5 = gpiozero.MCP3208(channel=5,
                                             differential=False,
                                             select_pin=13)
        print('SPI ADCs have been configured.')

        ######### Need code for MCP3208 ADCs

        ## Wait for the AQ sensor to be ready, then wait another few seconds for things to settle
        print('Waiting for sensors to be ready.')
        while not self.ccs811.data_ready:
            pass
        time.sleep(Sensors.INIT_WAIT_TIME)
        print('Sensors ready. Real time loop beginning.')
        print('------------------------------------------------\n')