# Gas station without pumps

## 2017 August 6

### Beacon detector board

I’m planning to sit in on CMPE 118/L (Mechatronics) this fall, and so I started looking over some of the material for the course from previous years.  One exercise involved designing a “beacon detector” that signals when it sees an infrared signal modulated with a 2kHz square wave. The exercise calls for an all-analog solution (phototransistor, transimpedance amplifier, active filter, rectifier, peak detector, …), which I plan to do when the time comes, but I got intrigued by the idea of doing an almost purely digital design.  That was the motivation for the Goertzel filter blog post.

I decided to take the digital design further and make a beacon detector that not only detects the 2kHz IR beacon, but also indicates what direction it is in.  To do this, I wanted 8 phototransistors around a circle, with one every 45°.  One can get a crude estimate of the angle from just which detector gets the strongest signal, but with wide-angle sensors one should be able to get finer estimates by looking at the ratio of the signals from two adjacent channels.

Because I was deliberately going for minimal analog design as an exercise, I used just a phototransistor and a pullup resistor for each channel, and a Teensy LC board for all the processing.  I chose SFH325FA side-look phototransistors, because they provide a nice, cubical package that I thought would make them easier to align.  They are surface-mount components, but with a 2.54mm pitch for the two terminals, they aren’t much harder to solder than through-hole parts.

For testing, I soldered one of the SFH325FA phototransistors to a pair of male header pins. This allowed me to experiment with different pullup resistor sizes in different lighting conditions and at different distances from an IR emitter.

My experimentation with different pullup resistors indicated that I could not operate in full sunlight, no matter what size pullup resistor I used—when the pullup was small enough that the phototransistor had sufficient voltage across it in full sunlight, the signal from the IR beacon was too small to be useful.  With AC-coupled amplifiers, I could have made it work, but I was committed to nearly pure digital solution.  If I had sunlight nearby, but the phototransistor itself was shaded, then I could go up to 22kΩ for the pullup without problems. The limiting factor was then that a very close beacon could saturate the detector, making it hard to determine power ratios.  I ended up choosing 22kΩ as my pullup, as I wanted to detect beacons from up to 2m away.

With a 22kΩ pullup and a strong signal, I can get a very clean “shark’s fin” waveform, because of the capacitance of the phototransistor acting with the resistor as a low-pass filter.  This low-pass filtering helps remove aliasing artifacts from the sampling by the analog-to-digital filter.

Behind each phototransistor I placed an LED, to indicate which channel had the maximum signal.  I charlieplexed the LEDs, so that I needed only 4 I/O pins for the 8 LEDs (I could encode up to 12 LEDs with 4 charlieplex wires). I used WP710A10SGC green LEDs for the indicators, because I had a lot of them around, but it would have been better to use an amber LED with a wide-angle, diffuse case, as the green indicators are only clearly visible over a fairly narrow angle.  The current-limiting resistors I used would keep the current low enough even with a low-forward-voltage red LED.

I also added an RGB LED to indicate the overall state—I used a common-anode one, because my son had a lot of them with diffuse cases, which are best for an indicator that needs to be seen from any angle.  The RGB LEDs were part of an unidentified lot from China, so I don’t have a part number or specs for them.  I hooked them up to PWM pins, so that I could adjust the brightness and color as needed.

I also designed in a connector for SPI connection, so that the board could be used a slave peripheral of another microcontroller.  I used Eagle on my old laptop to design the PCB (I know that in Need to find new PC board software and PCB CAD tools I said that I would be trying to switch to KiCAD or Diptrace, but I was lazy and stuck with what I already knew how to use).

I sent the design to Seeedstudio to make the PCB—like many of the Chinese firms that cater to hobbyists, they had a sale in July of boards up to 10cm×10cm for only $5. Of course, it cost me another$21 for shipping with DHL, because I was too impatient to wait for Chinese air mail (and not trusting enough of the reliability). I chose Seeedstudio because they had the best user interface to their design-rule check, and at least as good pricing as anyone else.

The boards arrived quite quickly—only 8 days from order to delivery. Here is what they look like:

The back of the board has some documentation to remind me what is connected where.

The front of the board has relatively little documentation.

