Top view of my second PC board. 3 copies of HexMotor 2.3 and 2 copies each of 3 different breakout boards for a pressure sensor.

I got the boards back from 4pcb.com about a week ago.

The HexMotor rev2.3 boards have several new features: LEDs for +5v and +6.25v, a reset button, 16-bit shift register instead of 8-bit, servo outputs connected to pins 13, 7, 2, 9, 10 (rather than to the pins used for PWM). The new board should be able to do either 6 PWM motors or 4 PWM motors, 5 servos, and 2 non-modulated reversible motors. I was going to have the robotics club solder the board today, but they did not have time.

I made some breakout boards for the MPXHZ6250A pressure sensors from Freescale Semiconductor, which gave me my first taste of SMD soldering. At least the design uses gull-wing pins, which can be hand soldered. The breakout board that I think that the robotics club will end up using puts a pressure sensor on one side and headers for a piggyback ADXL335 breakout board on the back. that way there only need to be one set of wires for connecting the analog inputs and power to the sensors.

That is the board I soldered a sensor to.

Top view of the breakout board with the sensor and headers soldered in place.

The pressure sensors are tiny! I found it fairly difficult to solder the sensor to the boards, even holding it with clamping tweezers. I did eventually get everything to stick with no shorts between the 3 signal wires, but I did have some trouble with the unused copper pads delaminating from the board. For future reference: all pads should have wires going to them (even the unused pads) to have enough surface area for good adherence and so that some of the pad is tucked under the solder mask.

Here are the solder connections on the side where none of the pins are used.

Here are the solder connections for the power and signal pins (and an SMD capacitor).

Despite the rather sloppy soldering, the pressure sensor does work. It turns out that the port size is just the right size for Lego pneumatics components, so testing was pretty easy.

Sensor attached to Lego pump and gauge for testing.

Here are the results of calibration tests with the (probably not very accurate) Lego gauge, done by my son and me.

The range is about right, since 22 psi plus one atmosphere is about 250kPa, which is supposed to be the high end of the sensor’s range. Also, 600″ (50′) of water is 21.67 psi, so the range from 367 to 1000 corresponds to about 50′, so the sensor should give the robotics team a resolution of about 1″ for measuring depth, as expected from the spec sheet.

The data are well fit by The club members will have to recalibrate the pressure sensor in water, to get calibration as depth in cm. They’ll probably have to re-zero the sensor every day they use it, to compensate for atmospheric pressure, since it is an absolute pressure gauge.

2011 October 8

I’m going to try embedding some short pieces of code in this post, and later work out a better way of distributing larger blocks of code.

The code I want to share today consists of a small C file and the associated header for creating WAV files for producing sounds on a laptop or desktop computer. This is not a full-featured WAV file module: the format has a lot of options and I didn’t want the complexity of dealing with all of them. I just wanted to output monophonic sound with a reasonable sampling rate.

Note that the above code is not a full program, just a tiny library routine that can be used to generate WAV files. Here is a test program to generate sine waves (inefficiently) to see if the program works. Once you have the basic idea, you can write arbitrary programs to generate WAV files and play them back with QuickTime Player, RealPlayer, Audacity, or any of several other sound-playing programs. This is really old-school computer music, from the days when computers were so slow that quality sounds could not be generated in real time. It provides a good way to get started in learning the algorithms, though, as you don’t need to worry about efficiency or all the details needed to compute samples and provide them to a DAC at exactly the right rate.

in one of my earliest posts on this blog (Hold the presses! Can’t distribute software!), I complained about not being able to discuss code on the wordpress.com blogs. I found out today that it is actually pretty easy to post software using WordPress.com, using the “sourcecode” tag documented at Posting Source Code. I don’t know if this is a new feature, or I just failed to find the documentation last time I looked.

I went back through my posts and added code to the ones that should have had it before (let me know if I missed one). I may be inspired now to write some of the posts that have been sitting around as unfinished drafts since the beginning of the summer, or to put up some of the little Arduino programs I’ve been writing for teaching physics.

4pcb.com put a hold on my second order from them, asking for an extra $50 (bringing the cost up to $100.30) for the new board, because there were multiple images.

