SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Kürzlich hochgeladen

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
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, Adobeapidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
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 WoodJuan lago vázquez
 
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...DianaGray10
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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
 
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...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

Empfohlen

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 HubspotMarius Sescu
 
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 ChatGPTExpeed Software
 
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 EngineeringsPixeldarts
 
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 HealthThinkNow
 
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.pdfmarketingartwork
 
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 2024Neil Kimberley
 
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)contently
 
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 2024Albert Qian
 
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 InsightsKurio // The Social Media Age(ncy)
 
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 2024Search Engine Journal
 
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 summarySpeakerHub
 
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 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 Tessa Mero
 
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 IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
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 managementMindGenius
 
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...RachelPearson36
 

Empfohlen (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