Gas station without pumps

2012 December 31

Data logging software for circuits course working

Over winter break, my son has been working nearly full time on writing data logging software for my students to use in the Applied Circuits for Bioengineers course. He has made the first public beta release (v1.0.0b1) today on BitBucket. (Note: you may have to click on the “tags” tab to get to the view that shows the v1.0.0b1 link. The BitBucket link directly to that view seems to be broken—that’s open issue 5504 in BitBucket’s own issue tracker.)

We’ve only tested the code on Mac OS X computers with Arduino Duemilanove and Uno boards, though we’ve tested a slightly earlier version on Windows.  The code should also run on Linux and with Leonardo and Mega boards, but has not been tested on these platforms. We welcome users testing the code for us—report any problems using the BitBucket issue tracker for the project.  The documentation is still in a fairly primitive state—report issues with that also, so that they can be fixed.

The overall goal is fairly simple: to have an easy-to-use way to record timestamps, voltages, and digital values from the Arduino into files on a host computer, without needing auxiliary hardware (like the Adafruit data logger shield that I bought for myself and assembled yesterday).

The user can specify what analog and digital pins to record and when to record the values.  When to record can be specified either   as interrupts on pins or as fixed timing intervals:

View of the two windows of the user interface.

View of the two windows of the user interface.

The “volts measured” for the reference is stored as metadata in the output file and can be used for scaling the Arduino numbers (if “Convert to Volts” is checked).  The scaling can be an arbitrary value for the full-scale reading or can be the voltage measured with an external multimeter at the AREF pin.

This software has been through several versions:

  1. The first version of the code was one I wrote last spring that just recorded interrupt times in an Arduino array and dumped them out over the USB cable after it was done (see Homemade super pulley).
  2. My son was not happy with that crude program of mine and rewrote it in June to have use the Arduino memory as a queue and send the time stamps to a Python program on the laptop (see Improved super pulley code).  That program introduced him to three new concepts: circular buffers for queues, interrupts, and multi-threading, all of which he researched for himself. That version of the code mainly used a command line interface, but he used the curses package for a crude user interface.
  3. He added a PyGUI graphical user interface, but that slowed down the code on the laptop and eventually grew to be difficult to maintain.
  4. He decided to try to make the software by portable between three platforms (Mac OS X, Windows, and Linux) despite their very different ways of dealing with the USB serial ports, to run under both Python2.7 and Python3, and to require only minimal non-standard packages (mainly PySerial and the Arduino package Timer1).  He refactored the code completely and built the GUI using Tkinter. This has lead to the current version of the code, which is finally working robustly enough to let the bioengineering students use it.

It has been a good software-engineering experience for my son, and he has learned a lot.  In the process of developing this code, he has learned a lot about interrupts, using queues to communicate between processors and between threads, platform-independence, a couple of different GUI libraries, the value of version control and bug-tracking, race conditions, interface design for non-expert users, and even some things about documentation.

I’ve been acting mainly as a customer for this code, entering bug reports and suggesting new features, though I have occasionally helped him debug.  For example, we just spent fifteen minutes reading Section 15 “16-bit Timer/Counter1 with PWM” of the ATMega328 data sheet, trying to figure out why the first time interval was wrong.  It turns out that timer interrupt is raised immediately when the interrupt is enabled, unless the timer-overflow flag is turned off first.

My son may use this project as a science fair entry this year, though it was not started with that idea, and we discussed that possibility for the first time today.  The big problem is that this is purely an engineering project, not a “science” project, and trying to fake a hypothesis is not something we’ll consider.

 

2012 in review

Filed under: Uncategorized — gasstationwithoutpumps @ 11:16
Tags: , , ,

The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog.

Here are some excerpts:

This blog was viewed about 110,000 times in 2012.

In 2012, there were 420 new posts, growing the total archive of this blog to 929 posts. There were 282 pictures uploaded, taking up a total of 34 MB. That’s about 5 pictures per week.

The busiest day of the year was May 14th with 705 views. The most popular post that day was 2011 AP Exam Score Distribution

Some of your most popular posts were written before 2012. Your writing has staying power! Consider writing about those topics again.

