This Example shows how to access GPIO pins via web interface.
First you need to install on mini2440 linux kernel with GPIO support.
Unfortunately FriendlyARM comes with kernel without GPIO and SPI support.
If you decide to try to compile kernel take a look at "Kernel Tweaking" link below. There is a good explanation how to do it.
The other option is to download already compiled kernel from
http://rapidshare.com/files/409529369/zImage-2.6.32.2-mini2440_gpio_spi.html
It is for 7" display but for this example only network access to mini2440 is needed.
I'm not going to explain how to upload the kernel image. It's shown in the board's manual.
HOW TO CONTROL GPIO FROM THE COMMAND LINE:
When the new kernel is uploaded let's first check the access to GPIO from the command line.
Telnet to mini2440 and go to sys/class/gpio folder:
$ telnet 192.168.1.230
[root@FriendlyARM /]# cd sys/class/gpio/
[root@FriendlyARM gpio]# ls
export gpiochip0 gpiochip128 gpiochip160 gpiochip192 gpiochip224 gpiochip32 gpiochip64 gpiochip96 unexport
Folders gpiochip0 , gpiochip128 .... represent GPIO drivers for each port. Ports are named A,B,C....
Check the port for each gpiochipX:
[root@FriendlyARM gpio]# cat gpiochip0/label
GPIOA
[root@FriendlyARM gpio]# cat gpiochip32/label
GPIOB
[root@FriendlyARM gpio]# cat gpiochip192/label
GPIOG
Each pin has it's corresponding access number. For example buzzer is connected to GPB0 ( Port B pin 0) and port B is accessible from gpiochip32 so the number to access the buzzer is 32.
Led1 is connected go GPB5. It's access number is 32+5 = 37
Buttons are connected to port G - gpiochip192
Function Port Access number
Buzzer GPB0 32
Led1 GPB5 37
Led2 GPB6 38
Led3 GPB7 39
Led4 GPB8 40
Btn1 GPG0 192
Btn2 GPG3 195
Btn3 GPG5 197
Btn4 GPG6 198
Btn5 GPG7 199
Btn6 GPG11 203
Now open access to the buzzer. :
[root@FriendlyARM gpio]# echo 32 > export
[root@FriendlyARM gpio]# ls
export gpio32 gpiochip0 gpiochip128 gpiochip160 gpiochip192 gpiochip224 gpiochip32 gpiochip64 gpiochip96 unexport
A new link gpio32 appeared now. Let's check the current direction and make it an output:
[root@FriendlyARM gpio]# cat gpio32/direction
in
[root@FriendlyARM gpio]# echo "high" > gpio32/direction
[root@FriendlyARM gpio]# cat gpio32/direction
out
Turn the buzzer on and off:
[root@FriendlyARM gpio]# echo "1" > gpio32/value
[root@FriendlyARM gpio]# echo "0" > gpio32/value
Close the access:
[root@FriendlyARM gpio]# echo 32 > unexport
CONTROL GPIO FROM WEB INTERFACE:
First stop the Led player as shown on one of previous posts.
The project consists from the following files:
access_num.h - definitions of GPIO driver access numbers
gpio.h gpio.cpp - class for control of GPIO. Each instance is for control of one pin
readbtn.cpp - CGI program that reads the state of the six board buttons and shows
it in table on a web page. The page is automatically refreshed each
two seconds.
ledbuzz.cpp - CGI program that reads the query string sent to the web server and
turns on/off the LEDs and the Buzzer.Then the state of the four board
leds and the buzzer are shown on a web page as checkboxes.
The user can change the checkboxes. When submit button is pressed
the new states are sent to the web server using GET method and the
same program is called again.
download the project folder from:
https://rapidshare.com/files/3267170017/webcontrol.zip
https://rapidshare.com/#!download|560tg|3267170017|webcontrol.zip|16
compile with command:
$ arm-linux-g++ gpio.cpp ledbuzz.cpp -o ledbuzz.cgi
$ arm-linux-g++ gpio.cpp readbtn.cpp -o readbtn.cgi
Note: In the project folder there are already compiled binaries ledbuzz.cgi and readbtn.cgi
upload ledbuzz.cgi and readbtn.cgi to the board to /www/cgi-bin folder and give them executable attribute
# chmod a+x ledbuzz.cgi
# chmod a+x readbtn.cgi
Run them from the command line. You should get HTML output
There is no index.html. Open CGIs from PC web browser directly:
http://192.168.1.230/cgi-bin/ledbuzz.cgi
http://192.168.1.230/cgi-bin/readbtn.cgi
LINKS:
Access to GPIO pins explained
http://www.avrfreaks.net/wiki/index.php/Documentation:Linux/GPIO
Kernel Tweaking
http://members.cox.net/ebrombaugh1/embedded/mini2440/index.html
P.S. If you find this articles useful please pay some attention to the ads.
Some of them might be interresting to you too. Thanks.
Абонамент за:
Коментари за публикацията (Atom)
Hi do you have the patches for the kernel for GPIO access?
ОтговорИзтриванеSorry, what do you mean patches?
ОтговорИзтриванеThere is already pre-compiled kernel for download from
http://rapidshare.com/files/409529369/zImage-2.6.32.2-mini2440_gpio_spi.html
Този коментар бе премахнат от автора.
ОтговорИзтриванеnevermind was my mistake for not reading the kernel twiking part you posted, I compile the kernel for the 3.5 inch if anyone needs it is here
ОтговорИзтриванеhttp://mini2440qt.googlecode.com/files/zImage_SPI
Hi The Rapid share files has been expire can you kindly mail me the lebbuzz and button codes to k.sundeep2007@gmail.com
ОтговорИзтриване