KS0213 Keyestudio RPI GPIO-PCF8591 Shield: Difference between revisions
Keyestudio (talk | contribs) No edit summary |
Keyestudio (talk | contribs) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 74: | Line 74: | ||
We will provide a Wiringpi installation package or click on this URL: https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/ <br> | 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> | (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| | <br>[[File:ks0213-3.png|700px|frameless|thumb]]<br> | ||
<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> | ||
Line 82: | Line 82: | ||
<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> | <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> | Here is the interface after installing WiringPi as shown in below figure.<br> | ||
<br>[[File:ks0213-4.png| | <br>[[File:ks0213-4.png|700px|frameless|thumb]]<br> | ||
<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:<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:<br> | ||
Line 88: | Line 88: | ||
* '''gpio readall''' <br> | * '''gpio readall''' <br> | ||
The interface as shown in below figure means complete installation.<br> | The interface as shown in below figure means complete installation.<br> | ||
<br>[[File:ks0213-5.png| | <br>[[File:ks0213-5.png|700px|frameless|thumb]]<br> | ||
<br> | <br> | ||
Line 109: | Line 109: | ||
<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. | ||
Line 116: | Line 117: | ||
==Documents == | ==Documents == | ||
https://fs.keyestudio.com/KS0213 | |||
https:// | |||
<br> | |||
== Buy From == | == Buy From == | ||
*[https://www.keyestudio.com/keyestudio-rpi-gpio-shield-with-pcf8591-ad-da-for-raspberry-pi-ce-certification-p0474-p0474.html '''Official website''' ] | *[https://www.keyestudio.com/keyestudio-rpi-gpio-shield-with-pcf8591-ad-da-for-raspberry-pi-ce-certification-p0474-p0474.html '''Official website''' ] |
Latest revision as of 10:27, 1 March 2021
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.
Connection Diagram
Plug it directly into Raspberry Pi to start your works as shown in below figure.
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:
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.
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.
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
https://fs.keyestudio.com/KS0213