KS0211 keyestudio RPI JoyStick Shield

From Keyestudio Wiki
Jump to: navigation, search

keyestudio RPI JoyStick Shield


thumb

Introduction

Welcome to the wonderful world of joystick control. Adding a joystick to your Raspberry Pi opens a lot of new doors. You can now use the Raspberry Pi and the joystick to control a robot, a camera, play games or do whatever you want.
The joystick shield provides two simple analog inputs and one analog output along with four separate buttons, one thumb joystick and two little buttons. We will provide installation package, source code and quickstart guide PDF. We will teach you step by step, so don’t worry!

Specification

  • Chip:pcf 85911
  • Supply Voltage: 5V
  • Four separate buttons, one thumb joystick and two little buttons

Connection Diagram

Directly plug it into the pi and max it with copper pillar and screws as shown in below figure.
thumb

Sample Code

 #include <wiringPi.h>
#include <pcf8591.h>
#include <stdio.h>

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

char dat;

int main(void)
{
        unsigned char value;
	wiringPiSetup();
        pinMode(25,INPUT);
        pinMode(7,INPUT);
        pinMode(0,INPUT);
        pinMode(2,INPUT);
        pinMode(3,INPUT);
        pinMode(4,INPUT);
        pinMode(5,INPUT);
 
        pullUpDnControl(25,PUD_UP);
        pullUpDnControl(7,PUD_UP);
        pullUpDnControl(0,PUD_UP);
        pullUpDnControl(2,PUD_UP);
        pullUpDnControl(3,PUD_UP);
        pullUpDnControl(4,PUD_UP);
        pullUpDnControl(5,PUD_UP);
	pcf8591Setup(BASE,Address);
	
	while(1)
	{
               value=analogRead(A0);              
               printf("X:%d   ",value);
               value=analogRead(A1);              
               printf("Y:%d    ",value);

               dat=digitalRead(25);
                  printf("K:%d   ",dat);

               dat=digitalRead(7);
                  printf("A:%d   ",dat);

               dat=digitalRead(0);
                  printf("B:%d   ",dat);

               dat=digitalRead(2);
                  printf("C:%d   ",dat);

               dat=digitalRead(3);
                  printf("D:%d   ",dat);


               dat=digitalRead(4);
                  printf("E:%d   ",dat);

               dat=digitalRead(5);
                  printf("F:%d\n",dat);
               delay(100);
		
               // analogWrite(BASE,value++);
               // printf("AOUT:%d\n",value++);
               // delay(50);	
	}
}

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 rpi_joystick provided by us and put it into your pi directory through winSCP. Next , type this command: cd rpi_joystick to go inside the rpi_joystick folder. Then type this command: make to make an executable file pcf8591-joytokey as shown in below figure. This means this is the file we run to launch the program.
Finally type this: sudo ./pcf8591-joytokey to launch the program.
thumb

Result

Press the thumb joystick and buttons, and values are printed on the terminal as shown in below figure. Then use Ctrl+C to quit the program.
thumb

Documents

PDF File:

https://drive.google.com/open?id=14r-C7PtOPOc1xJuy7oq7Yw1z7e4ri3s6

Installation Package:

https://drive.google.com/open?id=18NX_KAY7dudyl78y0WBwFoGSXrZ-ZpHR

Source Code:

https://drive.google.com/open?id=1ZYz7mdsV4OLVkxhUa2OXMfcOP9T8cfE0

Buy From

http://www.keyestudio.com/keyestudio-rpi-joystick-shield.html