Building a wireless sensor hub (part ii)

After well over a year sat on my ToDo list, I’ve finally got around to progressing my plan to turn a spare WRT54GL router into a wireless sensor hub. I decided that I didn’t want to stack interfaces, adding RS232 interfaces, then adding RS232 to 1-Wire converters to them, so after a quick check on my likely needs, I decided to instead simply add a single 1-wire interface directly to the router.

That will allow me to put the router out in the garage, where it can attach itself to the main house wireless network, and extended that to it’s wired ethernet ports, to which I can easily attach other devices in the future. In addition, I can add sensors and actuators to the routers newly added 1-wire network. Small programs on the router can read those sensors, and publish their readings to the MQTT server running on my home server back in the house, making them generally available. Similarly, messages published to that MQTT server can be read by programs on the router, and turned into commands to the 1-wire actuators, allowing the automated control of external equipment.

The Linksys WRT54GL has a pair of 3.3v TTL UARTS on the motherboard, which are not externalised. One of these is used by the router during start up, and can only be used after that startup has completed, but the other is completely unused. Both are exposed as pinouts on an unimplemented header (JP1) on the router PCB, as follows:

Pin 1:  3.3V         Pin 2:  3.3V
Pin 3:  Tx (ttyS1)   Pin 4:  Tx (ttyS0)
Pin 5:  Rx (ttyS1)   Pin 6:  Rx (ttyS0)
Pin 7:  NC           Pin 8:  NC
Pin 9:  GND          Pin 10: GND

Note that neither of the serial ports support hardware flow control (it’s not pinned out on JP1 on the Linksys PCB), so you need to use software flow control when connecting to these ports.

By attaching a DS2480B (Serial to 1-Wire Line Driver) the unused serial port can be used to control the 1-wire network. However, the DS2480B expects 5v TTL levels, not the 3.3v produced by the router, so some level conversion is required. I also wished to protect the router in the event of a lightning strike to the (potentially) long 1-wire cable. Together these requirements (and wanting to keep the router looking as normal as possible) meant that I needed to create some electronics – something I’ve not done in a while.

In the end I created a simple circuit to convert the levels between the 3.3v running in the router, and the 5v required by the 1-wire network. I powered the circuit from a combination of the 12v supply to the router, and the routers internal 3.3v power rail. The circuit I came up with takes inputs on the left of (top to bottom) 12v, 3.3v (Pin1 JP1), UART Rx (Pin5 JP1), UART Tx (Pin3 JP1) and GND (Pin9 JP1). The outputs on the right (top to bottom) are 12v, 5v, 1-wire, and GND, and will be externalised via a socket mounted on the case.

I then tried to lay it out on stripboard, using first VeeCAD and then Eagle (electronic design/layout systems) but in the end, for something this simple, it was proving more difficult to configure the tools than to just do the job manually. So I ended up with a traditional series of graph paper designs, finally settling on the following approximate layout:

After quite a lot of (very careful) soldering, this resulted in the following circuit, seen waiting to be attached to the router, and to some 1-wire devices. Note the use of a breakout board to convert the DS2480B from SOIC8 to something more compatible with breadboard & stripboard. The UK 50pence piece provides scale:

Sadly however, I wasn’t careful enough with my soldering. I managed to put the voltage regulator in back to front, swapping the input and output terminals. Worse, I didn’t notice when I checked the board. So when I connected it up, the resulting unexpected voltages let loose through the circuit have comprehensively let the magic smoke out of the DS2480B, which has in turn (I suspect) comprehensively cooked capacitor C3, and resistor R1. The good news is that the level converter MOSFETs that I installed to convert between 3.3v and 5v were man enough to cope with the 15v rampaging around my circuit, and saved the routers electronics from any problems.

So now I need to replace the DS2480B, the voltage regulator, C3 and R1. I’ll swap out the zener at the same time, “just in case”. What a pain.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s