The boards are 8cm×8cm, fitting comfortably within both the cheap manufacturing limit and the Eagle free-version size limit.  I made them this big so that the Teensy LC board would fit without interfering with mounting holes (for M2 and M3 screws) and a central hole for attaching the board to a servo arm.

Getting a good right angle for the surface-mount phototransistors took some practice:

My first solder joint for the SFH325FA phototransistor tilted the transistor substantially, because the solder underneath formed a wedge. I reworked it a couple of times and finally got something sort of acceptable.

By the fifth phototransistor, I had worked out a technique that seemed to hold the phototransistor cleanly at a right angle. There is probably not much solder underneath the phototransistor, but the large wedge behind the phototransistor should provide sufficient mechanical strength.

Here are pictures of the populated board:

The back of the board does not look very different after being populated. I put one M3 screw in the bottom M3 screw hole, in order to see how compatible the screw hole design is with the screw head.

The top of the board, when populated shows how close channels 0 and 7 come to the Teensy board.

Here the board is on (powered through the USB cable), detecting an IR beacon about a meter away in the direction of channel 4. The green LED by the channel indicates the direction, and the green RGB LED indicates a strong signal.

I put the header pins on the pullup resistors, so that I could record the signal seen by the analog-to-digital converters.  Unfortunately, the signal is much noisier than I expected:

The large spikes are at 15kHz, and probably correspond to noise injected by the ADC sampling.

I turned off the beacon and looked just at the noise spikes, using the 10× probe on the oscilloscope to get better bandwidth.  I sampled at 100MHz and averaged 1000 traces to get a clean view of the signal (the triggering was set far enough from the background level that only fairly large spikes were captured, but close enough that the 1000 frames were gathered as quickly as possible).

The pulses are very short (2–3 µs), so almost certainly correspond to the charging of the sampling capacitor. After looking at this waveform, I changed my sample time on the ADC to 2µs (it had been 1µs) to reduce the noise in what the ADC reports.

This post has gotten more than long enough, though I still have a couple of things that should be added: a schematic diagram of the board and a plot of the reported angle vs actual angle.

The schematics from Eagle are really ugly, so I’ve been thinking about redrawing them with SchemeIt—perhaps that can be a subsequent post.

The reported angle vs. actual angle plot is going to require building a jig that allow me to set the angle precisely.  I tried jury-rigging something out of Lego today, but the result had too much slop—the board could not be reliably set level with the IR emitter at a fixed angle.  The OED-EL-1L2 5mm IR emitter does fit in the middle hole of a Lego Technic brick, so I using Lego to align the IR emitter was attractive. I may have to make something out of wood and MDF (medium-density fiberboard) for a more solid test jig.  The M3 screw holes will allow me to attach the board firmly to MDF with standoffs, and I can drill holes in Lego bricks to make a stand for the IR emitter.

## 2014 July 18

### How to sell a widget

SparkFun has a tutorial on how to sell “widgets” through them at How to Sell Your Widget on SparkFun – Learn.SFE:

Have an awesome electronic widget that you want to get to market? Great! We are always listening for new ideas from our customers and the community. We get many inquires on this topic, so read this tutorial carefully to keep your product pitch from getting lost in the shuffle.

We’re lucky, here at SparkFun, to have an amazingly creative and talented group of customers. Not only can they identify gaps in the catalogs of electronics suppliers, they can create a gizmo that fills that hole. But, going beyond a prototype or even a limited-quantity production run, often the hardest task in getting your world-altering product out there is producing, marketing, and/or selling it to the masses. That’s where we come into the picture.

The advice there is seems fairly reasonable.  They offer a choice of two models: make it yourself and have them sell for you, or have them make it and pay you royalties.  They tell you how to pitch products to them and how to design for them to be able to manufacture stuff.  Most of the stuff they sell is PCB boards, so they give quite a bit of advice about PCB design to fit their pipeline—they use Eagle, but ‘All parts are placed on a 0.005″ grid. If possible, use a .05″ grid.’ That must get irritating with modern parts that are convenient round metric numbers, not mils.   They also want version numbers in the bottom copper, which is reasonable for some designs, but not all.  They also encourage people to use their Eagle libraries, but my son and I have found their pad layouts to be very sloppy (putting silkscreen over SMD layers, getting the keep-out areas off by a little bit, not fixing the fonts on the “>NAME” and “>VALUE” labels to meet their own requirements, and so forth).