Click here to see the complete report.

I’m a little surprised that I managed to average 1.15 posts per day—I knew I’d been spending too much time on the blog, but … I’ve been getting a lot of views (for an unaffiliated academic blog), over 8000 every month since March, despite my obsession since the middle of June with the design of the Applied Circuits course (98 posts and pages so far, and the course doesn’t even start for another couple of weeks).

I’m rather lax about posting pictures, so I was surprised to see the number up to 282 (and averaging 123kB each—I do use Photoshop Elements to crop, touch up, and downsample images before posting them).  I suspect that a lot of the “pictures” are actually circuit diagrams and gnuplot graphs, which would be much smaller if WordPress.com would allow a vector graphics format like SVG rather than insisting on raster graphics like PNG and JPG for everything.  I guess they feel they have to support obsolete browsers, like Internet Exploder, that still don’t support SVG.

Here are my top-viewed posts for the year (over 300 views):

Home page / Archives 28,751
2011 AP Exam Score Distribution 10,615
West Point Bridge Designer 2011 3,990
Installing gnuplot—a nightmare 2,836
Why no digital oscilloscope for Macbooks and iPads? 1,814
2012 AP Exam Score Distribution 1,638
How many AP courses are too many? 1,618
Bring back the mammoth! 1,424
West Point Bridge Design Contest 2012 1,320
County Fair with Pictures 925
Soda-bottle rockets 821
Why Discrete Math Is Important and The Calculus Trap 812
Teaching voice projection 711
Raspberry Pi 697
Underwater ROV contest 651
Waterproofing cameras for underwater ROVs 639
Resources for bioinformatics in AP Bio 637
Coursera Course Catalog 608
Soda-bottle rocket simulation: take 2 608
Learning to use I2C 591
Satisfying UC’s a–g requirements with home school 516
EMG and EKG works 503
Computer languages for kids 500
Speed of sound lab writeup 498
Underwater ROV 481
Magnetometer and accelerometer read simultaneously 474
Soda-bottle rocket simulation 472
Should high schools and colleges teach sentence diagramming? 470
Google Scholar vs. Scopus and SciFinder 466
DRACO: broad-spectrum antiviral drugs 398
Green beard effect 394
Adding bioinformatics to AP Bio 388
Carol Dweck’s Mindset 361
Medical Instrumentation, Chapter 6 355
NSF “clarifies” Broader Impacts 351
Better electrode placement for EKG blinky 351
Prevnar 13 approved for adults 341
Instrumentation amp lab 321
A critique of CS textbooks 315
iPad Oscilloscope 305

People coming to the home page are still the biggest single group, but overall, more people are finding my pages through search engines than by other means. It is a bit disappointing that two of my top pages are just pointers to someone else’s collection of AP exam score distributions, and another two are for middle-school students looking to cheat on the West Point bridge design contest (which apparently some schools assign as homework).

The gnuplot post is mainly used by people looking for a way to install gnuplot on Macs. I think that the gnuplot community really needs to get their act together and put up a proper binary installer for Mac OS X. They need to stop pretending that everything is fine if you can dual-boot your system or put up a 2Gbyte Linux-lookalike environment on your Mac.

There is now an ok USB oscilloscope for the Mac, though the code is still clearly beta-release quality.  I posted about it in FET threshold tests with Bitscope.

A couple of the popular posts are mainly fluff (the mammoth post and the Green Beard joke picture).

A lot of my most-viewed posts are technical ones on electronics, computer engineering, robotics, or physics, though more at a teaching or hobbyist level than professional, cutting-edge stuff.  I’m fairly happy with that, as I’m turning more into a teacher than a researcher over the past couple of years—I’ve always enjoyed creating new courses, and I’ve been putting a lot of time into that lately. My more philosophical musings have had less readership, perhaps because they are harder to find in a Google search and are less likely to be searched for.

I’m still not seeing many comments (about 2.4/post and 40% of the comments are by me).  I’d like to have more feedback from my readers, but with so many of them being one-time viewers who came via search, I can’t really expect much conversation in the comments.

