# Remote Control - As The Controller Device # # This script configures your OpenMV Cam to remotely control another OpenMV Cam using the RPC # library. This script can be run by any micropython board implementing the pyb module to # remotely control an OpenMV Cam. # # This script is designed to pair with "popular_features_as_the_remote_device.py". import json, rpc, struct # The RPC library above is installed on your OpenMV Cam and provides mutliple classes for # allowing your OpenMV Cam to control over CAN, I2C, SPI, or UART. ############################################################## # Choose the interface you wish to control an OpenMV Cam over. ############################################################## # Uncomment the below line to setup your OpenMV Cam for controlling over CAN. # # * message_id - CAN message to use for data transport on the can bus (11-bit). # * bit_rate - CAN bit rate. # * sampling_point - Tseg1/Tseg2 ratio. Typically 75%. (50.0, 62.5, 75, 87.5, etc.) # # NOTE: Master and slave message ids and can bit rates must match. Connect master can high to slave # can high and master can low to slave can lo. The can bus must be terminated with 120 ohms. # # interface = rpc.rpc_can_master(message_id=0x7FF, bit_rate=250000, sampling_point=75) # Uncomment the below line to setup your OpenMV Cam for controlling over I2C. # # * slave_addr - I2C address. # * rate - I2C Bus Clock Frequency. # # NOTE: Master and slave addresses must match. Connect master scl to slave scl and master sda # to slave sda. You must use external pull ups. Finally, both devices must share a ground. # # interface = rpc.rpc_i2c_master(slave_addr=0x12, rate=100000) # Uncomment the below line to setup your OpenMV Cam for controlling over SPI. # # * cs_pin - Slave Select Pin. # * freq - SPI Bus Clock Frequency. # * clk_polarity - Idle clock level (0 or 1). # * clk_phase - Sample data on the first (0) or second edge (1) of the clock. # # NOTE: Master and slave settings much match. Connect CS, SCLK, MOSI, MISO to CS, SCLK, MOSI, MISO. # Finally, both devices must share a common ground. # # interface = rpc.rpc_spi_master(cs_pin="P3", freq=10000000, clk_polarity=1, clk_phase=0) # Uncomment the below line to setup your OpenMV Cam for controlling over UART. # # * baudrate - Serial Baudrate. # # NOTE: Master and slave baud rates must match. Connect master tx to slave rx and master rx to # slave tx. Finally, both devices must share a common ground. # interface = rpc.rpc_uart_master(baudrate=115200) ############################################################## # Call Back Handlers ############################################################## def exe_face_detection(): result = interface.call("face_detection") if result is not None and len(result): print("Largest Face Detected [x=%d, y=%d, w=%d, h=%d]" % struct.unpack("