I asked them on the phone what the rule was now for defining multiple images. Although they did not give an exact algorithm, basically they are looking for separate pieces unconnected by copper traces. I suspect that they either do a quick look at the board manually or have some very crude program to detect probable repeats.

They are not looking just for exact repeats (which is the rule that Gabriel Elkaim told me they used), but anything that looks like multiple boards. Now I have to decide whether to pay the $50 surcharge, find another vendor, or redesign the board.

For the tiny breakout boards I may be better off with a BatchPCB.com order, at $2.50/sq in + $10 setup. I had 3 (slightly different) copies of the hexmotor 2.3 board, plus 2 each of 3 different breakout board designs for the pressure sensor.

The areas and prices for the boards (not including shipping) are

board

dimensions

area

BatchPCB.com price

pressure 1.3

0.7″ × 1.45″

1.015 sq in

$15.08 for 2

pressure 1.4

1.5″ × 1.0″

1.5 sq in

$17.50 for 2

pressure 1.5

0.475″ × 0.8″

0.38 sq in

$15.00 for 2

hexmotor 2.3

3.95″ × 3.15″

12.44 sq in

$41.11 for 1, $103.32 for 3

combined

7.537″ × 6.737″

50.78 sq in

$136.94 for 1

So if I keep the original order, I’m better off with 4pcb.com pricing, but if I get only 1 motor controller board, I could reduce the price to about $75+shipping (with a new combined board, to avoid the repeated $10 setup). If I just want the breakout boards, I could do all of them without the hexmotor board as 2 copies of a combined 1″ × 3.825″ board for $29.13+shipping.

UPDATE: I decided I want the new features of the hexmotor 2.3 board enough to spend the extra $60 rather than just using the old hexmotor 1.3 board. When I want tiny boards, though, I’ll try BatchPCB.com, which will be cheaper for boards smaller than about 13 square inches (depending on shipping and how many are ordered).

I’ve just sent a new set of boards for fab. The HexMotor rev2.3 boards have several new features: LEDs for +5v and +6.25v, a reset button, 16-bit shift register instead of 8-bit, servo outputs connected to pins 13, 7, 2, 9, 10 (rather than to the pins used for PWM). The new board should be able to do either 6 PWM motors or 4 PWM motors, 5 servos, and 2 non-modulated reversible motors.

I’m also making some breakout boards for the MPXHZ6250A pressure sensors from Freescale Semiconductor, which will require doing some SMD soldering. At least the design uses gull-wing pins, which can (supposedly) be hand soldered. One of the breakout boards also has a place for mounting an ADXL335 accelerometer, which may be more difficult to solder. I don’t think I want to spend the money for a hot-air rework station, and I’m a bit dubious about my ability to solder using a toaster oven.

The pressure sensors are tiny! My original suggestion to the robotics club was to drill a hole in the dry box and superglue the pressure sensor to the inside of the box (after the pressure sensor had been attached to the breakout board, of course). Now I’m not so sure that there will be enough glue area to hold firmly enough. Perhaps a dab of some sealant on the outside of the box might help, if we can keep from plugging the hole in the sensor.

The breakout board that I think that the robotics club will end up using puts a pressure sensor on one side and headers for a piggyback ADXL335 breakout board on the back. that way there only need to be one set of wires for connecting the analog inputs and power to the sensors.

One limitation of the Arduino for use with this combination of sensors is that the accelerometer is a 3v part and the pressure sensor is a 5v part. We’ll have to set up the analog-to-digital converter on the Arduino to have a 5v range, which reduces the precision of the acceleration readings.

I’ve also bought some other sensors (not for the underwater vehicle, but for physics class and dry robotics): a couple of ultrasonic rangefinders. More on those in a separate post, after I’ve had a chance to play with them.

I’ve been thinking about what other parts I need to buy for the high-school Robotics Club, so that they can finish their underwater vehicle.