I’ve seen a strong weekly periodicity in my viewership, with dips over the weekend (people must be goofing off at work when they access my blog).  The plot is particularly clear when I look at the Google Webmaster tools, which has minima on Saturdays:

As much history as Google's webmaster tools is willing to show me.  It would really help to have the clicks and impressions on a log scale, so that the clicks didn't have just a one-pixel fluctuation.  I suppose it is too much to expect Google to be willing to provide free tools that are actually well designed.

As much history as Google’s webmaster tools is willing to show me. It would really help to have the clicks and impressions on a log scale, so that the clicks didn’t have just a one-pixel fluctuation. I suppose it is too much to expect Google to be willing to provide free tools that are actually well designed for geeks like me.  My overall click-through rate of 4% is decent, I suppose,

My university web pages have a higher number of clicks, but 57% of them for the soda-bottle rocket launcher plans and the mead recipe, neither of which are related to my professional responsibilities.  The next few are for handouts from tech writing course I taught in 2003—I’ve not really been putting much of general interest on my University web pages lately.

Quantcast.com estimates my 2012 page views for my blog as about 103,000 (a bit less than WordPress.com number, which is more directly measured), but Quantcast also estimates the number of visits and people as about 55,000 and 43,000 respectively, so people are viewing about two pages per visit.  Somewhat surprisingly, given my age and how many of my posts are about educating my son, my demographics skews towards younger adults without kids.  Less surprisingly, given the technical content and academic tone, my demographics skew heavily towards people with graduate degrees.

Not visible to the outside world, I also have 169 draft posts (usually just a pointer to a web page I planned to comment on, or a couple of lines of notes) and 71 tabs in Firefox for web pages I planned to blog about but haven’t even gotten into draft posts yet.  So I have material for a couple hundred more posts, if I can remember what it was I wanted to say.  If I ever go through the lot of them, I’ll probably throw out ¾ of them as being no longer relevant or interesting—they weren’t compelling enough at the time to make me write the post immediately.

Overall, I’m fairly pleased with my blog this year, and hope that next year will continue to be successful—maybe I can get the draft-post backlog whittled down a little (though to-do lists always seem to grow rather than shrink, no matter how many things I do).

2012 December 30

Mic modeling lab rethought

Filed under: Circuits course — gasstationwithoutpumps @ 11:11
Tags: , , , ,

In Mic modeling lab too complicated, I complained about the following graph being too complicated for the 2nd week lab for the circuits for bioengineers course:

    Current vs. voltage curve for electret mic with more data points, showing that just making measurements from 1v to 10v was a bad idea.

Current vs. voltage curve for the electret mic The magenta curve (with the log dependence on voltage across the mic) was my previous model, based on data from 1v to 10v.  I don’t know what theory gives the appropriate slope to the saturation current—most of the models I’ve seen make that region constant current.

I spent all day yesterday rethinking this lab and trying a number of different approaches.  (Well, not quite all day—I spent some time in the morning testing all 12 pressure sensor boards I’d soldered up the day before.)

What I decided to do was to embrace the non-linearity and have students characterize the part, but I’ll give them some simple models to fit.  I also decided to have the students use the Arduino to automate the data measurement—I didn’t have enough use of the Arduino in the course, and automating tedious measurements is precisely why we decided to include the use of the Arduino in the course.

