Today I connected up a my prototype board for an I2C experiment with the pcDuino. Blinky Lights!
YouTube video of simple I2C parallel port test using Python.
Using I2C
If you want to try interfacing with the pcDuino I2C yourself, you will need to install the software for using the I2C bus:
1 2 |
sudo apt-get install i2c-tools sudo apt-get install python-smbus |
i2c-tools provides command line applications for checking and accessing i2c bus devices.
i2cdetect – scans an I2C bus for devices
i2cget – reads registers visible through the I2C bus
i2cset – writes registers visible through the I2C bus
python-smbus provides Python access to I2C (SMBus) devices.
Connecting PCF8574
Connect a PCF8574 I2C parallel port chip to the pcDuino I2C bus. For feedback, connect each of the outputs through resistors to LEDs. Be sure to connect power to 3.3 Vdc and GND. I connected the address select pins to ground (address 0x20). I can post a detailed wiring diagram if anyone is interested.
To verify your connections, use i2cdetect from the command line. It should show a single device at address 0x20 on bus 2 (the I2C bus available on the GPIO connectors).
1 2 3 4 5 6 7 8 9 10 |
i2cdetect -y 2 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- |
Python
Python source code for testing the I2C bus will cycle the LEDs as shown in the video.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
#! /usr/bin/env python ####################################################################### # Simple I2C parallel port demostration Python class # Originally developed for the pcDuino platform # # This class file may be included in other application to provide # simple read and write support for i2c attached 8574 i2c parallel # port. # # The connection will default to I2C Bus 2 - the default external I2C # bus on the pcDuino. The default parallel port address is 0x20 - the # first standard address for the 8574. # # If this file is executed, it will run a pattern demo output on the # parallel port. Best viewed by having LEDs connected to the outputs. # # Enjoy! # Bill ####################################################################### # Copyright (c) 2013 by William Greathouse, Brecksville, OH, USA # # Permission is granted to use the source code within this # file in whole or in part for any use, personal or commercial, # without restriction or limitation. # # No warranties, either explicit or implied, are made as to the # suitability of this code for any purpose. Use at your own risk. ####################################################################### import sys import smbus import time I2CBUS=2 PARADR=0x20 DELAY=0.05 class I2Cparallel: # initialize the i2c connection to the parallel port def __init__(self, adr=PARADR, bus=I2CBUS): self.bus=bus self.adr=adr self.i2c=smbus.SMBus() self.i2c.open(self.bus) # Set all outputs to high state (state required for input) # If this fails, chip is not responding on i2c bus try: self.i2c.write_byte(self.adr, 0xff) except: print "Unable to access parallel port on bus %d, addresss 0x%02x" % (self.bus, self.adr) sys.exit(1) # output value to parallel port def out_byte(self,value): self.i2c.write_byte(self.adr, value) # input value from parallel port def in_byte(self): return self.i2c.read_byte(self.adr) if __name__=="__main__": # initialize the interface, passing just the address as an example parport=I2Cparallel(PARADR) # flash all output lines for _ in range(10): parport.out_byte(0x00) time.sleep(DELAY) parport.out_byte(0xff) time.sleep(DELAY) # Do a scanning display, single bit on for _ in range(10): for i in range(8): parport.out_byte(1<<i) time.sleep(delay)="" for="" i="" in="" range(8):="" parport.out_byte(0x80="">>i) time.sleep(DELAY) # Do a scanning display, single bit off for _ in range(10): for i in range(8): parport.out_byte(~(1<<i)) time.sleep(delay)="" for="" i="" in="" range(8):="" parport.out_byte(~(0x80="">>i)) time.sleep(DELAY) # Set all outputs to high state (state required for input) parport.out_byte(0xff) |
Hi,
Thanks a lot for your excellent test.
I’m really interested in the detailed wiring diagram if possible.
@dariush I will add a simple schematic and wiring diagram this evening as a reference.
Enjoy!
Bill
@Bill
Thanks a lot.
I’m really grateful.
Did you add the schematic?
Hello Bill
Great Job. Did you moved the schematic of the circuit? Or how can I get that? Can you please kindly share again?
Jovanov