Still, it is good that they put out their design rules and provide clear guidelines to new designers.

I’ve thought a few times about putting out some of my designs through SparkFun or Adafruit Industries—perhaps an improved version of the blinky EKG as a kit.  SparkFun now sells EKG electrodes and snap leads for them, and even have a heart-rate monitor board (based on the AD8232 chip) and the “BITalino” biomedical board, so I suspect that they are interested in the market.

The BITalino is outrageously expensive and their EKG electrodes are about 3 times the price of buying them at Amazon, but the AD8232 chip actually looks like a nice one for building an EKG front-end and reasonably priced, so I’m not sure they’d have much interest in a through-hole part kit for do-it-yourself EKG that isn’t quite as good, unless it could be sold very cheaply or as an educational product (which is what the blinky EKG is aimed at, anyway).

I have some other ideas for products that I might be marketable, but I don’t know whether I have the time to refine them to the point of pitching them to SparkFun.  I can justify some time spent on doing electronics as a hobby, some as necessary learning for teaching my applied electronics course for bioengineers, and some as engineering-for-manufacture experience (something I never had any instruction in, despite my years as an engineering professor). But when the electronics work starts cutting into the time I need to spend on writing my book, teaching my classes, or doing collaborative research with other faculty, then I have to draw the line.  I’ve also got a lot of administrative responsibilities now (undergrad director and faculty adviser for two BS degrees, Program Chair for bioengineering, and Vice Chair for the Biomolecular Engineering Department), so writing time and research time have gotten doubly precious.

I do have one project this summer that I’m going to try to get fabricated for me—it is all SMD parts, including some that are hard to solder by hand (pads under the chips), so I don’t want to do it myself.  The project also calls for a lot of identical boards (20 to 50 of them), so a prototyping house seems like the way to go.

I’m looking currently at Smart Prototyping to do the PC board fabrication and assembly—they may not be the cheapest, but they have a comprehensible pricing scheme on their website, and they replied within 12 hours of my request for a quote. They also have a nearly turnkey system—I send them the Gerber files and the Bill of Materials (BOM), and they’ll make the boards, buy the parts, and assemble the boards.  They’ll even test them for an additional charge, though these boards are simple enough that I can test them myself at about 5 seconds a board, so their testing would not be worthwhile unless they guaranteed their assembly (which none of the prototype houses can afford to do with untested designs).

I also considered Elecrow, which has a similar service, but their pricing information on the web page is rather vague: “For BGA or IC with pads under IC, The quotation will be a little higher.” and “We will give a discount for the PCB assembly service according the some factors (assembly time,Hard or Easy to assemble or requirements etc.).” I prefer sites that have clear pricing even if it is slightly higher, so that there are no surprises. I suppose I could ask Elecrow for a quote and see if they respond as promptly as Smart Prototyping did.

Incidentally, my design does not follow all SparkFun’s guidelines—for one thing, I placed parts on a 0.5mm grid, not a 0.005″ gird, and the board is not rectangular.  Still, if the design I’m working on turns out well, I might pitch it to them, as I see some potential for it appealing to the open-source hardware market, and the violations of their design guidelines made good sense for this application.  Note: I’m deliberately not saying what the design is—I’ll reveal it once I’ve gotten a working prototype, when I’ve decided whether I want to commercialize it or not.

## 2014 April 7

### Feedback on first lab report

Filed under: Circuits course,Printed Circuit Boards — gasstationwithoutpumps @ 17:11
Tags: , , , , ,

Most of today’s class was taken up with feedback on the design reports that students turned in by e-mail on Saturday.  Overall the reports were not bad (better than the first reports last year), but I think that the students could do better.  Here are the main points:

• Anyone can redo the report to get it re-evaluated (and probably get a higher grade).
• No one attempted theV1 &V2 problem, so I reassigned it for Wednesday.

The circuit I had given as an exercise, asking them to determine the output voltage V_out.