Some I’ve known about for a while, but just haven’t gotten it together to buy the (expensive parts). For example, they will need several IP-68 connectors for the tether power, for the tether CAT-5 cable (see Long USB cable problem solved), for the motors, and for whatever suite of tools they build for this year’s challenge. I bought a 4-pin Buccaneer standard connector (made by Bulgin) for the power tether, and am leaning toward 8-pin mini Buccaneer connectors for the motor and tools. I’ve still not decided whether to get another 8-pin mini Buccaneer for the Ethernet connection, or to try using their IP-68 ethernet connector.

One that I only just started thinking about is a pressure sensor for determining depth. The challenges for the past 2 years have involved going to a particular depth, so having a depth gauge is a good idea.

Pressure sensors are classified into 4 types: differential, absolute, gauge, and sealed gauge. In truth they are all differential, measuring the difference in pressure. The absolute gauges measure the difference to a vacuum chamber, the gauge-pressure sensors measure the difference to atmospheric pressure, and the sealed gauge sensors measure the difference to a sealed chamber that has a known pressure in it (probably around one atmosphere).

If the club members put the pressure sensor sticking through the wall of the dry box, we could use any of the types of pressure sensor, but absolute or sealed gauge would be best, since we don’t know how much the pressure inside the drybox changes as we submerge it. The sidewalls will flex, so the pressure will go up, but we don’t know how much.

I spent some time today looking for pressure sensors at DigiKey. It looks like absolute pressure sensors are cheaper and easier to find than sealed-gauge, so we’ll go with them. There are also price variations depending on whether the sensor has temperature compensation, and on whether the output is a low-voltage differential signal or an amplified one ready for input to a microprocessor A/D input. I’m pretty sure that we need the simplest interface we can afford, so the ones that don’t need external amplifiers are the best bet.

I also spent some time reviewing how much pressure to expect at different depths, so that I could help the club select the appropriate part. I found an on-line pressure calculator that can convert depth of water to pressure (in PSI, kPa, or atmospheres). Each meter of depth adds 9.8 kPa (or 1.42 psi). In a 20′-deep pool, they could have up to 59.7 kPa, and in a 12m deep pool (like at NASA) they could have up to 117.6 kPa. Of course, this is just the water pressure that is added to the atmospheric pressure, so the real range they need to cover is 100 kPa to 220kPa.

It looks like Freescale Semiconductor makes some absolute pressure sensors with a 20–250 kPa range (for example, the MPXH6250AC6T1), which is just about right for us. They run on 5 v and provide a ratiometric output, that we should be able to read to 10 bits of precision, or about 0.25 kPa, which would be a depth resolution of 1 inch. The accuracy of the pressure sensors is only ±1.5% of 250kPA, which is ±3.75kPa, ±15in, or ±38cm. They get full points if they are within 50cm, so this is accurate enough for us. The could calibrate to higher accuracy, by lowering the machine at the side of a pool while looking at a ruler or tape measure along the side of the pool and taking measurements. So, now that I know what is needed, I can have the robotics club try to solve the design problems.

I think I will have to do one more thing for them, though—the pressure sensor is a surface-mount component, so I think that they will need a breakout board for it. I’ll design a breakout board that has room for some bypass capacitors and an output filter capacitor. Although surface-mount, the part has 0.05″ pitch leads sticking out, and so should be hand solderable, though it might be worthwhile to get a heat gun and solder paste to try reflow soldering.

Come to think of it, since the pressure sensor will be glued to the side of the drybox, it might be a good idea to mount the 3-axis accelerometer on the same board. That would reduce the amount of cabling they need to do. But the ADXL335 chip has the SMD pads underneath the chip, which can’t be easily hand-soldered. That brings up the question of whether we try soldering with a heat gun or toaster oven, or pay $12 more for the chip already on a breakout board. (The DigiKey breakout board is the same price and a similar design to the LadyAda breakout board—both are copying the ridiculously overpriced breakout board from Analog Devices.)

I could play around with a few different designs and stick them on my next PC board run—I want to do a revised version of the HexMotor board anyway, and it won’t cost any more to toss in some sensor boards on the same fab run.

At the meetup they confirmed that they will not be getting the sort of expensive shop equipment that places like TechShop (over the hill) have. The initial setup will be suitable for mechatronics work, similar to what Gabriel Elkaim teaches in the Mechatronics class at UCSC. Gabriel was the fifth of five speakers at the MeetUp and provided a nice overview of the Mechatronics class.

