From 52Pi Wiki
Jump to: navigation, search

Raspberry Pi GPIO Triple Expand Board


The "raspberry Pi GPIO Triple Expand Board" used for Raspberry Pi can copy Raspberry Pi's GPIO pin to the number of three ,in this case ,you do not worry about that some GPIO pins been occupied by external sensor modules ,you have three times of Raspberry Pi's GPIO pins

One to three 01.jpg





LCD module scale

Rgb1602 show3.JPG

RGB1602 pin description

pin number chart function
1 Vss GND
2 Vdd Voltage supply
3 Vo LCD contrast
4 RS register select
5 R/W read or write select
6 E enable
7 DB0 data pin 0
8 DB1 data pin 1
9 DB2 data pin 2
10 DB3 data pin 3
11 DB4 data pin 4
12 DB5 data pin 5
13 DB6 data pin 6
14 DB7 daata pin 7
15 LEDA LED backlight voltage supply
16 LEDR red LED backlight control
17 LEDG green LED backlight control
18 LEDB blue LED backlight control

1602 RGB test3.png


sudo vim.tiny lcd1602.c
1602 tech1.png

  • Copy and paste the following demo code into lcd1602.c

1602 tech2.png

  • Under the vim.tiny editor, type ":", then type "wq" and press "enter" to save the lcd1602.c file and exit editor

1602 tech3.png

  • Next you need to compile the code using gcc.

gcc lcd1602.c -lwiringPi /home/pi/wiringPi/devLib/lcd.o -o lcd1602
1602 tech5.png

  • You should find an executable file named "lcd1602" if the last step was completed. Type the following code sudo modprobe i2c-dev to load the I2C interface

1602 tech6.png
1602 tech8.png

  • Lastly, type sudo ./lcd1602 , and the module will be displaying the demo text, as the following photo shows.

1602 tech9.png

  • This is a gif showing the different backlight colors


Demo Code

#include <stdio.h>                                                            //include standard input output head file                                                            
#include <wiringPi.h>                                                         //include wiringpi                                                     
#include <mcp23017.h>                                                         //include mcp23017 control head file                                         
#include <lcd.h>                                                              //include LCD control head file                                                   
#include <softPwm.h>                                                          //include PWM control head file
int main()
	long value=0;       
	int rand_num;	 
	int value_blue;                                                       //the blue backlight brightness
	int value_red;                                                        //the red backlight brightness
	int value_green;                                                      //the green backlight brightness
	int display,i,count;                                                 
	wiringPiSetup();                                                      //init wiringPi                                                    
	mcp23017Setup (100, 0x20);                                            //init mcp23017 chip I2C address: 0x20,the first pin number: 100                                          
	printf ("Raspberry Pi - MCP23017 Test\n");                            //print information
	pinMode(100+i,OUTPUT);                                                //set pin 100 - 115 as output                          
	digitalWrite(101,0);                                                  //set pin 101 low voltage                              
	display=lcdInit(2,16,4,100,102,103,104,105,106,0,0,0,0);              //lcd init 2*16,4 bit control,use 100,101,102,103,104 pin as control pin         
	lcdHome(display);                                                     //reset cursor  
	lcdClear(display);                                                    //clear screen   
	lcdPosition(display,0,0);                                             //set display location (0,0)   
	lcdPuts(display,"Hello World");                                       //print string "Hello World"
	lcdPosition(display,0,1);                                             //set display location(0,1)  
	lcdPuts(display,"www.52pi.net");                            	      //print string "www.52pi.net"		
	pinMode(0, OUTPUT);                                                   //set Raspberry pi pin 0 as output   
	pinMode(2, OUTPUT);                                                   //set Raspberry Pi pin 2 as output  
	pinMode(3, OUTPUT);                                                   //set Raspberry Pi pin 3 as output
	softPwmCreate (3, 50, 100);                                           //set soft PWM pin 3 PWM scale (0-100) original 50
	softPwmCreate (2, 50, 100);                                           //set soft PWM pin 2 PWM scale (0-100) original 50
	softPwmCreate (0, 50, 100);                                           //set soft PWM pin 0 PWM scale (0-100) original 50
while(1)                                                                      //always display
	delay(200);                                                            //delay 200ms
        value_red=(value<100)?value:0;                                         //0-100 red change
	value_green=(value>100&&value<200)?(value-100):0;                      //100-200 green change 
	value_blue=(value>200)?(value-200):0;                                  //200-300 blue change        
	if(value>300)                                                          //>300 random colour
	softPwmWrite (3,value_red);                                             //soft PWM control red backlight
	softPwmWrite (2,value_green);                                           //soft PWM control green backlight
	softPwmWrite (0,value_blue);                                            //soft PWM control blue backlight

	if(value>900)                                                           //if value >900 return
	lcdPrintf(display,"%d",value);                                           //print number value


LCD manuals
demo code