<?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>gamaral - Software Engineer &#187; Quicky</title>
	<atom:link href="/category/quicky/feed/" rel="self" type="application/rss+xml" />
	<link>https://guillermoamaral.com</link>
	<description>Incredibly handsome engineer, gamedev and trekkie.</description>
	<lastBuildDate>Sun, 17 Nov 2013 03:45:05 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.7.1</generator>
	<item>
		<title>Xeno-GC Clone Mini</title>
		<link>https://guillermoamaral.com/read/xeno-gc-clone-mini/</link>
		<comments>https://guillermoamaral.com/read/xeno-gc-clone-mini/#comments</comments>
		<pubDate>Mon, 14 Oct 2013 19:43:28 +0000</pubDate>
		<dc:creator><![CDATA[gamaral]]></dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Quicky]]></category>
		<category><![CDATA[AVR]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Embedded]]></category>
		<category><![CDATA[Homebrew]]></category>
		<category><![CDATA[OSH]]></category>

		<guid isPermaLink="false">https://guillermoamaral.com/?p=885</guid>
		<description><![CDATA[<div><img width="150" height="150" src="/wp-content/uploads/2013/10/IMG_2609_small-150x150.jpg" class="attachment-thumbnail wp-post-image" alt="IMG_2609_small" style="margin-bottom: 15px;" /></div>Xeno-GC Clone Mini Since I wasn&#8217;t satisfied with how I laid out it&#8217;s big bother, I decided to redo the board, the Xeno-GC Clone Mini is the end result. It&#8217;s about the size of a quarter dollar and twice as sexy. Check out the images above and see for yourself. Make your own! The mini model, like it&#8217;s big brother, uses 0805 SMD components. No rework station or solder paste required; Just a standard soldering iron and some whiskey (Ok, the whiskey is optional). Parts 2x 100nF 0805 ceramic capacitors. 2x 1k&ohm; 0805 resistors. 2x 330&ohm; 0805 resistors. 1x 100&ohm; 0805 resistor. 1x Red 0805 LED. 1x Green 0805 LED. 1x Atmel AVR ATmega8L 32-pin TQFP. Order You can order your boards directly from (OSH Park)[http://oshpark.com/shared_projects/XDNLoePV]. If you have any questions, feel free to email me. Now go get your homebrew on!]]></description>
				<content:encoded><![CDATA[<div><img width="150" height="150" src="/wp-content/uploads/2013/10/IMG_2609_small-150x150.jpg" class="attachment-thumbnail wp-post-image" alt="IMG_2609_small" style="margin-bottom: 15px;" /></div><h1>Xeno-GC Clone Mini</h1>

<p>Since I wasn&#8217;t satisfied with how I laid out it&#8217;s big bother, I decided to redo the board, the Xeno-GC Clone Mini is the end result. It&#8217;s about the size of a quarter dollar and twice as sexy. Check out the images above and see for yourself.</p>

<h1>Make your own!</h1>

<p>The mini model, like it&#8217;s big brother, uses 0805 SMD components. No rework station or solder paste required; Just a standard soldering iron and some whiskey <em>(Ok, the whiskey is optional)</em>.</p>

<h2>Parts</h2>

<ul>
<li><strong>2x</strong> 100nF 0805 ceramic capacitors.</li>
<li><strong>2x</strong> 1k&ohm; 0805 resistors.</li>
<li><strong>2x</strong> 330&ohm; 0805 resistors.</li>
<li><strong>1x</strong> 100&ohm; 0805 resistor.</li>
<li><strong>1x</strong> Red 0805 LED.</li>
<li><strong>1x</strong> Green 0805 LED.</li>
<li><strong>1x</strong> Atmel AVR ATmega8L 32-pin TQFP.</li>
</ul>

<h2>Order</h2>

<p>You can order your boards directly from (OSH Park)[http://oshpark.com/shared_projects/XDNLoePV]. If you have any questions, feel free to email me. Now go get your homebrew on!</p>
]]></content:encoded>
			<wfw:commentRss>https://guillermoamaral.com/read/xeno-gc-clone-mini/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Make your own Raspberry Pi – PSU [R2]</title>
		<link>https://guillermoamaral.com/read/rpi-psu-r2/</link>
		<comments>https://guillermoamaral.com/read/rpi-psu-r2/#comments</comments>
		<pubDate>Tue, 17 Sep 2013 01:56:34 +0000</pubDate>
		<dc:creator><![CDATA[gamaral]]></dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Quicky]]></category>
		<category><![CDATA[AVR]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Embedded]]></category>
		<category><![CDATA[Make]]></category>
		<category><![CDATA[OSH]]></category>
		<category><![CDATA[Raspberry Pi]]></category>

		<guid isPermaLink="false">https://guillermoamaral.com/?p=802</guid>
		<description><![CDATA[<div><img width="150" height="150" src="/wp-content/uploads/2013/09/IMG_2530-150x150.jpg" class="attachment-thumbnail wp-post-image" alt="RPi-PSU R2" style="margin-bottom: 15px;" /></div>I received my Raspberry Pi PSU Revision 2 PCBs in the mail last week and I got a chance to populate and test them during the weekend. The R2 board is shared on OSH Park which means you can order your own boards and assemble for yourself. Components Here&#8217;s the board, fully populated and with all the parts values highlighted. All parts are fairly common, specially the passives. Here are a few suppliers for the parts you may have a hard time finding. ATTiny85 SparkFun: COM-09378 Mouser: 556-ATTINY85-20PU Programming You will need a way to program the ATTiny, I suggest getting yourself an Atmel AVR mkII, a Pocket AVR Programmer or if you already own an Arduino you can make an ArduinoISP. LD33V SparkFun: COM-00526 Mouser: 511-LD1117V33 TIP125 Mouser: 511-TIP125 2N2222A Mouser: 511-2N2222A Digi-Key: 497-2598-ND OBSOLITE R3 replaces this component with the 2N3904 and PN2222 Resources OSH Park: http://oshpark.com/shared_projects/clqtxZaD Video: http://youtu.be/xgsn7Mpjh7g]]></description>
				<content:encoded><![CDATA[<div><img width="150" height="150" src="/wp-content/uploads/2013/09/IMG_2530-150x150.jpg" class="attachment-thumbnail wp-post-image" alt="RPi-PSU R2" style="margin-bottom: 15px;" /></div><p>I received my Raspberry Pi PSU Revision 2 PCBs in the mail last week and I got a chance to populate and test them during the weekend.</p>

<p>The R2 board is <a href="http://oshpark.com/shared_projects/clqtxZaD">shared on OSH Park</a> which means you can order your own boards and assemble for yourself.</p>

<h1>Components</h1>

<p>Here&#8217;s the board, fully populated and with all the parts values highlighted.</p>

<p><a href="/wp-content/uploads/2013/09/IMG_2530-notes.jpg" rel="prettyphoto[802]"><img src="/wp-content/uploads/2013/09/IMG_2530-notes-300x200.jpg" alt="RPi-PSU R2 - Components" width="300" height="200" class="aligncenter size-medium wp-image-803" /></a></p>

<p>All parts are fairly common, specially the passives. Here are a few suppliers for the parts you may have a hard time finding.</p>

<h2>ATTiny85</h2>

<p>SparkFun: <a href="https://www.sparkfun.com/products/9378">COM-09378</a>
Mouser: <a href="http://www.mouser.com/ProductDetail/Atmel/ATtiny85-20PU/?qs=8jWQYweyg6NCiiaOb5GI9Q==">556-ATTINY85-20PU</a></p>

<h3>Programming</h3>

<p>You will need a way to program the ATTiny, I suggest getting yourself an <a href="http://www.mouser.com/ProductDetail/Atmel/ATAVRISP2/?qs=2mdvTlUeTfBRoycsKqwYpg==">Atmel AVR mkII</a>, a <a href="https://www.sparkfun.com/products/9825">Pocket AVR Programmer</a> or if you already own an Arduino you can make an <a href="http://arduino.cc/en/Tutorial/ArduinoISP">ArduinoISP</a>.</p>

<h2>LD33V</h2>

<p>SparkFun: <a href="https://www.sparkfun.com/products/526">COM-00526</a>
Mouser: <a href="http://www.mouser.com/ProductDetail/STMicroelectronics/LD1117V33/?qs=arR7071FstdSYX/AthFGRA==">511-LD1117V33</a></p>

<h2>TIP125</h2>

<p>Mouser: <a href="http://www.mouser.com/ProductDetail/STMicroelectronics/TIP125/?qs=ljbEvF4DwOOVTDztFiRz8A==">511-TIP125</a></p>

<h2>2N2222A</h2>

<p>Mouser: <a href="http://www.mouser.com/ProductDetail/STMicroelectronics/2N2222A/?qs=UMEuL5FsraBzcgM1cdcH3A==">511-2N2222A</a>
Digi-Key: <a href="http://www.digikey.com/product-detail/en/2N2222A/497-2598-ND/603623">497-2598-ND</a></p>

<p><strong>OBSOLITE</strong> R3 replaces this component with the 2N3904 and PN2222</p>

<h1>Resources</h1>

<p>OSH Park: <a href="http://oshpark.com/shared_projects/clqtxZaD">http://oshpark.com/shared_projects/clqtxZaD</a>
Video: <a href="http://youtu.be/xgsn7Mpjh7g">http://youtu.be/xgsn7Mpjh7g</a></p>
]]></content:encoded>
			<wfw:commentRss>https://guillermoamaral.com/read/rpi-psu-r2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Raspberry Pi GPIO&#8217;s using plain C and SysFS</title>
		<link>https://guillermoamaral.com/read/rpi-gpio-c-sysfs/</link>
		<comments>https://guillermoamaral.com/read/rpi-gpio-c-sysfs/#comments</comments>
		<pubDate>Sun, 04 Aug 2013 09:49:30 +0000</pubDate>
		<dc:creator><![CDATA[gamaral]]></dc:creator>
				<category><![CDATA[Quicky]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Embedded]]></category>
		<category><![CDATA[Raspberry Pi]]></category>

		<guid isPermaLink="false">https://guillermoamaral.com/?p=714</guid>
		<description><![CDATA[<div><img width="150" height="150" src="/wp-content/uploads/2012/11/IMG_2429-e1379609746295-150x150.jpg" class="attachment-thumbnail wp-post-image" alt="Marshmallow on the Raspberry Pi" style="margin-bottom: 15px;" /></div>Talk I recently gave a talk on the Raspberry Pi during which I mentioned using the GPIO sysfs interface instead of something like the WiringPi library, I was asked if I could provide a small example&#8230; I can. Example I&#8217;m about to unleash the electronic world&#8217;s version of the &#8220;Hello World!&#8221; program, a blinking LED. Remember, this example requires no special libraries since it uses the sysfs interface. blink.c 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184/* blink.c &#160;* &#160;* Raspberry Pi GPIO example using sysfs interface. &#160;* Guillermo A. Amaral B. &#60;g@maral.me&#62; &#160;* &#160;* This program blinks GPIO 4 (P1-07) while reading GPIO 24 (P1_18). &#160;*/ #include &#60;sys/stat.h&#62; #include &#60;sys/types.h&#62; #include &#60;fcntl.h&#62; #include &#60;stdio.h&#62; #include &#60;stdlib.h&#62; #include &#60;unistd.h&#62; #define IN &#160; 0 #define OUT &#160;1 #define LOW &#160;0 #define HIGH 1 #define PIN &#160;24 /* P1-18 */ #define POUT 4 &#160;/* P1-07 */ static int GPIOExport(int pin); static int GPIOUnexport(int pin); static int GPIODirection(int pin, int dir); static int GPIORead(int pin); static int GPIOWrite(int pin, int value); int main(int argc, char *argv[]) { &#160; &#160; int repeat = 9; &#160; &#160; /* &#160; &#160; &#160;* Enable GPIO pins &#160; &#160; &#160;*/ &#160; &#160; if (-1 == GPIOExport(POUT) &#124;&#124; -1 == GPIOExport(PIN)) &#160; &#160; &#160; &#160; return(1); &#160; &#160; /* &#160; &#160; &#160;* Set GPIO directions &#160; &#160; &#160;*/ &#160; &#160; if (-1 == GPIODirection(POUT, OUT) &#124;&#124; -1 == GPIODirection(PIN, IN)) &#160; &#160; &#160; &#160; return(2); &#160; &#160; do { &#160; &#160; &#160; &#160; /* &#160; &#160; &#160; &#160; &#160;* Write GPIO value &#160; &#160; &#160; &#160; &#160;*/ &#160; &#160; &#160; &#160; if (-1 == GPIOWrite(POUT, repeat % 2)) &#160; &#160; &#160; &#160; &#160; &#160; return(3); &#160; &#160; &#160; &#160; /* &#160; &#160; &#160; &#160; &#160;* Read GPIO value &#160; &#160; &#160; &#160; &#160;*/ &#160; &#160; &#160; &#160; printf(&#34;I'm reading %d in GPIO %d\n&#34;, GPIORead(PIN), PIN); &#160; &#160; &#160; &#160; usleep(500 * 1000); &#160; &#160; } &#160; &#160; while (repeat--); &#160; &#160; /* &#160; &#160; &#160;* Disable GPIO pins &#160; &#160; &#160;*/ &#160; &#160; if (-1 == GPIOUnexport(POUT) &#124;&#124; -1 == GPIOUnexport(PIN)) &#160; &#160; &#160; &#160; return(4); &#160; &#160; return(0); } int GPIOExport(int pin) { #define BUFFER_MAX 3 &#160; &#160; char buffer[BUFFER_MAX]; &#160; &#160; ssize_t bytes_written; &#160; &#160; int fd; &#160; &#160; fd = open(&#34;/sys/class/gpio/export&#34;, O_WRONLY); &#160; &#160; if (-1 == fd) { &#160; &#160; &#160; &#160; fprintf(stderr, &#34;Failed to open export for writing!\n&#34;); &#160; &#160; &#160; &#160; return(-1); &#160; &#160; } &#160; &#160; bytes_written = snprintf(buffer, BUFFER_MAX, &#34;%d&#34;, pin); &#160; &#160; write(fd, buffer, bytes_written); &#160; &#160; close(fd); &#160; &#160; return(0); } int GPIOUnexport(int pin) { &#160; &#160; char buffer[BUFFER_MAX]; &#160; &#160; ssize_t bytes_written; &#160; &#160; int fd; &#160; &#160; fd = open(&#34;/sys/class/gpio/unexport&#34;, O_WRONLY); &#160; &#160; if (-1 == fd) { &#160; &#160; &#160; &#160; fprintf(stderr, &#34;Failed to open unexport for writing!\n&#34;); &#160; &#160; &#160; &#160; return(-1); &#160; &#160; } &#160; &#160; bytes_written = snprintf(buffer, BUFFER_MAX, &#34;%d&#34;, pin); &#160; &#160; write(fd, buffer, bytes_written); &#160; &#160; close(fd); &#160; &#160; return(0); } int GPIODirection(int pin, int dir) { &#160; &#160; static const char s_directions_str[] &#160;= &#34;in\0out&#34;; #define DIRECTION_MAX 35 &#160; &#160; char path[DIRECTION_MAX]; &#160; &#160; int fd; &#160; &#160; snprintf(path, DIRECTION_MAX, &#34;/sys/class/gpio/gpio%d/direction&#34;, pin); &#160; &#160; fd = open(path, O_WRONLY); &#160; &#160; if (-1 == fd) { &#160; &#160; &#160; &#160; fprintf(stderr, &#34;Failed to open gpio direction for writing!\n&#34;); &#160; &#160; &#160; &#160; return(-1); &#160; &#160; } &#160; &#160; if (-1 == write(fd, &#38;s_directions_str[IN == dir ? 0 : 3], IN == dir ? 2 : 3)) { &#160; &#160; &#160; &#160; fprintf(stderr, &#34;Failed to set direction!\n&#34;); &#160; &#160; &#160; &#160; return(-1); &#160; &#160; } &#160; &#160; close(fd); &#160; &#160; return(0); } int GPIORead(int pin) { #define VALUE_MAX 30 &#160; &#160; char path[VALUE_MAX]; &#160; &#160; char value_str[3]; &#160; &#160; int fd; &#160; &#160; snprintf(path, VALUE_MAX, &#34;/sys/class/gpio/gpio%d/value&#34;, pin); &#160; &#160; fd = open(path, O_RDONLY); &#160; &#160; if (-1 == fd) { &#160; &#160; &#160; &#160; fprintf(stderr, &#34;Failed to open gpio value for reading!\n&#34;); &#160; &#160; &#160; &#160; return(-1); &#160; &#160; } &#160; &#160; if (-1 == read(fd, value_str, 3)) { &#160; &#160; &#160; &#160; fprintf(stderr, &#34;Failed to read value!\n&#34;); &#160; &#160; &#160; &#160; return(-1); &#160; &#160; } &#160; &#160; close(fd); &#160; &#160; return(atoi(value_str)); } int GPIOWrite(int pin, int value) { &#160; &#160; static const char s_values_str[] = &#34;01&#34;; &#160; &#160; char path[VALUE_MAX]; &#160; &#160; int fd; &#160; &#160; snprintf(path, VALUE_MAX, &#34;/sys/class/gpio/gpio%d/value&#34;, pin); &#160; &#160; fd = open(path, O_WRONLY); &#160; &#160; if (-1 == fd) { &#160; &#160; &#160; &#160; fprintf(stderr, &#34;Failed to open gpio value for writing!\n&#34;); &#160; &#160; &#160; &#160; return(-1); &#160; &#160; } &#160; &#160; if (1 != write(fd, &#38;s_values_str[LOW == value ? 0 : 1], 1)) { &#160; &#160; &#160; &#160; fprintf(stderr, &#34;Failed to write value!\n&#34;); &#160; &#160; &#160; &#160; return(-1); &#160; &#160; } &#160; &#160; close(fd); &#160; &#160; return(0); } You can download the source by clicking here.]]></description>
				<content:encoded><![CDATA[<div><img width="150" height="150" src="/wp-content/uploads/2012/11/IMG_2429-e1379609746295-150x150.jpg" class="attachment-thumbnail wp-post-image" alt="Marshmallow on the Raspberry Pi" style="margin-bottom: 15px;" /></div><h1>Talk</h1>

<p>I recently gave a talk on the Raspberry Pi during which I mentioned using the GPIO sysfs interface instead of something like the WiringPi library, I was asked if I could provide a small example&#8230; I can.</p>

<h1>Example</h1>

<p>I&#8217;m about to unleash the electronic world&#8217;s version of the &#8220;Hello World!&#8221; program, a blinking LED. Remember, this example requires no special libraries since it uses the sysfs interface.</p>

<h2>blink.c</h2>

<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">/* blink.c<br />
&nbsp;*<br />
&nbsp;* Raspberry Pi GPIO example using sysfs interface.<br />
&nbsp;* Guillermo A. Amaral B. &lt;g@maral.me&gt;<br />
&nbsp;*<br />
&nbsp;* This program blinks GPIO 4 (P1-07) while reading GPIO 24 (P1_18).<br />
&nbsp;*/<br />
<br />
#include &lt;sys/stat.h&gt;<br />
#include &lt;sys/types.h&gt;<br />
#include &lt;fcntl.h&gt;<br />
#include &lt;stdio.h&gt;<br />
#include &lt;stdlib.h&gt;<br />
#include &lt;unistd.h&gt;<br />
<br />
#define IN &nbsp; 0<br />
#define OUT &nbsp;1<br />
<br />
#define LOW &nbsp;0<br />
#define HIGH 1<br />
<br />
#define PIN &nbsp;24 /* P1-18 */<br />
#define POUT 4 &nbsp;/* P1-07 */<br />
<br />
static int GPIOExport(int pin);<br />
static int GPIOUnexport(int pin);<br />
static int GPIODirection(int pin, int dir);<br />
static int GPIORead(int pin);<br />
static int GPIOWrite(int pin, int value);<br />
<br />
int<br />
main(int argc, char *argv[])<br />
{<br />
&nbsp; &nbsp; int repeat = 9;<br />
<br />
&nbsp; &nbsp; /*<br />
&nbsp; &nbsp; &nbsp;* Enable GPIO pins<br />
&nbsp; &nbsp; &nbsp;*/<br />
&nbsp; &nbsp; if (-1 == GPIOExport(POUT) || -1 == GPIOExport(PIN))<br />
&nbsp; &nbsp; &nbsp; &nbsp; return(1);<br />
<br />
&nbsp; &nbsp; /*<br />
&nbsp; &nbsp; &nbsp;* Set GPIO directions<br />
&nbsp; &nbsp; &nbsp;*/<br />
&nbsp; &nbsp; if (-1 == GPIODirection(POUT, OUT) || -1 == GPIODirection(PIN, IN))<br />
&nbsp; &nbsp; &nbsp; &nbsp; return(2);<br />
<br />
&nbsp; &nbsp; do {<br />
&nbsp; &nbsp; &nbsp; &nbsp; /*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Write GPIO value<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (-1 == GPIOWrite(POUT, repeat % 2))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return(3);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; /*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Read GPIO value<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br />
&nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;I'm reading %d in GPIO %d\n&quot;, GPIORead(PIN), PIN);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; usleep(500 * 1000);<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; while (repeat--);<br />
<br />
&nbsp; &nbsp; /*<br />
&nbsp; &nbsp; &nbsp;* Disable GPIO pins<br />
&nbsp; &nbsp; &nbsp;*/<br />
&nbsp; &nbsp; if (-1 == GPIOUnexport(POUT) || -1 == GPIOUnexport(PIN))<br />
&nbsp; &nbsp; &nbsp; &nbsp; return(4);<br />
<br />
&nbsp; &nbsp; return(0);<br />
}<br />
<br />
int<br />
GPIOExport(int pin)<br />
{<br />
#define BUFFER_MAX 3<br />
&nbsp; &nbsp; char buffer[BUFFER_MAX];<br />
&nbsp; &nbsp; ssize_t bytes_written;<br />
&nbsp; &nbsp; int fd;<br />
<br />
&nbsp; &nbsp; fd = open(&quot;/sys/class/gpio/export&quot;, O_WRONLY);<br />
&nbsp; &nbsp; if (-1 == fd) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf(stderr, &quot;Failed to open export for writing!\n&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; return(-1);<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; bytes_written = snprintf(buffer, BUFFER_MAX, &quot;%d&quot;, pin);<br />
&nbsp; &nbsp; write(fd, buffer, bytes_written);<br />
&nbsp; &nbsp; close(fd);<br />
&nbsp; &nbsp; return(0);<br />
}<br />
<br />
int<br />
GPIOUnexport(int pin)<br />
{<br />
&nbsp; &nbsp; char buffer[BUFFER_MAX];<br />
&nbsp; &nbsp; ssize_t bytes_written;<br />
&nbsp; &nbsp; int fd;<br />
<br />
&nbsp; &nbsp; fd = open(&quot;/sys/class/gpio/unexport&quot;, O_WRONLY);<br />
&nbsp; &nbsp; if (-1 == fd) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf(stderr, &quot;Failed to open unexport for writing!\n&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; return(-1);<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; bytes_written = snprintf(buffer, BUFFER_MAX, &quot;%d&quot;, pin);<br />
&nbsp; &nbsp; write(fd, buffer, bytes_written);<br />
&nbsp; &nbsp; close(fd);<br />
&nbsp; &nbsp; return(0);<br />
}<br />
<br />
int<br />
GPIODirection(int pin, int dir)<br />
{<br />
&nbsp; &nbsp; static const char s_directions_str[] &nbsp;= &quot;in\0out&quot;;<br />
<br />
#define DIRECTION_MAX 35<br />
&nbsp; &nbsp; char path[DIRECTION_MAX];<br />
&nbsp; &nbsp; int fd;<br />
<br />
&nbsp; &nbsp; snprintf(path, DIRECTION_MAX, &quot;/sys/class/gpio/gpio%d/direction&quot;, pin);<br />
&nbsp; &nbsp; fd = open(path, O_WRONLY);<br />
&nbsp; &nbsp; if (-1 == fd) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf(stderr, &quot;Failed to open gpio direction for writing!\n&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; return(-1);<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; if (-1 == write(fd, &amp;s_directions_str[IN == dir ? 0 : 3], IN == dir ? 2 : 3)) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf(stderr, &quot;Failed to set direction!\n&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; return(-1);<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; close(fd);<br />
&nbsp; &nbsp; return(0);<br />
}<br />
<br />
int<br />
GPIORead(int pin)<br />
{<br />
#define VALUE_MAX 30<br />
&nbsp; &nbsp; char path[VALUE_MAX];<br />
&nbsp; &nbsp; char value_str[3];<br />
&nbsp; &nbsp; int fd;<br />
<br />
&nbsp; &nbsp; snprintf(path, VALUE_MAX, &quot;/sys/class/gpio/gpio%d/value&quot;, pin);<br />
&nbsp; &nbsp; fd = open(path, O_RDONLY);<br />
&nbsp; &nbsp; if (-1 == fd) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf(stderr, &quot;Failed to open gpio value for reading!\n&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; return(-1);<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; if (-1 == read(fd, value_str, 3)) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf(stderr, &quot;Failed to read value!\n&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; return(-1);<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; close(fd);<br />
<br />
&nbsp; &nbsp; return(atoi(value_str));<br />
}<br />
<br />
int<br />
GPIOWrite(int pin, int value)<br />
{<br />
&nbsp; &nbsp; static const char s_values_str[] = &quot;01&quot;;<br />
<br />
&nbsp; &nbsp; char path[VALUE_MAX];<br />
&nbsp; &nbsp; int fd;<br />
<br />
&nbsp; &nbsp; snprintf(path, VALUE_MAX, &quot;/sys/class/gpio/gpio%d/value&quot;, pin);<br />
&nbsp; &nbsp; fd = open(path, O_WRONLY);<br />
&nbsp; &nbsp; if (-1 == fd) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf(stderr, &quot;Failed to open gpio value for writing!\n&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; return(-1);<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; if (1 != write(fd, &amp;s_values_str[LOW == value ? 0 : 1], 1)) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf(stderr, &quot;Failed to write value!\n&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; return(-1);<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; close(fd);<br />
&nbsp; &nbsp; return(0);<br />
}</div></td></tr></tbody></table></div>

<p>You can <a href="http://dl.guillermoamaral.com/rpi/blink.c">download the source by clicking here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://guillermoamaral.com/read/rpi-gpio-c-sysfs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Spot the defect</title>
		<link>https://guillermoamaral.com/read/spot-the-defect-01/</link>
		<comments>https://guillermoamaral.com/read/spot-the-defect-01/#comments</comments>
		<pubDate>Mon, 15 Oct 2012 01:35:09 +0000</pubDate>
		<dc:creator><![CDATA[gamaral]]></dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Quicky]]></category>
		<category><![CDATA[AVR]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Embedded]]></category>
		<category><![CDATA[Raspberry Pi]]></category>

		<guid isPermaLink="false">https://guillermoamaral.com/?p=327</guid>
		<description><![CDATA[<div><img width="150" height="150" src="/wp-content/uploads/2012/11/12110014-150x150.jpg" class="attachment-thumbnail wp-post-image" alt="Raspberry Pi - Power Button Assembly (Back)" style="margin-bottom: 15px;" /></div>Right after I finished soldering I noticed a flaw that made me bust out laughing, durp. Can you spot it? (it&#8217;s not the power jack, I ran out so I hacked something else in it&#8217;s place)]]></description>
				<content:encoded><![CDATA[<div><img width="150" height="150" src="/wp-content/uploads/2012/11/12110014-150x150.jpg" class="attachment-thumbnail wp-post-image" alt="Raspberry Pi - Power Button Assembly (Back)" style="margin-bottom: 15px;" /></div><p>Right after I finished soldering I noticed a flaw that made me bust out laughing, <strong>durp</strong>. Can you spot it?</p>

<p><center>
<a href="/wp-content/uploads/2012/10/12100016.jpg" rel="prettyphoto[327]"><img src="/wp-content/uploads/2012/10/12100016-300x168.jpg" alt="" title="12100016" width="300" height="168" class="aligncenter size-medium wp-image-328" /></a></p>

<p><a href="/wp-content/uploads/2012/10/12100015.jpg" rel="prettyphoto[327]"><img src="/wp-content/uploads/2012/10/12100015-300x168.jpg" alt="" title="12100015" width="300" height="168" class="aligncenter size-medium wp-image-329" /></a>
</center></p>

<p>(it&#8217;s not the power jack, I ran out so I hacked something else in it&#8217;s place)</p>
]]></content:encoded>
			<wfw:commentRss>https://guillermoamaral.com/read/spot-the-defect-01/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Marshmallow Raspberry Pi Power Button &#8211; PCB [PROTOTYPE]</title>
		<link>https://guillermoamaral.com/read/rpi-pwrbtn-pcb-r1/</link>
		<comments>https://guillermoamaral.com/read/rpi-pwrbtn-pcb-r1/#comments</comments>
		<pubDate>Mon, 08 Oct 2012 03:38:33 +0000</pubDate>
		<dc:creator><![CDATA[gamaral]]></dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Quicky]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Embedded]]></category>
		<category><![CDATA[Make]]></category>
		<category><![CDATA[Marshmallow]]></category>
		<category><![CDATA[OSH]]></category>

		<guid isPermaLink="false">https://guillermoamaral.com/?p=317</guid>
		<description><![CDATA[<div><img width="150" height="150" src="/wp-content/uploads/2012/11/12110013-150x150.jpg" class="attachment-thumbnail wp-post-image" alt="Raspberry Pi - Power Button Assembly (Front)" style="margin-bottom: 15px;" /></div>First demo PCB board, single-side with 3 jumpers. It&#8217;s freshly exposed and ready for drilling. I used a copper board I had laying around, it was a bit scuffed so excuse the pockmarks. I&#8217;ll expose the double-sided version later this week, after I hit the electronics store. The rpi-pwrbtn repository on GitHub includes the double sided board schem and the MCU code: https://github.com/gamaral/rpi-pwrbtn]]></description>
				<content:encoded><![CDATA[<div><img width="150" height="150" src="/wp-content/uploads/2012/11/12110013-150x150.jpg" class="attachment-thumbnail wp-post-image" alt="Raspberry Pi - Power Button Assembly (Front)" style="margin-bottom: 15px;" /></div><p>First demo PCB board, single-side with 3 jumpers. It&#8217;s freshly exposed and ready for drilling. I used a copper board I had laying around, it was a bit scuffed so excuse the pockmarks.</p>

<p><center><a href="/wp-content/uploads/2012/10/IMG_2172.jpg" rel="prettyphoto[317]"><img src="/wp-content/uploads/2012/10/IMG_2172-300x200.jpg" alt="" title="RPI-PWRBTN PCB" width="300" height="200" class="aligncenter size-medium wp-image-318" /></a></center></p>

<p>I&#8217;ll expose the double-sided version later this week, after I hit the electronics store.</p>

<p>The <em>rpi-pwrbtn</em> repository on GitHub includes the double sided board schem and the MCU code: <a href="https://github.com/gamaral/rpi-pwrbtn">https://github.com/gamaral/rpi-pwrbtn</a></p>
]]></content:encoded>
			<wfw:commentRss>https://guillermoamaral.com/read/rpi-pwrbtn-pcb-r1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
