Posts Tagged Serial

Homebrew bubble counter

Counting bubbles during secondary fermentation

For a while now, my friends and I have been brewing beer at my house.  I was inspired by an old Sparkfun tutorial about a bubble logger for Nate’s terrible wine.  I figured that while logging bubbles is interesting and all, wouldn’t it be more useful to have real-time information on the fermentation process?  I basically copied the optical gate method of counting bubbles, added a sensitive pressure sensor, and an AVR development board (Yes, Arwen, that’s your old TekBots board! 🙂 ).

Just like the Sparkfun tutorial, I used an IR photogate sensor on an S-shaped airlock.  One thing that I thought was really interesting is that the water in the airlock doesn’t block the IR path, it actually improves it.  I ended up needing a potentiometer to adjust the LED brightness on the photogate, this is because it has to be just the right brightness to detect bubble transitions.

Counter closeup

The programming on the microcontroller was really simple.  All it does is keep a clock, and when there is a rising edge of photogate signal (bubble passed) it prints the time and a bubble count to the serial port:

01:20:16:16,01646
01:20:16:18,01647
01:20:16:20,01648
01:20:16:22,01649
01:20:16:24,01650
01:20:16:26,01651
01:20:16:28,01652
01:20:16:30,01653
01:20:16:32,01654
01:20:16:34,01655

I chose to use whole seconds as the time step.  That was certainly an oversight.  When I designed the software, the brew was in second fermentation.  There was a bubble once every 20 seconds or so.  I thought “It couldn’t be that much more during primary fermentation, right?”  Wrong.  During the beginning of primary fermentation, there can be 3 or 4 bubbles a second.  I made up for this oversight in the Ruby script I wrote on the server:

# Get an interval from the last to this bubble in seconds
interval = seconds - last_record_seconds
last_record_seconds = seconds

if interval == 0
	bubbles_per_second += 1
else
# if, in the last second, we counted more than one bubble
# find the frequency by multiplying the bubbles per second
# to bubbles per hour
	if bubbles_per_second > 0
		frequency = bubbles_per_second * 3600
		bubbles_per_second = 0
	else
	# Convert the interval into fractions of an hour
		interval = interval / 3600.0
		# Convert the interval to bubbles per hour
		frequency = 1.0 / interval
	end
		printf("%f bubbles per hour\n", frequency)
		RRD.update(rrd_name, "N:#{frequency.to_s}")

I’ve left out the parts where I initialize the serial port and the RRD database and parse the messages.  I’ve attached the whole script, including the script that generates the graph, at the end of the post.

Chocolate porter brewing record (primary fermentation)

Here is the bubble record from one of our beers.  I was very surprised by the 14,000 bubbles/hour rate achieved a half-day after pitching the yeast.  I adjusted the graph many times to make everything visible.  I absolutely had to use a logarithmic scale on the value access, there is just no other way to be able to see a 14k+ value while still being able to see where 60 bubbles/hour is (this is about when the brewing is finished).  These graphs are always updated, and are available online.  Of course that is only meaningful when there’s a brew going at the moment!

Sensitive pressure sensor

I had grand plans of adding a pressure sensor to try and measure the volume of co2 escaping out of the airlock.  I figured that if I subtracted the pressure after the bubble from the pressure before I could use the ideal gas law and measure the moles of co2 that escaped.  This was all fine and good during secondary fermentation (when I first tried it).

Pressure delta during slow fermentation

During slow fermentation, when bubbles happen less than once per 15 seconds or so, it’s easy to see and measure the pressure difference before and after the bubble.  In the image above, there is about 40 mV of swing before and after.  The time represented in this image is a full minute, so you can see the slow buildup of pressure.

Pressure measurement during fast fermentation

During very fast fermentation, on the other hand, individual bubbles don’t contribute to much difference in pressure.  In the image above, you can see general trends of pressure.  Sometimes, i assume, due to surface tension there aren’t bubbles for a while.  When pressure builds up to a sufficient level bubbles begin.  The pressure drops again and the cycle repeats.  I’m not really sure how much I can do with this data.  The time represented in this graph is 12 seconds, and the bubbles per hour is about 18,000 bubbles per hour (5 * 3600).

Close up of a bubble during fast fermentation

