Пример #1
0
  def __init__(self, integration_time, gain):
    self.integration_time = integration_time

    # Get LED ready
    wiringpi2.wiringPiSetupGpio()
    wiringpi2.pinMode(PIN_LED, MODE_OUTPUT)

    # Get I2C ready
    self.I2C_fd = wiringpi2.wiringPiI2CSetup(TCS34725_ADDRESS)

    # Are we really connected?
    dev_id = self.read8(REG_ID)
    if (dev_id != 0x44) and (dev_id != 0x10):
      raise Exception("ColorSensor device is not connected")

    self.write8(REG_ATIME, integration_time)
    self.write8(REG_CONTROL, gain)

    self.power_up_mode()
    print("CS Connected")
Пример #2
0
def init():
    """   
       BSP initialize function. Must be called before any other BSP related
       functions.
    
    """
    global gI2cFd

    if wiringpi2.wiringPiSetup() < 0:
        print "bsp_init: failed to initialize wiringPi"
        return -1

    gI2cFd = wiringpi2.wiringPiI2CSetup(LM75A_I2C_ADDR)

    if gI2cFd < 0:
        print "bsp_init: failed to initialize I2C"
        return -1

    if wiringpi2.wiringPiSPISetup(0, 1000000) < 0:
        print "bsp_init: failed to initialize SPI"
        return -1

    return 0
Пример #3
0
def init():
    """   
       BSP initialize function. Must be called before any other BSP related
       functions.
    
    """
    global gI2cFd

    if wiringpi2.wiringPiSetup() < 0:
        print "bsp_init: failed to initialize wiringPi"
        return -1
        
    gI2cFd = wiringpi2.wiringPiI2CSetup(LM75A_I2C_ADDR)
    
    if gI2cFd < 0:
        print "bsp_init: failed to initialize I2C"
        return -1
    
    if wiringpi2.wiringPiSPISetup(0, 1000000) < 0:
        print "bsp_init: failed to initialize SPI"
        return -1
    
    return 0
Пример #4
0
def turnRight():
    setMotors(150, -150)
    time.sleep(0.1)
    stop()
    time.sleep(0.1)


LeftTrack = 0
RightTrack = 0

# Configure wiring pi
wiringpi.wiringPiSetupPhys()
io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_GPIO)

# Open the i2C connection
i2cConnect = wiringpi.wiringPiI2CSetup(I2CAddress)
i2cFD = os.fdopen(i2cConnect, "rw", 0)

# Configure the GPIO
io.pinMode(SR04Trigger, io.OUTPUT)
io.pinMode(SR04Echo, io.INPUT)

io.digitalWrite(SR04Trigger, False)


def getDistance():
    start = 0
    stop = 0

    # Trigger the sensor
    io.digitalWrite(SR04Trigger, True)
Пример #5
0
    """ Clear the display
    """
    self.lines = [
      [ " " ] * 16,
      [ " " ] * 16
      ]
    self._update()

#----------------------------------------------------------------------------
# Main program
#----------------------------------------------------------------------------

if __name__ == "__main__":
  # Set up WiringPi and connect to the IO expander
  wiringpi2.wiringPiSetupPhys()
  dev = wiringpi2.wiringPiI2CSetup(0x20)
  if dev < 0:
    print "ERROR: Could not connect to device!"
    exit(1)
  # Now create the LCD interface
  lcd = i2cLCD(dev)
  lcd.setup()
  lcd.gotoXY(0, 0)
  lcd.write("clixx.io I2C-LCD")
  lcd.gotoXY(7, 1)
  lcd.write("It works!")
  sleep(3)
  lcd.gotoXY(0, 1)
  lcd.write(" " * 16)
  padding = ""
  while True:
Пример #6
0
def SHT20_Init():
    _i2c = wpi.wiringPiI2CSetup(0x40)
    return _i2c
Пример #7
0
import wiringpi2 as wpy
from time import sleep
from sys import getsizeof,stdin
from tty import setcbreak

from pprint import pprint
#init i2c with slave 0x03
wpy.wiringPiI2CSetup(3)

packet = bytearray(5)

packet[1]=5
packet[2]=0xf3
packet[3]=0xf2
packet[4]=0x02

pprint(packet[1:])
pprint(len(packet))

def send_packet(data):
	data[0] = 0
	i=0
	while i < len(data):
		pprint("loop: "+str(i)+" data "+str(data[i]))
		wpy.wiringPiI2CWrite(3,data[i])
		i+=1
#send_packet(11)

setcbreak(stdin)
while True:
	value = stdin.read(3)
Пример #8
0
def init():
	fd = wp.wiringPiI2CSetup(0x38)
	type = False

	if(fd==3):
		print "I2C device initialized \n"
	wp.delay(110)

	writeByte = 0x30 # 1100 0000

	LCD8bit(writeByte, type, fd)
	wp.delay(5)  

	LCD8bit(writeByte, type, fd) 
	wp.delayMicroseconds(110)

	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(50)

	writeByte = 0x20 #0100 0000

	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(50)
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(50)

	writeByte = 0x80                # sets up device to 2 lines5x7 pixel chars, 1/8 duty cycle
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)
	#============================= can switch to 4 bit
	writeByte = 0x00          # display on, cursor on (blink)
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0xF0
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0x10
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)
	writeByte = 0x40
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0x00          # display on, cursor on (blink)
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0x10
	LCD8bit(writeByte, type, fd)
	wp.delay(5)

	writeByte = 0x40
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)  

	writeByte = 0x10
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0x00          # display on, cursor on (blink)
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0x10
	LCD8bit(writeByte, type, fd)
	wp.delay(5)
		
	return fd
Пример #9
0
# Get a handle on the joystick
j = pygame.joystick.Joystick(0)
j.init()

print 'Initialized Joystick : %s' % j.get_name()

LeftTrack = 0
RightTrack = 0
PowerLimiter = POWER_LIMITER_DEFAULT
ServoPosition = 2500

# Configure wiring pi  
wiringpi.wiringPiSetupPhys()

# Open the i2C connection 
i2cConnect = wiringpi.wiringPiI2CSetup(I2CAddress)
i2cFD = os.fdopen(i2cConnect, "rw", 0)

try:
    # Only allow axis and button events
    pygame.event.set_allowed([pygame.JOYAXISMOTION, pygame.JOYBUTTONDOWN])

    # Make sure the motors are stopped
    stop()

    # Set the default servo position
    setServo(ServoPosition);
    
    # Read in current status
    outputStatus()
    
Пример #10
0
def SHT20_Init():
    _i2c = wpi.wiringPiI2CSetup(0x40)
    return _i2c