This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
user:jcavalu3:portfolio:datacomm3 [2013/11/13 21:51] – created jcavalu3 | user:jcavalu3:portfolio:datacomm3 [2013/11/25 21:36] (current) – jcavalu3 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | =====Wiring Together Two Raspberry Pi' | ||
+ | Our objective for this project was to wire together two raspberry pi's and have them send/ | ||
+ | |||
+ | The code: | ||
+ | |||
+ | <code c> | ||
+ | 1 #include " | ||
+ | 2 | ||
+ | 3 int main() | ||
+ | 4 { | ||
+ | 5 int counter = 0; | ||
+ | 6 int option; | ||
+ | 7 | ||
+ | 8 int led_1, led_2, led_3, led_4; // variables to hold the value that is read from the GPIO_READ functions (control on/off state of receiving pins) | ||
+ | 9 | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 30 | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 36 | ||
+ | | ||
+ | 38 | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 100 | ||
+ | 101 if( led_3 != 0 ) | ||
+ | 102 | ||
+ | 103 else | ||
+ | 104 | ||
+ | 105 | ||
+ | 106 if( led_4 != 0 ) | ||
+ | 107 | ||
+ | 108 else | ||
+ | 109 | ||
+ | 110 } | ||
+ | 111 | ||
+ | 112 | ||
+ | 113 | ||
+ | 114 | ||
+ | 115 | ||
+ | 116 | ||
+ | 117 | ||
+ | 118 } | ||
+ | 119 | ||
+ | 120 | ||
+ | 121 } | ||
+ | </ | ||
+ | |||
+ | The code, which is fully functional, asks the user whether he/she will be sending or receiving signals: | ||
+ | |||
+ | ====Choice 1: Sender==== | ||
+ | |||
+ | When sending, the program will run through a while loop and count from 0 to 15 (binary counter), which will then turn on/off the necessary pins for the value to be sent over to the other pi (the receiver). The the rest is left to the receiving pi. | ||
+ | |||
+ | ====Choice 2: Receiver==== | ||
+ | |||
+ | When receiving, the pi will set pins 4, 17, 27, and 22 as input, since they are the pins that will be receiving the data from the other pi. A while loop will then be run which sets led_1 equal to the value of the read gpio pin #4, led_2 equal to the value of the read gpio pin #17, etc., until all four input pins have been read, then the program will run the binary counter and display the data through pins 7 - 10. | ||
+ | |||
+ | |||
+ | ====Reflection==== | ||
+ | |||
+ | A few problems occurred in the writing of this program that, after many hours of frustration and headaches, we were able to overcome. | ||
+ | |||
+ | - **Correctly setting Input and Output properly is CRUCIAL!** - On multiple occasions, incorrectly setting I/O or not setting I/O at all messed the program up pretty good. The problem would be that the receiving pins would pick up random values and set LED's on at random, which is not what we wanted at all. | ||
+ | - **Setting up IF statements correctly** - I first set up the if statements to read led_1-4 as being equal to 0, when I wanted to check when it wasn' |