What the Makers Factory will have are low-cost 3D printing machines (which I suspect will not be useful for much, but are fun toys), a laser cutter, a vinyl cutter, and some electronics equipment (soldering stations and some oscilloscopes, I guess). They’ll probably also get some board shears. I think I talked them out of trying to do their own PC board fabrication, in favor of ordering boards from some place like 4pcb.com. You can probably do a class full of small boards as one $145 order from 4pcb.com (even without a .edu address) and give each person 4 copies of their board. The 2-week turnaround time is fine for a class. It would probably take longer than that to make your own using low-cost tools in a classroom setting with only a few hours of class time a week, and the quality would be much worse. I’d also hate to be the one in charge of getting rid of the hazardous waste produced by PC board etching.

I brought my HexMotor board with me to the MeetUp and showed it off to a few people, including Gabriel Elkaim, who was properly polite about it. He also told me about the new PC boards he had just sent out for fab—they are redoing the electronic cockroaches that are used for the first lab in Mechatronics, since the old ones have started acquiring too much damage. The problem is that students were much more inventive in discovering ways to damage the boards than originally expected, so the new design has a lot more protection circuitry.

I did get a chance to talk with Chris Yonge, who will be running Makers Factory. It sounds like he is interested in having me teach an Arduino programming class and PC board design using free tools. I recommended Eagle for PC board design, even though it is not open-source, because it is fairly mature, the free version is enough for classes and hobbyists, it runs on both PCs and Macs, it has an adequate auto-router, and the licensed version is still fairly cheap.

There are open-source projects for PCB design, like FreePCB, which runs only on Windows and has no auto-router, KICAD which runs under Linux and Windows (but not Mac OS X, I believe), and many others. There is a good list at http://www.olimex.com/pcb/dtools.html. The general consensus of the hobbyist community seems to be that currently Eagle is most fully featured and robust free PCB editor, and that none of the open-source projects comes close yet. Since I need Mac OS X software, and most of the open-source software is for Linux, my choices are more restricted still. I don’t know what sort of computers Makers Factory is planning to get for classes—but they should choose software as much as possible that is platform independent.

I got the board fully populated yesterday, plus I made a heat sink out of a piece of ¼” × ¾” aluminum bar stock. The heat sink makes an enormous difference. Before using it, running a small motor at low power for 20–30 seconds was enough to make the H-bridge uncomfortably hot. Now running the same 12v motor stalled at full current (3A) for a full minute raises the temperature only to 100ºF.

The motor got warmer than that, and I think I burned it out, since it no longer runs and has a 400kΩ resistance. I’m not really surprised—it was a cheap door-lock actuator, and only intended to be used with fraction of a second pulses. Further testing will require a more robust motor.

As you can see from the photo, the screw terminal for motor 4 (second from the bottom) is a bit crooked—I’ll have to unsolder it and straighten it. For the HexMotor 2 board, I’ll use slightly smaller holes so alignment is easier.

The thermal grease I used (Cooler Master IceFusion High Performance Thermal Compound 40G RG-ICF-CWR2-GP) was more liquid than I expected, especially since it comes with a little spatula for applying it. I had to put on a fairly thick layer, because the aluminum extrusion was not very smooth, and when I tightened the bolts the stuff oozed out making a sticky mess. Next time, I’ll sand the aluminum smooth first and use much less thermal grease.

Closeup, showing the excess thermal grease puddling under the H-bridges, where it is very difficult to wipe off.