• A lot of reports mixed together two different problems:the 1kΩ–3.3kΩ problem and the optimization to maximize sensitivity of the thermistor temperature sensor.  I encouraged students to use more section headers and avoid mixing different problems together.
• Figures should be numbered and have paragraph-long captions below each figure.  I reminded students that most engineering reports are not read in detail—readers flip through looking at the pictures and reading the picture captions. If the pictures and captions don’t have most of the content, then most readers will miss it. I also pointed out that many faculty, when creating new journal articles, don’t ask for an outline, but ask for the figures.  Once the figures tell the right story, the rest of the writing is fairly straightforward.
• A lot of the students misused  “would” in their writing, treating as some formal form of “to be”. The main use in technical writing is for contrary-to-fact statements: “the temperature would go down, if dissipating power cooled things instead of heating them”.  Whenever I see “would” in technical writing, I want to know why whatever is being talked about didn’t happen.
• A number of the students had the correct answer for the optimization problem, but had not set up or explained the optimization. Right answers are not enough—there must be a rational justification for them. In some cases, the math was incomprehensible, with things that weren’t even well-formed equations. I suspect that in many cases, the students had copied down the answer without really understanding how it was derived and without copying down the intermediate steps in their lab notebooks, so they could not redo the derivation for the report.
• A number of the plots showed incomplete understanding of gnuplot: improperly labeled axes, improperly scaled axes, plots that only included data and not the models that the data was supposed to match, and so forth. I pointed out the importance of sanity checks—there was no way that anyone ran their recording for 1E10 seconds! I was particularly bothered that no one had plotted the theoretical temperature vs. voltage calibration based on the parameters from their temperature vs. resistance measurements, so I could not tell whether the voltage divider was doing what they expected it to.
• No one really got the solution for the 1kΩ–3.3kΩ problem perfectly. A number of them set up the equations right and solved for R (getting 2.538kΩ), but then not figuring out what Vin had to be.  It turns out that Vin depends strongly on R, so rounding R to 2.2kΩ or 2.7kΩ results in different good values for Vin, and the 2.2kΩ choice gives a more desirable voltage (around 3.3v, which we have available from the KL25Z boards, as it is a standard power-supply voltage).

I also showed the students how I had expected them to setup and explain the optimization to maximize sensitivity at a particular operating temperature.

After that feedback, I started on new material, getting the explanation of amplitude, peak-to-peak, and RMS voltage. I think that the RMS voltage explanation was a bit rough.  I was deriving it from the explanation that we wanted a measurement that represented the same power dissipation in a resistor as the DC voltage, and I got everything set up with the appropriate integrals, but I forgot the trig identity $(cos(\omega t))^2 =\frac{1}{2} (1-cos(2 \omega t))$, and ran out of time before I could get it right.  I did suggest that they look up the trig identity and finish the integration.

I had hoped to get at least partway into Euler’s formula, complex sinusoids, and phasors, but the feedback took longer than I had expected. Those topics will have to wait until Wednesday or even Friday, since Wednesday we’ll want to do the modeling of the DC characteristics of the electret mic, and talk about how the mic works.

## 2014 April 4

### Third day of circuits class was low key

Filed under: Circuits course,Printed Circuit Boards — gasstationwithoutpumps @ 21:34
Tags: , , ,

Today’s class was not content-rich, but a low-key decompression after yesterday’s too-long lab.

I started out taking some questions from the class, which were mainly about what to do in the design report.

I then discussed my ideas about what had gone wrong with yesterday’s lab that made it take so long, and both how I planned to fix the problem next year, and what we could do as a class to keep it from happening again this year. I particularly stressed the importance of doing the pre-lab work early, so that they could ask questions in the lecture portion of the class, rather than taking up valuable lab time. I also suggested that they do the writeups for the Tuesday lab before Wednesday’s class, so that they would have much less to write up after the Thursday lab—making the Friday deadline for the writeup feasible.

I asked the students for their ideas about what were problems with the lab, and they agreed that the soldering and installing PteroDAQ software took up almost 2 hours, so it would be best to separate that into its own lab period. They also brought up their frustration with the design problems I had given them: not so much the optimization for the lab, but the design exercise I had added: Design a circuit to convert a 1kΩ–3.3kΩ variable resistance sensor to a 1v–2v voltage output, with 1v for the 1kΩ resistance and 2v for the 3.3kΩ resistance. Use standard resistor values that you have in your kit. They were frustrated because they did not know how they were supposed to approach the problem.

