This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
user:jcavalu3:portfolio:datacomm1 [2013/10/31 01:12] – [Tutorial #1: The Command Line] jcavalu3 | user:jcavalu3:portfolio:datacomm1 [2013/10/31 01:12] (current) – [Tutorial #2: The C Code] jcavalu3 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | =====Pertinent Links Project: GPIO Tutorials #1 and #2===== | ||
+ | ====Project #1: The Command Line==== | ||
+ | |||
+ | In this project, I was given a few links to websites that I needed to visit to begin accessing the GPIO pins on the Raspberry Pi. The [[https:// | ||
+ | |||
+ | First, in order to access any GPIO pins, the user must use SuperUser or just sudo before any command accessing the pins. | ||
+ | |||
+ | According to the website, when writing to the ./export file in the / | ||
+ | |||
+ | To create the GPIO file, the user must input the following: | ||
+ | |||
+ | <cli> | ||
+ | echo 11 > / | ||
+ | </ | ||
+ | |||
+ | Next, the Pin Direction must be set as Input or Output: | ||
+ | |||
+ | <cli> | ||
+ | echo out > / | ||
+ | </ | ||
+ | |||
+ | Lastly, a value of ' | ||
+ | |||
+ | <cli> | ||
+ | echo 1 > / | ||
+ | </ | ||
+ | |||
+ | This should have done it! | ||
+ | |||
+ | To turn it off, just repeat the step that turned the LED on, replacing the ' | ||
+ | |||
+ | <cli> | ||
+ | echo 0 > / | ||
+ | </ | ||
+ | |||
+ | To delete the file access, repeat the step that first created the file (export), but instead accessing the ' | ||
+ | |||
+ | <cli> | ||
+ | echo 11 > / | ||
+ | </ | ||
+ | |||
+ | ====Project #2: The C Code==== | ||
+ | |||
+ | This tutorial used C code to access the GPIO pins, which is what most of (if not the rest) of this class will focus on, the C code method of accessing the pins. | ||
+ | |||
+ | From the [[https:// | ||
+ | |||
+ | The necessary code is as follows: | ||
+ | |||
+ | rpi.h | ||
+ | |||
+ | <code c> | ||
+ | 1 #include < | ||
+ | 2 | ||
+ | 3 #include < | ||
+ | 4 #include < | ||
+ | 5 #include < | ||
+ | 6 | ||
+ | 7 #include < | ||
+ | 8 | ||
+ | 9 #include < | ||
+ | | ||
+ | 11 #define BCM2708_PERI_BASE | ||
+ | 12 #define GPIO_BASE | ||
+ | | ||
+ | 14 #define BLOCK_SIZE | ||
+ | | ||
+ | 16 //IO Access | ||
+ | 17 struct bcm2835_peripheral { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 23 }; | ||
+ | | ||
+ | 25 // struct bcm2835_peripheral gpio = {GPIO_BASE}; | ||
+ | | ||
+ | 27 extern struct bcm2835_peripheral gpio; // They have to be found somewhere, b ut can't be in the header | ||
+ | | ||
+ | | ||
+ | 30 // GPIO setup macros. Always use INP_GPIO(X) before using OUT_GPIO(x) | ||
+ | 31 #define INP_GPIO(g) | ||
+ | 32 #define OUT_GPIO(g) | ||
+ | 33 #define SET_GPI_ALT(G, | ||
+ | | ||
+ | 35 #define GPIO_SET | ||
+ | 36 #define GPIO_CLR | ||
+ | | ||
+ | 38 #define GPIO_READ(g) | ||
+ | </ | ||
+ | |||
+ | rpi.c | ||
+ | |||
+ | <code c> | ||
+ | |||
+ | 1 #include " | ||
+ | 2 | ||
+ | 3 struct bcm2835_peripheral gpio = {GPIO_BASE}; | ||
+ | 4 | ||
+ | 5 // Exposes the physical address defined in the passed structure using mmap o n /dev/mem | ||
+ | 6 int map_peripheral(struct bcm2835_peripheral *p) | ||
+ | 7 { | ||
+ | 8 // Open /dev/mem | ||
+ | 9 if ((p-> | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 31 } | ||
+ | | ||
+ | 33 void unmap_peripheral(struct bcm2835_peripheral *p) { | ||
+ | | ||
+ | | ||
+ | | ||
+ | 37 } | ||
+ | </ | ||
+ | |||
+ | The code that is seen above is what is necessary for the program that turns on the LED to work. | ||
+ | |||
+ | main.c | ||
+ | |||
+ | <code c> | ||
+ | 1 #include " | ||
+ | 2 | ||
+ | 3 int main() | ||
+ | 4 { | ||
+ | 5 | ||
+ | 6 { | ||
+ | 7 | ||
+ | 8 | ||
+ | 9 } | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 25 } | ||
+ | </ | ||
+ | |||
+ | The program has been run and successfully turns the LED on and off. |