SlideShare una empresa de Scribd logo
1 de 15
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
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.
CUSTARD PI 6 - FEATURES

www.sf-innovations.co.uk
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
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
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.
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
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.
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
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.
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)
SETTING UP THE I2C BUS – STEP 4

www.sf-innovations.co.uk

I2C devices with address 40 and 70 present on the bus.
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
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()
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

Más contenido relacionado

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Destacado

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Using the Custard pi 6 with I2C utilities

  • 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. 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. CUSTARD PI 6 - FEATURES www.sf-innovations.co.uk
  • 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. 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. 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. 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. 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. 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. 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. 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. SETTING UP THE I2C BUS – STEP 4 www.sf-innovations.co.uk I2C devices with address 40 and 70 present on the bus.
  • 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. 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. 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