KS0213 Keyestudio RPI GPIO-PCF8591 Shield: Difference between revisions

From Keyestudio Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
==keyestudio RPI GPIO-PCF8591 Shield==
<br>[[File:ks0213-1.png|500px|frameless|thumb]]<br>


<br>
==Introduction==
==Introduction==
There's no AD/DA function on the Raspberry Pi GPIO interface, this may trouble you in the Pi development. However, it won't be a problem anymore. The RPI GPIO-PCF8591 Shield allows you to add high-precision AD/DA functions to the Raspberry Pi.<br>
There's no AD/DA function on the Raspberry Pi GPIO interface, this may trouble you in the Pi development. However, it won't be a problem anymore. The RPI GPIO-PCF8591 Shield allows you to add high-precision AD/DA functions to the Raspberry Pi.<br>
The PCF8591 features four-8-bit analog to digital converters and a single 8-bit digital to analog converter.This will operate through the I2C interface on the Raspberry Pi.<br>
The PCF8591 features four-8-bit analog to digital converters and a single 8-bit digital to analog converter. This will operate through the I2C interface on the Raspberry Pi.<br>
<br>[[File:ks0213-1.png|500px|frameless|thumb]]<br>


<br>
==Connection Diagram ==
==Connection Diagram ==
Plug it directly into Raspberry Pi to start your works as shown in below figure.  
Plug it directly into Raspberry Pi to start your works as shown in below figure. <br>
<br>[[File:ks0213-2.png|500px|frameless|thumb]]<br>
<br>[[File:ks0213-2.png|500px|frameless|thumb]]<br>


<br>
==Sample Code==
==Sample Code==
<pre>
<pre>
Line 64: Line 67:
</pre>
</pre>


 
<br>
==Program Writing==
==Program Writing==
<br>
===1.Install Wiringpi Library===
===1.Install Wiringpi Library===
Wiring Pi is a library. WiringPi supports analog reading and writing, and while there is no native analog hardware on a Pi by default, modules are provided so other A/D and D/A devices can be implemented relatively easily. We will provide a Wiringpi installation package or click on this  
Wiring Pi is a library. WiringPi supports analog reading and writing, and while there is no native analog hardware on a Pi by default, modules are provided so other A/D and D/A devices can be implemented relatively easily. <br>
URL: https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/ (it should open in a new page) to download the latest version. This will download a .tar file with a name like wiringPi-b0a60c3.tar. Then copy the file and put it into the raspberry pi file as shown in below figure:
We will provide a Wiringpi installation package or click on this URL: https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/ <br>
(it should open in a new page) to download the latest version. This will download a .tar file with a name like wiringPi-b0a60c3.tar. Then copy the file and put it into the raspberry pi file as shown in below figure:<br>
<br>[[File:ks0213-3.png|500px|frameless|thumb]]<br>
<br>[[File:ks0213-3.png|500px|frameless|thumb]]<br>
 
<br>
Type in this command to unzip the source code and install:<br>
Type in this command to unzip the source code and install:<br>
tar xfz wiringPi-98bcb20.tar.gz<br>
* '''tar xfz wiringPi-98bcb20.tar.gz'''  <br>
cd wiringPi-98bcb20<br>
* '''cd wiringPi-98bcb20'''  <br>
./build<br>
* '''./build'''  <br>
Note that the actual file name will be different (may not be 98bcb20) – you will have to check the name and adjust accordingly. Here is the interface after installing WiringPi as shown in below figure.<br>
<span style=color;red> Note that the actual file name will be different (may not be 98bcb20) – you will have to check the name and adjust accordingly. <br>
Here is the interface after installing WiringPi as shown in below figure.<br>
<br>[[File:ks0213-4.png|500px|frameless|thumb]]<br>
<br>[[File:ks0213-4.png|500px|frameless|thumb]]<br>
 
<br>
WirtingPi includes a set of gpio commands to control the GPIO pins of the Raspberry Pi. Type in the command to check the installation:
WirtingPi includes a set of gpio commands to control the GPIO pins of the Raspberry Pi. Type in the command to check the installation:<br>
gpio -v<br>
* '''gpio -v''' <br>
gpio readall<br>
* '''gpio readall''' <br>
The interface as shown in below figure means complete installation.
The interface as shown in below figure means complete installation.<br>
<br>[[File:ks0213-5.png|500px|frameless|thumb]]<br>
<br>[[File:ks0213-5.png|500px|frameless|thumb]]<br>


