<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>logIt &#187; GPIO</title>
	<atom:link href="https://lakm.us/logit/tag/gpio/feed/" rel="self" type="application/rss+xml" />
	<link>https://lakm.us/logit</link>
	<description>Log Around The Clock</description>
	<lastBuildDate>Sat, 06 Jun 2015 14:17:37 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Any m-by-n Matrix Keypad for Raspberry Pi</title>
		<link>https://lakm.us/logit/2014/02/any-m-x-n-matrix-keypad-raspberry-pi/</link>
		<comments>https://lakm.us/logit/2014/02/any-m-x-n-matrix-keypad-raspberry-pi/#comments</comments>
		<pubDate>Sat, 08 Feb 2014 18:30:57 +0000</pubDate>
		<dc:creator>Arif</dc:creator>
				<category><![CDATA[ARM Linux]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[GPIO]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Raspberry Pi]]></category>

		<guid isPermaLink="false">http://lakm.us/logit/?p=746</guid>
		<description><![CDATA[What about instantiating any m x n matrix keypad by a Python class? Raspberry Pi takes me to learn how to build a Python class for the first time while expanding my initial WiringPi-based matrix keypad into a derivative work. A matrix keypad instance is defined by: Actual GPIO pins used forming the row and [...]]]></description>
				<content:encoded><![CDATA[<p>What about instantiating any m x n matrix keypad by a <a href="http://docs.python.org/2/tutorial/classes.html" title="Python Classes" target="_blank">Python class</a>? <a href="http://www.raspberrypi.org/" target="_blank">Raspberry Pi</a> takes me to learn how to build a Python class for the first time while expanding my initial <a href="../../2013/03/raspberry-pi-membrane-matrix-keypad-gpio-input-2/" title="Raspberry Pi: Membrane (Matrix) Keypad as GPIO Input" target="_blank">WiringPi-based matrix keypad</a> into a derivative work.</p>
<p>A matrix keypad instance is defined by:</p>
<ol>
<li>Actual GPIO pins used forming the row and column of the m x n matrix</li>
<li>Individual character in-use as symbol for each button</li>
</ol>
<p>Hence, I instantiate and call method like</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">...
<span style="color: black;">QPad</span>  = matrixQPi<span style="color: black;">&#40;</span>keyPad=keyPad,row=row,col=col<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> QPad.<span style="color: black;">scanQ</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>to print the character being pressed. Some examples pushed to <a href="https://github.com/bandono/matrixQPi/tree/v2.0" title="Github: matrixQPi v2.0" target="_blank">my github</a> explains how the above <code>keyPad</code>, <code>row</code>, and <code>col</code> are defined to scan-read pressed button of 2&#215;2, 2&#215;3, and 4&#215;3 matrix keypads <time datetime="2014-02-23">(or have it 3&#215;4 matrix keypads in other words)</time>.</p>
<div class="wp-caption aligncenter" style="width: 460px"><img alt="Illustration of any m-by-n matrix: 4x3, 2x2, and 2x3 keypad with different button symbols &#038; GPIO combinations" src="../../../../images/any-mxn-matrix-keypad-raspberry-pi.png" title="Illustration of any m-by-n matrix: 4x3, 2x2, and 2x3 keypad with different button symbols &#038; GPIO combinations" width="368" height="264" /><p class="wp-caption-text">Illustration of any m-by-n matrix: 4x3, 2x2, and 2x3 keypad with different button symbols &#038; GPIO combinations</p></div>
<p>I used deprecated <a href="https://github.com/WiringPi/WiringPi-Python" title="WiringPi-Python" target="_blank">Wiring-Pi Python</a> (they already moved to <a href="https://github.com/WiringPi/WiringPi2-Python" title="WiringPi2-Python" target="_blank">2.x version</a>) without problem. However, you&#8217;ll fail building from latest commit and must use combination of older commits as described by my updated part of <a href="../../2013/03/raspberry-pi-gpio-input-button-basics-1/" title="Raspberry Pi GPIO Input Button Basics" target="_blank">an old-post</a>. By the way, there&#8217;s I/O expander support for <a href="https://github.com/WiringPi/WiringPi2-Python" title="WiringPi2-Python" target="_blank">WiringPi2-Python</a> which is good, considering:</p>
<blockquote><p>GPIO is expensive and for the sake of a keypad, you should not spend all.</p></blockquote>
<p>(A friend told me that once)</p>
]]></content:encoded>
			<wfw:commentRss>https://lakm.us/logit/2014/02/any-m-x-n-matrix-keypad-raspberry-pi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Raspberry Pi: Membrane (Matrix) Keypad as GPIO Input</title>
		<link>https://lakm.us/logit/2013/03/raspberry-pi-membrane-matrix-keypad-gpio-input-2/</link>
		<comments>https://lakm.us/logit/2013/03/raspberry-pi-membrane-matrix-keypad-gpio-input-2/#comments</comments>
		<pubDate>Wed, 13 Mar 2013 08:55:13 +0000</pubDate>
		<dc:creator>Arif</dc:creator>
				<category><![CDATA[ARM Linux]]></category>
		<category><![CDATA[ARMv6]]></category>
		<category><![CDATA[embedded system]]></category>
		<category><![CDATA[GPIO]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[shell script]]></category>

		<guid isPermaLink="false">http://lakm.us/logit/?p=533</guid>
		<description><![CDATA[Membrane matrix keypad using GPIO as Raspberry Pi input has been my goal since WiringPi deployed in the first place. To begin with, GPIO hacking was initially started with some important basics (see previous post). Without external system (other interfacing chip), the 3&#215;4 membrane keypad reserved all seven GPIO pins plus one pin used for [...]]]></description>
				<content:encoded><![CDATA[<p>Membrane matrix keypad using GPIO as <a href="http://www.raspberrypi.org" target="_blank">Raspberry Pi</a> input has been my goal since <em><a href="https://projects.drogon.net/raspberry-pi/wiringpi/" target="_blank">WiringPi</a></em> deployed in the first place. To begin with, GPIO hacking was initially started with some important basics (see <a href="./2013/03/raspberry-pi-gpio-input-button-basics-1/" target="_blank">previous post</a>). Without external system (other interfacing chip), the <a href="http://www.adafruit.com/products/419" title="Similar product from Adafruit: Membrane Matrix Keypad 3x4" target="_blank">3&#215;4 membrane keypa</a>d reserved all seven GPIO pins plus one pin used for LED indicating successful reading of pressed key.</p>
<p><time datetime="2014-02-09"><br />
<blockquote style="background-color:lightyellow;"><strong><em>Updated:</em></strong> for those who fail to build using <a href="https://github.com/WiringPi/WiringPi-Python" title="WiringPi-Python" target="_blank">deprecated WiringPi-Python</a>, check <a href="../../2013/03/raspberry-pi-gpio-input-button-basics-1/" title="Raspberry Pi GPIO Input Button Basics" target="_blank">this updated post</a> to know which commit that build without error. There is now also <a href="../../2014/02/any-m-x-n-matrix-keypad-raspberry-pi/" title="Any m-by-n Matrix Keypad for Raspberry Pi" target="_blank">a Python class for matrix keypad</a>.</p></blockquote>
<p></time></p>
<p>My idea of having the keypad is to make alternative input available under no keyboard presence nor shell access. List of things I can think of for instances, pressed key &#8220;0&#8243; will make the Raspberry Pi (RPi) dial GPRS to a specific ISP and act as router to the USB WiFi stick, pressed key &#8220;7&#8243; will convert it to a router that will bridge the ethernet to WiFi, etc. In short, those key readings will invoke subsequent scripts to run inside RPi.</p>
<p>The physical connection schematic drawings and code are gitified (visit <a href="https://github.com/bandono/matrixQPi/tree/v1.2" title="gitHub: matrixQPi v1.2" target="_blank">v1.2 of the project on gitHub</a>). A nice animated image on how the buttons connect pins forming a matrix can be found in <a href="http://www.hackyourmind.org/blog/rpi-hw-interfacing-the-raspberry-pi-with-matrix-keypad/" target="_blank">hackyourmind.org</a>.</p>
<div class="wp-caption aligncenter" style="width: 460px"><a href="http://www.flickr.com/photos/aqila_rifti/8541074196/" title="Raspberry #Pi membrane (matrix) keypad. Longer hours with the circuitry in fear of bricking it. The code took half day of work instead by aqila_rifti, on Flickr"><img src="http://farm9.staticflickr.com/8375/8541074196_a22dccbd2a.jpg" width="310" height="310" alt="Raspberry #Pi membrane (matrix) keypad. Longer hours with the circuitry in fear of bricking it. The code took half day of work instead"></a> <p class="wp-caption-text">Matrix keypad: alternative quick input for Raspberry Pi to start certain command</p></div>
<p>Some remarks over what the code does:<br />
<span id="more-533"></span></p>
<ul>
<li>It only read one pressed key at a time.</li>
<li>It uses no interrupt. To read input it must wait and scan (this waiting experience is by far negligible to human sense).</li>
<li>Debouncing doesn&#8217;t seem necessary as <em>WiringPi</em> already provided this by software (I suppose <a href="https://github.com/WiringPi/WiringPi/blob/master/examples/wfi.c" title="WiringPi: wfi.c" target="_blank">this timing method on their gitHub</a> deals with debounce).</li>
</ul>
<p>How it works? <a href="http://www.raspberrypi.org/phpBB3/viewtopic.php?t=30376&#038;p=291617" title="RPi Forum: Membrane Keypad Circuit Help" target="_blank">RPi forum thread</a> gives a general idea that applies in my case:</p>
<ol>
<li>Divide the 3&#215;4 matrix as columns and rows. 4 GPIO pins as rows are pulled-up with 10k resistors and initialized as input.</li>
<li>Other 3 GPIO pins as columns are initialized as output low.</li>
<li>First loop will scan for one pressed key being read as one of the rows pulled-low</li>
<li>After the loop breaks, all columns are set as input, then the row pin found in the loop is set as output-high</li>
<li>Second loop will scan for column being pulled-high by that row pin. Between both loops, it is assumed that the key press is still in effect. In reality, normal human act of pressing this key elapses long enough for the software to run the scans in two loops.</li>
<li>Bingo! The code reads row-column combination of the pressed key.</li>
</ol>
<p>Example of the code&#8217;s output by calling from shell:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">true</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>matrixQPi.py -i; <span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #000000;">3</span>
<span style="color: #000000;">6</span>
<span style="color: #000000;">9</span>
<span style="color: #000000;">8</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">*</span></pre></div></div>

<p>(In the above example <code>^C</code> will throw Python <code>KeyboardInterrupt</code> messages before  breaking the <code>bash</code> loop)</p>
]]></content:encoded>
			<wfw:commentRss>https://lakm.us/logit/2013/03/raspberry-pi-membrane-matrix-keypad-gpio-input-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Raspberry Pi GPIO Input Button Basics</title>
		<link>https://lakm.us/logit/2013/03/raspberry-pi-gpio-input-button-basics-1/</link>
		<comments>https://lakm.us/logit/2013/03/raspberry-pi-gpio-input-button-basics-1/#comments</comments>
		<pubDate>Mon, 11 Mar 2013 02:57:58 +0000</pubDate>
		<dc:creator>Arif</dc:creator>
				<category><![CDATA[ARM Linux]]></category>
		<category><![CDATA[ARMv6]]></category>
		<category><![CDATA[embedded system]]></category>
		<category><![CDATA[GPIO]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Raspberry Pi]]></category>

		<guid isPermaLink="false">http://lakm.us/logit/?p=500</guid>
		<description><![CDATA[When you start hacking Raspberry Pi&#8217;s GPIO, first thing to keep in mind is the +3.3V CMOS logic level voltage despite the 5V supply. Secondly, read references about current limiting resistors (eLinux Wiki has a section there). What to avoid then? Try not to physically short the GPIO pin to ground when it is programmed [...]]]></description>
				<content:encoded><![CDATA[<p>When you start hacking Raspberry Pi&#8217;s GPIO, first thing to keep in mind is the +3.3V CMOS logic level voltage despite the 5V supply. Secondly, read references about current limiting resistors (eLinux Wiki has <a href="http://elinux.org/RPi_Tutorial_EGHS:Switch_Input" title="RPi_Tutorial_EGHS:Switch_Input" target="_blank">a section there</a>). What to avoid then? Try not to <strong>physically</strong> short the GPIO pin to ground when it is <strong>programmed</strong> as the opposite output-high.</p>
<p>GPIO pin logic state (meaning voltage) are both programmable and driven by physical-connection. I choose <em><a href="https://projects.drogon.net/raspberry-pi/wiringpi/" title="WiringPi" target="_blank">wiringPi</a></em> for practical reasons: availability of its <a href="https://github.com/WiringPi/WiringPi-Python" title="WiringPi-Python" target="_blank">Python wrapper</a> and its simple syntax (glancing it at first sight). <strong>WiringPi</strong> has an option of using its own pin numbering to address it in the code instead of the original GPIO numbering (there are board revisions to watch for in some cases of usage, not mine). Every pin can be initialized as input or output.</p>
<p><time datetime="2014-02-08"><br />
<blockquote style="background-color:lightyellow;"><strong><em>Updated:</em></strong> <a href="https://github.com/WiringPi/WiringPi-Python" title="WiringPi-Python" target="_blank">Wiring-Pi Python</a> is deprecated and moving to <a href="https://github.com/WiringPi/WiringPi2-Python" title="WiringPi2-Python" target="_blank">2.x version</a> that supports I/O expander. However, you can still find this combination of commits that will work and build without error message:</p>
<p>- main module: <a href="https://github.com/WiringPi/WiringPi-Python/tree/9c77bde53fb5fa6283268b4a529e47048f8a379d">WiringPi-Python@9c77bde</a><br />
- submodule: <a href="https://github.com/WiringPi/WiringPi/tree/89bbe97856407979fa75c4c793fabf4db839a0ee">WiringPi@89bbe97</a></p>
<p>(Check how to build on my <a href="https://github.com/bandono/matrixQPi/tree/v2.0" title="matrixQP v2.0" target="_blank">README</a>)</p></blockquote>
<p></time></p>
<p>Using an <a href="http://overseas.sanwa-meter.co.jp/items/detail.php?id=85" title="Sanwa Multimeter: DIY KIT-8D" target="_blank">analog multitester</a>, here are behavioral findings:</p>
<ul>
<li>GPIO pin voltage swings to high logic after reboot (the meter&#8217;s needle is rocking for a second or so). It is in low voltage afterward until being programmed or physically pulled-up.</li>
<li>Two pins, wiringPi pin 8 and 9, remain in high logic voltage after reboot. They are SDA0 and SCL0 to be used as an I²C, however they can be used to read button as well. (<a href="http://elinux.org/RPi_Low-level_peripherals" title="RPi low-level peripherals" target="_blank">eLinux Wiki</a>: &#8220;there are 1.8 k pulls up resistors on the board for these pins&#8221;)</li>
<li>I did short the high logic to ground accidentally, it invoked reboot. (I don&#8217;t know how many times or how long of this will brick the Raspberry Pi)</li>
</ul>
<p>Prior to trying the push-button switch, I didn&#8217;t have proper circuitry and working with wires as probes, prone to accident that was. I found an advice to insulate the +5V pin voltage so I could worry less.</p>
<div class="wp-caption aligncenter" style="width: 460px"><br />
<a href="http://www.flickr.com/photos/aqila_rifti/8440986498/" title="Raspbery Pi: Getting Started with GPIO Hack by aqila_rifti, on Flickr"><img src="http://farm9.staticflickr.com/8230/8440986498_5acd920148.jpg" width="300" height="300" alt="Raspbery Pi: Getting Started with GPIO Hack"></a><p class="wp-caption-text">Insulate the +5V pin of Raspberry Pi</p></div>
<p>A 10k pull-up resistor and a button are enough to test the following. Go to interactive Python shell and run line by line until the button push is read as low logic (GPIO7 in this example):</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># python</span>
Python 2.7.3rc2 <span style="color: black;">&#40;</span>default, May  <span style="color: #ff4500;">6</span> <span style="color: #ff4500;">2012</span>, <span style="color: #ff4500;">20</span>:02:<span style="color: #ff4500;">25</span><span style="color: black;">&#41;</span> 
<span style="color: black;">&#91;</span>GCC 4.6.3<span style="color: black;">&#93;</span> on linux2
Type <span style="color: #483d8b;">&quot;help&quot;</span>, <span style="color: #483d8b;">&quot;copyright&quot;</span>, <span style="color: #483d8b;">&quot;credits&quot;</span> <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #483d8b;">&quot;license&quot;</span> <span style="color: #ff7700;font-weight:bold;">for</span> more information.
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">import</span> wiringpi
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> INPUT=<span style="color: #ff4500;">0</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> OUTPUT=<span style="color: #ff4500;">1</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> HIGH=<span style="color: #ff4500;">1</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> LOW=<span style="color: #ff4500;">0</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> SETUP=wiringpi.<span style="color: black;">wiringPiSetup</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">print</span> SETUP
<span style="color: #ff4500;">0</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> wiringpi.<span style="color: black;">pinMode</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">7</span>,INPUT<span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> RESULT=wiringpi.<span style="color: black;">digitalRead</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">7</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">print</span> RESULT
<span style="color: #ff4500;">1</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> RESULT=wiringpi.<span style="color: black;">digitalRead</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">7</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">print</span> RESULT
<span style="color: #ff4500;">1</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> RESULT=wiringpi.<span style="color: black;">digitalRead</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">7</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">print</span> RESULT
<span style="color: #ff4500;">0</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span></pre></div></div>

<p>These basics convince me to go ahead with my goal of having a <a href="http://www.adafruit.com/products/419" title="Adafruit: Membrane Matrix Keypad 3x4" target="_blank">membrane (matrix) keypad</a> as input for Raspberry Pi to run some script (see <a href="../../../2013/03/raspberry-pi-membrane-matrix-keypad-gpio-input-2/" title="Raspberry Pi: Membrane (Matrix) Keypad as GPIO Input" target="_blank">next post</a>).</p>
<p>(Check also <a href="./2013/03/raspberry-pi-common-usb-problems/" title="Raspberry Pi Common USB Problems" target="_blank">RPi common USB problems post</a>)</p>
]]></content:encoded>
			<wfw:commentRss>https://lakm.us/logit/2013/03/raspberry-pi-gpio-input-button-basics-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