This closeup photo, in addition to showing the pooled excess thermal grease, shows the header pins with shorting jumpers to configure the H-bridges for either lock antiphase or sign-magnitude control. (Because of the last-minute change from TLE-5205 to TLE-5206 chips, the silk-screen labeling of the header pins is wrong—this board is actually configured for sign-magnitude throughout not lock antiphase.

The photos also show that I did not leave room for the heat sink between the electrolytic capacitors. The HexMotor 2.0 board will fix this problem also.

The HexMotor software now can handle 3 different boards: the HexMotor rev 1.3 board shown here, the Adafruit Motor Shield, and the HexMotor rev 2 board, which I am just about done fussing with the design for. I’ve only tested with an Arduino Duemilanove board, but the software should work with an Arduino Mega as well.

2011 August 6

I expanded the HexMotor.cc and HexMotor.h library today, so that I can use the same library with both my HexMotor board and the Adafruit Industries motor shield. The only differences from a user’s standpoint are

Declare an AdafruitMotorBoard instead of HexMotorBoard.

Use motors 1,2,3,4 instead of 0,1,2,3,4,5.

motor.release() works on the AdafruitMotorBoard, but is not usable on the HexMotorBoard, which only brakes when off.

I also figured out a way to get some debugging capability into the library, so that people could check that their configuration is consistent (though there is no way to check whether the jumpers and wiring are actually what the user says they are supposed to be). I can’t use “assert” statements the way I’m used to, so I did explicit if-statements and provided output through Serial.print() calls. This only works for tests that come after the Serial.begin() call, so I put the tests in the HexMotorBoard::setup() method, assuming that it would be called after Serial.begin() in setup().

The tests can be turned off by commenting out the #define HEX_MOTOR_DEBUG 1 line in the HexMotor.h file, reducing the size of the downloaded program by 860 bytes. Actually, almost everyone will have to turn the debugging off, since every run() command sends debugging output to the serial line, so the default is to have the debugging off.

The software library is pretty much done for controlling brushed motors, except for changing PWM frequency. Currently motors 0 and 1 (1 and 2 on the Adafruit board) run at 490Hz, while motors 2 and 3 (3 and 4 of the Adafruit board) run at 976.5Hz and motors 4 and 5 at 490Hz. I don’t want to mess with the PWM for motors 2 and 3, since that timer is also used for the delay() and millis() calls, so I probably want to change the PWM frequency for the other PWM pins.

Update 8 October 2011: Since I’ve just found out how to put source code into WordPress blogs, let me put the latest versions of HexMotor.h and HexMotor.cpp here:

// HexMotor.h
// copyright Kevin Karplus 8 August 2011
// Creative Commons license Attribution-NonCommercial
// http://creativecommons.org/licenses/by-nc/3.0/
#ifndef _HexMotor_h_
#define _HexMotor_h_
#include <inttypes.h>
#include <avr/io.h>
// Define HEX_MOTOR_DEBUG if you want to get error messages from setup() for erroneous setup.
// #define HEX_MOTOR_DEBUG 1
// Declaring a HexMotorBoard gives the jumperable configuration for the board.
// The relevant jumpers are which pins drive the motor speed inputs
// and whether the H-bridges are configured for lock antiphase or sign-magnitude.
//
// IN2 of the H-bridge is always connected to SIGN XOR MAG
//
// IN1 of the H-bridge can be connected to either SIGN or MAG.
// If IN1 is connected to SIGN, then the TLE-5206 H-bridge will
// be running in a sign magnitude mode, with the Speed pin low meaning BRAKE
// and Speed pin high meaning RUN (with the sign bit indicating which way to turn).
// If IN1 is connected to MAG, then the TLE-5206 H-bridge will
// be in lock antiphase, running if the SIGN bit is high and BRAKING if the SIGN bit is low.
// The MAG bit determines which way the motor runs.
// If the MAG bit is not a PWM output, then IN1 should be connected to MAG.
// Note: on the rev 1.3 boards, the silkscreen for the jumpers is misleading.
// The center of the 5 holes for header pins is MAG and the outer one is SIGN.
// The PWM frequency for all channels defaults to 1kHz (actually 16Mz/ 2^14 = 976.56Hz)
// Changes could be made in the HexMotorBoard::setup() routine if other PWM frequencies are needed.
class HexMotorBoard
{ protected:
uint8_t SpeedPins[6];
// which pins are connected to the "speed" (MAG) inputs of each H-bridge?
// Numbers 0-54 are for Arduino pins
// Numbers 0xA0..0xA7 are for the low byte of the serial output latch
// Numbers 0xA8..0xAF are for the high byte of the serial output latch
// (on rev2 or later)
// Number 0xFF means that the MAG bit is tied to +5V
//
// Note: all SpeedPins should be connected to something.
// Note: on Arduinos other than Mega, using the Servo library means that pins 9 and 10
// are not PWM pins. If used, they should be set up as ON/OFF pins.
enum{NOT_THERE, SIGN_MAG, ANTIPHASE, FORWARD_BACKWARD_BRAKE, ONE_BIT, ADAFRUIT} MotorMode[6]; // MotorMode[i] is
// NOT_THERE if motor_i is not usable on this board
// SIGN_MAG if IN1 of motor i is connected to SIGN, and MAG is assumed to be PWM
// ANTIPHASE if IN1 of motor i connected to MAG and MAG is a PWM bit
// FORWARD_BACKWARD_BRAKE if IN1 of motor i connected to MAG, but MAG is ON/OFF, not PWM.
// ONE_BIT if IN1 is connected to MAG, which is tied to +5v, so the
// the motor is always either running forward or backward, controlled by the SIGN bit
// ADAFRUIT if this is not a HexMotor board, but an Adafruit Motor shield
//
uint8_t LatchPin, ClockPin, DataPin;
// which Arduino pins are used for talking to the Hexmotor shift register?
uint16_t ShiftRegister; // the current or future contents of the HexMotor shift register
uint8_t Version; // which model of board is used
// set (or clear) a bit in the ShiftRegister corresponding to the specified motor
inline void set_signbit(uint8_t motor, bool value=1)
{ digitalWrite(0xA0+motor, value);
}
void serial_out(void); // transfer the shift register to the HexMotor board.
public:
HexMotorBoard(
const char *antis,
const uint8_t *pins=0, // defaults to {11, 3, 6, 5, 9,10}
uint8_t version=1,
uint8_t clock=4,
uint8_t data=8,
uint8_t latch=12);
// An array of pins is given to indicate where the MAG output for each motor goes.
// The 6 antis characters are
// '-' for NOT_THERE
// 'S' or 's' for SIGN_MAG (IN1==SIGN)
// 'A' or 'a' for ANTIPHASE (IN1==MAG)
// 'F' or 'f' for FORWARD_BACKWARD_BRAKE (IN1==MAG, but MAG is not PWM bit)
// 'O' or 'o' for ONE_BIT
// 'M' or 'm' for ADAFRUIT motor shield
// The version is the integer part of the board rev number (rev1.3 is 1, rev 2.3 is 2).
// This indicates, for example, whether the board has 8 or 16 bits of shift register.
// Use rev 0 to indicate an Adafruit motorshield.
// latch, data, and clock are Arduino pins that are used for the serial output to the shift register.
void setup(void);
// makes sure that PWM frequencies are appropriately set and turns all motors off.
// Should be called during the global setup() procedure.
// QUERY: should PWM frequency be settable here (or even as separate call?)
void digitalWrite(uint8_t pin, bool value); // write a single bit to a pin (using SpeedPins naming convention)
friend class HexMotor;
};
// Declaring an AdafruitMotorBoard sets up the HexMotorBoard interface for an AdaFruit Industries Motor Shield,
// rather than for a HexMotor board.
// The declaration has no parameters, as the AdaFruit motor shield is not configurable.
// For compatibility with the M1 through M4 labeling on the motor shield, motors 1 through 4 are used,
// rather than 0 through 3.
class AdafruitMotorBoard : public HexMotorBoard
{ protected:
typedef enum{FORWARD, BACKWARD, BRAKE} MotorDir;
void change_motor_bits(uint8_t motor, MotorDir control);
public:
AdafruitMotorBoard(void);
friend class HexMotor;
};
class HexMotor
{ protected:
uint8_t Motor;
HexMotorBoard* Board;
public:
HexMotor(HexMotorBoard &board, uint8_t motor_num);
void run(int speed);
// speed is between -256 (full reverse) and 255 (full forward)
// 0 is off (braking on HexMotor, released on Adafruit)
void brake(void);
void release(void); // Available on Adafruit Motor shield,
// but not on HexMotor boards rev1 or rev 2
// since the TLE-5206 chips do not have a Hi-Z output
};
#endif