<br>
===2.Enable I2C Utility===
===2.Enable I2C Utility===
The I2C bus allows multiple devices to be connected to your Raspberry Pi. Before using I2C it needs to be configured. Run this command: sudo raspi-config and follow the prompts to install I2C. Now complete the following steps :<br>
The I2C bus allows multiple devices to be connected to your Raspberry Pi. Before using I2C it needs to be configured. <br>
Select “9 Advanced Options”<br>
Run this command: '''sudo raspi-config''' and follow the prompts to install I2C. Now complete the following steps: <br>
Select “A6 I2C”<br>
* Select “9 Advanced Options” <br>
* Select “A6 I2C” <br>
The screen will ask if you want the ARM I2C interface to be enabled :<br>
The screen will ask if you want the ARM I2C interface to be enabled :<br>
Select “Yes”<br>
* Select “Yes” <br>
Select “Ok”<br>
* Select “Ok” <br>
Select “Finish” to return to the command line<br>
* Select “Finish” to return to the command line <br>
When you next reboot the I2C module will be loaded.<br>
When you next reboot the I2C module will be loaded.<br>


<br>
===3.Programming===
===3.Programming===
Copy the file pcf8591 provided by us and put it into your pi directory through winSCP. Next , type this command: cd pcf8591 to go inside the pcf8591 folder. Then type this command: make to make an executable file. This means this is the file we run to launch the program.  <br>
Copy the file pcf8591 provided by us and put it into your pi directory through winSCP.  
Finally type this: sudo ./TTP229 to launch the program. <br>
Next, type this command: '''cd pcf8591''' to go inside the pcf8591 folder. Then type this command: '''make''' to make an executable file. This means this is the file we run to launch the program.  <br>
Finally type this: '''sudo ./TTP229''' to launch the program. <br>


<br>
==Result==
==Result==
DA source code makes AOUT interface output 0-5V voltage; the pi will prints digital value among 0-255 on the terminal after reading out voltage set by AD source code.
DA source code makes AOUT interface output 0-5V voltage; the pi will prints digital value among 0-255 on the terminal after reading out voltage set by AD source code.


<br>
==Documents ==
==Documents ==


'''PDF File:'''
* '''PDF File:''' <br>
 
https://drive.google.com/open?id=1KGHWkoRwcH26PSLvVD6jLZxRa5-qIp-r
https://drive.google.com/open?id=1KGHWkoRwcH26PSLvVD6jLZxRa5-qIp-r


'''Installation Package Download:'''
* '''Installation Package Download:'''<br>
 
https://drive.google.com/open?id=18pp8aNUe05B6EzyphTb9JLnE6gQaBOL6
https://drive.google.com/open?id=18pp8aNUe05B6EzyphTb9JLnE6gQaBOL6


''' Source Code Download :'''
* ''' Source Code Download:'''<br>
https://drive.google.com/open?id=1bwUSsxDyB-st2qaLyK2phvpbelvUph9S


https://drive.google.com/open?id=1bwUSsxDyB-st2qaLyK2phvpbelvUph9S


