User Tools

Site Tools


user:ccornair:portfolio:datacomm5

Objectives

To connect 2 raspberry pis and have them count in binary

Prerequisites

raspberry pie,monitor, keyboard, data cable, hdmi to usb cable, network cable, LEDs

Background

The Raspberry Pi is a credit-card-sized single-board computer developed in the UK by the Raspberry Pi Foundation with the intention of promoting the teaching of basic computer science in schools.[7][8][9][10][11]

The Raspberry Pi is manufactured through licensed manufacturing deals with Newark element14 (Premier Farnell), RS Components and Egoman. All of these companies sell the Raspberry Pi online.[12] Egoman produces a version for distribution solely in China and Taiwan, which can be distinguished from other Pis by their red coloring and lack of FCC/CE marks. The hardware is the same across all manufacturers.

Code

conduit

#include "rpi.h"
#include<stdlib.h>
int i,j,k,l;
int main()
{
  if(map_peripheral(&gpio) == -1)
  {
    printf("Failed to map the physical GPIO registers into the virtual memory space.\n");
    return -1;
  }


/*    INP_GPIO(17);
        OUT_GPIO(7);
*/
    INP_GPIO(22);
        OUT_GPIO(10);
/*
    INP_GPIO(9);
        OUT_GPIO(11);
    INP_GPIO(8);
    OUT_GPIO(23);
*/
        GPIO_CLR = 1 << 8;
        GPIO_CLR = 1 << 9;
        GPIO_CLR = 1 << 22;
        GPIO_CLR = 1 << 17;




    while(1)
    {


        i = GPIO_READ(8);
        printf("%d \n", i);
        if(i !=0)
        {
        GPIO_SET = 1 << 23;
        }
        else
        {
        GPIO_CLR = 1 << 23;
        }

                j = GPIO_READ(9);
                printf("%d \n", j);
                if(j !=0)
                {
                GPIO_SET = 1 <<11;
                }
        else
        {
                GPIO_CLR = 1 << 11;
                }

                k = GPIO_READ(22);
                printf("%d \n", k);
                if(k !=0)
                {
                GPIO_SET = 1 << 10;
                }
        else
        {
                GPIO_CLR = 1 << 10;
                }

                l = GPIO_READ(17);
                printf("%d \n", l);
                if(l !=0)
                {
                GPIO_SET = 1 << 7;
                }
        else
        {
                GPIO_CLR = 1 << 7;
                }



    }
}

receiver

#include "rpi.h"
#include <stdlib.h>
#include <stdio.h>

void clear()
{
    GPIO_CLR = 1 << 23;
    GPIO_CLR = 1 << 11;
    GPIO_CLR = 1 << 10;
    GPIO_CLR = 1 << 7; 
    sleep(1); 
}


int main()
{

int i;
char place = 0, counter = 0, *bin;
bin = (char *)malloc(sizeof(char) +4); 


  if(map_peripheral(&gpio) == -1) 
  {
    printf("Failed to map the physical GPIO registers into the virtual memory space.\n");
    return -1;
  }

  // Define pin 7 as output
    INP_GPIO(25);
  OUT_GPIO(23);

  INP_GPIO(8);//red
  OUT_GPIO(11);

  INP_GPIO(24);//blue second in
  OUT_GPIO(10);

  INP_GPIO(22);//yellow far right
  OUT_GPIO(7);


	int pins[4];
	pins[0] = 23;
	pins[1] = 11;
	pins[2] = 10;
	pins[3] = 7;




    while(1)
    {   
        place = counter;

        if((place - 8) >= 0)
        {   
            *(bin + 0)  = 1;
         place = place - 8;
        }   
        else
            *(bin + 0) = 0;

        if((place - 4) >= 0)
        {   
            *(bin + 1) = 1;
            place = place - 4;
        }   
        else
            *(bin + 1) = 0;

        if((place - 2) >= 0)
        {   
            *(bin + 2) = 1;
            place = place - 2;
        }   
        else
            *(bin + 2) = 0;

        if(place == 1)
        {   
            *(bin + 3) = 1;
        }   
        else
            *(bin + 3) = 0;

        for(i = 0; i <= 3; i++)
        {   
            if( *(bin + i) == 1)
            {   
                GPIO_SET = 1 << pins[i]; 
            }   
            else
                GPIO_CLR = 1 << pins[i]; 
        }   
		printf( "%d", *(bin + 0));
		printf( "%d", *(bin + 1));
		printf( "%d", *(bin + 2));
		printf( "%d\n", *(bin + 3));
		
        counter++;

        if(counter > 15) 
        {   
            counter = 0;
        
		}
        
		usleep(1000000);   
}

clear();

  return 0; 
}

reflection

this was a pretty easy project actually, everything went pretty smoothly for once

user/ccornair/portfolio/datacomm5.txt · Last modified: 2013/12/14 01:36 by ccornair