Exemplo n.º 1
0
  def __init__(self, clock, data, n, *, brightness=0.2, auto_write=True,
               pixel_order=BGR, baudrate=4000000, dev=2, spi=None):
    if spi == None:
      # Pins given, initialize SPI bus ...
      self._spi = None
      try:
        self._spi = busio.SPIBus(baudrate, clock, data, spidev=dev)
      except (NotImplementedError, ValueError, OSError):
        self.dpin = dio.DigitalOut(data)
        self.cpin = dio.DigitalOut(clock)
        self.cpin.value = False
    else:
      # SPI bus is already initialized
      self._spi = spi

    # Supply one extra clock cycle for each two pixels in the strip.
    self._n = n
    self.end_header_size = n // 16
    if n % 16 != 0:
      self.end_header_size += 1
    self._buf = bytearray(n * 4 + START_HEADER_SIZE + self.end_header_size)
    self.end_header_index = len(self._buf) - self.end_header_size
    self.pixel_order = pixel_order

    # Four empty bytes to start.
    for i in range(START_HEADER_SIZE):
      self._buf[i] = 0x00

    # Mark the beginnings of each pixel.
    for i in range(START_HEADER_SIZE, self.end_header_index, 4):
      self._buf[i] = 0xff

    # 0xff bytes at the end.
    for i in range(self.end_header_index, len(self._buf)):
      self._buf[i] = 0xff
    self._brightness = 1.0

    # Set auto_write to False temporarily so brightness setter does _not_
    # call show() while in __init__.
    self.auto_write = False
    self.brightness = brightness
    self.auto_write = auto_write

    t = "6x12 DotStar ({0})". format("software" if self._spi == None else "spi")
    print("[{0:>12}] {1:35} ({2}): ok".format(CHIP_NAME, t, __version__))
Exemplo n.º 2
0
    def __init__(self, mode, pinA_EN, pinA_PHASE, pinB_EN, pinB_PHASE):
        """ Initialises the pins that are connected to the H-bridges
    """
        # Initialize pins depending on mode
        # (Mode is set by jumper J1 on the Robotling board;
        #  w/ J1->Phase/Enable, w/o J1->IN/IN mode)
        self._mode = MODE_NONE
        self._speed = array.array('i', [0, 0])
        if mode == MODE_PH_EN:
            self.pinA_EN = dio.PWMOut(pinA_EN, freq=PWM_FRQ, duty=0)
            self.pinA_PH = dio.DigitalOut(pinA_PHASE)
            self.pinB_EN = dio.PWMOut(pinB_EN, freq=PWM_FRQ, duty=0)
            self.pinB_PH = dio.DigitalOut(pinB_PHASE)
            self._mode = MODE_PH_EN
        elif mode == MODE_IN_IN:
            print("IN/IN mode not implemented.")

        print("[{0:>12}] {1:35} ({2}): {3}".format(
            CHIP_NAME, "2-channel DC motor driver", __version__,
            "ok" if self._mode != MODE_NONE else "FAILED"))
Exemplo n.º 3
0
  def __init__(self, spi, pinCS):
    """ Requires already initialized SPIBus instance to access the 12-bit
        8 channel A/D converter IC (MCP3208). For performance reasons,
        not much validity checking is done.
    """
    self._spi   = spi
    self._cmd   = bytearray(b'\x00\x00\x00')
    self._buf   = bytearray(3)
    self._data  = array.array('i', [0]*CHAN_COUNT)
    self._pinCS = dio.DigitalOut(pinCS, value=True)
    self._channelMask = 0x00

    print("[{0:>12}] {1:35} ({2}): ok"
          .format(CHIP_NAME, "8-channel A/D converter", __version__))
Exemplo n.º 4
0
    def __init__(self, devices=[]):
        """ Additional onboard components can be listed in `devices` and, if known,
        will be initialized
    """
        print(
            "Robotling (board v{0:.2f}, software v{1}) w/ MicroPython {2} ({3})"
            .format(BOARD_VER / 100, __version__, platform.sysInfo[2],
                    platform.sysInfo[0]))

        print("Initializing ...")

        # Initialize some variables
        self._devices = devices
        self._ID = platform.GUID

        # Initialize on-board (feather) hardware
        self.onboardLED = dio.DigitalOut(rb.RED_LED, value=False)
        self._adc_battery = aio.AnalogIn(rb.ADC_BAT)

        # Initialize analog sensor driver
        self._SPI = busio.SPIBus(rb.SPI_FRQ, rb.SCK, rb.MOSI, rb.MISO)
        self._MCP3208 = mcp3208.MCP3208(self._SPI, rb.CS_ADC)

        # Initialize motor driver
        self._motorDriver = drv8835.DRV8835(drv8835.MODE_PH_EN, rb.A_ENAB,
                                            rb.A_PHASE, rb.B_ENAB, rb.B_PHASE)

        # Get I2C bus
        self._I2C = busio.I2CBus(rb.I2C_FRQ, rb.SCL, rb.SDA)

        self.Compass = None
        self._VL6180X = None
        self._DS = None

        # Initialize further devices depending on the selected onboard components
        # (e.g. which type of magnetometer/accelerometer/gyro, etc.)
        if "lsm303" in devices:
            # Magnetometer and accelerometer break-out, import drivers and
            # initialize lsm303 and respective compass instance
            import driver.lsm303 as lsm303
            from sensors.compass import Compass
            self._LSM303 = lsm303.LSM303(self._I2C)
            self.Compass = Compass(self._LSM303)

        if "compass_cmps12" in devices:
            # Very nice compass module with tilt-compensation built in
            from sensors.compass_cmps12 import Compass
            self.Compass = Compass(self._I2C)

        if "vl6180x" in devices:
            # Time-of-flight distance sensor
            from sensors.adafruit_tof_ranging import AdafruitVL6180XRangingSensor
            self._VL6180X = AdafruitVL6180XRangingSensor(i2c=self._I2C)

        if "dotstar_feather" in devices:
            # DotStar array is mounted
            from driver.dotstar import DotStar
            self._DS = DotStar(0, 0, 6 * 12, auto_write=False, spi=self._SPI)
            self._iDS = 0
            self._DS[0] = 0
            self._DS.show()

        # Initialize Neopixel (connector)
        self._NPx = NeoPixel(rb.NEOPIX, 1)
        self._NPx0_RGB = bytearray([0] * 3)
        self._NPx0_curr = array.array("i", [0, 0, 0])
        self._NPx0_step = array.array("i", [0, 0, 0])
        self.NeoPixelRGB = 0
        print("NeoPixel ready.")

        # Initialize spin function-related variables
        self._spin_period_ms = 0
        self._spin_t_last_ms = 0
        self._spin_callback = None
        self._spinTracker = TimeTracker()

        # Done
        print("... done.")