This gave me an opportunity to explain what I was trying to do with problems like that. It was indeed entirely appropriate that they should have been uncomfortable with the problem, because I was trying to push them to think in new ways—to handle problems that were not completely laid out for them ahead of time, but where they had to struggle a bit to figure out how to formulate the problem. This is precisely what engineers have to do—to take problem statements that may be unclear or not precisely solvable, figure out how to formulate them more precisely, set up equations, solve them, check that the design they come up with makes sense, and (often) adjust the problem statement to reflect what is actually doable.  (I didn’t say it, but in this case you have to accept a few percent error in the output voltage or the resistances in order to use standard values.)  I promised them more uncomfortable problems in future, in an attempt to stretch them.  They seemed a little more at ease with the difficulty they’d been having, once they realized that this was expected—I think some had been afraid that they were in over their heads and were panicking.

Another student mentioned having heard of an analogy between programming and engineering. I pointed out that programming was a form of engineering, and that all engineering required identifying problems, breaking them into subproblems, and solving the subproblems.  Programming tends to involve many, many subproblems, with formal interfaces between them, but even the simple hardware we’d do in this course involves breaking problems into subproblems, using block diagrams (which I promised to talk more about later in the course).

Somewhere in the discussion of what engineers do, I brought up the example of the student who had presorted his resistors and taped them into a booklet.  What the student had done was to identify a problem (that it would be hard to find the resistors he needed), come up with a solution, and implemented it. I pointed out that the technology he used (scotch tape) was available to them all, as was the notion of sorting. The engineering thinking comes in looking at something unpleasant (finding a sheet of resistors in a pile of 64 different sizes) as a design problem to solve, rather than something to get irked about or try to avoid. I’m hoping to get them thinking more like engineers during the course of the quarter—anticipating problems and looking for ways to solve them.

Generic voltage divider circuit.

I took more questions from the class—there were a few about voltage dividers, which I explained again in a different way, using analogies to similar triangles and giving them the voltage divider formula in the form $I = \frac{V_{out}}{R_{1}} = \frac{V_{in}}{R_{1}+R_{2}}$.  I did not give the voltage divider in the “ground-reference” format shown to the left, but drew lines out horizontally from the nodes, and had the voltages indicated as distances between the lines (like in a mechanical drawing), to give them a more visual representation of voltages as differences.  I also had them figure out what the voltage across R2 would be and how it would relate to the other voltages.

The more different ways they work with voltage dividers, the better they will internalize the concepts and be able to use them in designs.

The circuit I had given as an exercise, asking them to determine the output voltage V_out.

The circuit with explicit sources and voltmeter implied by the circuit I had given them.

A question also came up about what it meant to have 2 input voltages with no ground shown in a circuit (as I had given them as an exercise in the first lab handout).  That is an excellent question—one that uncovered an assumption I had been making that I had never explained to them! I explained that what an “input voltage” meant was shorthand way of drawing two voltage sources.

I’ll have to fix the handout next year to include this explicit explanation of a common shorthand—I’ve used it for so many decades that it simply hadn’t occurred to me that it wasn’t obvious. I apologized to the class for having skipped the explanation, and pointed out the importance of them asking questions, because otherwise I would never know where some omission like this was confusing them unnecessarily.

When they ran out of questions, I got in some new material, explaining the difference between “precision”, “repeatability”, and “accuracy”. The digital thermometers they used in lab were a good example—they had a precision of 0.1°C, were repeatable within a single thermometer to about ±0.2°C, but between thermometers were repeatable only to about ±2°C. The accuracy is unknown, since we did not have anything traceable to a temperature standard, but the ice water baths should have been close to 0°C, so the thermometers we used on Thursday were probably less than 1°C off, but the larger set we used on Tuesday included some that were 3°C or 4°C off. In the repeatability part of the talk, I managed to bring in the biologists’ notion of technical replicates (different measurements of the same sample) and biological replicates (different cultures or tissue samples), and why biological replicates show less repeatability.

I also used this as a chance to talk about the uselessness of ±0.1°C or error bars without an explanation of what the range means (standard deviation, 90% confidence interval, 3σ, 5σ, observed range, …), and the even greater uselessness of “significant figures” as a way of expressing uncertainty.  I told them that I’d rather see 1.031±0.2 than 1.0 as a way of expressing the uncertainty in a measurement.