This is just a close up of a single bubble.  There isn’t really any measurable difference in pressure before and after the bubble.  Ultimately, the pressure measurement stuff is on hold for the moment.  If someone reads this that’s really good with the ideal gas law has ideas let me know!

The next step for me is to figure out an elegant way to support many brews.  We’ve got a wine, apple cider, and a beer going at the moment, so I would like to have 3 channels.  Oh well, another project for another day.

Supporting files:

firmware

ruby script

Development board schematic

, , , , , , , ,

18 Comments

Transceiver enclosures

Transciever enclosure

It has been a while since I finished the transceiver modules, and I how now used them in an actual application.  But, before I talk about that, I’d like to show some pictures of the process I used to put them into enclosures.  I had some of these cast aluminum enclosures lying around, so I thought I’d use them.  They’re a little on the heavy side, as the completed weight is around half a pound, but it’s well within the carrying capacity of my Kadet.

Before diving into the process of cutting the holes, I want to show some images of the transceiver board with the RFI fence installation process.

Cutting copper sheet

For use with the spectrum analyzer project, I found some sheet copper at the craft store.  It was sold at a local crafts store, and I think it was for etching.  I chose the thickest one they had.  So far, the best way I’ve found to cut it is using an exact and straight edge.  I tried scissors, and it didn’t really work.

RFI Fence

Once I had a strip of copper cut, I cut openings for the power and control traces and soldered it onto the PCB.  I also soldered it onto the SMA connector.  Once all that was finished, I soldered on a lid.  Lots of solder flux helps here.

Once the board was prepared, both by soldering on a fence and replacing the pin header with a right-angle one, I began to prepare the enclosure.  I was intending to drill a hole for the SMA connector, then cut a hole for the digital connection.  The SMA connector hole was trivial to make, though the connector I soldered onto the board was a little short.  I ended up having to use an O-Ring from the hardware store (look in the plumbing section) to hold it in.  When an antenna or cable is screwed on the O-Ring compresses, having the nice side-effect of sealing it.

DB-9 template

For the digital connection, I decided on using a DB-9 connector.  I figured it was a prolific connector, so I should have lots of connectors laying around.  That didn’t turn out to be as helpful as I had hoped, but I’ll get into that later.  To create nice holes for the DB-9 connectors I decided that I could use an old PCI bracket as a template.  I lined the bracket up against the side of the enclosure and traced it.  On the black box, I traced it using a knife, and on the grey box I used sharpie.

DB-9 template using sharpie

Once the outline was traced onto the box, I drilled holes for the retention screws.  Then, I drilled out as much as I could of the trapezoid shaped interior.  I most used the drill press, then the dremel with a router/cutter bit.  I made sure to leave a margin inside the perimeter to remove with the files.  I had avoided purchasing a set of jewelers files for a while, I think I assumed that they were expensive.  They’re not, you should get a set.

Finished penetration

In the photo above, you can see the finished penetration for the DB-9.  I beveled the inside edge to make room for the fillet on the connector that I had.  The black box got a male DB-9, and the grey box got a female one.  The holes need to be about the same size, as the male shroud always has to fit over the female connector body.

DB-9 connector installed

In addition to the RF and digital connectors, I needed a way to securely mount the internal circuit boards.  The way I chose to do this was first to drill holes in the bottom of the box, then “countersink” some screws into it.  I have countersink in quotes because I don’t have a countersink bit, so I used a larger drill bit.  You can see the results of this in the headline picture of this post.  Though I think it looks pretty good, I still decided to buy a drill & tap for 4-40 screws after building the black box.  For the grey box, I used the tap and screwed directly into the box.  This requires slightly less hardware and looks pretty good, I think.

Breadboard transceiver circuit

