[vc_row][vc_column width=”1/1″][vc_column_text]This is the latest installment of my series of pcDuino tutorials. This tutorial will show you how to setup and program the pcDuino to respond to an external interrupt.
This assumes that you have a basic working knowledge of the pcDuino and Linux. It builds upon thepcDuino – Blink Totorial.[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Hardware Set Up” tab_id=”1389063392-1-67″][vc_column_text]For this tutorial you will need the following items:
- A pcDuino running the 20130531 Ubuntu image.
- A breadboard.
- A button such as the Mini Push Button Switch sold by Sparkfun.
- Three jumper wires.
- A 10K ohm resistor.
- The source code below for building interrupt.c.
Hardware Setup
The setup for this is simple. You connect one end of the switch to the 3.3V pin on the pcDuino. You connect the other end of the switch to GPIO2 pin on the pcDuino and to ground through the 10K resistor. The 10K resistor as it is connected to ground is a pull-down resistor. It keeps the signal at 0V when the switch is open. If a pull-up or pull-down resistor was not used the signal would float which could cause intermittent interrupts when one was not signaled.
The pins used are shown by the red arrows in the board diagram above.[/vc_column_text][/vc_tab][vc_tab title=”Interrupt Program” tab_id=”1389063392-2-31″][vc_column_text]An interrupt is described in Wikipedia as a signal to the processor emitted by hardware or software indicating an event that needs immediate attention. In this tutorial we are working with a hardware interrupt.
The pcDuino is setup with two pins that can be used for interrupts: GPIO2 and GPIO3. The program is written to use SWIRQ_PIN1 and GPIO2. However, SWIRQ_PIN2 is also define which corresponds to GPIO3.
The way the program works is that when the switch is opened gpio pin 2 is is connected to ground at 0V. When the switch is pushed it connects 3.3V to gpio pin 2 which is read by the system and results in an interrupt service routine (ISR) being called if one is defined.
There are 5 types of interrupts:
- Rising – called when the signal goes from low to high.
- Falling – called when the signal goes from high to low.
- High – called when the signal is high.
- Low – called when the signal is low.
- Change – called when the signal goes from low to high and then again when it goes from high to low.
Download the code here: interrupt[/vc_column_text][/vc_tab][vc_tab title=”Program Setup” tab_id=”1389074024208-2-4″][vc_column_text]Program Setup
Using the editor of your choice or the command “cat > interrupt.c” you will need to get the program on to your pcDuino. See the Blink Tutorial for screen shots on how to do this.
Next you will need to load the appropriate driver if it isn’t already loaded when you boot your system. You can check using the lsmod command and then load the driver using “sudo modprobe sw_interrupt” again there are screenshots of this in the Blink Tutorial.
Next compile your program using “gcc interrupt.c –o interrupt” and then run it using “./interrupt”. When you press the button you should get a number printed on your screen. You will need to use ctrl-c to exit the program.
Acknowledgements
Thanks to the folks at Sparkfun and their great Getting Started with pcDuino for getting me started with putting this tutorial together. Also thanks to the folks on the pcDuino website for their support. Check out the website and forums for more information.
Source: http://digitalhacksblog.blogspot.com/2013/09/pcduinointerrupt-tutorial.html[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.