<?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>gizmologi.st</title>
	<atom:link href="http://gizmologi.st/feed/" rel="self" type="application/rss+xml" />
	<link>http://gizmologi.st</link>
	<description>Notes and tutorials on open source electronics and robotics.</description>
	<lastBuildDate>Tue, 10 Nov 2009 05:48:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>First Numitron Clock Prototype</title>
		<link>http://gizmologi.st/2009/11/first-numitron-clock-prototype/</link>
		<comments>http://gizmologi.st/2009/11/first-numitron-clock-prototype/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 05:46:16 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://gizmologi.st/?p=95</guid>
		<description><![CDATA[
For a few months now, I&#8217;ve been toying with the idea of taking my experience in accelerometer-enabled nixie clock construction (see Mercury Retrograde) and leveraging it into the design of a high-quality kit.  This meant jumping into the world of PCB design and manufacturing, which up until two months ago, was completely alien to [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://gizmologi.st/wordpress/wp-content/uploads/2009/11/iv9_1.jpg" alt="IV-9 Prototype" title="IV-9 Prototype" width="290" height="218" class="alignleft size-full wp-image-96 bordered" /></p>
<p>For a few months now, I&#8217;ve been toying with the idea of taking my experience in accelerometer-enabled nixie clock construction (see <a href="http://voisen.org/electronics/2009/mercury_retrograde/">Mercury Retrograde</a>) and leveraging it into the design of a high-quality kit.  This meant jumping into the world of PCB design and manufacturing, which up until two months ago, was completely alien to me.  So, to get started I designed a very simple numitron-based clock using IV-9 numitrons and had the board made using Sparkfun&#8217;s <a href="http://batchpcb.com">BatchPCB</a> board service.  Above is a photo of the final product.</p>
<p>BatchPCB has proven to be a wonderful and cost-effective service.  I highly recommend it if you&#8217;re only prototyping one or two boards and don&#8217;t mind waiting a little longer for your order (the site quotes an average 3-4 week delivery time, but my first order arrived in 12 days).</p>
<p>I&#8217;ve already submitted a completely revised prototype board to BatchPCB that may be a candidate for the first clock kits.  More details to follow, but suffice it to say that the clock kit will be as nice as I can manage for a first-time product.  I&#8217;m spending as much time thinking about the case (milled aluminum, acrylic and hardwood) as I am about the circuit itself.</p>
]]></content:encoded>
			<wfw:commentRss>http://gizmologi.st/2009/11/first-numitron-clock-prototype/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>C328R Camera Library: Version 003</title>
		<link>http://gizmologi.st/2009/11/c328r-camera-library-version-003/</link>
		<comments>http://gizmologi.st/2009/11/c328r-camera-library-version-003/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 07:07:58 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Announcements]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[c328r]]></category>
		<category><![CDATA[camera]]></category>

		<guid isPermaLink="false">http://gizmologi.st/?p=90</guid>
		<description><![CDATA[I finally got around to posting an updated version of the C328R camera library. The new version is a minor update that now adds checksums to ensure no data is corrupted when transferring JPEGs from the camera. I&#8217;ve never encountered any data corruption in the past with this camera, and thus never added the feature, [...]]]></description>
			<content:encoded><![CDATA[<p>I finally got around to posting an updated version of the <a href="http://gizmologi.st/code/c328r-camera-library/">C328R camera library.</a> The new version is a minor update that now adds checksums to ensure no data is corrupted when transferring JPEGs from the camera. I&#8217;ve never encountered any data corruption in the past with this camera, and thus never added the feature, but it&#8217;s definitely a welcome addition. The update is courtesy of a patch submitted by <a href="http://jarv.org">John Jarvis,</a> as featured in his very nice <a href="http://jarv.org/sdcam.shtml">geotagger project.</a> Thanks John!</p>
]]></content:encoded>
			<wfw:commentRss>http://gizmologi.st/2009/11/c328r-camera-library-version-003/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;Numitrons&#8221; and the Arduino</title>
		<link>http://gizmologi.st/2009/08/arduino-numitron/</link>
		<comments>http://gizmologi.st/2009/08/arduino-numitron/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 21:19:08 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Experiments]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[numitron]]></category>

		<guid isPermaLink="false">http://gizmologi.st/?p=73</guid>
		<description><![CDATA[
I have this peculiar fascination with obsolete display technologies like nixies and numitrons; they emanate a warm, inviting glow, they have a bit of heft, you can physically see how they work, and they&#8217;re nicely encased in glass. It&#8217;s little wonder, then, that my first &#8220;real&#8221; electronics project was a nixie clock. Nixies are fantastic [...]]]></description>
			<content:encoded><![CDATA[<div class="bordered"><object width="608" height="342"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=6304142&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=cc0000&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=6304142&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=cc0000&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="608" height="342"></embed></object></div>
<p>I have this peculiar fascination with obsolete display technologies like nixies and numitrons; they emanate a warm, inviting glow, they have a bit of heft, you can physically see how they work, and they&#8217;re nicely encased in glass. It&#8217;s little wonder, then, that my first &#8220;real&#8221; electronics project was a <a href="http://voisen.org/electronics/2009/mercury_retrograde/">nixie clock</a>. Nixies are fantastic eye candy, but they are also somewhat of a hassle to work with because they require a high-voltage power supply (180V) and something like the long-outdated TTL &#8220;power pig&#8221; 74141 to drive their respective cathodes.  Recently, however, I got a hold of a bunch of Russian IV-9 &#8220;Numitrons&#8221; for additional, cheaper, clock projects &mdash; an easier-to-use display technology that doubles as a nice Nixie alternative. I use &#8220;Numitron&#8221; in quotes because the word Numitron is originally a trademarked name of RCA, the originator of Numitron technology (circa 1970), and what I have are cheap Russian knock-offs of the real thing. (Real RCA Numitrons currently cost about $10 a piece on eBay, whereas the IV-9 can be purchased in bulk for less than $1 per unit.)</p>
<p>If you&#8217;re at all familiar with common anode 7-segment LED displays, then working with like a Numitron shouldn&#8217;t prove too difficult. In fact, the procedure is pretty much the same &mdash; just substitute each individual LED in a 7-segment LED with a glowing filament (like an incandescent bulb) and you have a Numitron. And because they use a glowing filament, unlike LEDs, Numitrons do not require a current-limiting resistor on each cathode.</p>
<p>I read &mdash; somewhere &mdash; that the recommended max voltage for IV-9s is 4.2V. Standard Arduinos run at 5V, but a simple 1N4001 diode in series with the Numitron anode gives the exact 0.8V drop needed to achieve 4.2V.</p>
<p>In the video above I use an Allegro A6278 serial-parallel LED driver to drive each of the individual cathodes. Shift registers like these are a great way to conserve I/O pins on the Arduino (I always give out A6278s at my &#8220;Intro to Arduino&#8221; workshops) and they are not at all difficult to use, even for the beginner. <a href="http://www.arduino.cc/en/Tutorial/ShiftOut">This tutorial</a>, which uses the popular 74HC595 will get you up and running with shift registers if you&#8217;ve never used them before. (Pay particular attention to the <code>shiftOut()</code> function provided in the code samples.) The A6278 works almost identically to the 74HC595, with the exception of an REXT pin on the A6278 that requires an external resistor for setting the desired current for the outputs. The beauty of this feature, however, is that for LED applications you need only 1 external resistor instead of the normal 7 (1 per cathode) you&#8217;d need with the 74HC595! A 900&#8486; resistor on the REXT pin, for instance, will give you a 20mA output on each output pin, exactly what you&#8217;d need for a red LED display.</p>
<p>IV-9s are readily available on eBay, so if this is a display technology that tickles your fancy, try picking up a few to hack around with on your next project.</p>
]]></content:encoded>
			<wfw:commentRss>http://gizmologi.st/2009/08/arduino-numitron/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Intro to Arduino Workshop: August 8, 2009</title>
		<link>http://gizmologi.st/2009/07/arduino-workshop/</link>
		<comments>http://gizmologi.st/2009/07/arduino-workshop/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 18:51:54 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Announcements]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[workshops]]></category>

		<guid isPermaLink="false">http://gizmologi.st/?p=49</guid>
		<description><![CDATA[NOTE: Registration for this event is now closed.
The first-ever Gizmologi.st workshop &#8212; Intro to Arduino: Electronics for Artists, Tinkerers, Inventors and Hackers &#8212; will be taking place on August 8, 2009 at San Diego State University.
Come join us on this all-day hacking session. This will be a great workshop for beginners to the DIY electronics [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>NOTE: Registration for this event is now closed.</strong></em></p>
<p>The first-ever Gizmologi.st workshop &mdash; Intro to Arduino: Electronics for Artists, Tinkerers, Inventors and Hackers &mdash; will be taking place on August 8, 2009 at San Diego State University.</p>
<div id="attachment_57" class="wp-caption alignleft" style="width: 250px"><img src="http://gizmologi.st/wordpress/wp-content/uploads/2009/07/3567630129_a050053bc0_m.jpg" alt="Photo by Todbot" title="Arduino Todbot Snapshot" width="240" height="180" class="bordered size-full wp-image-57" /><p class="wp-caption-text">Photo by Todbot</p></div>
<p><strong>Come join us on this all-day hacking session.</strong> This will be a great workshop for beginners to the DIY electronics world of microcontrollers, as well as for altruistic &#8220;old hands&#8221; looking to show off their skills and help the newcomers. If you&#8217;ve ever dreamed of building your own robot, UAV, home automation system, digital clock, synthesizer, portable gaming system, etc., but aren&#8217;t quite sure how to get started, then this is the workshop for you.</p>
<h3>What You&#8217;ll Learn</h3>
<p>We&#8217;ll cover as much as possible from the list below:</p>
<ul>
<li><strong><a href="http://www.arduino.cc">Arduino</a> basics:</strong> Getting up and running, basic Arduino programming, blinking an LED</li>
<li><strong>Beginning digital circuits:</strong> Using shift registers to control 7-segment LED displays and multiple LEDs simultaneously</li>
<li><strong>Sensor basics:</strong> Reading and acting on digital and analog sensors, including buttons, photocells, thermistors and maybe some more sophisticated sensors like ultrasonic range finders or heartrate monitors</li>
<li><strong>Communicating with PCs:</strong> Fundamentals of Arduino serial communication</li>
<li><strong>Controlling motors:</strong> Using relays to control motors and/or solenoids</li>
</ul>
<p><span id="more-49"></span></p>
<h3>Date/Time/Location/Cost</h3>
<ul>
<li><strong>Date:</strong> Saturday, August 8, 2009</li>
<li><strong>Time:</strong> 10AM to 5PM (or longer as desired/necessary)</li>
<li><strong>Location:</strong> SDSU Engineering Building, Room 300A</li>
<li><strong>Cost:</strong> $60.00 materials fee. (Includes Arduino Duemilanove, wiring, sensors, resistors, motors, LEDs, etc. that you get to keep. If you have your own Arduino, bring it for a $25 fee reduction.) Please bring cash or checks payable to &#8220;Sean Voisen.&#8221; This is a non-profit event. The cost is for the materials only.</li>
<li><strong>Parking:</strong> SDSU has a $1.00/hour parking fee. You may wish to take the trolley or bus to avoid paying for parking.</li>
</ul>
<h3>What to Bring</h3>
<ul>
<li>A laptop running Windows, Mac OS X or Linux</li>
<li>An A-B USB cable (the kind you usually find on a USB printer)</li>
<li>A positive, can-do attitude</li>
</ul>
<h3>RSVP</h3>
<p>Space is limited to 20 participants. Register by July 24, 2009.</p>
<p><em><strong>NOTE: Registration for this event is now closed.</strong></em></p>
]]></content:encoded>
			<wfw:commentRss>http://gizmologi.st/2009/07/arduino-workshop/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Taking Pictures with Arduino</title>
		<link>http://gizmologi.st/2009/04/taking-pictures-with-arduino/</link>
		<comments>http://gizmologi.st/2009/04/taking-pictures-with-arduino/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 21:10:18 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[camera]]></category>
		<category><![CDATA[photography]]></category>
		<category><![CDATA[processing]]></category>

		<guid isPermaLink="false">http://gizmologi.st/?p=5</guid>
		<description><![CDATA[Have you ever wanted to build your own wearable spy camera, UAV or other small, camera-enabled gizmo, gadget or device? While Arduino provides a wonderful prototyping platform for creating all sorts of DIY electronic gadgets, experimentations in physical computing, robotic artworks, and the like, it&#8217;s slim pickins&#8217; when it comes to finding a tiny, easy-to-use [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Have you ever wanted to build your own wearable spy camera, UAV or other small, camera-enabled gizmo, gadget or device?</strong> While <a href="http://www.arduino.cc">Arduino</a> provides a wonderful prototyping platform for creating all sorts of DIY electronic gadgets, experimentations in physical computing, robotic artworks, and the like, it&#8217;s slim pickins&#8217; when it comes to finding a tiny, easy-to-use digital camera to pair it up with. Fortunately, a company out of Hong Kong, <a href="http://www.comedia.com.hk/">COMedia Ltd.</a>, makes the <a href="http://www.electronics123.com/s.nl/sc.8/category.207684/.f">C328R</a>, a relatively small cell-phone style camera module that includes built-in JPEG image compression and UART serial communication. Couple the camera module with an Arduino and external storage (EEPROM, microSD, etc.) and you can have an instant Arduino-powered digital still image or video capture solution. That is to say, &#8220;instant,&#8221; once you have a working software driver &#8230; Fortunately for you, I&#8217;ve already done that work.</p>
<p>While working on a pigeon-based aerial photography solution as part of <a href="http://beatrizdacosta.net/pigeonblog.php">PigeonBlog</a> for <a href="http://beatrizdacosta.net">Beatriz da Costa</a>, I wrote <a href="http://gizmologi.st/downloads/c328r_arduino">a library</a> in C++ that allows the Arduino to communicate with the C328R camera over UART using the camera&#8217;s built-in communications protocol. Here&#8217;s a sample picture to prove that it works:</p>
<div id="attachment_14" class="wp-caption alignright" style="width: 310px"><img class="size-medium wp-image-14 bordered" title="Me, Taken with C328R Camera" src="http://gizmologi.st/wordpress/wp-content/uploads/2009/04/photo_5-300x225.jpg" alt="Sample C328R picture" width="300" height="225" /><p class="wp-caption-text">Sample C328R picture</p></div>
<p>The camera can take pictures in a variety of color depths (2- to 8-bit grayscale, 12- to 16-bit color, JPEG) and resolutions (80&#215;64 to 640&#215;480) with serial communication up to 115,200 baud. It&#8217;s fairly versatile and not terribly expensive (~$50) given the fact that it does a lot of work for you (i.e. on-board JPEG compression).</p>
<p>The rest of this post assumes that you have the camera and an Arduino Duemilanove (or similar) in hand. If you don&#8217;t, I suggest that you <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=666">get</a> <a href="http://www.electronics123.com/s.nl/sc.8/category.207684/.f">them</a>. You&#8217;re also going to need some type of external storage for the pictures, because the Arduino doesn&#8217;t provide any sufficient storage on-board. The sample code that follows assumes a <a href="http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&amp;name=AT25256A-10PU-2.7-ND">256KB Atmel SPI serial EEPROM</a> or similar SPI EEPROM.</p>
<p><span id="more-5"></span></p>
<h3>How to Use the Camera</h3>
<p>Using the C328R camera involves a fairly straightforward issuance of commands. After power on, you essentially just have to synchronize with the camera, tell it what size and color-depth you want your pictures to be, and optionally set the byte size of the data packets it will send back to you (default 64 bytes), light frequency to use, etc. It looks something like this, assuming you want a JPEG photo:</p>
<ol>
<li>Power on camera.</li>
<li>Issue &#8220;sync&#8221; command.</li>
<li>Issue &#8220;initial&#8221; command (tell the camera the desired color-depth, resolution, etc.).</li>
<li>Wait about 2 seconds for the camera to settle.</li>
<li>Issue &#8220;snapshot&#8221; command. This will tell the camera to take a snapshot and store it in its internal memory.</li>
<li>Issue &#8220;getPicture&#8221; command. The camera will then begin sending the JPEG image over serial in a series of data packets (default 64 bytes).</li>
<li>Take each data packet and store its image data sequentially in the EEPROM, until all image data has been retrieved. (A 640&#215;480 JPEG can be upwards of 20KB. At 64 bytes a packet, this would be 320 individual data packets per photo.)
</ol>
<p>All of these commands are issued over a proprietary serial communications protocol. The <a href="http://gizmologi.st/code/c328r-camera-library">C328R Arduino library</a> takes care of all of this behind the scenes, and reduces the complexity to nothing more than a series of function calls.</p>
<h3>Download the Library</h3>
<p>You can download the camera library <a href="http://gizmologi.st/code/c328r-camera-library">here.</a> Standard Arduino library installation instructions apply.</p>
<h3>Making the Connections</h3>
<p>The camera should be powered at 3.3V, with the TX (yellow wire) connected to the RX pin on the Arduino, and the RX (green wire) connected to the TX pin on the Arduino. The wiring that comes with the camera is thin and stranded, so you may want to solder on some headers for a more robust electrical connection, especially if you plan on using a breadboard.</p>
<p>The SPI EEPROM, assuming you&#8217;re using an Atmel SPI EEPROM or another SPI EEPROM with the same pin layout, should be connected per the instructions found <a href="http://www.arduino.cc/en/Tutorial/SPIEEPROM">here.</a></p>
<p>An LED, with appropriate resistor, should be connected to pin 8. This will be used as an indicator LED to let you know when the Arduino is done writing the picture to the EEPROM.</p>
<h3>Sample Code and Application</h3>
<p>The following sample code operates in two parts: The first part captures a picture with the camera, stores it on an external EEPROM at address 0, then powers off the camera. The second part sends the JPEG image data from the EEPROM to the computer over USB, allowing a simple program written in <a href="http://www.processing.org">Processing</a> to read the data and save it to disk for viewing.</p>
<p><strong>IMPORTANT NOTE:</strong> This sample code is designed primarily for testing and debugging purposes. Because the Arduino has only one hardware serial port, and the camera and computer (via USB) are both connected to that port, we use the indicator LED to notify us when the Arduino is done saving the data to the EEPROM and has powered off the camera. This way we know that any subsequent data being sent over serial is picture data that should be captured on the computer and saved to disk. By default, the code gives us 5 seconds to MANUALLY tell the Processing sketch to begin listening for and saving the serial data. You do this simply by pressing any key on the keyboard when the Processing sketch is running. After it is done reading the data, press any key again to write it to disk.</p>
<p>First up, the Arduino code. You will need to have the <a href="http://www.arduino.cc/playground/Code/Spi">SPI library</a> already installed. Save this as a sketch and upload it to your Arduino:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;CameraC328R.h&quot;</span>
<span style="color: #339933;">#include &quot;Spi.h&quot;</span>
&nbsp;
<span style="color: #339933;">#define LED_PIN 8</span>
<span style="color: #339933;">#define PAGE_SIZE 64</span>
<span style="color: #339933;">#define BAUD 38400</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// EEPROM Opcodes</span>
<span style="color: #339933;">#define WREN 6</span>
<span style="color: #339933;">#define WRDI 4</span>
<span style="color: #339933;">#define RDSR 5</span>
<span style="color: #339933;">#define WRSR 1</span>
<span style="color: #339933;">#define READ 3</span>
<span style="color: #339933;">#define WRITE 2</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Buffer for EEPROM data</span>
byte pageBuffer<span style="color: #009900;">&#91;</span>PAGE_SIZE<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
CameraC328R camera<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">static</span> uint16_t pictureSizeCount <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> uint16_t pageBufferIndex <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> uint16_t currentAddress <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
bool dirtyBuffer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Reads one byte from the EEPROM at the given address.
 */</span>
byte readByte<span style="color: #009900;">&#40;</span> uint16_t address <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  byte data<span style="color: #339933;">;</span>
&nbsp;
  digitalWrite<span style="color: #009900;">&#40;</span> SS_PIN<span style="color: #339933;">,</span> LOW <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Spi.<span style="color: #202020;">transfer</span><span style="color: #009900;">&#40;</span> READ <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Spi.<span style="color: #202020;">transfer</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>byte<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>address <span style="color: #339933;">&gt;&gt;</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Spi.<span style="color: #202020;">transfer</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>byte<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>address<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  data <span style="color: #339933;">=</span> Spi.<span style="color: #202020;">transfer</span><span style="color: #009900;">&#40;</span> <span style="color: #208080;">0xFF</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span> SS_PIN<span style="color: #339933;">,</span> HIGH <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> data<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Writes the data in the buffer to the EEPROM at the page
 * starting at the given address.
 */</span>
<span style="color: #993333;">void</span> writeBuffer<span style="color: #009900;">&#40;</span> uint16_t address<span style="color: #339933;">,</span> uint16_t bufferSize <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Write enable</span>
  digitalWrite<span style="color: #009900;">&#40;</span> SS_PIN<span style="color: #339933;">,</span> LOW <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Spi.<span style="color: #202020;">transfer</span><span style="color: #009900;">&#40;</span> WREN <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span> SS_PIN<span style="color: #339933;">,</span> HIGH <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  delay<span style="color: #009900;">&#40;</span> <span style="color: #0000dd;">10</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Begin write</span>
  digitalWrite<span style="color: #009900;">&#40;</span> SS_PIN<span style="color: #339933;">,</span> LOW <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Spi.<span style="color: #202020;">transfer</span><span style="color: #009900;">&#40;</span> WRITE <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Send the address</span>
  Spi.<span style="color: #202020;">transfer</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>byte<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>address<span style="color: #339933;">&gt;&gt;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// MSB</span>
  Spi.<span style="color: #202020;">transfer</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>byte<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>address<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// LSB</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Send the data</span>
  <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span> uint16_t i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> bufferSize<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    Spi.<span style="color: #202020;">transfer</span><span style="color: #009900;">&#40;</span> pageBuffer<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  digitalWrite<span style="color: #009900;">&#40;</span> SS_PIN<span style="color: #339933;">,</span> HIGH <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Fills the page buffer for the EEPROM with data.
 */</span>
<span style="color: #993333;">void</span> fillPageBuffer<span style="color: #009900;">&#40;</span> byte<span style="color: #339933;">*</span> data<span style="color: #339933;">,</span> uint16_t dataSize <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span> uint16_t i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> dataSize<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    pageBuffer<span style="color: #009900;">&#91;</span>pageBufferIndex<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> data<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    dirtyBuffer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    pageBufferIndex<span style="color: #339933;">++;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> pageBufferIndex <span style="color: #339933;">==</span> PAGE_SIZE <span style="color: #339933;">&amp;&amp;</span> dirtyBuffer <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      pageBufferIndex <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
      writeBuffer<span style="color: #009900;">&#40;</span> currentAddress<span style="color: #339933;">,</span> PAGE_SIZE <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      currentAddress <span style="color: #339933;">+=</span> PAGE_SIZE<span style="color: #339933;">;</span>
      dirtyBuffer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
      delay<span style="color: #009900;">&#40;</span> <span style="color: #0000dd;">50</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Sends a picture to the computer.
 */</span>
<span style="color: #993333;">void</span> transferPicture<span style="color: #009900;">&#40;</span> uint16_t startAddress<span style="color: #339933;">,</span> uint16_t size <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  uint16_t endAddress <span style="color: #339933;">=</span> startAddress <span style="color: #339933;">+</span> size<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span> uint16_t i <span style="color: #339933;">=</span> startAddress<span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> endAddress<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span> readByte<span style="color: #009900;">&#40;</span> i <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> BYTE <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * This callback is called EVERY time a JPEG data packet is received.
 */</span>
<span style="color: #993333;">void</span> getJPEGPicture_callback<span style="color: #009900;">&#40;</span> uint16_t pictureSize<span style="color: #339933;">,</span> uint16_t packageSize<span style="color: #339933;">,</span> uint16_t packageCount<span style="color: #339933;">,</span> byte<span style="color: #339933;">*</span> package <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// packageSize is the size of the picture part of the package</span>
  pictureSizeCount <span style="color: #339933;">+=</span> packageSize<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// package contains everything in the package</span>
  fillPageBuffer<span style="color: #009900;">&#40;</span> package<span style="color: #339933;">,</span> packageSize <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> pictureSizeCount <span style="color: #339933;">==</span> pictureSize <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Is there still stuff in the buffer?</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> dirtyBuffer <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      writeBuffer<span style="color: #009900;">&#40;</span> currentAddress<span style="color: #339933;">,</span> pageBufferIndex <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    camera.<span style="color: #202020;">powerOff</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    digitalWrite<span style="color: #009900;">&#40;</span> LED_PIN<span style="color: #339933;">,</span> HIGH <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// DONE!</span>
    Serial.<span style="color: #202020;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    delay<span style="color: #009900;">&#40;</span> <span style="color: #0000dd;">5000</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Give us 5 seconds to hit a key ...</span>
    transferPicture<span style="color: #009900;">&#40;</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> pictureSize <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span> BAUD <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span> SS_PIN<span style="color: #339933;">,</span> HIGH <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// disable device</span>
  pinMode<span style="color: #009900;">&#40;</span> LED_PIN<span style="color: #339933;">,</span> OUTPUT <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>camera.<span style="color: #202020;">sync</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Sync failed.&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>camera.<span style="color: #202020;">initial</span><span style="color: #009900;">&#40;</span> CameraC328R<span style="color: #339933;">::</span><span style="color: #202020;">CT_JPEG</span><span style="color: #339933;">,</span> CameraC328R<span style="color: #339933;">::</span><span style="color: #202020;">PR_160x120</span><span style="color: #339933;">,</span> CameraC328R<span style="color: #339933;">::</span><span style="color: #202020;">JR_640x480</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Initial failed.&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>camera.<span style="color: #202020;">setPackageSize</span><span style="color: #009900;">&#40;</span> <span style="color: #0000dd;">64</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Package size failed.&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>camera.<span style="color: #202020;">setLightFrequency</span><span style="color: #009900;">&#40;</span> CameraC328R<span style="color: #339933;">::</span><span style="color: #202020;">FT_50Hz</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Light frequency failed.&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Let camera settle, per manual</span>
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>camera.<span style="color: #202020;">snapshot</span><span style="color: #009900;">&#40;</span> CameraC328R<span style="color: #339933;">::</span><span style="color: #202020;">ST_COMPRESSED</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Snapshot failed.&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>camera.<span style="color: #202020;">getJPEGPicture</span><span style="color: #009900;">&#40;</span> CameraC328R<span style="color: #339933;">::</span><span style="color: #202020;">PT_JPEG</span><span style="color: #339933;">,</span> PROCESS_DELAY<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>getJPEGPicture_callback <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Get JPEG failed.&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Next up, the Processing code. This code doubles as a serial monitor, so you can run it as soon as you plug in the Arduino to USB, and ignore the built-in Arduino serial monitor. Again, note that you must hit a key within 5 seconds of the LED lighting up, and again once data is done reading to save it to disk. By default, it will be saved as a file called &#8220;photo.jpg&#8221; in the same folder as your Processing sketch.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">processing.serial.*</span><span style="color: #339933;">;</span>
&nbsp;
Serial myPort<span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> filename <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;photo.jpg&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> photo <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">Boolean</span> readData <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  println<span style="color: #009900;">&#40;</span> Serial.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  myPort <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Serial<span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">this</span>, Serial.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>, <span style="color: #cc66cc;">38400</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> buffer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">64</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> readData <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span> myPort.<span style="color: #006633;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">int</span> readBytes <span style="color: #339933;">=</span> myPort.<span style="color: #006633;">readBytes</span><span style="color: #009900;">&#40;</span> buffer <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      print<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Read &quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      print<span style="color: #009900;">&#40;</span> readBytes <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      println<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot; bytes ...&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> readBytes<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        photo <span style="color: #339933;">=</span> append<span style="color: #009900;">&#40;</span> photo, buffer<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span> myPort.<span style="color: #006633;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      print<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;COM Data: &quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      println<span style="color: #009900;">&#40;</span> myPort.<span style="color: #006633;">readString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> keyPressed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> photo.<span style="color: #006633;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    readData <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    print<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Writing to disk &quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    print<span style="color: #009900;">&#40;</span> photo.<span style="color: #006633;">length</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    println<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot; bytes ...&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    saveBytes<span style="color: #009900;">&#40;</span> filename, photo <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    println<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;DONE!&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    readData <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    myPort.<span style="color: #006633;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    println<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Waiting for data ...&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>That should be enough to get started.  The sample code above does not cover using the camera for RAW image capture, which is considerably faster and more useful as a solution for video (5 frames per second), but the library includes this functionality.</p>
<p>Feel free to post questions, comments or ideas below.</p>
]]></content:encoded>
			<wfw:commentRss>http://gizmologi.st/2009/04/taking-pictures-with-arduino/feed/</wfw:commentRss>
		<slash:comments>64</slash:comments>
		</item>
	</channel>
</rss>