Towards the end of the 70-minute period, I got in a little discussion of AC voltages as time-varying voltages, and that we usually did analysis in terms of simple sinusoids, rather than the complex waveforms that we’d actually be measuring. I did assure them that, though there was a lot of mathematical machinery (Fourier analysis) that justified this way of doing things, the math was outside the scope of the class and I’d only be giving them intuitive ways of working with AC. I only got as far as giving them amplitude—telling them that I’d start with RMS voltage next time. (I’d originally hoped to explain RMS voltage today, but that would have taken another five minutes, and we were already 3 minutes over.)

Overall, I was fairly pleased with how today’s class went—the students are getting more comfortable asking questions and I’m getting a better sense of what they already know and what they need explained.  Undoubtedly I’ll make more mistakes like not explaining the “hidden voltage source at inputs” convention, but I think we’ll recover from such mistakes a little quicker each time, as the students get more confident in asking for clarification.

## 2013 September 3

### My son’s first PC board

In Towards automatic measurement of conductivity of saline solution, I complained about not being able to use the KL25Z board, because my son was using it.  What he was doing with was building his first prototype for the light gloves project:

Here is his first PC board design, populated and mounted on the Freedom KL25Z board. The 5cm×5cm board (the cheap size from Iteadstudio) is a bit smaller than the KL25Z board is wide, so it only plugs in on one side (there is a screw acting as a spacer to keep it from being a cantilever). He has not yet mounted the Bluetooth module.

The prototype board has many differences from the final design: no battery, no battery charger, no buck/boost regulator, no flash memory, no processor, screw terminals instead of jacks—even the LED driver chip is different, since the chip he plans to use is only available as a surface-mount device. But there is enough of the design here to start demoing and writing code.  They are hoping to keep the final board below 5cm×5cm, so as to get low PC board prices even in very small production runs.  That will mean all surface-mount parts, so I think I’ll have to get a hot-air rework tool so that they can assemble a prototype—I’ve been thinking that I might want one for myself to play with surface mount designs, so this isn’t really a hardship.

My son still owes me some money for buying him the PC board run, the screw terminals, the Bluetooth module and some heat-shrink tubing. It is a bit annoying that he isn’t old enough to get his own Visa card, so that he can do his shopping without me as an intermediary. (We’re not talking big bucks here—we’ve spent more on pizza for him when they work through dinner than they’ve spent on all parts combined.)

I’m pleased that he got his first PC board working on the first attempt—he did the design entirely on his own, though he did ask my advice about things like via sizes and how fat to make the wires. Since there can be moderately high currents for the LED driver, I recommended that he make the ground and power lines as fat as he could, and he decided to do a flood for each. The board looks quite nice:

The top view of the board with the screw terminal to be mounted on the top and sides, the header on the lower left, and the Bluetooth module on lower right. The hole near the top right is for the screw that acts as a spacer.

This is what the glove looks like with the five RGB LEDs lit up (I understand that the final design will have more LEDs—but the through-hole driver chip has limited pinout). They don’t have the user interface written yet, so the lights were set up by a quick-and-dirty Python script talking to the KL25Z board over a USB cable (which is also supplying power).

They have not implemented programmable flashing yet, but the pulse-width modulation (PWM) frequency is set very low here (much lower than what they intend to use in the final design), so that one gets a stroboscopic effect even with steady light settings, just from the PWM. That’s not my son in the picture, but the high-school student who started the project—my son has done most of the electronics and programming, but did not originate the idea.

The two teens spent a big chunk of the day wiring up the LEDs and writing a small test program, as they want to demo the glove tomorrow for the back-to-school event. It may also be an enticement for teens to join an Arduino/microcontroller club—look at the cool stuff you can learn to make!

Another view of the prototype light glove in action.

Once they got the demo working, they invited over a third member of the team to do some brainstorming about what else needs to be done (and how they’ll do it). It looks like they’ll be talking half the night.

Since it is clear that my son will be spending a lot of time on this engineering project this year, we decided to make it part of his official school work.  In addition to the engineering design work, he’ll also do some a paper for his econ course (on pricing the components and manufacturing, and setting a retail price for the gloves), and papers for a tech writing course.

His first tech writing assignment is to write up a description of the color space he decided to use for representation of colors in the program, and why he chose that color space out of the dozens available.  He spent a week thinking about color spaces anyway, before settling on a commonly chosen one—so writing up that reasoning for the other members of his team will be a good writing exercise.

Next Page »