Of course, there are some limitations of the Arduino analog-to-digital converter that are important for this lab:

  • The highest voltage allowed is 5v and the lowest is 0v.
  • The resolution is only 10 bits (1024 steps).
  • The steps seem to be more uniformly spaced at the low end of the range than the high end (so differences at the high end are less accurate than differences at the low end).
  • The external reference voltage AREF must be at least 0.5v (this is not in the data sheet, but when I tried lower AREF voltages, the reading was always 1023.

I think I’ll have the students start with using the multimeter and the bench power supply to measure voltage and current pairs for 1V to 10v in steps of 1v.  Then I’ll have them wire up a simple circuit on the breadboard:

Circuit for measuring DC characteristics of an electret microphone.  The four labeled nodes are connected to the Arduino.

Circuit for measuring DC characteristics of an electret microphone. The four labeled nodes are connected to the Arduino.

The idea is simple: the bench power supply will provide a known voltage (between 0.5v and 5.0v) to the external reference AREF, and the data logger code will measure the voltage across the load resistor and across the load resistor every 100msec. The students will adjust the trimpot (they have 18-turn 10kΩ trimpots in their parts kits), while the Arduino measures the voltages. They’ll  then use gnuplot to plot the i-vs.-v and r-vs.-v curves for the device. They’ll probably have to collect two or three files of data, with different AREF voltages (0.55v, 2v, 5V, for example) in order to cover the full range of values with adequate precision.

I put the load resistor on the lower leg, so that I could get more accurate readings of low currents. I had tried it on the upper-leg first, but the results were not as consistent with different AREF voltages.

I’ll give them four models to fit and some hints on how to fit multi-variable models with gnuplot, here expressed as resistances:

  • constant resistance r
  • constant saturation current v/i_{sat}
  • blend of resistance and saturation current \sqrt{r^2 + (v/i_{sat})^2}
  • power-law slope for resistance in saturation region \sqrt{r^2 + (v^{v_{exp}}/i_{sat})^2}

The first two models are the ones most often used as rules of thumb when designing.  The third one provides a decent blending between them, though it is purely an empirical fit—there is no theory that says this is the right model in the sublinear region (though the usual model for pinch-off current seems just as arbitrary to me).  The last model has no theoretical justification at all, it just provides a good way to match the empirically observed dependence of the “saturation” current on voltage.  I played with lots of models before deciding on these four.

Here are some plots of how well they fit the data I measured:

On a log-log scale, both the blended models look pretty good.

On a log-log scale, both the blended models look pretty good.

i_vs_v_all_nologi

Changing the current to a linear scale makes the problems with the constant saturation current model clearer.
The multimeter measurements are almost certainly better than the measurements with the Arduino, but the sheer number of measurements with the Arduino (about 1200, once duplicates are removed) makes those measurements dominate the fitting.

It was actually from looking at the equivalent resistance of the microphone that I saw a simple way to produce the blended model without having to introduce new parameters (like saturation voltage).

It was actually from looking at the equivalent resistance of the microphone that I saw a simple way to produce the blended model without having to introduce new parameters (like saturation voltage).  On this plot, the improved fit in the sublinear region for my model is clearer.

I think that the “linear” region may actually be better modeled with a resistance that varies with voltage, rather than a constant resistance, but the data I have at the low voltage end is rather bad: the quantization errors are extreme and I don’t really trust the numbers.  Trying to add more complexity for the linear region did not seem to improve the fit, and we never use the mic in the linear region anyway, so I decided to keep the models simple.

So the microphone lab will have two major components:

  • DC characterization of the microphone, using the Arduino to automate measurements.
  • Visualization of AC waveforms using the oscilloscope.

I just hope that there is enough time in the 3-hour lab for the students to do both.

 

2012 December 28

Parts packed, pressure sensors assembled, more thoughts on power amp

Filed under: Circuits course,Pressure gauge — gasstationwithoutpumps @ 22:54
Tags: , , , , ,

The DigiKey order arrived today, so I spent some time repacking all the parts into DIP tubes and little plastic bags.  I also assembled and soldered all 12 of the breakout boards for the MPX2053DP pressure sensors, but I’ve not tested the assembled boards yet.  I have an instrumentation amp set up for the boards, that I used when I was debugging the instrumentation amp lab and the breakout board with my own MPX2053DP pressure sensor, so I should be able to run through the dozen tomorrow fairly quickly (as long as there are no problems).

I was surprised by one thing in the DigiKey order, though I shouldn’t have been.  Because they were out of the original IR emitter I had chosen, I had quickly substituted the next cheapest one.  I had not noticed that it was a 5mm part instead of a 3mm part.  That doesn’t matter for this course (we’ll be sticking them in a breadboard anyway), and it might actually turn out to be an advantage, since the photodiode looks a lot like the IR emitter, but is a 3mm part.  It might have been difficult to keep them straight if both had been 3mm parts.

Incidentally, the alligator clips that I bought www.amazon.com/gp/product/B005HJXZ42/ turned out to have even worse quality control than I expected.  The box of 100 only had 98 alligator clips, and only 96 screws, so two of the clips ended up screwless. The plastic red and black sleeves are looser than on other alligator clips I’ve had, and the whole clip seemed a little flimsy.  I still think they were a reasonably good deal for the low price, but they are definitely low-end parts.

Yesterday I drilled and cut 12 electrode spacers for the stainless steel electrodes out of an old plastic cutting board, but I decided to buy 24″ bolt cutters to cut the 1/8″ stainless steel welding rod, rather than using the cutoff wheel on my wife’s Dremel motor tool.  The bolt cutters should arrive by the middle of next week, and I’ll finish making the stainless steel electrodes then.  I think that the only other lab equipment that is needed is a hotpot for boiling water (I’ll donate the old one from my office, if it still works), an ice bucket, some thermoses, and disposable coffee cups for the first lab.  The lab support staff have already put the secondary containment tubs in the lab.

I’ve also arranged for some stock NaCl solutions (1M,0.1M, and 0.01M) for the electrode lab, so I think the equipment situation is pretty good—I’ll have to convince my son to go in one more time to finish setting up the other 6 computers to run Python and the Arduinos correctly.  It’s looking like he’ll have the data logger code done this weekend, so we are tentatively planning to go in on Monday to install it. If our Leonardo Arduino board hasn’t arrived by then we may delay a day or two so that we can test the data logger customization with it—there are so many differences on the Leonardo board that something is almost bound to break in the code.  We should test on an Arduino Mega board as well, but I wasn’t willing to spend that much just for testing, as I don’t expect any of the students in the class to be bringing in a Mega board.

I also spent a fair amount of time this morning playing with the power amp design and learning to use the Bitscope USB oscilloscope better.  The function generator on the Bitscope Pocket Analyzer is not very good: it can produce adequate sine waves into a high-impedance resistive load, but it had trouble with triangle waves and with driving the input to the amplifier (which I thought was pretty high impedance).  I ended up switching back to my Elenco FG500 function generator, which seems to produce better waveforms, at least in this application.  I also noticed that the Bitscope picks up a lot of noise when measuring low-level signals (about 1mV of noise, even on a 10mV signal).  I compared the Bitscope display to the display on my Kikusui COS5060 for the same signal and found that most of the noise was not present in the source.  It was probably being generated either in the Bitscope leads or in the input stage of the Bitscope A to D.

I was able to drive the 8Ω speakers that the students will be using down to about 3 or 4Hz and up to about 240kHz (though, of course, I couldn’t hear anything above 15kHz).  I think that there may still be some crossover distortion in the amp, so I’m going to rewire it tomorrow with a trimpot in the middle of the bias network to see if I can eliminate the crossover problem without overheating the transistors.  The PTN7800W regulator I’m using to provide 6.6v doesn’t start limiting the current until 3.2A, so I could dissipate as much as 32W in the FETs if I’m not careful.  I started them smoking once (they recovered without signs of permanent damage), and I don’t want to do that again.  I’ll have to make sure that the lab writeup explains how to set the current limits on the bench power supplies and that the students limit their current to 0.5A until they are sure their design is working.

One thing I noticed today is that there was a quiet oscillation around 4.4KHz, probably due to the large delay in driving the capacitive load of the FET gates.  I added a compensating capacitor from the op amp output to the negative input, just by trial and error (0.1µF seems ok, though I suspect I could go smaller), since computing the correct compensation is rather messy.  I should probably read Intersil Application note AN9415.3 (or some similar App Note) to learn how to do the compensation correctly, but it is certainly beyond the scope of this course.  I’m now going to have to think very carefully about how the power amp design task is going to be formulated, so that it is doable by the students but not cookbook.

My Laser Boyfriend’s Grad School Survival Guide

Filed under: Uncategorized — gasstationwithoutpumps @ 11:05
Tags: , , ,

I’ve been meaning to recommend to all the grad students in my department that they read My Laser Boyfriend’s Grad School Survival Guide: How to make the most of the worst four to seven years of your life.

The advice in that blog post is excellent, particularly the parts about making friends with other grad students, finding a lab mentor, being nice to the lab techs, budgeting your time, backing up your computer, fixing things that need fixing, and seeking professional counseling if you get depressed.

Depression is a problem for grad students. I think that about 10% of grad students seek counseling each year, but that is based on a fairly small sample of one computational STEM department—it might vary with the field, with the mentoring styles of the faculty, and with the quality of the social support among the grad students. According to a 2008 blog post from PsychCentral, at UC Berkeley

within one year:

• About 45 percent experienced “an emotional or stress-related problem that significantly affected their well being and/or academic performance.”

• 10 percent “seriously considered suicide.”

They also reported

The majority of grad students actually don’t get help.

While some students consider seeking services, they don’t pursue them. For instance, the Berkeley study found that although nearly 52 percent thought about seeking services, only 27 percent did.

Also, international students are less likely to seek mental health services because of lack of knowledge about services and the stigma associated with mental illness and seeking help.

Their citation for the Berkeley Graduate Student Mental Health Survey has a broken link, but I think I found the 2004 survey as Appendix E to an information packet for the UC Regents, and I’ve provided a link to that packet.  The report does describe their survey method, which relied on responses to to an online survey, a sampling method that is likely to bias the results fairly strongly (but they got a 34.5% response rate, so the numbers can’t be more than a factor of 3 too large, even with the worst bias possible).

So it looks like my view of graduate student mental health may be particularly rosy. I don’t have access to confidential student medical records (nor should I), so it may be that there are more students seeking help in my department than I’m aware of.  Or it may be that our department is less stressful than many, or that our students are more competent than many and so suffer less from imposter syndrome (we do get to be very selective), or that our informal support mechanisms (like an awesome staff grad adviser) work better than most.  I think that my work as grad director for our department could be improved if I knew more about the mental health of the grad students in general, but I don’t know how much I can really do to improve conditions for them.

I’ve been putting off recommending My Laser Boyfriend’s blog post for one reason—the bad title.  There is no way that grad school should be the worst years of your life.  Yes, it is probably the most intense time of learning you will encounter, and you will finally meet and work with people smarter than you, possibly much smarter, but those are good things, not bad things.

Of course, I’m basing part of my opinion here on my own experience, where my 8 years of grad school were some of my best years—low stress, lots of cool things to do, and time to do them.  Having had fellowships that allowed me not to worry about funding or having to please a particular adviser who held the purse strings may have made a big difference here.  That’s one reason I encourage all grad students to apply for any fellowship that they might qualify for—it’s not just to stretch the funding budget but to give the grad students the freedom to explore topics that are not grant funded.

For those seeking an academic career, grad school should be a joy.  After all, the work load is lighter than that of an assistant professor, the schedule more flexible, and the stakes lower.  A student who finds grad school too stressful (under ordinary conditions, not counting demon advisers, family tragedies, or funding disasters) will probably find life as a professor miserable, and should seek a less-stressful work environment.

I’ve been told that the national labs and industrial research both provide less stressful environments, except for the fear of corporate mergers and massive layoffs in industrial jobs. My Dad worked at IITRI and at Argonne National Lab, and I do know that he was sometimes quite worried about the periodic layoffs, but he did not talk about it—so I don’t know how stressful those concerns really were. My own experience has all been in academia, other than one summer in Argonne National Lab and one summer in Bell Labs, both of which were student intern positions and not representative of full-time employment, so I don’t really know whether the national labs or industry are really less stressful than academia, or just different.  A fair comparison would probably require surveying hundreds of people who have had several years in both sorts of jobs and can compare them directly—I’m not interested in doing that sort of work, but I’d be glad of a pointer to research someone else has done.

Popular wisdom claims that the stress of an academic job drops enormously after getting tenure, since job security is then quite high.  I’ve not found that to be the case—it seems to me that the associate and full professors are just as stressed as the assistant professors, but more about how they will handle all the demands on their time and how they will fund their grad students and postdocs than by whether they will have a job in 5 years.

Next Page »

%d bloggers like this: