Esempio n. 1
0
 def setup(self):
   """ Set up the connection to the device
   """
   # Set up the IO expander
   wiringpi2.wiringPiI2CWriteReg8(self.device, self.GPIO,  0x00) # Clear outputs
   wiringpi2.wiringPiI2CWriteReg8(self.device, self.IODIR, 0x00) # Direction
   wiringpi2.wiringPiI2CWriteReg8(self.device, self.GPPU,  0x00) # Pull ups
   wiringpi2.wiringPiI2CWriteReg8(self.device, self.IPOL,  0x00) # Polarity
   # Initialise the display in 4 bit mode
   self._writeLCD(0x33, True)
   self._writeLCD(0x32, True)
   self._writeLCD(0x28, True)
   # Set up initial state
   self._writeLCD(0x0C, True)
   self._writeLCD(0x06, True)
   self._writeLCD(0x01, True)
Esempio n. 2
0
def LCD8bit(writeByte, type, fd):	
	writeByte = writeByte>>4#clear the lower nibble since it isn't used
	writeByte = writeByte<<4
	if(type):
		value = 4 #set bit 2
		writeByte = writeByte|value# set CD to 1 for data (bit2)

	  #=====================================================write
	wp.wiringPiI2CWriteReg8(fd, reg, writeByte)

	wp.delayMicroseconds(10)

	value = 8
	writeByte = writeByte|value #pulse enable pin (bit3)
	wp.wiringPiI2CWriteReg8(fd, reg, writeByte)

	wp.delayMicroseconds(10)

	writeByte = writeByte^value#clear enable pin	
	wp.wiringPiI2CWriteReg8(fd, reg, writeByte)

	wp.delayMicroseconds(10)
	return
#!/usr/bin/python

import time
import wiringpi2 as wpi

i2c_dev = "/dev/i2c-1"
i2c_addr = 0x62

wpi.wiringPiSetup()
i2c_fd = wpi.wiringPiI2CSetupInterface(i2c_dev, i2c_addr)

writeResult = wpi.wiringPiI2CWriteReg8(i2c_fd, 0x1e, 0x00)
print("write result: " + str(writeResult))

reg_addr = 0x00

while (reg_addr <= 101):
    #print("testing address: " + str(reg_addr))
    if (reg_addr != 30):
        output = wpi.wiringPiI2CReadReg8(i2c_fd, (reg_addr))
        print(hex(reg_addr) + ":" + "{0:b}".format(output))
        #print("\n")
        time.sleep(0.01)
    reg_addr += 1

#print("before: " + str(i2c_fd))

#wpi.wiringPiI2CRead(i2c_fd)

#wpi.wiringPiI2CWriteReg8(i2c_fd, 0x00, 0x00)
Esempio n. 4
0
 def _writeLCD(self, value, cmd = False):
   """ Write command or data to the LCD
   """
   # Make Sure "EN" is 0 or low
   wiringpi2.wiringPiI2CWriteReg8(self.device, self.GPIO, 0x00)
   # Set "R/S" to 0 for a command, or 1 for data/characters
   out = 0x00
   if not cmd:
     out = out | self.LCD_COMMAND
   wiringpi2.wiringPiI2CWriteReg8(self.device, self.GPIO, out)
   # Put the HIGH BYTE of the data/command on D7-4
   out = out | ((value >> 4) & self.LCD_DATA)
   wiringpi2.wiringPiI2CWriteReg8(self.device, self.GPIO, out)
   # Set "EN" (EN= 1 or High)
   out = out | self.LCD_ENABLE
   wiringpi2.wiringPiI2CWriteReg8(self.device, self.GPIO, out)
   # Wait At Least 450 ns!!!
   sleep(self.PULSE)
   # Clear "EN" (EN= 0 or Low)
   out = out & ~self.LCD_ENABLE
   wiringpi2.wiringPiI2CWriteReg8(self.device, self.GPIO, out)
   # Wait 5ms for command writes, and 200us for data writes.
   sleep(self.DELAY)
   # Put the LOW BYTE of the data/command on D7-4
   out = (out & ~self.LCD_DATA) | (value & self.LCD_DATA)
   wiringpi2.wiringPiI2CWriteReg8(self.device, self.GPIO, out)
   # Set "EN" (EN= 1 or High)
   out = out | self.LCD_ENABLE
   wiringpi2.wiringPiI2CWriteReg8(self.device, self.GPIO, out)
   # Wait At Least 450 ns!!!
   sleep(self.PULSE)
   # Clear "EN" (EN= 0 or Low)
   out = out & ~self.LCD_ENABLE
   wiringpi2.wiringPiI2CWriteReg8(self.device, self.GPIO, out)
   # Wait 5ms for command writes, and 200us for data writes.
   sleep(self.DELAY)
Esempio n. 5
0
 def write8(self, register, write_val):
   reg = register | TCS34725_COMMAND_BIT
   retval = wiringpi2.wiringPiI2CWriteReg8(self.I2C_fd, reg, write_val)
   if retval < 0:
     raise Exception("write8 error")
Esempio n. 6
0
def write(writeByte, type, fd):

	#===============================extract upper nibble
	value = writeByte
	#clear the lower nibble
	value = value>>4
	value = value<<4
	#place in register
	upperNibble = value
	#==================================extract lower nibble
	value = writeByte
	#move the lower nibble to the upper nibble
	value = value<<4
	#place in register
	lowerNibble = value


	if(type):
		value = 4 #set bit 2
		upperNibble = upperNibble|value# set CD to 1 for data (bit2)
		lowerNibble = lowerNibble|value
	#else CD is 0 for a command



	#=====================================================write upperNibble
	wp.wiringPiI2CWriteReg8(fd, reg, upperNibble)

	wp.delayMicroseconds(10)

	value = 8
	upperNibble = upperNibble|value #pulse enable pin (bit3)
	wp.wiringPiI2CWriteReg8(fd, reg, upperNibble)

	wp.delayMicroseconds(10)

	upperNibble = upperNibble^value#clear enable pin

	wp.wiringPiI2CWriteReg8(fd, reg, upperNibble)

	wp.delayMicroseconds(10)
	#=====================================================write lowerNibble
	wp.wiringPiI2CWriteReg8(fd, reg, lowerNibble)

	wp.delayMicroseconds(10)

	value = 8
	lowerNibble = lowerNibble|value #pulse enable pin (bit3)
	wp.wiringPiI2CWriteReg8(fd, reg, lowerNibble)

	wp.delayMicroseconds(10)

	lowerNibble = lowerNibble^value#clear enable pin	
	wp.wiringPiI2CWriteReg8(fd, reg, lowerNibble)

	wp.delayMicroseconds(10)

	return