For whatever reason, the board I built for the black box using some veroboard-style construction didn’t work the same as the breadboard.   Because I was under time constraint (I was planning on flying one of the transceivers over the weekend.  I decided to put it back on the breadboard and use it as the base station.  This version uses an FTDI cable to connect to my computer.

Flyable transceiver module

For the grey box, I used an extra ATMega48 breakout board I had.  This one worked just fine in the enclosure, so I flew it.  I also built a power regulation/distribution board, seen on the right of the photo.  This concludes this article.  Now that I’ve got at least one flight worthy transceiver I can test them in flight.  That’ll be detailed on a future post.

, , , , , , , , , ,

No Comments

How to hand-solder a Micrel module (don’t)

I’ve been developing a RF transceiver for use with my Kadet.  I really like these Micrel RadioWire modules, but they basically must be reflow soldered.  They’re also about $16/ea. in single unit quantities, so I want to make sure that the carrier PCB works before I solder on the module (I’ve made that mistake already!).  With that in mind, I had to figure out how to solder the module on after all the other components were installed.  This means hand soldering.  Looking on the datasheet, they say that it can be done, using solder paste.  So, here’s documentation of my attempt.

PCB ready for module

PCB ready for module

This is the starting point.  I cleaned the surface with isopropyl alcohol (IPA).

Solder paste applied

Solder paste applied

I applied the solder paste as normal, and cleaned the module with IPA as well.

Module seated, waiting for heating

Module seated, waiting for heating

This is just before heating the pads with a soldering iron.  I heated each one until the solder melted, but it didn’t bond with the module.  Before I got too far, I removed the module and examined the results.

Results of the first attempt

Results of the first attempt

I cleaned all the surfaces with solder wick and IPA, and tried again.

Results of attempt two

Results of attempt two

This time, I held the soldering iron on each pad for much longer.  The solder bonded to the module and the PCB, and it held tight.  However, I took a multimeter to it, checking for continuity.  Nearly every pad was shorted with it’s neighbor.  This sucks.

Another view of try two

Another view of try two

With the module throughly bonded with the PCB, and no way to remove it and try again, I decided to try the hail-mary.  I figured that at this point, unless I could think of something, the whole thing was ruined.  With that in mind, I decided to try to reflow the whole thing.  I really had no idea if it was going to screw everything up, especially the FTDI chip on the bottom of the board.

During reflow

During reflow

The reflow went well, I’m pleased with the look of everything.  I also confirmed that the pins are electrically isolated.  Also, on first glance, everything seems to work.  The microcontroller and USB-to-serial chip still work.  I really just need to verify that the transceiver module works, and it will be a complete success.

The moral of the story is:  Don’t attempt to hand-solder the Micrel module.  It probably won’t work.  On the other hand, if you do get it to work, drop me a line, I’d like to know how.

, , , , , , , , ,

No Comments

iPhone controlled TV Lift

Video of the iPhone TV Lift controller working!

Hardware

This was probably one of my most time consuming projects.  Hopefully I can do some justice to the time and work spent through this post.  I should probably begin by describing the whole system.  First, the TV is lifted up & down by a “Lift Tech” lift.  By the way, they get the prize for the most original company name ever.  Their controller box has a port that allows home automation systems to control its operation.  They did a really good job of making it extensible.  You can control it in a variety of ways: short one pair for going up, another for going down; short a pair for down, open for up; etc.  I had intended to use the first mode, but I think I fried a channel on my opto-isolator.  I ended up using the second method because it only required one channel.  Unfortunately that means I can only have the TV up, or down.  I wasn’t too disappointed, though, because I don’t expect to want it any other way very often 😉 .

TV Lift controller box

TV Lift controller box

The board I designed to interface the TV Lift to the server was fun to design and build, even though it was prone to error.  I had originally intended to use the Microchip ENC28J60 ethernet controller. I thought it’d be cool to have the iPhone app connect directly to the board’s ethernet controller and microcontroller. Unfortunately, I screwed up the interface from the ethernet controller (specifically the physical layer circuitry) and the magnetics. This interface is harder than it looks, trust me. I thankfully included a serial port on the board (which I had other plans for) and used that instead. This choice made the microcontroller software extremely simple. All it really has to do is wait for a ‘d’ character over the serial port and lower the TV, a ‘u’ character lifts the TV, and a ‘s’ character queries the controller for the current state. I’ve included an image of the schematic for the board, in case you are curious about my lofty intentions.

TV Lift Schematic

TV Lift Schematic

If you’re interested, the board I used on my reflow soldering toaster oven page is the TV Lift board.  Incase you don’t want to go over there, here is a picture of it mostly finished up:

Controller board installed

Controller board installed

Using the RTS line for reset

Using the RTS line for reset

There is one more thing that I had to change.  For some reason the controller board that I made crashes after a while.  I have to use a ladder to reboot it (power-cycle).  Hauling the ladder around is annoying, and I don’t like doing it.  To allow myself to reboot it remotely, I added a diode from the MCLR line (reboot) of the microcontroller to the RTS line of the serial port.  The RTS line is used for modems from back in the day.  Now I can use it to force MCLR low, to reboot the controller, if it’s “low” (-5 volts).  It’s a hack, but what are you going to do?

Software

The software for this project is deceptively simple.  The iPhone software basically connects to the server using a socket, and if the “up” button is pressed it sends a ‘u’ over the socket, and a ‘d’ if the down button is pressed.  That’s it!  Server software is almost identical, however it listens to the return of the serial port and expects my controller board to return a ‘U’ or a ‘D’ from the ‘u’ and ‘d’ command.  If these are not received, the board is reset and the command is tried again.

Conslusion

Well, that’s all there is.  I hope you’ve enjoyed it, I know I have.  Please, feel free to ask any questions in the comments section!

, , , , , , ,

14 Comments

Adding a serial port to the Netgear WGR614L

Netgear Serial Port

I added a serial port to my wireless router so it could monitor the weather.  I know, why does a router care what the weather is like?  Well, it doesn’t, but I do.  Actually, I want to add a weather widget to this blog and also upload it to weather underground (not the one with Bill Ayers 😉 ).  << Correction! I’ve finished the weather station, and I’m not using the netgear router or weather underground.  See this post for details. >> I haven’t finished any of that yet, but it came in handy later when I bricked it!
When they designed this AP, Netgear was nice enough to make it easy to open.  All that you need to do is pull back the rubber feet and use a T-9 screwdriver.  The little feet even stay captive during the process, mighty convenient.

Removing the screws

Removing the screws

The bottom plate comes right off, revealing the mainboard, which lifts out.

Disassembled

Disassembled

Unfortunately, I don’t have a device without headers installed, but you can see them installed in the lower left corner.  The single-row one is the serial port, the double-row is the JTAG.  From the factory mine had solder blobs on the serial port.  I had to use solder wick to remove it.  Once the holes are cleaned out, installing the header is a snap.

Now that it’s easy to attach to the port, we need to convert the 3.3v CMOS serial signal to true RS232.  The typical way you do this is to use a RS232 transceiver.  I had a SIPEX transceiver lying around, so I used that.  Just follow the datasheet for whatever you use.  The pinout for the serial port on the netgear is:

1 -- VCC
2 -- RXD
5 -- TXD
6 -- GND

I’ve attached the approximate schematic that I used.  There are a couple of important things to note, because the router uses 3.3v and the RS232 transceiver uses 5v we need to negotiate the difference.  Referencing the transceiver’s datasheet, the minimum voltage necessary for a ‘1’ is low enough that a 3.3v CMOS signal is sufficient, so we can just hook it up.  The signal going toward the router, however should not exceed it’s VCC.  To achieve this using a minimum of parts we use a pull-up resistor fed from the device’s VCC and a diode biased toward the transceiver.  This way, when the transceiver is outputting a ‘1’ the 5v are blocked, but while outputting a ‘0’ it will drop the voltage sufficiently enough for the router to see it as a logical low.

schematic

schematic

Top view of the adapter

Top view of the adapter

Bottom view

Bottom view

If you want the router to be the “slave” of the serial connection (like a modem) then reverse the TXD/RXD pins on the DB9 connector (pins 2 &3).  I specifically wanted the router to be the master to hook it up to other stuff (my weather station, remember).

To get the 5V necessary for the transceiver I tapped the 12V power from the wall adapter and fed it through a 7805.

Stealing 12V from the wall adapter

Stealing 12V from the wall adapter

Adapter installed on mainboard

Adapter installed on mainboard 

Adapter board installed

Adapter board installed 

Mainboard and adapter in case

Mainboard and adapter in case

Connected with a NULL Modem cable

Connected with a NULL Modem cable

In the above photo I’m using a NULL Modem cable because, remember, the router serial port was installed as if it’s a computer.

Netgear preboot console

Netgear preboot console

It works!  The photo above is the preboot console of the router.  Notice that the MAC address is FF:FF:FF:FF:FF:FF.  I’m not just paranoid, this is one of the failure modes of these routers.  The DD-WRT firmware overwrites some of the NVRAM in a weird way and this happens.  It’s pretty screwed, but at least with a serial port you can fix it 🙂

Anyway, enjoy!

, , , , , , , ,

No Comments