<br>
== Buy From ==
== Buy From ==
http://www.keyestudio.com/keyestudio-rpi-gpio-pcf8591-shield.html
*[https://www.keyestudio.com/keyestudio-rpi-gpio-shield-with-pcf8591-ad-da-for-raspberry-pi-ce-certification-p0474-p0474.html    '''Official website''' ]
 
*[https://www.aliexpress.com/store/product/Keyestudio-RPI-GPIO-shield-with-PCF8591-AD-DA-for-Raspberry-Pi/1452162_32780174618.html?spm=2114.12010612.8148356.5.6e9660ffsewRl7  '''Aliexpress store''' ]




[[Category:Raspberry Pi]]
[[Category:Raspberry Pi]]

Revision as of 14:24, 17 April 2019



Introduction

There's no AD/DA function on the Raspberry Pi GPIO interface, this may trouble you in the Pi development. However, it won't be a problem anymore. The RPI GPIO-PCF8591 Shield allows you to add high-precision AD/DA functions to the Raspberry Pi.
The PCF8591 features four-8-bit analog to digital converters and a single 8-bit digital to analog converter. This will operate through the I2C interface on the Raspberry Pi.

thumb


Connection Diagram

Plug it directly into Raspberry Pi to start your works as shown in below figure.

thumb


Sample Code

DA(Digital to Analog) Source Code:
#include <wiringPi.h>
#include <pcf8591.h>
#include <stdio.h>

#define Address 0x48
#define BASE 64          //DA Output
#define A0 BASE+0
#define A1 BASE+1
#define A2 BASE+2
#define A3 BASE+3

int main(void)
{
    unsigned char value;
	wiringPiSetup();
	pcf8591Setup(BASE,Address);    //configuration pcf8591	

	while(1)
	{		
               analogWrite(BASE,value);      //write the value output on AOUT interface
               printf("AOUT:%d\n",value);     //print that value
               delay(50);	
	}
}

AD(Analog to Digital) Source Code:
#include <wiringPi.h>
#include <pcf8591.h>
#include <stdio.h>

#define Address 0x48         //pcf8591 address 
#define BASE 64
#define A0 BASE+0           //A0 input
#define A1 BASE+1           //A1 input
#define A2 BASE+2           //A2 input
#define A3 BASE+3           //A3 input
int main(void)
{
    unsigned char value;
	wiringPiSetup();
	pcf8591Setup(BASE,Address);        //configurationpcf8591
	
	while(1)
	{
               value=analogRead(A0);     // read A0 value          
               printf("A0:%d\n",value);  // print A0 value
               delay(100);	
	}
}


Program Writing


1.Install Wiringpi Library

Wiring Pi is a library. WiringPi supports analog reading and writing, and while there is no native analog hardware on a Pi by default, modules are provided so other A/D and D/A devices can be implemented relatively easily.
We will provide a Wiringpi installation package or click on this URL: https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/
(it should open in a new page) to download the latest version. This will download a .tar file with a name like wiringPi-b0a60c3.tar. Then copy the file and put it into the raspberry pi file as shown in below figure:

thumb

Type in this command to unzip the source code and install:

  • tar xfz wiringPi-98bcb20.tar.gz
  • cd wiringPi-98bcb20
  • ./build

Note that the actual file name will be different (may not be 98bcb20) – you will have to check the name and adjust accordingly.
Here is the interface after installing WiringPi as shown in below figure.

thumb

WirtingPi includes a set of gpio commands to control the GPIO pins of the Raspberry Pi. Type in the command to check the installation:

  • gpio -v
  • gpio readall

The interface as shown in below figure means complete installation.

thumb


2.Enable I2C Utility

The I2C bus allows multiple devices to be connected to your Raspberry Pi. Before using I2C it needs to be configured.
Run this command: sudo raspi-config and follow the prompts to install I2C. Now complete the following steps:

  • Select “9 Advanced Options”
  • Select “A6 I2C”

The screen will ask if you want the ARM I2C interface to be enabled :

  • Select “Yes”
  • Select “Ok”
  • Select “Finish” to return to the command line

When you next reboot the I2C module will be loaded.


3.Programming

Copy the file pcf8591 provided by us and put it into your pi directory through winSCP. Next, type this command: cd pcf8591 to go inside the pcf8591 folder. Then type this command: make to make an executable file. This means this is the file we run to launch the program.
Finally type this: sudo ./TTP229 to launch the program.


Result

DA source code makes AOUT interface output 0-5V voltage; the pi will prints digital value among 0-255 on the terminal after reading out voltage set by AD source code.



Documents

  • PDF File:

https://drive.google.com/open?id=1KGHWkoRwcH26PSLvVD6jLZxRa5-qIp-r

  • Installation Package Download:

https://drive.google.com/open?id=18pp8aNUe05B6EzyphTb9JLnE6gQaBOL6

  • Source Code Download:

https://drive.google.com/open?id=1bwUSsxDyB-st2qaLyK2phvpbelvUph9S



Buy From