1.ขั้นแรกสร้าง folder เพื่อใช้เก็บ library และ source
#mkdir /store
#mkdir /store/lib
2.เข้าไปที่ folder /store/lib
#cd /store/lib
3.Download source code library จาก http://www.open.com.au/mikem/bcm2835/bcm2835-1.17.tar.gz
ด้วยคำสั่ง #wget http://www.open.com.au/mikem/bcm2835/bcm2835-1.17.tar.gz
4.extract tar file ด้วยคำสั่ง #tar -vxf bcm2835-1.17.tar.gz
5.เข้าไปใน folder bcm2835-1.17 #cd bcm2835-1.17
6.ใช้คำสั่ง #./configure เพื่อสร้าง make file
7.สั่ง #make และ #make install
จากนั้นลองมาเขียนโปรแกรมทดสอบกันดูครับ โดย
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*********************** | |
*Author Ultra MCU | |
* Website : http://miiniq.blogspot.com/ | |
* */ | |
#include <bcm2835.h> | |
#include <stdio.h> | |
void main() | |
{ | |
bcm2835_init(); | |
bcm2835_gpio_fsel(RPI_GPIO_P1_11, BCM2835_GPIO_FSEL_OUTP);//set pin 11 output | |
bcm2835_gpio_fsel(RPI_GPIO_P1_15, BCM2835_GPIO_FSEL_INPT);//set pin 15 input | |
bcm2835_gpio_set_pud(RPI_GPIO_P1_15 , BCM2835_GPIO_PUD_UP);//set pull up pin 15 | |
while(1) | |
{ | |
bcm2835_gpio_write(RPI_GPIO_P1_11, HIGH); | |
sleep(1); | |
bcm2835_gpio_write(RPI_GPIO_P1_11, LOW); | |
sleep(1); | |
printf("Read Value %d\r\n",bcm2835_gpio_lev(RPI_GPIO_P1_15)); | |
} | |
} |
โปรแกรมสำหรับ test i/o ใช้คำสั่ง #vi testio.c
จากนั้น compile ด้วยสำสั่ง gcc -o app_testio testio.c -L/store/lib/bcm2835-1.14/src/ -lbcm2835 -lrt และ run ด้วยสำสั่ง ./app_testio และ pin 11 ก็ลองนำ led มาต่อดูครับ หลอดจะกระพริบติด 1 วินาที ดับ 1 วินาทีครับ ส่วน switch นำมาต่อที่ pin 15
0 ความคิดเห็น:
แสดงความคิดเห็น