<?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>Bald Wisdom</title>
	<atom:link href="http://baldwisdom.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://baldwisdom.com</link>
	<description>Seeking wisdom and fun!</description>
	<lastBuildDate>Thu, 17 May 2012 18:32:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Interfacing Scratch to the Arduino Platform</title>
		<link>http://baldwisdom.com/itchyduino/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=itchyduino</link>
		<comments>http://baldwisdom.com/itchyduino/#comments</comments>
		<pubDate>Thu, 17 May 2012 02:45:34 +0000</pubDate>
		<dc:creator>Kevin Osborn</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[projects]]></category>

		<guid isPermaLink="false">http://baldwisdom.com/?p=622</guid>
		<description><![CDATA[I&#8217;m a big fan of Scratch, the educational programming language created at MIT. International Scratch Day is coming up, and when we went two years ago, we had a blast. Last time, I added a distance sensor to an Arduino, made it emulate a Scratch Sensor Board, and  put it under a trampolene. This year, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a big fan of <a title="Scratch website" href="http://scratch.mit.edu/" target="_blank">Scratch</a>, the educational programming language created at MIT. <a title="Scratch Day!" href="http://day.scratch.mit.edu/" target="_blank">International Scratch Day</a> is coming up, and when we went two years ago, we had a blast. Last time, I added a distance sensor to an Arduino, made it emulate a Scratch Sensor Board, and  put it under a trampolene. This year, I decided to document the general process of making your own scratch sensors and bring a compact sensor module for the kids to play with.</p>
<p><a href="https://lh6.googleusercontent.com/-HajSlrBCkf8/T4SPKX2D4JI/AAAAAAAAIEY/avuTRsJkl-8/s454/IMAG0416.jpg"><img class="alignnone" title="ItchyDuino -- scratch sensor module" src="https://lh6.googleusercontent.com/-HajSlrBCkf8/T4SPKX2D4JI/AAAAAAAAIEY/avuTRsJkl-8/s454/IMAG0416.jpg" alt="" width="272" height="233" /></a></p>
<p>At one point during our research at work, we needed a way to measure the movement and relative distance of a camera platform, so I designed, and my tech put together a combination of a <a title="Teensy website" href="http://www.pjrc.com/teensy/" target="_blank">Teensy </a>(Arduino Compatible microcontroller), an <a title="accelerometer product page" href="https://www.adafruit.com/products/163" target="_blank">Adafruit ADXL335 Accelerometer breakout</a>, and a <a title="Adafruit product page" href="https://www.adafruit.com/products/164" target="_blank">Sharp IR distance sensor.</a></p>
<p>I dug up my old code for the trampolene hack, which was based on some code I got off the Scratch forums. It didn&#8217;t work!</p>
<p>What we are actually doing is emulating what was originally called a &#8220;Scratchboard&#8221; and now produced by a company called the Playful invention company and called a <a href="http://www.picocricket.com/picoboard.html" target="_blank">&#8220;PicoBoard&#8221;</a>.</p>
<p>There&#8217;s a spec (and schematics) at <a href="http://info.scratch.mit.edu/sites/infoscratch.media.mit.edu/files/file/ScratchBoard_Tech_InfoR2.pdf">http://info.scratch.mit.edu/sites/infoscratch.media.mit.edu/files/file/ScratchBoard_Tech_InfoR2.pdf</a></p>
<p>Turns out, the platform used to be more forgiving, and now it expects a report of all the sensors (whether we are using them or not.)</p>
<p>The IR distance Sensor outputs an analog voltage proportional to the distance to the nearest thing in it&#8217;s path, and likewise the accelerometer outputs a voltage proportional to the acceleration (including gravity). I mapped the distance sensor to the &#8220;slider&#8221; sensor, and the X, Y and Z outputs to the Resistance A, B and C sensors.</p>
<p>Here&#8217;s a demo video:</p>
<p><a href="http://www.youtube.com/watch?v=wVa8QUz5DxI"><img src="http://img.youtube.com/vi/wVa8QUz5DxI/2.jpg"></a></p>
<p><a href="http://www.youtube.com/watch?v=wVa8QUz5DxI">Click here</a> to view the video on YouTube.</p>

<p>I&#8217;m planning on re-working the interface code into an Arduino Library, and I&#8217;ll post that here when I get it done.</p>
<p>In the meantime here&#8217;s the Arduino code:</p>
<pre>// Scratchboard emulation
// by Kevin Osborn
// http://baldwisdom.com
// Feel free to use this code in any way you wish! (Though if you want to link
// to my blog, that would be cool)
// The Scratchmote has a sharp ir distance sensor
// and a 3 axis accellerometer

#define DISTSENSE A0
#define ACCELX    A1
#define ACCELY    A2
#define ACCELZ    A3

#define TESTMODE  0

// Format output for ScratchBoard emulation
// sensor=0-7, value=0-1023 (rescaled by Scratch to 0-100)
// 0="A", 1="B", 2="C", 3="D",
// 4="Slider", 5="Light", 6="Sound", 7="Button"
void ScratchBoardSensorReport(int sensor, int value)
{
  Serial.write( B10000000
                 | ((sensor &amp; B1111)&lt;&gt;7) &amp; B111));
  delayMicroseconds(400);
  Serial.write( value &amp; B1111111);
}
int flatx,flaty,flatz; // might be used to set midpoint
int maxX,minX; //testing purposes
int lastx,lasty,lastz;

void setup()
{
  pinMode(DISTSENSE, INPUT);
  pinMode(ACCELX,INPUT);
  pinMode(ACCELY,INPUT);
  pinMode(ACCELZ,INPUT);

  lastx =maxX= minX = flatx=analogRead(ACCELX);
  lasty = flaty=analogRead(ACCELY);
  lastz = flatz=analogRead(ACCELZ);

  Serial.begin(38400);
}

void loop()
{
  int distance = abs(map(analogRead(DISTSENSE),0,650,0,1023)-1023);
  //experimenting with the ADXL335 gives us readings between low single digits
  // and &lt; 700 for human powered movements   int x = map(analogRead(ACCELX),0,700,0,1023);   int y = map(analogRead(ACCELY),0,700,0,1023);   int z = map(analogRead(ACCELZ),0,700,0,1023);      int rx = (x +lastx)/2;   int ry = (y +lasty)/2;   int rz = (z +lastz)/2;      lastx = rx;   lasty = ry;   lastz = rz; #if TESTMODE Serial.println(distance); /* Serial.print("x,y,z= "); Serial.print(x);Serial.print(","); Serial.print(y);Serial.print(","); Serial.println(z); */ if (x &gt; maxX) maxX=x;
if (x&lt; minX) minX=x;
Serial.print("maxX = ");Serial.println(maxX);
Serial.print("minX = ");Serial.println(minX);
delay(500);

#else
if (Serial.available())
{
  if (Serial.read() == 0x01){
  ScratchBoardSensorReport(0,rx);
  ScratchBoardSensorReport(1,ry);
  ScratchBoardSensorReport(2,rz);
  ScratchBoardSensorReport(3,0);
  ScratchBoardSensorReport(4,distance);
  ScratchBoardSensorReport(5,0);
  ScratchBoardSensorReport(6,0);
  ScratchBoardSensorReport(7,0);
  }
 //ScratchBoardSensorReport(1,analogRead(POT2));
 // ScratchBoardSensorReport(7,digitalRead(BUTTON1)?0:1023);
  delay(30);
}
#endif

}</pre>
<p>The Scratch examples are on the scratch site:</p>
<ul>
<li>Accelerometer demo: <a href="http://scratch.mit.edu/projects/osbock/2542866" target="_blank">http://scratch.mit.edu/projects/osbock/2542866</a></li>
<li>Distance sensor theremin: <a href="http://scratch.mit.edu/projects/osbock/2542860" target="_blank">http://scratch.mit.edu/projects/osbock/2542860</a></li>
</ul>
<p>Note you can&#8217;t play them directly from the site, as you need the sensors!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://baldwisdom.com/itchyduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Soldering Tips from Dorkbot PDX&#8217;s Scott Dixon</title>
		<link>http://baldwisdom.com/soldering-tips-from-dorkbot-pdxs-scott-dixon/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=soldering-tips-from-dorkbot-pdxs-scott-dixon</link>
		<comments>http://baldwisdom.com/soldering-tips-from-dorkbot-pdxs-scott-dixon/#comments</comments>
		<pubDate>Mon, 07 May 2012 13:36:27 +0000</pubDate>
		<dc:creator>Kevin Osborn</dc:creator>
				<category><![CDATA[electronics]]></category>

		<guid isPermaLink="false">http://baldwisdom.com/?p=601</guid>
		<description><![CDATA[I love google+ it often exposes me to really amazing people and projects. Even better, sometimes when you comment, people are very generous with their help. I recently saw a post on Dangerous Prototypes blog about a group build of one of their the Bus Pirate V4. They laid out the parts and did two [...]]]></description>
			<content:encoded><![CDATA[<p>I love google+ it often exposes me to really amazing people and projects. Even better, sometimes when you comment, people are very generous with their help. I recently saw a <a title="Original story" href="http://dangerousprototypes.com/2012/05/01/bus-pirate-v4-build-workshop-update/" target="_blank">post on Dangerous Prototypes</a> blog about a group build of one of their the Bus Pirate V4. They laid out the parts and did two shifts to build 30 copies of the board.</p>
<div></div>
<div><img class="alignnone" title="Dorkbot group build" src="http://farm8.staticflickr.com/7229/7082675543_7e6ec5aa36_z.jpg" alt="" width="512" height="288" /></div>
<div></div>
<div></div>
<p>It was done at<a href="http://dorkbotpdx.org/" target="_blank"> Dorkbot PDX</a> (People Doing Strange Things with Electricity in Portland Oregon), and I noticed that they were using a<a title="Instructable..." href="http://www.instructables.com/id/Closing-the-Loop-on-Surface-Mount-Soldering/" target="_blank"> really cool PID controlled hotplate</a> for surfacemount soldering, using a hacked Harbor Freight IR thermometer, and an optimized for the task Arduino clone.</p>
<p>I commented (Google +) on one of the pictures taken by Scott Dixon, one of the organizers, and developers of the soldering system with some questions.  The conversation that ensued was very informative and I wanted to share it with you:</p>
<p>Kevin: I&#8217;m newish to SMD, but I&#8217;m finding in some ways it&#8217;s easier than through hole. No more trying to get things flat, etc.</p>
<p>Scott: Definitely.  Also no turning the board over all the time to solder the leads, etc&#8230;</p>
<p>Kevin: Someone showed me how to use a toaster oven, but a lot of folks I know use the hotplate. Is one better than another?</p>
<p>Scott: For boards with parts primarily on one side, the hot plate is simpler and works fine.  I haven&#8217;t used a toaster oven but I hear some models work quite well particularly when you want to reflow both sides at once.  That was one of the reasons I put the thermocouple interface on the board but so far we haven&#8217;t used it for that.  Also, some day I might try sous vide.</p>
<p>Kevin: I recently built my first all SMD board. I did it by hand, with a little guidance from an experienced technician. Is there a time when it&#8217;s better to use one technique or the other?</p>
<p>There is an interesting cross over point between hand soldering and hot plate reflow depending on the complexity of the board (and how good you are at hand soldering).  As an experiment, three of us hand soldered the Bus Pirate.  We all have pretty good equipment, including stereo microscopes and we are all pretty good at hand soldering (although nowhere in the league of a tech who does it all the time).  It took each of us about 2 hours to do the BPV4 by hand.  By comparison, the first time we did the BP on the hotplate it took about 45-50 minutes or so (including getting the parts off the reels, etc).  We had a solder paste stencil so that made it somewhat faster.  So for something with that many parts it was over twice as long to hand solder.  A simpler project would be closer and a really simple project would be faster by hand, compared to setting up the hotplate and cleaning the stencil, etc.  If you don&#8217;t have a stencil and have to put the solder paste on by hand, that is somewhat slower.</p>
<p>I guess the only other thing I&#8217;d add is that we have done a number of SMD workshops and training sessions and our success rate for people walking out with a working project is often 100% and never very much below that.  So I would encourage people to give it a try.  It is almost certainly easier than you think.  It helps if you can find a workshop or class the first time but you can certainly learn on your own.</p>
<div>
<p>It doesn&#8217;t take that much specialized equipment:  Some moderate magnification (3X or so,  like reading glasses or a hands free magnifying glass) and a good pair of fine point anti-magnetic tweezers.  Maybe a 10X or so magnifier for inspection.  If you don&#8217;t want to spring for a temperature controlled hot plate or toaster oven, you can certainly make do by manually controlling the heat.  Having a temperature control system does reduce the stress though and decrease the likelihood that you will overcook some parts.</p>
<p>And, at least at first, I&#8217;d recommend using professionally produced PC boards with solder mask.  That helps to control the solder and minimizes solder bridges.  DorkbotPDX is a great place to get <a title="dorkbot pcb order info" href="http://dorkbotpdx.org/wiki/pcb_order" target="_blank">high quality inexpensive PC boards made</a>!</p>
<p>Oh, and one more thing:  If you are putting solder paste on by hand (without a stencil) you will almost certainly err on the side of depositing way too much paste.  Think about the fact that a stencil only leaves a solder paste layer a few mils thick and how little paste that actually is.</p>
<div>
<p id=":1tw" data-tooltip="Show trimmed content"><img src="https://mail.google.com/mail/images/cleardot.gif" alt="" /></p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://baldwisdom.com/soldering-tips-from-dorkbot-pdxs-scott-dixon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ahoy! Bus Pirating GPS</title>
		<link>http://baldwisdom.com/ahoy-bus-pirating-gps/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ahoy-bus-pirating-gps</link>
		<comments>http://baldwisdom.com/ahoy-bus-pirating-gps/#comments</comments>
		<pubDate>Fri, 04 May 2012 03:59:03 +0000</pubDate>
		<dc:creator>Kevin Osborn</dc:creator>
				<category><![CDATA[electronics]]></category>
		<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://baldwisdom.com/?p=577</guid>
		<description><![CDATA[As a new member of Wyolum.com, I&#8217;ve been pitching in on their (our?) I2GPS project (Now available for pre-order!). Wyolum has a terrific LED array board, originally intended to build word clocks, but Justin and others have also built a large format digital clock/timer display out of several of these boards, and the Super Accurate [...]]]></description>
			<content:encoded><![CDATA[<p>As a new member of Wyolum.com, I&#8217;ve been pitching in on their (our?) I2GPS project (<a title="Preorder I2GPS!" href="http://wyolum.com/shop/20-i2gps.html" target="_blank">Now available for pre-order!</a>).</p>
<p><img class="alignnone" title="i2gps" src="http://www.briankrontz.com/Product/ClockThree/i-9RvvctZ/0/M/0H0C9638-1-M.jpg" alt="" width="600" height="400" /></p>
<p>Wyolum has a terrific LED array board, originally intended to build <a title="Clock3 Jr." href="http://wyolum.com/shop/14-clockthreejr-diy-kit.html" target="_blank">word clocks</a>, but Justin and others have also built a large format digital clock/timer display out of several of these boards, and the Super Accurate GPS clock will make it a terrific Race Clock.</p>
<p>I wanted to test out some GPS modules from an Asian source, and I felt that whatever Arduino code I had time to write was bound to be incomplete, so I decided to use the manufacturer&#8217;s PC progam.</p>
<p>We&#8217;re using the Fastrax UPS501, and the software is called Fastrax Workbench. The UPS501 is a terrific module, very sensitive (gets a good fix and tracks 9-10 satellites from within my house!) The reason Justin and Anool picked it, though, is that it has a 1 PPS output. This one Pulse Per Second can be used to get <a title="GPS disciplined RTC" href="http://wyolum.com/?p=795" target="_blank">microsecond accuracy by lining this up with the GPS time as well</a>.</p>
<p>Although it&#8217;s trivial, I thought I&#8217;d share how I used <a href="http://dangerousprototypes.com/docs/Bus_Pirate" target="_blank">Dangerous Prototype&#8217;s Bus Pirate</a> to hook up the GPS module to a PC for testing.</p>
<p>Since the UP501 GPS module communicates via TTL Serial, I wanted to use the Bus Pirate in &#8220;Transparent UART Bridge&#8221; mode.</p>
<p><img class="alignnone" title="bus pirate hookup." src="https://lh5.googleusercontent.com/-Br8kVS600Us/T6CnqqpyRiI/AAAAAAAAIxQ/rhqQR91TvYI/s800/IMAG0520.jpg" alt="" width="480" height="287" /></p>
<p>I used this pinout chart to determine what was needed: <a href="http://dangerousprototypes.com/docs/Common_Bus_Pirate_cable_pinouts">http://dangerousprototypes.com/docs/Common_Bus_Pirate_cable_pinouts</a></p>
<ul>
<li>Pin 1 is RXD on the GPS and this goes to TXD on the Bus Pirate: Grey wire or MOSI</li>
<li>Pin 2 is TXD on the GPS and this goes to RXD on the Bus Pirate:  Black wire or MISO</li>
<li>Pin 3 is GND on the GPS to GND on the Bus Pirate:  Brown Wire</li>
<li>Pin 5 and 6 are power and backup power, hook both those up to 3.3v Red wire on Bus Pirate</li>
</ul>
<div>The bus pirate talks at 115200 baud. connect with your favorite terminal program (I&#8217;m using Teraterm Pro). Here&#8217;s the transcript of the commands to set it up (the semicolon and the comment following are not to be typed)</div>
<pre>HiZ&gt;m    ; Mode
1. HiZ
2. 1-WIRE
3. UART
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. LCD
x. exit(without change)</pre>
<pre>(1)&gt;3     ;UART
Set serial port speed: (bps)  
 1. 300
 2. 1200
 3. 2400
 4. 4800
 5. 9600            ; Default baud for the GPS
 6. 19200
 7. 38400
 8. 57600
 9. 115200
10. BRG raw value</pre>
<pre>(1)&gt;5      ;9600
Data bits and parity:
 1. 8, NONE *default
 2. 8, EVEN
 3. 8, ODD
 4. 9, NONE
(1)&gt;      ;default - 1-8-none
Stop bits:
 1. 1 *default
 2. 2
(1)&gt;              ; default 1
Receive polarity:
 1. Idle 1 *default
 2. Idle 0
(1)&gt;           ;default 1
Select output type:
 1. Open drain (H=Hi-Z, L=GND)
 2. Normal (H=3.3V, L=GND)</pre>
<pre>(1)&gt;2      ;Normal
Ready
UART&gt;W          ; Turn on the power supplies
POWER SUPPLIES ON
UART&gt;(1)    ; Select the transparent UART Bridge. If you forget this, you can type (0) for the options
UART bridge
Reset to exit
Are you sure? Y</pre>
<p><strong>Then it will start spitting out NMEA sentences</strong></p>
<pre>$GPGGA,235957.037,,,,,0,0,,,M,,M,,*43
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,00*79</pre>
<p>Exit the program and fire up FastTrax Workbench. The only tricky part here is to select the correct baud rate. Since the Bus Pirate talks to the host at 115200 Baud, and the GPS at 9600 baud, we use 115200.</p>
<p><a href="http://baldwisdom.com/ahoy-bus-pirating-gps/justin-gps/" rel="attachment wp-att-586"><img class="alignnone  wp-image-586" title="Fastrax Workbench" src="http://baldwisdom.com/wp-content/uploads/2012/05/justin-gps-1024x531.jpg" alt="" width="614" height="319" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://baldwisdom.com/ahoy-bus-pirating-gps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debut of the DuckyBots!</title>
		<link>http://baldwisdom.com/debut-of-the-duckybots/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=debut-of-the-duckybots</link>
		<comments>http://baldwisdom.com/debut-of-the-duckybots/#comments</comments>
		<pubDate>Sat, 28 Apr 2012 20:22:34 +0000</pubDate>
		<dc:creator>Kevin Osborn</dc:creator>
				<category><![CDATA[electronics]]></category>
		<category><![CDATA[FamilyFun]]></category>
		<category><![CDATA[projects]]></category>

		<guid isPermaLink="false">http://baldwisdom.com/?p=548</guid>
		<description><![CDATA[Charlotte, Mason and I hopped into Cambridge last Friday for the Mini Maker Faire at the Cambridge Science Festival. They helped me set up a table to introduce DuckyBots! to the attendees. We had probably close to 500 kids (and a few adults) making ducky bots in the 4 hours of the Faire, and almost [...]]]></description>
			<content:encoded><![CDATA[<p>Charlotte, Mason and I hopped into Cambridge last Friday for the Mini Maker Faire at the Cambridge Science Festival. They helped me set up a table to introduce DuckyBots! to the attendees. We had probably close to 500 kids (and a few adults) making ducky bots in the 4 hours of the Faire, and almost got into trouble because people didn&#8217;t want to stop. We were the last ones to shut down. An unqualified success! (more details after the picture)</p>
<div class="wp-caption alignnone" style="width: 470px"><a href="http://makerfairecambridge.wordpress.com/"><img title="maker faire cambridge" src="http://makerfairecambridge.files.wordpress.com/2012/04/dsc_0056.jpg?w=460" alt="" width="460" height="691" /></a><p class="wp-caption-text">Photo by Chris Conners</p></div>
<p>The idea for duckybots started from a conversation at the Boston Robotics Meetup with Meredith Garniss.  In addition to trying to involve kids in robotics, we thought it would be good to inspire the adult robotics crew to create for kids.</p>
<p>Programs like FIRST robotics, and school programs are already full of people interested in STEM and robotics, and we wanted to find something that would turn kids on to the joys of Science and Engineering.</p>
<p>The basic idea is to use turning rubber ducks into robots as a platform for experimentation, creativity and learning.<br />
We thought we could apply this at many ages and levels. Really young kids can exercise their creativity by decorating ducks (drawing, gluing on.)</p>
<p>The middle level would concentrate on mechanical physics, making ducks move, maybe racing (but also have to offer non-competitive challenges for kids scared of  competition.)</p>
<p>To keep the ideas coming in, we can also have an advanced level, perhaps Sumo ducks (on water!)</p>
<p>For their first appearance, I needed an activity that could be be done by hundreds of kids in a short period of time, so I focused on &#8220;making them Move&#8221;</p>
<p><img class="alignnone" title="Getting Wet" src="https://lh3.googleusercontent.com/-n79ExVhALW0/T5GyfSzr2XI/AAAAAAAAIV0/rOedpoKcYLA/s553/IMAG0465.jpg" alt="" width="553" height="331" /></p>
<p>Rather than presenting them with a blank slate, I put together some modules that represent different propulsion types.</p>
<p>I created a fan unit from a toy motor, a AA battery box (with switch) and a fan propeller sold as a spare for snap circuits.</p>
<p><a href="http://baldwisdom.com/wp-content/uploads/2012/04/motive-unit.jpg"><img class="alignnone size-full wp-image-566" title="motive unit" src="http://baldwisdom.com/wp-content/uploads/2012/04/motive-unit.jpg" alt="" width="640" height="514" /></a></p>
<p>I also had some playmobil underwater motors, and lots of Duck(!) tape (especially yellow).</p>
<p>As kids strapped on the motors, and found the ducks tipping over,  presenting an engineering challenge! I also had some closed cell foam (from packing materials) that they could use for floats, and outriggers.</p>
<p>There was lots of inventing, trying, doing things &#8220;wrong&#8221; (turns out those air fans work fine underwater!)</p>
<p>I was thinking that this was a good test to see if I should spend any more time on this, and I think the answer is yes!</p>
<p>These ducks have legs!</p>
<div class="wp-caption alignnone" style="width: 469px"><a href="http://makerfairecambridge.wordpress.com/"><img title="duckybots" src="http://makerfairecambridge.files.wordpress.com/2012/04/dsc_0060.jpg?w=460" alt="" width="459" height="305" /></a><p class="wp-caption-text">Photo by Chris Conners</p></div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://baldwisdom.com/debut-of-the-duckybots/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>April Fools</title>
		<link>http://baldwisdom.com/april-fools/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=april-fools</link>
		<comments>http://baldwisdom.com/april-fools/#comments</comments>
		<pubDate>Sun, 01 Apr 2012 21:53:57 +0000</pubDate>
		<dc:creator>Kevin Osborn</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[pranks]]></category>

		<guid isPermaLink="false">http://baldwisdom.com/?p=514</guid>
		<description><![CDATA[About a week ago, Sparkfun posted a great prank in their weekly new product video. As April 1 was coming up, and I thought the kids would enjoy it, I ordered the bits that I didn&#8217;t have, and managed to pull it off.  Sparkfun didn&#8217;t give many details, so I thought I&#8217;d share my implementation.First [...]]]></description>
			<content:encoded><![CDATA[<p>About a week ago, <a href="http://www.sparkfun.com/">Sparkfun </a>posted a <a href="http://www.sparkfun.com/news/832">great prank</a> in their weekly new product video. As April 1 was coming up, and I thought the kids would enjoy it, I ordered the bits that I didn&#8217;t have, and managed to pull it off.  Sparkfun didn&#8217;t give many details, so I thought I&#8217;d share my implementation.First here&#8217;s a video showing my wife getting pranked. She was a super good sport, (even not minding posting a video of her in her bathrobe!)</p>
<p>NOTE: Someone on google+ pointed out that at 8 amps, these horns could seriously heat up the li-po, and a hot li-po is not a good thing (fires/explosions!) so do this at your own risk. I only pulse the horns for 1 second at a time (twice per activation) so the battery never gets hot, but if you had a programming error, and it was stuck on, look out! Another good reason for the cutout switch and testing without the horns connected.</p>
<p><a href="http://www.youtube.com/watch?v=Hn6xDEUDoMw"><img src="http://img.youtube.com/vi/Hn6xDEUDoMw/2.jpg"></a></p>
<p><a href="http://www.youtube.com/watch?v=Hn6xDEUDoMw">Click here</a> to view the video on YouTube.</p>

<p>Here&#8217;s what you&#8217;ll need for this prank:</p>
<ol>
<li>Arduino</li>
<li>Accelerometer: I used <a href="http://shop.moderndevice.com/products/mma7260qt-3-axis-accelerometer">this one from ModernDevices</a></li>
<li><a href="http://www.sparkfun.com/products/11042">Digitally controlled relay</a>. I used the same one they used in the Sparkfun prank</li>
<li><a href="http://www.sparkfun.com/products/10966">The Horns</a>!</li>
<li><a href="http://www.sparkfun.com/products/10470">A (nearly) 12V lightweight battery</a>. Sparkfun has this nice 1500 MAH 11.1 LIPO for a good price</li>
<li><a href="http://www.sparkfun.com/products/10473">A compatible charger. Sparkfun recommends the IMAX B6</a> This can also be found on Amazon</li>
<li>Wires, connectors, a good way to connect all the parts together</li>
</ol>
<p><a href="https://lh3.googleusercontent.com/-UvtgorZbUIs/T3dMOTfepOI/AAAAAAAAH10/DUYwLly7s2g/s1152/IMAG0379.jpg"><img class="alignnone" src="https://lh3.googleusercontent.com/-UvtgorZbUIs/T3dMOTfepOI/AAAAAAAAH10/DUYwLly7s2g/s1152/IMAG0379.jpg" alt="" width="415" height="248" /></a>.</p>
<p>Here I wired the battery to power the Arduino, one leg of power went directly to both horns, and the other switched through the relay. I also put a toggle switch inline  with the power to the horns so I could shut off the horns for testing (The relay has an led and also clicks, so you can tell if it&#8217;s operating).</p>
<p><a href="https://lh3.googleusercontent.com/-JsHJ0CvkEdo/T3dMTnOxE8I/AAAAAAAAH18/QW9RCSUxLnI/s720/IMAG0380.jpg"><img class="alignnone" src="https://lh3.googleusercontent.com/-JsHJ0CvkEdo/T3dMTnOxE8I/AAAAAAAAH18/QW9RCSUxLnI/s720/IMAG0380.jpg" alt="" width="431" height="720" /></a></p>
<p>I had a proto-screw-shield on hand which was convenient for hooking up both the accelerometer and connecting to the relays.</p>
<p><a href="https://lh4.googleusercontent.com/-TQLdSO5uJqc/T3dM9NQkgBI/AAAAAAAAH2Q/cSa8U1h30Nc/s720/IMAG0382.jpg"><img class="alignnone" src="https://lh4.googleusercontent.com/-TQLdSO5uJqc/T3dM9NQkgBI/AAAAAAAAH2Q/cSa8U1h30Nc/s720/IMAG0382.jpg" alt="" width="431" height="720" /></a></p>
<p>Here it&#8217;s almost all hooked up. The relay connections are made to the analog side of the arduino to simplify wire routing. (Both 5V ground and io pins together.)</p>
<p>I use the button and LED on the protoshield to arm the device and indicate it&#8217;s status.</p>
<p><a href="https://lh6.googleusercontent.com/-GnhBX002pkM/T3djgo788OI/AAAAAAAAH24/TNjQoE3zBmE/s1152/IMAG0383.jpg"><img class="alignnone" src="https://lh6.googleusercontent.com/-GnhBX002pkM/T3djgo788OI/AAAAAAAAH24/TNjQoE3zBmE/s1152/IMAG0383.jpg" alt="" width="691" height="413" /></a></p>
<p>The bolts on the horns were too short to go through 1/4 &#8221; plywood, so I used the supplied mounting plates to offset mount the horns.</p>
<p><a href="https://lh4.googleusercontent.com/-aBKTQxz-Tj8/T3hLRMvPr8I/AAAAAAAAH5I/GjlXcr-qfhY/s1152/IMAG0390.jpg"><img class="alignnone" src="https://lh4.googleusercontent.com/-aBKTQxz-Tj8/T3hLRMvPr8I/AAAAAAAAH5I/GjlXcr-qfhY/s1152/IMAG0390.jpg" alt="" width="691" height="413" /></a></p>
<p>Here it is all put together.  Here&#8217;s the <a href="http://baldwisdom.com/data/fudge.ino">Arduino sketch</a>, but I recommend you try to program this yourself!</p>
]]></content:encoded>
			<wfw:commentRss>http://baldwisdom.com/april-fools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adafruit Fingerprint Reader on the PC</title>
		<link>http://baldwisdom.com/adafruit-fingerprint-reader-on-the-pc/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=adafruit-fingerprint-reader-on-the-pc</link>
		<comments>http://baldwisdom.com/adafruit-fingerprint-reader-on-the-pc/#comments</comments>
		<pubDate>Tue, 27 Mar 2012 03:47:15 +0000</pubDate>
		<dc:creator>Kevin Osborn</dc:creator>
				<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://baldwisdom.com/?p=502</guid>
		<description><![CDATA[I just got my Adafruit Fingerprint sensor for a project at work, and it&#8217;s super cool! I&#8217;m planning on writing a python library/command line utility for its use with a PC. I&#8217;ve got it hooked up to an adafruit FTDI breakout. The wiring (labels) are reversed from the Arduino, so while the tutorial says to wire [...]]]></description>
			<content:encoded><![CDATA[<p>I just got my <a href="http://www.adafruit.com/products/751">Adafruit Fingerprint sensor</a> for a project at work, and it&#8217;s super cool!<br />
I&#8217;m planning on writing a python library/command line utility for its use with a PC.<br />
I&#8217;ve got it hooked up to an <a href="http://www.adafruit.com/products/284">adafruit FTDI breakout</a>. The wiring (labels) are reversed from the Arduino, so while the tutorial says to wire white to Digital Pin 0 (labeled RX) it actually goes to TX on the breakout, and green goes to RX.</p>
<p><img class="alignnone" title="Hookup of fingerprint reader" src="https://lh6.googleusercontent.com/-gntrrrmoik0/T3CqoYp4tHI/AAAAAAAAHyo/UBPFoZTw7kw/w570-h341-k/IMAG0376.jpg" alt="" width="570" height="341" /></p>
<p>The one other gotcha, was windows assigned something like com28 to the FTDI breakout, and the windows test program only goes to com16. You can fix this in the device manager, by opening up the appropriate port, go to port settings,advanced, and change the COM Port Number. Then you can assign it a lower number (it would only let me use 1 and 2, as I think the rest were taken up by various Arduinos I&#8217;ve plugged in!)<br />
Fire up the demo program, and you&#8217;re cooking with gas! I&#8217;ll be updating as I develop the code.</p>
<p><a href="http://baldwisdom.com/wp-content/uploads/2012/03/changing-comm-port.png"><img class="alignnone size-large wp-image-503" title="changing comm port" src="http://baldwisdom.com/wp-content/uploads/2012/03/changing-comm-port-1024x469.png" alt="" width="1024" height="469" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://baldwisdom.com/adafruit-fingerprint-reader-on-the-pc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>We Interrupt our regular programming&#8230;.</title>
		<link>http://baldwisdom.com/we-interrupt-our-regular-programming/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=we-interrupt-our-regular-programming</link>
		<comments>http://baldwisdom.com/we-interrupt-our-regular-programming/#comments</comments>
		<pubDate>Fri, 23 Mar 2012 20:40:49 +0000</pubDate>
		<dc:creator>Kevin Osborn</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://baldwisdom.com/?p=486</guid>
		<description><![CDATA[I made an attempt to improve the SoftwareSerial library to make it possible to use Pin Change Interrupts in conjunction. I made some progress, but it&#8217;s not working yet. I&#8217;ll share what I&#8217;ve learned, and spell out a simple (though Kludgy) workaround. &#160; Implementing asynchronous serial without hardware isn&#8217;t an easy task, and the Software [...]]]></description>
			<content:encoded><![CDATA[<div>I made an attempt to improve the SoftwareSerial library to make it possible to use Pin Change Interrupts in conjunction. I made some progress, but it&#8217;s not working yet. I&#8217;ll share what I&#8217;ve learned, and spell out a simple (though Kludgy) workaround.</div>
<p>&nbsp;</p>
<div>Implementing asynchronous serial without hardware isn&#8217;t an easy task, and the Software Serial library is a pretty cool hack. It takes processor resources to implement that protocol though, especially with any speed, and as always there&#8217;s often competition for resources.</div>
<p>&nbsp;</p>
<div>The limitations of Software Serial are widely discussed in various Arduino forums, and there are alternatives such as  Paul Stoffregen&#8217;s <a href="http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html" target="_blank">AltSoftSerial</a> which looks very promising but comes with it&#8217;s own set of tradeoffs (it uses one of the timer&#8217;s so disables PWM on some of the pins)</div>
<p>&nbsp;</p>
<div>The limitations of SoftSerial that comes with the Arduino IDE appear to be 2:</div>
<div>
<ol>
<li>Interrupts are disabled during transmit so you can&#8217;t transmit and receive at the same time, and it may cause you to miss other interrupts. (Paul&#8217;s library deals with this)</li>
<li>It uses Pin Change interrupts in such a way as to eliminate their use for anything else.</li>
</ol>
</div>
<p>&nbsp;</p>
<div>It  is this second limitation that my friend <a href="http://wyolum.com" target="_blank">Justin Shaw of Wyolum labs</a> and I were discussing, and I thought I&#8217;d take a look to see if it could be remedied.</div>
<p>&nbsp;</p>
<div> There&#8217;s one pin change interrupt vector per port (and a mask register as well)</div>
<div>That means if you are using more than one pin from a port for pinchange interrupts, the interrupt handler for that port has to determine what to do.</div>
<div></div>
<div>Interrupts are covered in many fine pages on the web, so I won&#8217;t go into details here, but there are two kinds on the arduino:</div>
<div>1. Dedicated external interrupts &#8211; tied to pin 2 and 3 each with their own interrupt vector.</div>
<div>2. Pin Change Interrupts &#8211; allow&#8217;s you to use any IO pin. There are registers to tell which pin(s) you want to watch in each port, and a vector for each set of IO pins (Ports) on an Atmega 328, there are three: Port B, C and D.</div>
<p>&nbsp;</p>
<div>There are libraries (such as PinChangeInt.h) that handle setting up these handlers, but SoftwareSerial doesn&#8217;t use them. It has it&#8217;s own interrupt handling routine, and uses the Interrupt service vectors in a very selfish way. It points all the port interrupt vectors to it&#8217;s own routine, even if it&#8217;s only using a couple of pins from a single port.</div>
<p>&nbsp;</p>
<div>The code below from SoftwareSerial.cpp sets the interrupt handler for all the ports that are defined (by processor type)</div>
<div>PCINT0 is for Port B (PB0-PB7)</div>
<div>PCINT1 is for Port C (PC0-PC6)</div>
<div>PCINT2 is for Port D (PD0-PD7)</div>
<div>PCINT3 isn&#8217;t defined for atmega328p</div>
<pre>#if defined(PCINT0_vect)</pre>
<pre>ISR(PCINT0_vect)</pre>
<pre>{</pre>
<pre>  SoftwareSerial::handle_<wbr>interrupt();</wbr></pre>
<pre>}</pre>
<pre>#endif</pre>
<pre>#if defined(PCINT1_vect)</pre>
<pre>ISR(PCINT1_vect)</pre>
<pre>{</pre>
<pre>  SoftwareSerial::handle_<wbr>interrupt();</wbr></pre>
<pre>}</pre>
<pre>#endif</pre>
<pre>#if defined(PCINT2_vect)</pre>
<pre>ISR(PCINT2_vect)</pre>
<pre>{</pre>
<pre>  SoftwareSerial::handle_<wbr>interrupt();</wbr></pre>
<pre>}</pre>
<pre>#endif</pre>
<pre>#if defined(PCINT3_vect)</pre>
<pre>ISR(PCINT3_vect)</pre>
<pre>{</pre>
<pre>  SoftwareSerial::handle_<wbr>interrupt();</wbr></pre>
<pre>}</pre>
<pre>#endif</pre>
<p>&nbsp;</p>
<div>So, if you are using PB5 as a softserial rx,</div>
<div>you could comment out the code for PCINT1-PCINT3.</div>
<div>If you are using the PinChangeInt.h library, you&#8217;d also want to add:</div>
<pre><span style="font-family: 'courier new', monospace;"> #define NO_PORTB_PINCHANGES </span></pre>
<div><span style="font-family: arial, helvetica, sans-serif;">Ahead of your #include PinChangeInt.h</span></div>
<div><span style="font-family: arial, helvetica, sans-serif;">so it doesn&#8217;t try to hook the vector softserial is using.</span></div>
<div><span style="font-family: arial, helvetica, sans-serif;"><br />
</span></div>
]]></content:encoded>
			<wfw:commentRss>http://baldwisdom.com/we-interrupt-our-regular-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LCDBootDrive: Selectable Files!</title>
		<link>http://baldwisdom.com/lcdbootdrive-selectable-files/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=lcdbootdrive-selectable-files</link>
		<comments>http://baldwisdom.com/lcdbootdrive-selectable-files/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 05:15:17 +0000</pubDate>
		<dc:creator>Kevin Osborn</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[BootDrive]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://baldwisdom.com/?p=460</guid>
		<description><![CDATA[I added a LCD User Interface to my bootdrive project. Learn how to hook it up, and select the files you want to load onto your Arduino without a PC!]]></description>
			<content:encoded><![CDATA[<h2>New toy (o-o-o)</h2>
<p>After I showed the BootDrive on the Adafruit Show and Tell, I watched their weekly &#8220;Ask an Engineer&#8221; show where they showcased a new product, an <a href="http://www.adafruit.com/products/714" target="_blank">LCD shield with an RGB backlight</a>. The really cool thing is that the LCD AND 5 buttons only need 2 IO pins on the Arduino, because the shield is designed with an I2C expander. I ordered it the next day (close to 5pm) selected UPS ground shipping and it was at my house the next day!</p>
<p><img class="alignnone" title="LCD Bootdrive" src="https://lh5.googleusercontent.com/-3Kk4Uw9YJxU/T1WcwciQS8I/AAAAAAAAHWs/XNSVJwuxypI/s1033/IMAG0288.jpg" alt="" width="502" height="301" /></p>
<p>Here&#8217;s a quick video before I go through the blow-by-blow:</p>
<p><a href="http://www.youtube.com/watch?v=w5jPm3thkWo"><img src="http://img.youtube.com/vi/w5jPm3thkWo/2.jpg"></a></p>
<p><a href="http://www.youtube.com/watch?v=w5jPm3thkWo">Click here</a> to view the video on YouTube.</p>

<p>I soldered the <a href="http://www.adafruit.com/products/254" target="_blank">micro-sd breakout</a> onto an <a href="http://www.adafruit.com/products/51" target="_blank">Adafruit SD Shield</a>, and a 6 pin right angle header to connect an FTDI cable. Adafruit also had a <a href="http://www.adafruit.com/products/206" target="_blank">pre-made 6pin-6pin female cable</a> that was perfect for this project!</p>
<p><img class="alignnone" title="BootDrive Shield: Proto-edition" src="https://lh3.googleusercontent.com/-d1Enw4dP44w/T0awOd9DwmI/AAAAAAAAHKA/CaVGCgGBCGM/s1600/IMAG0259.jpg" alt="" width="493" height="295" /></p>
<p>I wired it with fine wire-wrap wire on the bottom</p>
<p><img class="alignnone" title="Wiring" src="https://lh6.googleusercontent.com/-SgQehXQrkyw/T0m5BE24BYI/AAAAAAAAHL0/B6kqp1Oy-94/s1600/IMAG0262.jpg" alt="" width="512" height="306" /></p>
<p>The wiring is almost identical to the original BootDrive, except I changed the reset pin assignment:</p>
<p>Digital Pin5  –&gt; FTDI Pin 6 (CTS)<br />
GND                –&gt; FTDI Pin 1 (GND)<br />
Digital Pin1 (RX) –&gt;FTDI Pin 4 (TX)<br />
Digital Pin2 (TX)–&gt;FTDI Pin 5 (RX)</p>
<p><strong>SD Card Interface:<br />
</strong>Digital Pin 10 –&gt; SD-breakout CS<br />
Digital Pin 11  –&gt;  SD breakout DI<br />
Digital Pin 12  –&gt; SD breakout DO<br />
Digital Pin 13  –&gt; SD breakout CLK<br />
GND                    –&gt; SD breakout GND<br />
5V                       –&gt; SD breakout 5V</p>
<h2>Debugging</h2>
<p>I incorporated the directory listing code from the SD library examples, and instead of listing all the files, I did an openNextFile() each time the &#8220;down&#8221; button was pressed. It would be nice to be able to scroll up and down, but I&#8217;m pretty tight on memory as it is, so I didn&#8217;t want to cache the directory, or do some kludgy re-reading the whole directory to get to the file we are on.</p>
<p>The first problem I ran into was it worked fine until you scrolled through what turned out to be 25 names (actually the same 3 names 8+ times) and then it started repeating the same name over and over. When I realized it was always 25, I knew it wasn&#8217;t some overflow, and I finally figured out the example code had a bug in it! They list the directory by opening each file (with openNextFile() to get the name, but they never close it! If you try the listfiles example with more than 25 files on the card, you&#8217;ll see only the first 25. Easy enough to fix, as I&#8217;m scrolling I close the file after I get it&#8217;s name. I reopen it if you press the &#8220;select&#8221; or program button.</p>
<p>The next problem was a bit harder. The hex programs seemed to work on some boards but not others, even though there were apparently no errors. I created new test programs and suddenly they didn&#8217;t work either. Since the writing to flash seemed to be working, I figured that there must be some corruption of data. I read back the programmed AVR code from the target arduino (with avrdude  &lt;programmer parameters&#8230;.&gt; -U f:r:readfile.hex:i) and compared it with the file I was sending to be programmed. It turns out I was advancing to the next &#8220;line&#8221; of 16 bytes even when I read less. Files that ended in shorter lines were getting placed ahead of where they needed to be and so the program was corrupt. Probably on some, the data that was already there was harmless, or the program didn&#8217;t actually execute that part of it&#8217;s memory, but in some cases it clearly was. Fixed, putback to github!</p>
<p>Have fun and let me know if you try it!</p>
<p><a title="Source code" href="https://github.com/osbock/Baldwisdom/tree/master/LCDBootDrive" target="_blank">https://github.com/osbock/Baldwisdom/tree/master/LCDBootDrive</a></p>
]]></content:encoded>
			<wfw:commentRss>http://baldwisdom.com/lcdbootdrive-selectable-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Precious Memory</title>
		<link>http://baldwisdom.com/precious-memory/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=precious-memory</link>
		<comments>http://baldwisdom.com/precious-memory/#comments</comments>
		<pubDate>Fri, 24 Feb 2012 17:12:37 +0000</pubDate>
		<dc:creator>Kevin Osborn</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://baldwisdom.com/?p=443</guid>
		<description><![CDATA[There are two kinds of memory(well three including EEPROM, but we won&#8217;t deal with that here) you can run out of when doing an Arduino project (or any embedded project): Flash Memory: For a lot of applications, the Arduino has a fairly big flash memory (the UNO and all atmega328 based Arduinos give you 32k [...]]]></description>
			<content:encoded><![CDATA[<p>There are two kinds of memory(well three including EEPROM, but we won&#8217;t deal with that here) you can run out of when doing an Arduino project (or any embedded project):</p>
<ol>
<li>Flash Memory: For a lot of applications, the Arduino has a fairly big flash memory (the UNO and all atmega328 based Arduinos give you 32k flash.) The Arduino IDE will also tell you if your program size exceeds the amount of flash in the particular Arduino you have selected.</li>
<li>Static RAM: Atmega328 in the UNO gives you 2k of RAM. This is the most precious commodity in Arduino programming, and it&#8217;s often surprising how fast you can run out. The bad thing is,  the IDE won&#8217;t warn you, and your program can go from working to behaving really weirdly by doing something as simple as adding an additional debug print statement. This post will attempt to explain this, and give you a few tips for understanding your RAM use.</li>
</ol>
<p><strong>Where Did it All Go?<br />
</strong>When you run out of SRAM, your program can just stop working, for reasons ranging from one data structure overwriting another (so your program does something based on the wrong value) to overflowing into the stack. When that happens, generally, your program dies a horrible death, because returning from subroutines can cause the processor to jump to random places in memory. If you make an innocuous change to your code (like adding another debug statement) and your program suddenly behaves very differently, chances are you have run out of SRAM.</p>
<p>It&#8217;s obvious if you declare large variable arrays like:</p>
<blockquote>
<pre>int valueArray[1024];</pre>
</blockquote>
<p>would instantly overflow memory because int&#8217;s occupy 2 bytes in atmega land. You also need to leave room for stack, and any other variables your libraries, and the Arduino software itself uses.</p>
<p><strong>What&#8217;s Harvard got to do with it?<br />
</strong>Not so obvious is the fact that:</p>
<blockquote>
<pre>Serial.println("Hello");
const char constantString[] = {"Hello"};</pre>
</blockquote>
<p>both  occupy 6 bytes in both flash memory and in SRAM (c-strings are terminated with a Null, or 0&#215;00 byte).  The reason is AVR 8 bit microcontrollers use a <a href="http://en.wikipedia.org/wiki/Harvard_architecture" target="_blank">Harvard architecture </a>addressing scheme. This means that when an instruction addresses memory, there are two versions, one that addresses program memory (flash), and another to address RAM. Most routines like Serial.println use regular RAM, as they don&#8217;t know if you&#8217;ll be passing in constant info or stuff that you&#8217;ve constructed. As a result, even static strings (with a const declaration) are copied from flash to SRAM at system startup. It&#8217;s possible to write routines to only use flash (using the PROGMEM attribute) and it&#8217;s definitely useful, but that&#8217;s covered <a href="http://arduino.cc/en/Reference/PROGMEM" target="_blank">elsewhere</a>.</p>
<p>I ran into this porting the avrdude stk500 routines to Arduino, blindly converting the printfs into Serial.print statements. In order to get enough RAM I ended up using numeric codes for errors (I&#8217;ll probably eventually get around to PROGMEM-ing them).</p>
<p>So, how do you tell if you are nearly running out, or have already? The IDE won&#8217;t tell you, so you have to dig in a little.</p>
<p>The build process for arduino produces an <a href="http://en.wikipedia.org/wiki/ELF_file_format" target="_blank">&#8220;ELF&#8221; file</a> or Executable and Linkable File. This is used to create the actual HEX file for programming, but still has memory segment information embedded in it.</p>
<p>First find your build directory. On Windows 7 this is \users\&lt;youruser&gt;\AppData\Temp\build&lt;a bunch of numbers&gt;.tmp</p>
<p>Now, assuming you have the avrdude files somewhere in your path, use the command:</p>
<pre>avr-size -C --mcu=atmega328p &lt;yourelf-file.elf&gt;</pre>
<p>For example, the current version of Bootdrive gives me:</p>
<blockquote>
<pre>avr-size -C --mcu=atmega328p BootDrive.cpp.elf
 AVR Memory Usage
 ----------------
 Device: atmega328p</pre>
<pre>Program: 19272 bytes (58.8% Full)
 (.text + .data + .bootloader)</pre>
<pre>Data: 1340 bytes (65.4% Full)
 (.data + .bss + .noinit)</pre>
</blockquote>
<p>It&#8217;s probably best not to go beyond 95% full for your Data (that&#8217;s the SRAM part) to save room for your stack, and even less if you pass big variables on the stack or have deep call chains.</p>
]]></content:encoded>
			<wfw:commentRss>http://baldwisdom.com/precious-memory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BootDrive for Arduino</title>
		<link>http://baldwisdom.com/bootdrive/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=bootdrive</link>
		<comments>http://baldwisdom.com/bootdrive/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 03:21:30 +0000</pubDate>
		<dc:creator>Kevin Osborn</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[BootDrive]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://baldwisdom.com/?p=411</guid>
		<description><![CDATA[Announcing the formal release of BootDrive for Arduino. If you&#8217;ve been reading the blog, you know that I&#8217;ve been working with Justin Shaw of Wyolum labs to enable their I2SD (Arduino clone with a micro-sd card) to bootload a program onto another Arduino. After battling several issues, mostly related to porting avrdude code to the [...]]]></description>
			<content:encoded><![CDATA[<p>Announcing the formal release of<a title="github link for source code" href="https://github.com/osbock/Baldwisdom/tree/master/BootDrive" target="_blank"> BootDrive for Arduino</a>. If you&#8217;ve been reading the blog, you know that I&#8217;ve been working with Justin Shaw of <a href="http://wyolum.com" target="_blank">Wyolum labs </a>to enable their I2SD (Arduino clone with a micro-sd card) to bootload a program onto another Arduino. After battling several issues, mostly related to porting avrdude code to the Arduino (assumptions about infinite memory, etc!) it&#8217;s working well enough people can fool around with it.</p>
<p>Right now the code looks for a single file (&#8220;program.hex&#8221;) and waits 5 sec and then blasts it into the target arduino. Details about setting up to try this yourself follow the video.</p>
<p>Here&#8217;s a demo of it in action:</p>
<p><a href="http://www.youtube.com/watch?v=i4wJ4kRO80E"><img src="http://img.youtube.com/vi/i4wJ4kRO80E/2.jpg"></a></p>
<p><a href="http://www.youtube.com/watch?v=i4wJ4kRO80E">Click here</a> to view the video on YouTube.</p>

<p>If you&#8217;d like to try this with a couple of Arduinos, you&#8217;ll also need an SD card (or micro-sd) interface such as the <a title="Adafruit Micro-sd breakout" href="http://www.adafruit.com/products/254" target="_blank">Adafruit Micro-SD breakout</a>. This board is great because it has onboard 3.3v conversion so it&#8217;s safe to use with 5V (stock) Arduinos. Download the code from github: https://github.com/osbock/Baldwisdom/tree/master/BootDrive<br />
or<a href="https://github.com/osbock/Baldwisdom/raw/master/releases/BootDrive1.0.zip" target="_blank"> a zipped version here</a></p>
<p>Hook up your Arduinos like this:</p>
<p><a href="http://baldwisdom.com/wp-content/uploads/2012/02/bootdrive.jpg"><img class="alignnone size-full wp-image-422" title="BootDrive Connection diagram" src="http://baldwisdom.com/wp-content/uploads/2012/02/bootdrive.jpg" alt="" width="520" height="425" /></a>I</p>
<p>The basic setup is:</p>
<p><strong>Arduino Control:</strong><br />
Master Digital Pin6  &#8211;&gt; Target reset<br />
GND                                &#8211;&gt; GND<br />
MASTER Digital Pin1 &#8211;&gt;Target Digital Pin2<br />
MASTER Digital Pin2 &#8211;&gt;Target Digital Pin3</p>
<p><strong>SD Card Interface:<br />
</strong> Master Digital Pin 10 &#8211;&gt; SD-breakout CS<br />
Master Digital Pin 11  &#8211;&gt;  SD breakout DI<br />
Master Digital Pin 12  &#8211;&gt; SD breakout DO<br />
Master Digital Pin 13  &#8211;&gt; SD breakout CLK<br />
Master GND                    &#8211;&gt; SD breakout GND<br />
Master 5V                       &#8211;&gt; SD breakout 5V</p>
<p><strong>Optional debugging serial interface </strong>(This lets you see error messages and the like)<strong><br />
</strong>Master GND    &#8211;&gt; FTDI cable Pin 1 (GND)<br />
Master Digital Pin 4 &#8211;&gt; FTDI cable Pin 5 (diagram is wrong, but you can change it in the code if you need to)</p>
<p>Here are the defines you can change to swap the pins around:</p>
<p>#define BOOT_BAUD 115200 // This is the Arduino UNO&#8217;s bootloader baud rate. Other boards are different!<br />
#define DEBUG_BAUD 19200 // for software serial debugging<br />
#define txPin 4<br />
#define rxPin 5 // not really used&#8230;<br />
#define rstPin 6</p>
<p>Also if you want to put your SD card on a different line (or are using a shield that uses a different chip select) change this:</p>
<p>const int chipSelect = 10;</p>
<p><strong>Action!</strong></p>
<p>Right now, 5 seconds after initialization, the program blasts a file called &#8220;program.hex&#8221;. You can add your own user interface to select amongst multiple programs.<br />
Just call:</p>
<pre>void programArduino(char *filename)</pre>
<p>with the filename, e.g.&#8221;</p>
<pre>programArduino("program2.hex");</pre>
<p>You can build new hex files by grabbing them from the Arduino build directory. Make sure you have the IDE set up for your target board and press the &#8220;compile/verify&#8221; button.</p>
<p>From <a href="http://arduino.cc/en/Hacking/BuildProcess">http://arduino.cc/en/Hacking/BuildProcess</a>:</p>
<blockquote><p>The .hex file is the final output of the compilation which is then uploaded to the board. During a &#8220;Verify&#8221; the .hex file is written to /tmp (on Mac and Linux) or \Documents and Settings\&lt;USER&gt;\Local Settings\Temp (on Windows). During upload, it&#8217;s written to the applet sub-directory of the sketch directory (which you can open with the &#8220;Show Sketch Folder&#8221; item in the Sketch menu)</p></blockquote>
<p>Note on Windows7, the base directory is \users\&lt;USER&gt; \appdata\local\Temp\build&lt;some bunch of numbers&gt;.tmp\&lt;sketchname&gt;.cpp.hex</p>
<p>Note that if you want to load an Arduino other than UNO, you&#8217;ll need to change the baud rate. You can find that in &#8220;hardware/arduino/boards.txt&#8221; in the arduino directory. This won&#8217;t work on MEGA based Arduinos as they use the stk500v2 protocol (thanks westfw!)</p>
]]></content:encoded>
			<wfw:commentRss>http://baldwisdom.com/bootdrive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

