A depth sensor has arrived: a Measurement Specialties 5541C, which should be good to 14 bar (at least 450 feet of depth). It’s quite simple, featuring 8 solder points, of which only 6 are needed for normal operation.
It uses the Serial Peripheral Interface, though not by name (the documentation merely mentions a “three-wire interface”). However, a little research shows that removing the device select wire from standard 4-wire SPI gives you the same connections as the sensor uses. Like the camera (next post), the sensor operates with a lower supply voltage than the Arduino, so level-shifting is needed.
This should be relatively easy. Here’s the hard part:
Mounting it to a PCB with some sort of 6-pin connector is going to be a major challenge.
Hardware development has been suspended for some time while some fundamental software improvements are made. In an earlier post, a plan was shown to use an XBee connected to a PC to control Poolbot in remote mode. This required some serious software changes, but hard work pays off. The following features have now been implemented in the Arduino Mega 2560 R3 software inside Poolbot:
diagnostic checks of all sensors and electronics (except the motor shield), with timeouts, have been moved into the setup() function
reporting of diagnostics over hardware serial (usually over USB to a PC in drydock)
XBee communications with the base station include signal strength reporting and confirmation of successful receipt
(biggest of all) motor speed and direction are now controlled remotely; no more pre-programmed paths
The great XBee libraries for Arduino from Andrew Rapp enables transmission and reception of simple text string “payloads” (100 bytes each), taking care of the details of checksums and packet assembly between Poolbot and a base station. Each payload can be used to carry commands, data requests, and the like. To do this, Poolbot needed its own custom control protocol, so that the base station could command the motors to do something, or request sensor status, or even change operating state. The format for the protocol was blatantly ripped off from lovingly constructed in homage to NMEA codes used for the GPS. The format is comma-separated and looks like:
$M<2-character motor ID>,<motor speed percentage>,<direction>
So, to tell the right dive motor to spin backwards at 60% of maximum speed, the command would be:
Using comma separators permits using strtok to token-ize the command string. The compact format also allows Poolbot to communicate without violating the 100-byte XBee data payload limit. “P” is used in the second position to indicate propulsion motors, while “L” would indicate the left motor, and “F” indicates forward. “$MAS” instructs all motors to stop.
In future, sensor status can be reported with a “$Sxx” structure, but other non-motor commands are possible. The only limit to the language is the Mega’s storage. The entire program is about 23 kB in size, which is 2/3 of the maximum supported by an Uno, but still pretty small for a Mega.
This means that the PC side hardware can be reduced to this:
This also means that a Linux box, or even a Raspberry Pi, could be used as the Poolbot base station (think battery-operated!) – multiple operating systems are now supported. The Python program is somewhat simple at present, featuring a simple set of pre-programmed commands, but it does respond to user input and reports XBee status and received signal strength.
How does it all look working together? Check out the results on a single 32-bit Microsoft Windows XP laptop, with Poolbot in drydock on COM5 (left side), and the Python input/output from the control XBee on COM4 (right side):
The commands are pretty obvious from the screen shot. Further, the frame ID tracking ensures that commands aren’t accidentally missed. The programs both wait for interaction, so Poolbot can be left on and waiting indefinitely – no more rushing to seal up the ‘bot before the motors click on. And, yes, the correct motors turned off and on when expected.
The hardest part of all of this was, believe it or not, getting strings vs. bytes sorted out correctly in both Python and Arduino’s flavor of C.
Future enhancements will include:
adding sensor $S reporting to the Poolbot language
fixing the XBee signal strength (yes, it’s really on the order of -80 dBm, even though the two XBees were only a few feet apart; this is likely due to bad soldering during recent repairs)
a control GUI…
That last one is the real reason for using Python – the tkinter binding/toolkit allows cross-platform graphical displays and controls. This means that the command language can be abstracted away in favor of buttons, dials, text boxes, and pretty LED-like lights where appropriate. Here’s the first crude attempt:
At the very least, the speed adjustments shown will allow motor calibration without permanently adding encoders to each motor.
Three languages, multi-OS support, and a new GUI – not bad for five days’ work.
Selecting batteries or even solidifying the electronics means figuring out the maximum dimensions of any given rectangular shape that will still fit within the tube. If only the diameter is limited, then a variety of rectangles may fit. Time to pull out some geometry…
Thanks to a particularly good website for batteries, a complete set of dimensions for a variety of batteries is available. The equation above can show whether a particular battery will fit in the tube or not, based on its width and length (assuming “depth” extends along the tube’s axis). Performing some calculations with the existing central tube, electronics and two batteries, some options emerge:
using an alternative 12 V battery, at 3.8 Ah, measuring 7.6″ x. 2.8″ x 1.85″
stacking the electronics within a 5″ x 2.25″ area gives 2.68″ of available height for both the electronics and ballast (not much, but usable)
Motor load measurements are still needed to confirm that 3.8 Ah is sufficient for propulsion. The Arduino Mega and Motor Shield fit within an area 5″ x 2.25″, but the connectors and DHT11 sensor need to be cleverly stacked on top. And 2.5 lbs of ballast needs to fit under the electronics within about 2.28″ of space, total.
It’s either this or recalculating displacement using a longer tube, plus actually building it.
What’s Poolbot’s maximum operating time in-water before needing to recharge?
The motors are tied to two (2) 6 V, 4.5 Ah batteries. It would be convenient to use the same kind of supply for the electronics, but it depends on the current drawn. For the electronics alone (not the motors), a quick set of measurements reveals some unfortunate numbers:
the Arduino Mega 2560 R3 alone draws a reasonable 70 mA, which would allow at least 70 hours of operation (assuming correct reading of the capacity charts) before needing a recharge
the GPS and XBee (1 mW) draw only about 7 mA
the current draw by the motor shield is a less reasonable 200 mA
At 277 mA, Poolbot will need a recharge after only about 17 hours of operation. It’s also not known how long the 12 V solar panel will take to recharge the battery packs. If it takes more than 7 hours, or if there’s less than full sunlight, Poolbot may need significant “basking”/sleeping time between operations. This assumes that the electronics can be effectively turned off, and doesn’t even count needing to charge the motor batteries. What happens if Poolbot drifts while charging?
There’s another issue. There’s no room left inside Poolbot for all the new electronics, ballast, and four 6 V batteries. With two batteries for the motors, at 1.75 lbs of weight per battery, about 6.5 lbs of ballast and electronics battery weight remains to maintain Poolbot’s neutral buoyancy (see previous post).
Using a single 6 V battery to power the Arduino Mega and its accompanying electronics is a bad idea; below 7 V, the Arduino’s on-board regulator won’t work well and operation will become unstable. So, either a single 12 V battery with the right dimensions and similar Ah figure must be used (good luck) or some significant filtering must be used on a single supply for both the motors and the electronics.
The minor update: a recent pool test showed Poolbot making only starboard turns; this turned out to be due to a broken starboard propeller.
The more significant issue involves ballast.
Both the ComPod and the main body of Poolbot were recently analyzed for displacement and overall ballast neededto dive. Recall that ComPod has to protrude from the water at least partially in order to allow the XBee inside to communicate with the shore.
Previous displacement checks were done on Poolbot alone, less to get an actual displacement number and more simply to visually check buoyancy, and adjust trim and freeboard in the water. The ComPod was tested for actual displacement in the kitchen at least once, but using some dificult and questionable methods. To get a better number, the following extremely high-tech test bed was assembled:
The hard plastic bowl is filled to just before overflowing. The softer plastic bin will catch the water displaced by the ComPod once it’s inserted into the bowl. Measure the water in the bin to get displacement.
This measurement went exceptionally well, and resulted in a displacement within about 12 mL of the previous ComPod checks. The final numbers:
ComPod’s volume (displacement): approximately 1470 mL
ComPod’s weight: 549 g (including internal electronics)
For neutral buoyancy, the item weight must equal the weight of the volume of water displaced. As 1 kg of fresh water = 1 L of fresh water (pretty clever that metric system is), ComPod’s required ballast is… 921 g, or 2 lbs, 0.5 oz.
To measure Poolbot’s displacement, aside from the ComPod, is harder. Poolbot is rather large, requiring a tank at least 25 inches (sorry metric system) long and 11 inches wide, with about the same depth. Any catch basin must be larger still, to accommodate the overflow without losing any.
Thanks to several smaller bins, four plastic bags, and some tape, a reasonable up-scaled version of the previous dunk tank was created; there’s just enough clearance to allow water to overflow straight down into the smaller bins. The flaw in this design will be obvious from this post-dunking picture.
Use a rigid container, if possible, for the actual dunking. The soft plastic deformed enough to raise concerns about accuracy. The strap shown above is wrapped around the bin and several pieces of acrylic plastic and plywood, to make the sides more stable. The risk is that the plastic will deform, rather than water overflow, when the object is dunked.
Poolbot floats, so is obviously guilty of witchcraft.
Here are the numbers, +/- 100 mL or so for water loss and bin expansion:
Poolbot’s volume (displacement, without ComPod): 8050 mL
Poolbot’s weight (without ComPod or batteries): 3.6 kg
This means that Poolbot’s ballast must be 4.45 kg, or 9.82 lbs, to compensate for buoyancy. This number includes all of its current electronics, but does not include batteries.
The challenges that remain:
Can the ComPod be kept sufficiently above the waterline to transmit and receive messages? Or is it time for the extended antenna?
If ComPod protrudes enough for XBee communications, are the motors powerful enough to allow for diving without dive planes or some sort of ballast compensation system?
Unfortunately, there’s a third problem lurking, which will be addressed in the next post…
The latest Poolbot program updates have enabled XBee transmission of arbitrary strings up to the 100 byte payload limit. In drydock, the Arduino is connected via USB to a PC, used as a “dumb terminal”; the Arduino is doing all the display work, and the XBees operate in a simple loop confirming that a communications link exists.
The next steps are to move all the serial link data processing from the Arduino Mega 2560 to a PC. The Arduino can then transmit compressed sensor data via XBee payloads, and let the PC locally decompress the payload and print the information in a human-readable format. Remote control of the motors becomes possible.
Pictures sometimes explain better than words, so here’s the design today, and what’s planned for the future.
Thanks to the brains behind Arduiniana, Mikal Hart, Poolbot has moved to the brand-new GPS library set, TinyGPS++. This saved enormous time in developing custom code to process and check the validity of NMEA codes. Here’s a screenshot of Poolbot’s latest drydock test program, using TinyGPS++ grabbing data indoors (hence the improbable rate of movement):
Here is a close-up image of the Poolbot main control board, using the Arduino Mega 2560 R3. The Adafruit Motor/Stepper/Servo shield is mounted on top, while individual wires connect to the motors, batteries, and ComPod. The DFRobot “wings” from the Arduino Uno R3 came in handy for making these connections.
The motor batteries are not connected in this picture.
The small blue rectangle in the center is the DHT11 temperature/humidity sensor. This, plus a few capacitors, is mounted to a breadboard, and can indicate whether Poolbot overheats or encounters a severe-but-not-catastrophic leak.
Yes, that’s a rubber band on the right-hand side. It’s called a “prototype” for a reason.
The initial motor tests of Poolbot in the pool used an Arduino Uno R3 and the motor shield, and not much else. The program waited two minutes after the batteries were connected to start the motors in a timed pattern. No sensors, no I/O, no intelligence.
In order to accommodate additional sensors and features, moving to the Arduino Mega 2560 R3 was needed. However, the first obstacle was getting the original motor program to work with the new hardware — on first attempt with the Mega, only one motor worked. Some research and code updates got the Mega to work with the motors.
The next step was to integrate some new components, specifically:
The latter two were tied into Poolbot and its software without a hitch. Using two of the Mega’s four hardware serial ports enabled direct, fast connections of the XBee and the GPS shield. While the XBee took some adjustment, it functions. The GPS shield, however, was flaky in the extreme. Satellites wouldn’t lock, and data would arrive corrupted.
As it turns out, the GPS shield is physically fine. After some research, it turns out that the shield’s GPS module, a SkyTraq ST22, has its own nifty configuration software, which can be used with an Arduino Mega configured to echo between serial ports. Using this showed the Dexter module worked great – the libraries just didn’t function reliably.
Most GPS modules write out information using simple ASCII strings called NMEA codes. Thanks to a simple program from perceptive coder “Muthanna”, the Mega was able to read incoming GPS data and write it to a laptop screen using a local USB serial port; even when the ComPod was sealed up, Poolbot could even write directly to the SkyTraq viewer software through the USB serial port (some of the GPS information has been blacked out, to avoid revealing the Secret Location of Poolbot’s Development Cabana):
After writing custom code to pick off the GPS NMEA codes, Poolbot can now (at least on dry land):
report its RTC date and time settings
establish a serial link with a nearby XBee
read GPS data, including date, time, location, and heading
read and report internal temperature and humidity information
All this is done through a direct USB link, so in-water testing of all this isn’t yet possible. The Mega, along with attached sensors, exposed ComPod “guts”, and the separate XBee receiver, is shown below (note the green light showing an active link and receiver signal strength on the XBee labeled “2”; this is connected to a USB cellular charger – no controls here!).
Note that ComPod has been moved (more on that in an upcoming post). Thanks to the SkyTraq software, the GPS module has been configured for “boat” mode, and updates every second.
And here the serial data reported back through the Poolbot USB connection can be seen; all this text is being generated by the Arduino Mega 2560 on-board custom code, developed here at the Poolbot drydock, based on what Poolbot’s sensors report. The PC is simply a “dumb terminal”:
The GPS doesn’t always report the full set of NMEA codes, due to some faulty string parsing. This will be fixed shortly. The other sensors work just fine (the XBee sometimes takes a few seconds to respond, but the code now has a built-in retry mechanism).
The next steps are:
Enable reporting of this status data through the remote XBee receiver rather than Poolbot “local” USB
Post-process the GPS NMEA codes, checking for signal stability before reporting
Reduce the data reported via XBee, and use local Processing code to expand compressed data from Poolbot
Increase the serial port speeds
Seal everything up and run some water tests, including dives