tag:blogger.com,1999:blog-81169038805679444232024-03-05T06:04:31.831-08:00Musings of a closet engineerHard whack- some projects just need a good one.Peter Kimhttp://www.blogger.com/profile/05995962509217517266noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-8116903880567944423.post-72118593248438817052013-05-13T16:56:00.001-07:002013-05-16T12:10:35.570-07:00Embedding python in Mac OS XI have been trying to figure out how to embed Python on the Mac. Trying the simple example found at <a href="http://docs.python.org/2/extending/embedding.html">http://docs.python.org/2/extending/embedding.html</a>,<br />
<br />
<br />
<pre style="background-color: #eeffcc; border-bottom-color: rgb(170, 204, 153); border-bottom-width: 1px; border-style: solid none; border-top-color: rgb(170, 204, 153); border-top-width: 1px; color: #333333; line-height: 15px; overflow-x: auto; overflow-y: hidden; padding: 5px;"><span class="cp" style="color: #007020;">#include <Python.h></span>
<span class="kt" style="color: #902000;">int</span>
<span class="nf" style="color: #06287e;">main</span><span class="p">(</span><span class="kt" style="color: #902000;">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt" style="color: #902000;">char</span> <span class="o" style="color: #666666;">*</span><span class="n">argv</span><span class="p">[])</span>
<span class="p">{</span>
<span class="n">Py_SetProgramName</span><span class="p">(</span><span class="n">argv</span><span class="p">[</span><span class="mi" style="color: #208050;">0</span><span class="p">]);</span> <span class="cm" style="color: #408090; font-style: italic;">/* optional but recommended */</span>
<span class="n">Py_Initialize</span><span class="p">();</span>
<span class="n">PyRun_SimpleString</span><span class="p">(</span><span class="s" style="color: #4070a0;">"from time import time,ctime</span><span class="se" style="color: #4070a0; font-weight: bold;">\n</span><span class="s" style="color: #4070a0;">"</span>
<span class="s" style="color: #4070a0;">"print 'Today is',ctime(time())</span><span class="se" style="color: #4070a0; font-weight: bold;">\n</span><span class="s" style="color: #4070a0;">"</span><span class="p">);</span>
<span class="n">Py_Finalize</span><span class="p">();</span>
<span class="k" style="color: #007020; font-weight: bold;">return</span> <span class="mi" style="color: #208050;">0</span><span class="p">;</span>
<span class="p">}</span></pre>
<br />
<br />
I got the error message that Python.h couldn't be found:<br />
<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">$ gcc test.c</span><br />
<span style="font-family: Courier New, Courier, monospace;">test.c:1:20: error: Python.h: No such file or directory</span><br />
<br />
<br />
Adding the header files to the search path then led to a linking problem:<br />
<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">$gcc -I /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Headers test.c </span><br />
<span style="font-family: Courier New, Courier, monospace;">Undefined symbols for architecture x86_64:</span><br />
<span style="font-family: Courier New, Courier, monospace;"> "_PyRun_SimpleStringFlags", referenced from:</span><br />
<span style="font-family: Courier New, Courier, monospace;"> _main in cch6pSfx.o</span><br />
<span style="font-family: Courier New, Courier, monospace;"> "_Py_Finalize", referenced from:</span><br />
<span style="font-family: Courier New, Courier, monospace;"> _main in cch6pSfx.o</span><br />
<span style="font-family: Courier New, Courier, monospace;"> "_Py_Initialize", referenced from:</span><br />
<span style="font-family: Courier New, Courier, monospace;"> _main in cch6pSfx.o</span><br />
<span style="font-family: Courier New, Courier, monospace;"> "_Py_SetProgramName", referenced from:</span><br />
<span style="font-family: Courier New, Courier, monospace;"> _main in cch6pSfx.o</span><br />
<span style="font-family: Courier New, Courier, monospace;">ld: symbol(s) not found for architecture x86_64</span><br />
<span style="font-family: Courier New, Courier, monospace;">collect2: ld returned 1 exit status</span><br />
<div>
<br /></div>
<br />
The all knowing Google was of limited help-- I could not find an explanation for how to embed python on the Mac platform. After divining the error message tea leaves, and pouring over man pages, I have finally found out how to EMBED PYTHON ON THE MAC!! (cue 2001: A Space Odyssey theme!)<br />
<br />
The magic incantation is<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">gcc -I /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Headers -L /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib -lpython2.7 foo.c</span><br />
<br />
I have macports python installed, but if you don't, you will need to change the "/opt/local/Library..." to "/System/Library..."<br />
<br />
The <span style="font-family: Courier New, Courier, monospace;">-I</span> option adds a directory for finding header files. The <span style="font-family: Courier New, Courier, monospace;">-L</span> adds a directory for finding lib files. The <span style="font-family: Courier New, Courier, monospace;">-l</span><i>x</i> option loads the library file named lib<i>x</i>.dylib.<br />
<br />
I then added a bash alias:<br />
<span style="font-family: Courier New, Courier, monospace;">alias pygcc='gcc -I /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Headers -L /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib -lpython2.7'</span><br />
<br />
I can now invoke the compiler using<br />
<span style="font-family: Courier New, Courier, monospace;">pygcc foo.c</span><br />
<br />
Another thing I found out is that the current directory is not in sys.path. You therefore can't load modules that are in the current directory. You can add the current directory by adding <span style="font-family: Courier New, Courier, monospace;">PySys_SetArgv(argc, argv);</span> after the call to <span style="font-family: Courier New, Courier, monospace;">Py_Initialize();</span> so that it looks like:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">Py_Initialize();</span><br />
<span style="font-family: Courier New, Courier, monospace;">PySys_SetArgv(argc, argv); //adds current directory to sys.path</span><br />
<span style="font-family: Courier New, Courier, monospace;">...</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: inherit;">Update: It seems that there is a slightly easier way to add the proper include and library directories using the </span><span style="font-family: Courier New, Courier, monospace;">python-config</span><span style="font-family: inherit;"> command (which doesn't have a man page on Mac OS BTW). Calling </span><span style="font-family: Courier New, Courier, monospace;">python-config</span><span style="font-family: inherit;"> with </span>--<span style="font-family: Courier New, Courier, monospace;">includes</span> --<span style="font-family: Courier New, Courier, monospace;">ldflags</span> returns the appropriate options for <span style="font-family: Courier New, Courier, monospace;">gcc</span>:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">$ python-config --includes --ldflags</span><br />
<span style="font-family: Courier New, Courier, monospace;">-I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7</span><br />
<span style="font-family: Courier New, Courier, monospace;">-L/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config -ldl -framework CoreFoundation -lpython2.7 -u _PyMac_Error /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python</span><br />
<br />
<span style="font-family: inherit;">So you can shorten the gcc incantation to:</span><br />
<span style="font-family: Courier New, Courier, monospace;">gcc `python-config --includes --ldflags`</span><br />
<span style="font-family: inherit;">and shorten the alias to</span><br />
<span style="font-family: Courier New, Courier, monospace;">alias pygcc='gcc `python-config --includes --ldflags`'</span><br />
Peter Kimhttp://www.blogger.com/profile/05995962509217517266noreply@blogger.com1tag:blogger.com,1999:blog-8116903880567944423.post-89679016242766836392013-05-05T02:06:00.000-07:002013-05-06T12:23:05.510-07:00Solder stencil using ShapeokoI purchased two Sick of Beige Bus Pirate v4 from schazamp on the DangerousPrototypes forums a couple of months ago and have been dragging my feet assembling them. I used hand soldering for the SMD parts on my DIY Bus Pirate v3 but for v4, I wanted to try making a solder stencil and reflow using a hot air rework station. There have been several articles recently about etching <a href="http://hackaday.com/2011/12/21/how-to-etch-your-own-solder-paste-stencils/">copper</a> and <a href="http://dangerousprototypes.com/2013/02/08/soda-pop-can-diy-solder-paste-stencil/">aluminum</a> stencils and also a recent article about using a <a href="http://www.instructables.com/id/Create-Solder-Paste-Stencils-with-Cricut/">Cricut to cut a stencil out of overhead transparencies</a>.<br />
<br />
I recently built a Shapeoko and wondered whether it could be used to make solder stencils.<br />
<br />
I used the Eagle CAM processor to output the tCream layer as a HPGL file. I then used a <a href="https://www.gnu.org/software/hp2xx/">GNU hp2xx</a> to convert the HPGL file into SVG. (It took a bit of tweaking to get hp2xx to compile on Mac OS X 10.7.)<br />
<br />
The command<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">hp2xx -t -m svg tCream.pltd</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
will convert the .plt HPGL file into a SVG file which looks like this:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5m2pBMFwYWgN2JN3Ir6MbHQ-1q56BYRWqwvsN-q67tz01ojwJkA23jfEf8MpdhjwOfr6eCjRQjp0XGnLTZCyL5zjCt56EU219uDPJw2qNIkn_-ftpVVRiqlz-MMyAzzHOnFKNeRx9RlUO/s1600/start.tiff" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="288" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5m2pBMFwYWgN2JN3Ir6MbHQ-1q56BYRWqwvsN-q67tz01ojwJkA23jfEf8MpdhjwOfr6eCjRQjp0XGnLTZCyL5zjCt56EU219uDPJw2qNIkn_-ftpVVRiqlz-MMyAzzHOnFKNeRx9RlUO/s400/start.tiff" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
I then used Illustrator to make 0.039" circles to approximate the holes from a #61 size drill bit. I used a red fill and a small stroke to make things easy to see and keep track of but the color and even the size of the hole don't really matter-- only the center coordinates are extracted. I tried approximating the drill hole area to the area of the pad. Big pads were filled with several holes. The small pads on the TQFP chip in the middle were a bit of a challenge. I guess I could have put a drill hole in the center of each pad but ended up with a staggered line of drill holes. The end result looked like this:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs5QI2FDpP_fLT932oLlQn-zsTtjJ67B75scvbrqeYZfvGMGZlZlkcttmOqU7kVedeUgwQKJuFBeJ8h2IUPDC-2rkYjoa1cg_oFJla8Is8GZMG_EgDuslmblCFnoRwAls42ytUqW-Nm_JL/s1600/done.tiff" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="290" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs5QI2FDpP_fLT932oLlQn-zsTtjJ67B75scvbrqeYZfvGMGZlZlkcttmOqU7kVedeUgwQKJuFBeJ8h2IUPDC-2rkYjoa1cg_oFJla8Is8GZMG_EgDuslmblCFnoRwAls42ytUqW-Nm_JL/s400/done.tiff" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Then came the task of turning the red dots into something I can send to the Shapeoko. I used the python <a href="https://pypi.python.org/pypi/svglib/">svglib</a> library to read in the modified SVG file and spit out all the circle coordinates. This part was surprisingly easy but kludgy. The SVG file is read into something called a ReportLab format and I had some difficulty figuring out the class/data structure-- if anyone knows of a better/cleaner/more robust way of evaluating/interrogating the report lab object, I would appreciate the help (my python introspection-fu not strong).</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">import svglib</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">dr = svglib.svg2rlg('tCream.svg')</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">print "G20 G17 G40 G49 G64 P0.005 G80 G90 G94" ## magical gcode incantation to start</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">print "G1 Z0.15 F10" ##lift before moving!!</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">for i in dr.contents[0].contents:</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;"> if i.__class__.__name__ == 'Circle':</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;"> #print "circle at %f, %f"%(i.cx,i.cy)</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;"> print "G0 X%f Y%f"%(i.cx/72.,i.cy/72.)</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;"> print "G1 Z-0.05 F15"</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;"> print "G1 Z0.15 F15"</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">print "M5\nM2" #magical gcode incantation to end</span></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
The result was a gcode program I could send to the Shapeoko:</div>
<div class="separator" style="clear: both;">
</div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">G20 G17 G40 G49 G64 P0.005 G80 G90 G94</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">G1 Z0.15 F10</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">G0 X0.685014 Y0.568389</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">G1 Z-0.05 F10</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">G1 Z0.15 F10</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">G0 X0.708736 Y0.603111</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">.....</span></div>
<div class="separator" style="clear: both;">
</div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">G0 X1.160417 Y0.848500</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">G1 Z-0.05 F10</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">G1 Z0.15 F10</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">M5</span></div>
<div class="separator" style="clear: both;">
<span style="font-family: Courier New, Courier, monospace;">M2</span></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
All told, 270 holes to drill-- took about 20 minutes (I ended up breaking two drill bits). Might be able to speed things up a bit using a traveling salesman algorithm but the order extracted from the SVG file is not too bad. Here is a link to a <a href="http://www.youtube.com/watch?v=mxpWO5GDRL8&feature=youtu.be">video of the Shapeoko in action</a>. And a picture of the completed stencil.</div>
<div class="separator" style="clear: both;">
<span id="goog_1160700041"></span><span id="goog_1160700042"></span><br /></div>
<div class="separator" style="clear: both;">
<br /></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLAjaI9-a116jAhaphaju7rwAUaYCaXAXaqAKSNMcBwTQYbU6AL5FqX8t_JzKigoD_a2ju3C8g7XEzwZfZEmm0AUDTFCR1i_y4g5LnvvI6BVKrlwOOkdzpKF1iQvBrny8iIWWBH8XzGfSM/s1600/IMG_20130505_000247.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="308" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLAjaI9-a116jAhaphaju7rwAUaYCaXAXaqAKSNMcBwTQYbU6AL5FqX8t_JzKigoD_a2ju3C8g7XEzwZfZEmm0AUDTFCR1i_y4g5LnvvI6BVKrlwOOkdzpKF1iQvBrny8iIWWBH8XzGfSM/s400/IMG_20130505_000247.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
The whole process is surprisingly quick and easy. Drawing the circles is slightly tedious but only took 5 minutes for this small board so not too bad. Some of the pads are a bit wonky-- after the drill bit(s) broke, I rezeroed the Z axis with a new drill bit and ran the gcode again. Some of the holes have actually been drilled three times. Overall the registration between the runs was very good-- the registration between the stencil and the board is quite good. I can't wait to try it out-- I am waiting for delivery of my Mouser order.</div>
Peter Kimhttp://www.blogger.com/profile/05995962509217517266noreply@blogger.com0tag:blogger.com,1999:blog-8116903880567944423.post-15906895880917592122012-06-14T10:16:00.003-07:002013-12-13T12:20:38.898-08:00Soldering iron driver v1.5 buildSo I finally have my soldering iron driver v1.5 from dangerousprototypes (designed by Arhi, laid out by Arakis) in a condition that is stable and useable.<br />
<br />
A few words of advice for people building this<br />
<br />
<ol>
<li>When you populate the board, build the power supply section first and test it to make sure it works. You don't want to find out your buck converter is not working when smoke comes out of your op amp or PIC18F.</li>
<li>The adjustment of the trim pots in the positive temperature coefficient (PTC) amplifier is explained in a readme file in the hardware section. This adjusts the constant current source into the PTC thermistor.</li>
<ol>
<li>Remove sensor from PTC connector</li>
<li>Attach milliampermeter to PTC connector</li>
<li>Power the device on</li>
<li>Turn CAL1 pot until you get exactly 1.000mA going trough. </li>
</ol>
<li>Once you have the current source trimmer set, set the gain as follows.</li>
<ol>
<li>Remove sensor/milliampermeter and connect a 100 OHM resistor (1% or better) to PTC connector. </li>
<li>remove jumper from JP1</li>
<li>Power on device </li>
<li>Turn the RV2 pot until you get on the top pin of JP1 exactly 3.00V</li>
</ol>
<li>I had problems with the heater control section. It turns out the opto-triac was bad. Not sure if I received a bad one or I fried it somehow. I ended up picking up a non-zero-crossing opto-triac at the local All Electronics. In case you were wondering, a non-zero-crossing works just fine.</li>
<li>Arhi recommended not installing the capacitors for the low-pass Sallen-Key filter. I didn't see that warning until after installing them. They actually worked well with a time constant pretty close to the calculated value so I left them in.</li>
</ol>
<br />
<div>
After the board was fully populated, except for the NTC and the thermocouple amplifier sections, I squeezed everything into a plastic box. The enclosure was actually a container for Korean pepper paste (gochujang). I was impressed with Egor who correctly identified the container from a front/side shot.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhQtfdSqXfJ2_7INgVUmvNv_jdOrKsMykTz9kYJG8v8zAso1tPoPJq1JY4ytTG74oFvdgG2bK0JFvmf5RUKq_KmztGNzVg_UDBLzwi7ErhVL9bBT2SyI4YkX2lwQ8wT2Q-I2ReUOrAH4ub/s1600/SID+front+view.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhQtfdSqXfJ2_7INgVUmvNv_jdOrKsMykTz9kYJG8v8zAso1tPoPJq1JY4ytTG74oFvdgG2bK0JFvmf5RUKq_KmztGNzVg_UDBLzwi7ErhVL9bBT2SyI4YkX2lwQ8wT2Q-I2ReUOrAH4ub/s320/SID+front+view.jpg" height="240" width="320" /></a></div>
<div>
Here is a picture of the top clearly showing its source.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcWSNfA72mcWg58vH0cGGM2h3N7jJq6sOObiwbu76Kfp-X0E3tjKn29wi-zHYQeKwi5FOxX4JALjjcS982iDoGrMceIHvG0pLry9kDySpZK6QWs1Ojw_9DcGRzHawYUzL9J-_H4tJ_FctM/s1600/IMG_5703.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcWSNfA72mcWg58vH0cGGM2h3N7jJq6sOObiwbu76Kfp-X0E3tjKn29wi-zHYQeKwi5FOxX4JALjjcS982iDoGrMceIHvG0pLry9kDySpZK6QWs1Ojw_9DcGRzHawYUzL9J-_H4tJ_FctM/s320/IMG_5703.jpg" height="240" width="320" /></a></div>
<br />
I hooked up buttons for menu, + and -. These were interrupt driven and the switch bounces caused a lot of problems. Arhi wrote a debounce routine but the button presses were limited to 5 per second and there was no autorepeat which made adjusting the temperature a bit tedious.</div>
<div>
<br /></div>
<div>
I rewrote the debounce code and added autorepeat. This made the interface much easier to use. I posted the changes in the forum <a href="http://dangerousprototypes.com/forum/viewtopic.php?f=56&t=2457&start=495#p41587">http://dangerousprototypes.com/forum</a></div>
<div>
<br /></div>
<div>
Here is a shot of the inside.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjE09oQOlfERj46bwb_kSTL0A4sdGTn-VZHSs_bsZF6jRX8SbkUiW4rJO5svjf58Lq5WtZaPHb0sIC7S2vYRgtnQVAV6ZiOZvMp_m_87Nq_xOPpyvNPqhj2CiFrGe8KtGA5r-5il9Apn3AZ/s1600/IMG_5701.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjE09oQOlfERj46bwb_kSTL0A4sdGTn-VZHSs_bsZF6jRX8SbkUiW4rJO5svjf58Lq5WtZaPHb0sIC7S2vYRgtnQVAV6ZiOZvMp_m_87Nq_xOPpyvNPqhj2CiFrGe8KtGA5r-5il9Apn3AZ/s320/IMG_5701.jpg" height="240" width="320" /></a></div>
I need to secure the circuit board inside. There is a lot of empty space inside and I am always short on benchtop space. If I am motivated, I might move everything into a smaller enclosure (Korean soybean paste (doenjang) container perhaps). I will have to use a smaller LCD display (8x2 characters) and rewrite the firmware to be more succinct and frugal.<br />
<br />
Here is a shot of the completed circuit board. In the second picture, you can see the diode lead art for the bridge rectifier. The capacitor to the right of the diode was a bit big and the diode was squeezed for space. There is another diode standing upright just behind the cap as well.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjT6rThTqAvWYFnb35WfUGKPh0uNbhm-7iPHg8yAoTI8CFSf_HbDtYgHyzhiOoA52iOlqxpfMWmlNXMWBIcFlSa4S14M4yW13bxicSKg0xhGUF75of3HGM7sfi1LxuzlaTSifejf-QLWKZh/s1600/SID+PCB.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjT6rThTqAvWYFnb35WfUGKPh0uNbhm-7iPHg8yAoTI8CFSf_HbDtYgHyzhiOoA52iOlqxpfMWmlNXMWBIcFlSa4S14M4yW13bxicSKg0xhGUF75of3HGM7sfi1LxuzlaTSifejf-QLWKZh/s320/SID+PCB.jpg" height="304" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxIgt5bybtxV0C_s7G77-B2s9NkjyFuQUTrUzkYtJAfkI3X2IxHckDe_pf_lSWigutwz28wx78RZET-p2Fh6o0adEsd0GvcLQiTChpmL4pZKxTo2KncqhEC8PP_Z9sGMcnEv9qEHDS4_8J/s1600/IMG_5700.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxIgt5bybtxV0C_s7G77-B2s9NkjyFuQUTrUzkYtJAfkI3X2IxHckDe_pf_lSWigutwz28wx78RZET-p2Fh6o0adEsd0GvcLQiTChpmL4pZKxTo2KncqhEC8PP_Z9sGMcnEv9qEHDS4_8J/s320/IMG_5700.jpg" height="232" width="320" /></a></div>
<br />
<br />
The transformer was salvaged from a lab freezer controller board. It has multiple primary windings for different input voltages and two separate secondary windings. In its current configuration it puts out 20V AC. Even after its been on for an hour, I can't detect a temperature increase above ambient. The triac gets a bit warm, possibly because the input voltage is lower than the expected 24V so I am going to put a heatsink on it.</div>
<div>
<br />
Addendum: I have received several requests for precompiled binaries. I have uploaded the modified source along with the compiled binaries (with and without bootloader versions) to github. You can get them at<br />
<br />
https://github.com/hardwhack/Soldering-iron-driver</div>
Peter Kimhttp://www.blogger.com/profile/05995962509217517266noreply@blogger.com10tag:blogger.com,1999:blog-8116903880567944423.post-37397931797574236362012-05-08T12:42:00.003-07:002012-05-08T12:42:49.192-07:00Making Tris buffers by mixingOne of my least favorite lab activities is measuring pH. It dates back titrating buffers using burettes in chemistry lab-- drip dropping one droplet at a time, becoming impatient, and then overshooting. Barnacles!<div>
<br /></div>
<div>
I try to avoid making Tris buffers for the same reason-- it requires careful drip dropping of HCl. If you overshoot a little, you can bring the pH back using NaOH but then you have added NaCl to your buffer. I found out the hard way making TAE buffer this way-- the NaCl conducts electricity too well.</div>
<div>
<br /></div>
<div>
I need to make Tris pH 7.7 for protein purification and was wondering if there was a way to mix Tris base and Tris HCl to come close to the desired pH. It turns out you can using the Henderson Hasselbalch equation.</div>
<div>
<br /></div>
<div>
pH = pK + log([A-]/[HA])</div>
<div>
<br /></div>
<div>
pK for Tris is 8.1 at 25 deg C</div>
<div>
<br /></div>
<div>
[A-] = 0.285 and [HA] = 0.715 for a 1M solution when pH = 7.7</div>
<div>
<br /></div>
<div>
Using FW for Tris base and HCl that translates to 112.7g of Tris HCl and 34.5g Tris base.</div>
<div>
<br /></div>
<div>
Here is a python script I wrote to solve for the values. Save it as pH.py then make it executable using chmod u+x pH.py. To use it, type pH.py 7.7. Here is a sample output:</div>
<div>
<br /></div>
<div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">$ pH.py 7.7</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">For pH 7.7 Tris buffer at 25 deg</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">112.72 g of Tris-HCl for 1L of 1M soln</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">34.49 g of Tris-base for 1L of 1M soln</span></div>
<div>
<br /></div>
</div>
<div>
Here is the python script.</div>
<div>
<br /></div>
<div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">#!/usr/bin/python</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">import sys</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">ph = float(sys.argv[1])</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">pk = 8.1 ## at 25 deg</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"> ##N.B. per Sigma catalog, pH drops 0.03 to 0.05 per ten fold dilution</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"> ## also increases ~0.03 per deg C</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">mwb = 121.136 # FW of tris base</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">mwa = 157.59 # FW of tris HCl</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"># use henderson hasselbalch equation to solve for a and b</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"># pH = pKa +log10(b/a)</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">a = 1./(1+10**(ph-pk)) #solve for a and b</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">b=1.-a # for a+b =1, i.e. 1M soln</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"> # math is your friend</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">print "For pH %2.1f Tris buffer at 25 deg" % (ph)</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">print "%.2f g of Tris-HCl for 1L of 1M soln" % (a*mwa)</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">print "%.2f g of Tris-base for 1L of 1M soln" % (b*mwb)</span></div>
</div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span></div>
<div>
<span style="font-family: Times, 'Times New Roman', serif;">OK, this is high school chemistry, but that was a long time ago. Hope you find this useful.</span></div>Peter Kimhttp://www.blogger.com/profile/05995962509217517266noreply@blogger.com0tag:blogger.com,1999:blog-8116903880567944423.post-1954859732154478172012-04-09T02:21:00.002-07:002012-04-19T16:24:49.082-07:00ApProg430I would like to win one of the elusive free PCB coupons from Dangerous Prototypes. Finish one, get another! How can you beat that deal? Haven't won yet, but it is only a matter of time.<br />
<br />
I have to admit, I was one of the people who requested the opportunity to buy PCBs from the PCB drawer. When I saw Ian's <a href="http://dangerousprototypes.com/2012/02/29/how-not-to-sell-pcbs-pcb-drawer-first-year-sales-breakdown/">breakdown of first year sales</a> of the Bus Pirate, I felt twinges of guilt because I had not yet purchased. I plunked down my $10 and received two DIY Bus Pirates PCBs. I sent in a Mouser order for the parts (plus extra SMD resistors because they are easy to lose).<br />
<br />
All told, the PCBs, components, plus shipping/handling came out to about $50 for the two Bus Pirates. Considering <a href="http://www.seeedstudio.com/">Seeed Studio</a> will sell you one for $27, assembled, programmed, and shipped, this was starting to look like a losing proposition. Did I mention the twinges of guilt driving the purchase?<br />
<br />
I soldered up the boards in an evening. This was my first time assembling SMD parts but after watching the HOWTO videos on Dangerous Prototypes, it wasn't so bad. Patience, flux, and desoldering braid.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgW0skRKNSmky3FOBLr3dtvd0PEYVyJelqjik6l03VYa9PZ7lgxVONhmZEQUguCeOeBG_cx3kM11NEGlZXhk_Fj1JvDqY1ZdxTLhNUyG9ucKP3ZxFPkD-iRHAaPn7TOs0N6R6uUqJCO4sn3/s1600/DIY+Bus+Pirates.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgW0skRKNSmky3FOBLr3dtvd0PEYVyJelqjik6l03VYa9PZ7lgxVONhmZEQUguCeOeBG_cx3kM11NEGlZXhk_Fj1JvDqY1ZdxTLhNUyG9ucKP3ZxFPkD-iRHAaPn7TOs0N6R6uUqJCO4sn3/s320/DIY+Bus+Pirates.jpg" width="271" /></a></div><br />
When I plugged in a USB cable, the PWR LED came on and the computer recognized the FT232 chips. So far so good. Now I needed to program the PIC24 chips but I don't have a PIC programmer. I didn't want buy a PicKit because that would really make for a losing proposition. I saw that Jozef had devised a way to <a href="http://dangerousprototypes.com/forum/viewtopic.php?f=28&t=3093">program the devices using a AVR microcontroller</a>. He was kind enough to share source, precompiled binaries, and firmware. Great! But I don't have a AVR programmer. Talk about bootstrapping problems!<br />
<br />
I do have a MSP430 Launchpad and I figured I could have the MSP430 emulate the AVR. I modified the firmware code to run on a MSP430G2553. I picked this part because it has a built in UART. You can probably modify the code to run on MSP430s with software UART but I am not going there.<br />
<br />
Here is a picture of the programmer hooked up. PGC is on P2.0, PGD on P2.1 (through a 1K resistor), and MCLR on P2.2. The Launchpad runs at 3.6V but this is within the electrical specs for the PIC24 so I figured why not. Fortunately, it works just fine.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3FJBglch-HhqrDMnS7TJTncJIAOZj9i_-KbFUmI1hjVkvqOAF7QPWEaWQrFoGaNt5wzzlpTbkFw9wcJgkC-E_bK2RAy3synKheYZAgCBuH7Jqo6wyK7Ttn323EFFFVockSzQUpbNpZKc8/s1600/ApProg430.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3FJBglch-HhqrDMnS7TJTncJIAOZj9i_-KbFUmI1hjVkvqOAF7QPWEaWQrFoGaNt5wzzlpTbkFw9wcJgkC-E_bK2RAy3synKheYZAgCBuH7Jqo6wyK7Ttn323EFFFVockSzQUpbNpZKc8/s320/ApProg430.jpg" width="320" /></a></div><br />
I programmed the v4.4 bootloader using ApProg using the Launchpad running the modified firmware. The firmware came next using the ds30 loader GUI. This is much faster than trying to program the combined bootloader/firmware using ApProg. The ApProg binary is available <a href="https://github.com/JoKr2/ApProg">here</a>.<br />
<br />
And it works! I have two functional Bus Pirates. No more twinges of guilt. So the final cost for the two Bus Pirates (PCBs, parts, Launchpad) came out to almost exactly what I could have ordered from Seeed Studio. But mine have DIY silkscreened on the boards!<br />
<br />
Here is the source code for the MSP430. It has been condensed into a single file. You can create a new project in code composer studio v5, copy and paste into main.c and compile. <strike>Some day, perhaps I will take the time to learn how to host files on github.</strike> Posted on <a href="https://github.com/hardwhack/ApProg430">github</a>.Peter Kimhttp://www.blogger.com/profile/05995962509217517266noreply@blogger.com9