Test­ing on your Rasp­berry Pi

OpenSource For You - - DEVELOPERS LET'S TRY -

Boot up your Rasp­berry Pi us­ing minicom and you will see the con­sole that re­sem­bles mine (Fig­ure 2).

Run ‘sudo dmesg –C’. (This com­mand would clean up all the ker­nel boot print logs.) Run ‘sudo make’. (This com­mand would com­pile GPIO driver. Do this only for the sec­ond method.) Run ‘sudo in­s­mod gpi­o_­driver.ko’. (This com­mand in­serts the driver into the OS.) Run ‘dmesg’. You can see the prints from the GPIO driver and the ma­jor num­ber al­lo­cated to it, as shown in Fig­ure 3. (The ma­jor num­ber plays a unique role in iden­ti­fy­ing a spe­cific driver with whom the process from the ap­pli­ca­tion space wants to com­mu­ni­cate with, whereas the mi­nor num­ber is used to recog­nise hard­ware.) Run ‘sudo mknod /dev/bcm­gpio c ma­jor­num 0’. (The ‘mknod’ com­mand cre­ates a node in / dev di­rec­tory, ‘ c’ stands for character de­vice and ‘ 0’ is the mi­nor num­ber.) Run ‘sudo gcc gpi­o_app.c ­o gpi­o_app’. (Com­pile the GPIO con­trol ap­pli­ca­tion.) Now let’s test our GPIO driver and ap­pli­ca­tion. To ver­ify whether our driver is in­deed com­mu­ni­cat­ing with GPIO, short pins 25 and 24 (one can use other avail­able pins like 17, 22 and 23 as well but make sure that they aren't mixed up for any other pe­riph­eral) us­ing the fe­male-to-fe­male jumper (Fig­ure 4). The de­fault val­ues of both the pins will be 0. To con­firm the de­fault val­ues, run the fol­low­ing com­mands:

sudo ./app -n 25 -g 1 This will be the out­put. The out­put value of GPIO 25 = 0. Now run the fol­low­ing com­mand:

sudo ./app -n 24 -g 1

This will again be the out­put. The out­put value of GPIO 24 = 0.

That’s it. It’s ver­i­fied (see Fig­ure 5). Now, as the GPIO pins are shorted, if we out­put 1 to 24 then it would be the in­put value of 25 and vice versa.

To test this, run:

sudo ./app -n 24 -d 1 -v 1 -s 1

This com­mand will drive the value of GPIO 24 to 1, which in turn will be routed to GPIO 25. To ver­ify the value of GPIO 25, run:

sudo ./app -n 25 -g 1

This will give the out­put. The out­put value of GPIO 25 = 1 (see Fig­ure 6).

One can also con­nect any ex­ter­nal de­vice or a sim­ple LED (through a re­sis­tor) to the GPIO pin and test its out­put.

Ar­gu­ments passed to the ap­pli­ca­tion through the com­mand lines are: -n : GPIO num­ber -d : GPIO di­rec­tion (0 - IN or 1 - OUT) -v : GPIO value (0 or 1) -s/g : set/get GPIO The files are: gpi­o_­driver.c : GPIO driver file gpi­o_app.c : GPIO con­trol ap­pli­ca­tion gpio.h : GPIO header file Make­file : File to com­pile GPIO driver

After con­duct­ing this ex­per­i­ment, some cu­ri­ous folk may have ques­tions like: Why does one have to use vir­tual ad­dresses to ac­cess GPIO? How does one de­ter­mine the vir­tual ad­dress from the phys­i­cal ad­dress? We will dis­cuss the an­swers to th­ese in later ar­ti­cles.

Fig­ure 6: Out­put show­ing GPIO 25=1

Fig­ure 5: Out­put show­ing GPIO 24=0

Fig­ure 3: dmesg out­put

Fig­ure 4: R-pi GPIO

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.