def configure_devices(self, debug=False): """ Configures i2c devices when running in appropriate environment. """ # only configure devices for Linux if not(platform.system() == "Linux"): logging.info("CFG:\tNot running on Linux distro. Not configuring i2c or other devices.") self.set_dummy_devices() return # although i2c may work if in correct user group, GPIO needs confirming. # for now, clearer just to object if not running as root (sudo) #if not(os.getuid() == 0): # logging.info("Not running on as root. Not configuring i2c or other devices.") # self.set_dummy_devices() # return # running as root on linux so can scan for devices and configure them # although inline imports normally not encouraged # enables me to load dependencies only when I know I can (eg linux, i2c, root, etc...) import raspberrypi # i2c devices try: logging.info("CFG:\tConfiguring i2c devices...") # scan for connected devices i2c_addresses = self.scan_i2c(debug=debug) # lookup available device drivers by address for addr, in_use in i2c_addresses: device_name, device_driver = self.lookup(addr, debug=debug) self._devices.append([addr, device_name, device_driver, in_use]) except Exception as ex: logging.exception("CFG:\tError scanning i2c devices - %s" % ex) # if no GPS (eg i2c) set up, then import a serial one. Should check for device present first. if not(self.gps_sensor): try: from sensor.GPS_serial import GPS_AdafruitSensor self.gps_sensor = GPS_AdafruitSensor(serial_bus=raspberrypi.serial_bus(), debug=debug) except Exception as ex: logging.warning("CFG:\tError setting up GPS over serial - %s" % ex) # CameraController (over USB) # TODO: look at different controller, eg m-jpeg stream over local connection, start script from here try: from sensor.camera import CameraController self.camera_controller = CameraController(self, debug=debug) except Exception as ex: logging.info("CFG:\tCamera support unavailable - %s" % ex) self.camera_controller = DummyCameraController(self.resources_folder()) # any remaining dummy devices if not(self.drive_controller): self.drive_controller = DummyDriveController()
def configure_devices(self, debug=False): """ Configures i2c devices when running in appropriate environment. """ # only configure devices for Linux if not (platform.system() == "Linux"): logging.info( "CFG:\tNot running on Linux distro. Not configuring i2c or other devices." ) self.set_dummy_devices() return # although i2c may work if in correct user group, GPIO needs confirming. # for now, clearer just to object if not running as root (sudo) #if not(os.getuid() == 0): # logging.info("Not running on as root. Not configuring i2c or other devices.") # self.set_dummy_devices() # return # running as root on linux so can scan for devices and configure them # although inline imports normally not encouraged # enables me to load dependencies only when I know I can (eg linux, i2c, root, etc...) import raspberrypi # i2c devices try: logging.info("CFG:\tConfiguring i2c devices...") # scan for connected devices i2c_addresses = self.scan_i2c(debug=debug) # lookup available device drivers by address for addr, in_use in i2c_addresses: device_name, device_driver = self.lookup(addr, debug=debug) self._devices.append( [addr, device_name, device_driver, in_use]) except Exception as ex: logging.exception("CFG:\tError scanning i2c devices - %s" % ex) # if no GPS (eg i2c) set up, then import a serial one. Should check for device present first. if not (self.gps_sensor): try: from sensor.GPS_serial import GPS_AdafruitSensor self.gps_sensor = GPS_AdafruitSensor( serial_bus=raspberrypi.serial_bus(), debug=debug) except Exception as ex: logging.warning("CFG:\tError setting up GPS over serial - %s" % ex) # CameraController (over USB) # TODO: look at different controller, eg m-jpeg stream over local connection, start script from here try: from sensor.camera import CameraController self.camera_controller = CameraController(self, debug=debug) except Exception as ex: logging.info("CFG:\tCamera support unavailable - %s" % ex) self.camera_controller = DummyCameraController( self.resources_folder()) # any remaining dummy devices if not (self.drive_controller): self.drive_controller = DummyDriveController()
# FishPi - An autonomous drop in the ocean # # Simple test of GPS sensor # import raspberrypi from time import sleep from GPS_serial import GPS_AdafruitSensor if __name__ == "__main__": print "Testing GPS sensor (running 5x with 5s pause)..." print "Initialising..." gps_sensor = GPS_AdafruitSensor(debug=True, serial_bus='/dev/ttyUSB0') print raspberrypi.serial_bus() # heading print "Reading 1..." (fix, lat, lon, heading, speed, altitude, num_sat, timestamp, datestamp) = gps_sensor.read_sensor() print fix, lat, lon, heading, speed, altitude, num_sat, timestamp, datestamp sleep(5) print "Reading 2..." (fix, lat, lon, heading, speed, altitude, num_sat, timestamp, datestamp) = gps_sensor.read_sensor() print fix, lat, lon, heading, speed, altitude, num_sat, timestamp, datestamp sleep(5) print "Reading 3..." (fix, lat, lon, heading, speed, altitude, num_sat, timestamp, datestamp) = gps_sensor.read_sensor() print fix, lat, lon, heading, speed, altitude, num_sat, timestamp, datestamp
# FishPi - An autonomous drop in the ocean # # Simple test of GPS sensor # import raspberrypi from time import sleep from GPS_serial import GPS_AdafruitSensor if __name__ == "__main__": print "Testing GPS sensor (running 5x with 5s pause)..." print "Initialising..." gps_sensor = GPS_AdafruitSensor(debug=True, interface='/dev/ttyUSB0') print raspberrypi.serial_bus() # heading print "Reading 1..." (fix, lat, lon, heading, speed, altitude, num_sat, timestamp, datestamp) = gps_sensor.read_sensor() print fix, lat, lon, heading, speed, altitude, num_sat, timestamp, datestamp sleep(5) print "Reading 2..." (fix, lat, lon, heading, speed, altitude, num_sat, timestamp, datestamp) = gps_sensor.read_sensor() print fix, lat, lon, heading, speed, altitude, num_sat, timestamp, datestamp sleep(5) print "Reading 3..."