Saturday, February 24, 2018

Raspberry PI GPIO Test

GPIO Test Using Raspberry Pi

This post will talk about how fast raspberry pi can trigger GPIO. 
I did not want to investigate it deeply here but just wanted to quickly check it.
So, I decided to use the well maintained python GPIO library for raspberry pi.
For this test, I wired the output pin to input pin and measure the loopback time using timers.

Connect GPIO pins:
In my case, using GPIO16(pin #36) as output and GPIO20(pin #38) as input.
I used female jumper wires to connect those pins.
GPIO pin numbering diagram


The GPIO software module for python is installed by default if you are using Raspbian.
If you want to double check the versions and/or install the latest version, refer to this site.

Python Code

Python code is pretty simple.
You call "import RPi.GPIO as GPIO" in the beginning and set the mode.
This is the python example code.
import RPi.GPIO as GPIO
import time
GPIO.setup(16, GPIO.OUT)
GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def my_callback(channel):
              print(str(elapsed) + " ms")
raw_input("Press Enter\n")
GPIO.add_event_detect(20, GPIO.FALLING, callback=my_callback, bouncetime=300)
              while True:
                           GPIO.output(16, 1)
                           GPIO.output(16, 0)
except KeyboardInterrupt:

There are 2 types of mode settings.
GPIO.BOARD means it is referring to the pins by the number of the pin.
GPIO.BCM means it is referring to the pins by the "Broadcom SOC channel" number.
For the details, you can refer to this great article here.

Crate a python script file as below and copy&paste the above code.
Run the python script.


The result was quite interesting.
It was around 0.2ms.
I think this is not a problem for the projects I do.



No comments:

Post a Comment