Using the Custard pi 6 with I2C utilities

4,010 views

Published on

This PowerPoint presentation shows how to use the built in I2C process of the Raspberry Pi Linux Operating System to do the same thing.

Published in: Technology
2 Comments
1 Like
Statistics
Notes
No Downloads
Views
Total views
4,010
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
0
Comments
2
Likes
1
Embeds 0
No embeds

No notes for slide

Using the Custard pi 6 with I2C utilities

  1. 1. CUSTARD PI 6 & I2C USING THE RASPBERRY PI I2C UTILITIES 8 Relay card with ribbon connector and I2C bus interface 18th Nov 2013 SF Innovations
  2. 2. FUNCTIONS FOR CONTROLLING THE CUSTARD PI 6 RELAY CARD Original set of Instructions This PowerPoint presentation shows how to use the built in I2C process of the Raspberry Pi Linux Operating System to do the same thing. www.sf-innovations.co.uk In an earlier instruction we showed how to control the Custard Pi 6 8relay card using the functions provided in cpi6.py routine. This used “bit banging” to provide a basic I2C bus serial interface to address the Custard Pi 6 board and switch relays ON and OFF.
  3. 3. CUSTARD PI 6 - FEATURES www.sf-innovations.co.uk
  4. 4. CUSTARD PI 6 - ADDITIONAL DETAILS To Custard Pi 6 Notch to the right The 12V adaptor to supply the Custard Pi 6 is NOT supplied. This can easily be purchased on Amazon or EBay. Spec: 12V DC, 1 Amp www.sf-innovations.co.uk To Raspberry Pi Notch to the right
  5. 5. GPIO CONNECTIONS www.sf-innovations.co.uk Only 4 pins used 3.3V and 0V to power the I2C chip and driver & I2C SDA and SCL pins
  6. 6. USING THE CUSTARD PI 6 We supply a set of routines to make it very easy to control the Custard Pi 6. Just download the file “cpi6x.txt” and place this in the same directory as the program that you are developing. Rename it as “cpi6x.py”. Addressing the board You can use up to 8 different Custard Pi 6 boards to control a total of 64 relays. Use switch S1 to set the address of the card that you are using. Download cpi6 control cpi6x.txt www.sf-innovations.co.uk Then just use the following commands to control each individual relay on the card.
  7. 7. USING SWITCH S1 TO SET THE ADDRESS S1 pos 2 S1 pos 3 S1 pos 4 Address ON ON add0 OFF ON ON add1 ON OFF ON add2 OFF OFF ON add3 ON ON OFF add4 OFF ON OFF add5 ON OFF OFF add6 OFF OFF OFF add7 Position 1 is not used. www.sf-innovations.co.uk ON
  8. 8. SETTING UP THE I2C BUS – STEP 1 At the command prompt type: sudo nano /etc/modules Add the following two lines to this file i2c-bcm2708 i2c-dev Then save and exit the file using CTRL-x and Y. www.sf-innovations.co.uk This uses the nano editor to make some changes to the modules file.
  9. 9. SETTING UP THE I2C BUS – STEP 2 Make sure that you have the I2C utilities installed by executing the following two commands. The Pi will need to be connected to the Internet for this. If you get a 404 error do an update first: sudo apt-get update Note : The installation could take a few minutes to do, depend on how busy the server is. Now add a new user to the i2c group: sudo adduser pi i2c www.sf-innovations.co.uk sudo apt-get install python-smbus sudo apt-get install i2c-tools
  10. 10. SETTING UP THE I2C BUS – STEP 3 On the Raspberry Pi, the I2C and the SPI buses are usually disabled. This is done in the /etc/modprobe.d/raspi-blacklist.conf file. sudo nano /etc/modprobe.d/raspi-blacklist.conf If the I2C and the SPI is blacklisted, you will see the following commands. blacklist spi-bcm2708 blacklist i2c-bcm2708 Insert a # in front of these to comment them out. Then save and exit the file using CTRL-x and Y. After editing the file, you will need to reboot for the changes to take effect. www.sf-innovations.co.uk If this file is not present then there is nothing to be done. Otherwise edit the file by typing the following at the command prompt.
  11. 11. SETTING UP THE I2C BUS – STEP 4 Now we need to test if the I2C bus is working correctly. Connect up the Custard Pi 6 board (or any other I2C bus device) and run the following command. Or sudo i2cdetect -y 0 (for Rev 1 boards which uses port 0) If everything is OK, then the I2C address of the device will be shown as on the following slide. www.sf-innovations.co.uk sudo i2cdetect -y 1 (for Rev 2 boards which uses port 1)
  12. 12. SETTING UP THE I2C BUS – STEP 4 www.sf-innovations.co.uk I2C devices with address 40 and 70 present on the bus.
  13. 13. USING THE CUSTARD PI 6 First, set all the pins to be as outputs by using the following command. board1=cpi6x.add1 cpi6x.setasoutput(board1) cpi6x.setbit(board1, cpi6x.ONrelay0) The following command clears relay 0 on board 1 – ie turns it OFF cpi6x.clrbit(board1, cpi6x.OFFrelay0) www.sf-innovations.co.uk The following command sets relay 0 on board 1 – ie turns it ON
  14. 14. PYTHON PROGRAM This program sets relays 0,1&7 on board 1 ON and then turns them all OFF again. This is done continuously until the program is aborted by a CTRL C. When testing, please make sure that switch S1 is set correctly for add1. www.sf-innovations.co.uk #1/usr/bin/env python import RPi.GPIO as GPIO import time import cpi6x GPIO.setmode(GPIO.BOARD) #start program board1=cpi6x.add1 cpi6x.setasoutput(board1) while True: cpi6x.setbit(board1, cpi6x.ONrelay0) cpi6x.setbit(board1, cpi6x.ONrelay1) cpi6x.setbit(board1, cpi6x.ONrelay7) cpi6x.clrbit(board1, cpi6x.OFFrelay0) cpi6x.clrbit(board1, cpi6x.OFFrelay1) cpi6x.clrbit(board1, cpi6x.OFFrelay7) GPIO.cleanup() import sys sys.exit()
  15. 15. Blog dedicated to electronics & Raspberry Pi Custard Pi 5 available from stockists Up-to-date info on stockists on website www.sf-innovations.co.uk Further information

×