Dog Water Bowl Scale, Part 3: Final assembly and installation

In my previous post, I covered the mechanical construction of the scale. In this post, I finish assembling the scale, calibrating it, and installing it.

After painting I put feet on the scale so it won’t soak in water spilled on the floor.

Adding feet to the scale
Adding feet to the scale

…then bolted the Arduino 101, Load Cell, and Load Cell Amplifier to the bottom plate.

The parts bolted into the final assembly
The parts bolted into the final assembly

Here’s what the bottom looks like, with the USB (power, really) cable snaking out of it.

The underside of the finished scale
The underside of the finished scale

Next step: calibration.  I read out the scale value for the empty scale; that’s the Offset. I then weighed a nominally-5-pound exercise weight on a food scale, then placed that weight on the scale and calculated the difference in value divided by the measurement from the food scale – that’s the Scale; the Slope; the second calibration to perform.  With those two measurements complete, the calibration was complete.

Weighing the calibration weight
Weighing the calibration weight
weighing the calibration weight on the scale
weighing the calibration weight on the scale

Then to test the calibration, I weighed the partially-filled water bowl on the food scale, then weighed it on the bowl scale, and read the BLE (Bluetooth Low Energy) Arduino 101 output on my phone.  Happily, the two readings were close: 1.168 kg vs. 1.170 kg.

Weighing the water bowl on the 'standard' food scale
Weighing the water bowl on the ‘standard’ food scale
Weighing the bowl on the bowl scale
Weighing the bowl on the bowl scale
The water bowl weight read on my phone
The water bowl weight read on my phone

I then modified the Raspberry Pi Node.js Service from my Dog Bed Scale to read the one weight from the bowl scale rather than the five weights from the dog bed scale.

With everything working, I created a stream on data.sparkfun.com, finished off the scale with a cutout from a waterproof placemat and placed the scale and the Raspberry Pi in the family room – score!

The installed scale - and yes, I used a Minions placemat on the top
The installed scale – and yes, I used a Minions placemat on the top

You can view the stream of data on Sparkfun’s data warehouse, at https://data.sparkfun.com/streams/ZGaqKmR75DtQrx80a4vW. All the source, mechanical notes, materials list, etc. are Open Source, on Github, at https://github.com/bneedhamia/CurieBLEBowlScale.

What might you make from this sort of scale? A dog food scale, a scale under your cat’s favorite sleeping spot, a scale under your coffee cup at work?  Have fun!

Next, I’ll see what the scale says about Pippa’s drinking and when we fill her bowl.

 

Dog Water Bowl Scale, Part 2: Measure Twice; Cut Once

In my previous post, I started working on the scale. In this post, I finish the woodworking, and painfully re-learn the woodworker’s adage: “Measure twice; cut once”.

I was so excited about the progress I’d made, and so eager to finish the drilling that I carefully measured, drilled the holes for one half of the Load Cell, then counterbored the hole for the first Load Cell nut… then discovered in my haste I’d counterbored the wrong side, and ruined the bottom plate of the scale.

I counterbored the wrong side
I counterbored the wrong side

Oops.  So I started over, and 1 and 1/2 hours later I had finished the drilling… correctly this time.

The correctly-drilled bottom plate
The correctly-drilled bottom plate

Next I changed my mind about how to get the USB or power cable from the electronics to the outside of the scale without creating a path for spilled water. I decided to route a path on the bottom of the bottom plate so the cable will go from the Arduino 101 through the center hole, and out the routed path.

I've routed a path for the cable
I’ve routed a path for the cable

“Measure Twice; Cut Once” part 2: Again I was trying to save time as I drilled the holes in the top plate for the upper bolts of the Load Cell… forgetting that the four bolts of the Load Cell are not the same size: the Load Cell bolts to attach the bottom plate are M5 bolts, while the bolts to attach the top plate are M4 bolts – they’re smaller.

Look carefully and you’ll notice that the left hole is larger than the right one – that’s because I used the same drill bit for the first of the two top holes as I made the bottom plate holes with… DOH! Luckily I can ignore the not-too-serious problem rather than cutting a new top plate.

Oops. The left hole is larger than the right one.
Oops. The left hole is larger than the right one.

So the lesson of woodworking is to double-check before each cut into the wood, because you can’t undo a cut: “Measure Twice; Cut Once”

With the holes drilled, I test-mounted the Load Cell to the top and bottom plates of the scale.  It’s turning out well.

The load cell test-mounted to the top and bottom
The load cell test-mounted to the top and bottom

I then test-placed all the wooden parts and the Load Cell, to double check the left-right and top-bottom clearance of the bottom plate and the sides that will be attached to the top.

checking left-right clearance (scale is upside-down)
checking left-right clearance (scale is upside-down)
Checking that the sides overlap the bottom a little, to keep water out
Checking that the sides overlap the bottom a little, to keep water out

Next I glued the sides to the top plate.

Gluing and clamping the sides to the top plate
Gluing and clamping the sides to the top plate

While the top glue dries, I spray-painted the bottom plate with a waterproof paint.  This will keep moisture from causing the wood to warp and swell.

Painting the bottom plate
Painting the bottom plate

In my next post, I finish the scale and install it.

Dog Water Bowl Scale, part 1: initial design work

Now that my Dog Bed Weight Scale is sending data, I’m going to have a go at a water bowl scale. The idea is that, like the bed, the bowl will periodically send its weight to a cloud. This data should tell me when Pippa drinks, when we refill her bowl, and (maybe) how much she drinks.

The work-in-progress sources on Github, contain the beginnings of the Arduino 101 Sketch, Bill of Materials (Parts List), mechanical design/construction details, and a day-by-day project diary.

Since I was already familiar with Sparkfun’s Load Cell Amplifier, I only needed to pick a Load Sensor/Cell. I decided to go with their 10kg bar Load Cell because it should be easy to mount as a single-point weight sensor, and it’s relatively inexpensive.

I decided to construct the scale from 1/2-inch MDF (Medium Density Fiberboard) because it’s thick enough to minimize bending and it’s not too heavy. Although raw MDF swells and warps if you get it wet, that’s not a problem if you put a good coat of paint all over it – so I’ll be painting the parts before I assemble the whole scale.

With the major parts chosen, I sketched the to-scale wooden parts and the layout of the electronic parts.

to-scale sketch of the scale
to-scale sketch of the scale

I then cut the MDF pieces and bored the access hole that will let me assemble the last of the parts.

Cutting the access hole, using a Forstner bit
Cutting the access hole, using a Forstner bit

I then test-laid-out the parts on the bottom plate of the scale.  Doing that reminded me that the assembled scale needs a way for a USB or power cable to get out of the scale.  I decided to probably cut a diagonal channel in the bottom plate to allow for a cable – if I’d put the Arduino 101 where I initially planned to put it, the USB cable shroud would be in the way of the lid.

Note: the lid includes a water curtain on its sides, which needs to overlap with the edge of the bottom plate to keep spilled water from getting into the circuitry.

Rough layout of parts. Note the space required for the USB cable
Rough layout of parts. Note the space required for the USB cable

I then used a drill press to drill the holes for the mounting screws and counterbore the holes for the nuts on the bottom.

I counterbored holes for the nuts
I counterbored holes for the nuts

The next step was to make the connectors for the circuitry. I probably should have soldered thicker wires (an inch or so in length) to the Load Cell wires, because the Load Cell wires were actually too thin to crimp connectors onto – the Load Cell wires are very fragile.

Ready to crimp connectors onto the Load Cell wires
Ready to crimp connectors onto the Load Cell wires

Because there’s only one Load Cell, and because it connects directly to the Load Cell Amplifier (unlike the half-load-cell Load Sensors I used in the Bed Scale), the circuit is pretty simple.

The assembled circuit (awaiting Load Cell mechanical parts)
The assembled circuit (awaiting Load Cell mechanical parts)

I’ve ordered parts from McMaster-Carr to mount the Load Cell to the top and bottom of the scale.  That mounting will look a lot like the Two Plate Configuration shown in Sparkfun’s Load Cell Amplifier Hookup Guide, except that my scale will have a lip fastened to the top plate to keep spilled water out of the electronics.

In my next post, I finish the woodworking… with some surprises.

Dog Weight Scale part 16: Data!

In my previous post I changed the uploader app to run when the Raspberry Pi turns on, and installed the scale under Pippa’s dog bed. In this post, I get interesting data from the scale.

The scale has been running for a little over a week now, and has been surprisingly reliable for a first version. There is some sort of bug in which, every few days, the scale stops supplying new data BLE notifications to the gateway. I plan to refactor the scale and gateway to avoid that, but that’s another post.

Today I looked at the data and saw some very interesting things.

Total weight in the bed, over 8 nights
Total weight in the bed, over 8 nights

You can clearly see when Pippa is in or out of the bed, from the large jump or drop in weight. Ignore the angled line – that’s an artifact of the scale stopping and the graphing program drawing through the missing data.

Most nights Pippa sleeps through the night, with one or two 15-minute periods of wandering around the bedroom in the middle of the night.  On the two Monday nights, she seems to get up a lot more. Monday evenings we take Pippa to Nose Work class – the hobby version of bomb-sniffing dogs – where she works very hard, gets lots of treats, and gets dinner about 3 hours later than normal.  We’re not sure which of these things makes her sleep poorly on Monday nights.

Weight from each corner of the bed over 8 nights
Weight from each corner of the bed over 8 nights

Pippa does flop around in bed every night. The above graph shows the weight measured by each of the four corner Load Sensors in the scale (again, ignore the angled lines). Whenever the values change, it indicates Pippa has shifted her weight in the bed – for example, by turning over.

If I want to see Pippa’s weight gain or loss, I do need to calibrate the bed better.  If the bed were properly calibrated, the total weight on the bed should remain close to the same number as Pippa shifts about in bed.  Looking back at the Total Weight graph, you can see how Pippa seems to become lighter and heavier as she moves around in bed – clearly not true. By the way, I’m now thinking of calibration as two distinct factors: 1) how closely sum of the four Load Sensors remains the same as the weight shifts (how closely the Load Sensors are matched), and 2) how accurately the sum of the weights reflects the actual weight on the bed. More on that in a later post.

Weight at the four corners for one night - July 12
Weight at the four corners for one night – July 12

Pippa shifts a little every few minutes, all through the night. Does this mean she’s uncomfortable? …dreaming of chasing rabbits? …listening to coyotes? …cooling off? More data means more questions.

The Quantified Dog is here. All this data is readable at Pippa’s Bed Weight stream.  Upload your own dog or cat’s bed weight at data.sparkfun.com

Dog Weight Scale part 15: scale is installed and uploading real data

In my previous post, I wrote the Raspberry Pi Node.js code to upload data from Pippa’s dog bed scale to data.sparkfun.com. This post covers how to make a Node.js program run automatically when the Pi is turned on. Oh, and at the end I installed the finished scale under Pippa’s bed.

Pippa, her bed, and the scale underneath
Pippa, her bed, and the scale underneath

Advice to bloggers: Date your posts! I wasted a day trying to follow advice from a blog entry labeled “Dec 31” – no year – that described how to use /etc/init.d to create a Daemon (a process that starts on power-up and runs continuously). When I ran into problems, one of the (dated) StackOverflow comments I found pointed out that /etc/init.d has been obsoleted in Raspbian (the Raspberry Pi default OS) for a while.

Once I learned that systemd is the path to pursue, things went together pretty quickly. I found a wonderful post by Ralph Slooten describing almost exactly what I wanted to do.

Here is the file I created and put in /etc/systemd/system/scalegateway.service:


[Unit]
Description=scalegateway Dog Bed Weight uploader
Documentation=https://github.com/bneedhamia/CurieBLEWeightMonitor
Requires=bluetooth.service
After=bluetooth.service

[Service]
Environment=NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
ExecStart=/usr/bin/node –use_strict /home/pi/Documents/CurieBLEWeightMonitor/scalegateway/scalegateway.js
User=pi
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=scalegateway

[Install]
WantedBy=multi-user.target

The really nice thing about this is that by saying “User=pi”, the script runs as the user “pi” – so it understands how to find the .cfg file I created in /home/pi, and (miraculously) understands how to find the Noble node BLE package in /home/pi/node_modules.

A few things to point out in the script above:

  1. The Requires= and After= lines tell the system to start this service sometime after the bluetooth service is running – that’s because my script uses BLE (Bluetooth Low Energy).
  2. This service description has no comments.  I had a lot of trouble caused by systemd trying to interpret my comments as commands.  So I removed all the comments.
  3. Notice that I added NODE_PATH to the environment, copied from running “echo $NODE_PATH” as user pi.  I’m not sure whether this is strictly necessary for my particular script, but it didn’t hurt.
  4. I use the –use_strict flag on my node scripts so that I can find little mistakes that Javascript would otherwise patch over and hide.
  5. The Install block is necessary to inform systemd that this is a service that can be manually installed.  Without this, systemctl complained when I tried to enable the service.

All the details are in my CurieBleWeightMonitor git repo, in the scalegateway directory.

Once I was sure that my Node.js script was running automatically at boot time, I unplugged the scale and the Raspberry Pi and moved both of them out of my office and to Pippa’s bed. The scale is under the bed and the Pi is plugged in to a wall socket behind Pippa’s crate (to the left of the bed in the photo).

A quick check of my stream on Sparkfun showed the live data was being uploaded from the bed to the Pi, and from there to Sparkfun’s data warehouse. The whole system is now uploading live, continuous weight from the scale – score!

In my next post I get to find out how much time Pippa spends in her bed at night while we’re asleep. Does she sack out the whole night?  Does she get up and wander around? Does she flop about in the bed? We’ll see.

Dog Weight Scale part 14: uploading data to data.sparkfun.com

In my previous post I finished the hardware for the scale and calibrated it. This post covers getting data from the scale to Sparkfun’s Data Warehouse.

By the way, the nRF Master Control Panel (BLE) from Nordic is the perfect tool for debugging Bluetooth Low Energy devices and messages.  It understands a pile of standard Bluetooth data types,as well as the Physical Web, so it’s a quick way to find out whether your Arduino project is sending the right data.

As you can see from the screenshot below, the scale is sending the Bluetooth Standard Weight Scale data: flags about what the scale supports, plus a weight measurement, in kg, and a user ID for that weight.

The Scale Data appearing in Nordic's BLE debugging app
The Scale Data appearing in Nordic’s BLE debugging app

Once I could see that the scale was sending the right data, the next step was to set up a Raspberry Pi 3 to receive and process that data, using Node.js. I was surprised to find that although one big selling point of the Pi 3 is its built-in BLE device, it took me a while to find all the bits and pieces needed to configure the Pi to do BLE communications from Node.  My resulting “how to” notes are in the CurieBleWeightMonitor repository, under piconfig.txt. That file describes how to configure the Pi out of the box, how to bring Bluez – the Linux Bluetooth stack – up to date, how to install a current version of Node.js, and how to install Sandeep Mistry’s Noble library for doing BLE I/O in Node.

My next step was to (re)learn Javascript in Node – it was a breeze. After learning a few basics about Javascript, I wrote a script that happily read data from the scale once per minute.

The next step was to a) setup a cloud to store the scale’s data, and b) write code to transfer the weight data to that cloud.

data.sparkfun.com is a wonderful thing for IoT (Internet of Things) experimenters: it offers public, free data storage for data from whatever devices you want to create. It was a matter of minutes to setup a Stream to store the data from the scale: total weight and the weight sensed by each of the four Load Sensors.

Armed with the public and private keys from creating that Stream, I wrote more Node code to format the weight data for Sparkfun and to upload it. You can browse the resultant data at the Pippa Dog Bed Weight stream on data.sparkfun.com.

Pippa's weight scale on data.sparkfun.com
Pippa’s weight scale on data.sparkfun.com

My next step is to configure that Node program as a Linux Service so that it runs when the Pi is plugged in.  Once that’s done I can put Pippa’s bed on the scale, plug in the Pi, and start looking at real data.

To recap: I have built a simple IoT implementation involving a BLE sensor, a BLE-to-Wifi gateway, and a cloud data warehouse, and all the code is Open Source on GitHub. Imagine what you can build by modifying that code to, for example, track how much sunlight your living room gets over the year, how often you have visitors over, or when and how often your dog drinks from her water bowl.

In my next post, I turn the Node script into a daemon that runs at power-up, and I install the scale under Pippa’s bed – the end is in sight.

Dog Weight Scale Part 13: Load Sensor Mounting and Final Assembly

In my previous post, I designed and printed a Centering Guide to line up the top and bottom pieces of the scale.  In this post, I finish assembling the scale.

Now that I have the Load Sensor Holders that I designed and printed, I drilled mounting holes in the blocks that will hold the Load Sensors.

Holding a Load Sensor over a support block that has mounting holes in it
Holding a Load Sensor over a support block that has mounting holes in it

(I used only the two front holes you see in the picture; not the other hole)

From there I lined up the support blocks on the bottom plywood circle, used a hand drill to extend the mounting holes through that part, then used a drill press and Forstner bit (on the bottom side of the plywood circle) to counterbore the holes that will hold the nuts that hold the bolts down.

Counterboring holes to hold the nuts
Counterboring holes to hold the nuts

Note in the above picture that I’m using a support stand to hold the large plywood disk while I drill using the drill press.  The support stand looks like a roller on a vertical bar.  It’s a safety thing, to keep the plywood from crashing to the ground at the wrong time.

Closeup of counterboring
Closeup of counterboring

Once that was done it was an easy matter to line up each Load Sensor with the support blocks below it, slip the bolts through, and fasten them with the nuts.

The assembled Load Sensor on its support blocks
The assembled Load Sensor on its support blocks

After mounting the Load Sensors, I mounted and connected all the other parts: the Arduino, Load Cell Amplifiers, Protoboard with resistors on it, and the plastic Centering Guide.

Mounted and Assembled Version 2 Scale electronics
Mounted and Assembled Version 2 Scale electronics

Finally, here is the long-awaited, assembled version 2 Dog Bed Weight Scale, ready to be calibrated.  It contains 4 Load Sensors, a pair of resistors per Load Sensor to change the Load Sensor into a Wheatstone Bridge, a Load Cell Amplifier per Load Sensor to measure the weight on each Load Sensor, and an Arduino to make sense of it all.

Top view of the assembled scale
Top view of the assembled scale

In my next post, I’ll describe the Raspberry Pi code to transfer data from the scale to the cloud.

 

Dog Weight Scale Part 12: More 3D Printing

In my previous post, I did a little woodworking on the scale.  In this post, I start designing a 3D printed part that will keep the top of the scale centered on the bottom.

Ever since I measured the center of gravity of the top plywood circle, I’ve been puzzling through how to make sure that center of gravity stays centered on the bottom part of the scale.  Without some sort of connection between the top and bottom plywood circles, the top will inevitably slide over time, messing up all the center of gravity calculations.  On the other hand, if this connection between the top and bottom has much vertical friction, it will take some of the load of the scale, throwing off the weight calculation.

After having such success 3D printing a Load Sensor holder, I decided to have a go at a plastic part that would help keep the top and bottom plywood pieces aligned.

First draft Centering Guide
First draft Centering Guide

My plan is to drive a nail down through the top of the top plywood circle. Then whenever I need to place the top plywood circle on the bottom one, I can get close enough to center that the nail will be somewhere inside the 1.5″ diameter cone in the Centering Guide.  From there, the sides of the cone should guide the nail to the center of the bottom plywood circle. Then the top and bottom pieces will be aligned.

At least that’s the theory.  We’ll see.

Being new at designing for 3D printing, I’m not sure how to build an arch or corbel to support the cone. So I relied on the default Cura support structures, which take a lot of plastic.

Centering Guide being printed
Centering Guide being printed

Note the large amount of infill in the cylinder.  I should be able to (eventually) come up with a design that doesn’t require so much plastic.  On the other hand, since I’m only making one, I can put up with using 3.5 meters of filament this time.

While I was designing the Centering Guide, I tried to print four Load Sensor holders at once.  Little did I know that I should mess with the print parameters for such a large print.  I stopped the resulting print part way through.  It was weird: the filament wouldn’t stick to the print bed, so little hairs started sticking up.  The hairs then caught other print lines, until the whole thing started looking too frizzy to be useful.  Going back to one-at-a-time prints seems to work fine.

The result of 10% infill
The result of a big print: trying 4 load sensor holders in one print

In my next post, I finish mounting the Load Sensors and complete the final assembly of the scale.

 

Dog Weight Scale Part 11: Routing Counterbore holes

In my previous post, I 3D-printed parts to hold down the Load Sensors. In this post, I fix the counterbored holes that keep the nuts from protruding below the bottom of the bottom piece of plywood.

In the woodworking post, I used a router to cut counterbore holes on the bottom side of the bottom piece of plywood.  These holes hold the nuts that hold the circuit boards.

bad counterbore holes that don't hold the nuts
bad counterbore holes that don’t hold the nuts

Unfortunately, the router bit wouldn’t cut the center of the hole, so it couldn’t cut deeper than about 1/8″ – about half of what I needed.  Oh, and I probably burned the router bit too – don’t force the router, kids.

So I decided to try a Forstner bit.  Forstner bits are designed for drilling counterbore holes; they make a nice, flat cylindrical hole. But I didn’t know whether I could use a Forstner bit in a router. It turned out well – the bit fit in the router and fits great in the plunge router.

A Forstner bit in the router
A Forstner bit in the router
The bit fits fine in the plunge router stand
The bit fits fine in the plunge router stand

I was able to set the plunge depth to the 1/4″ I need for the circuit board nuts, and in no time had cut all the holes to the correct depth. I think I set the speed low enough to keep from burning the bit.

Setting the bit depth to 1/4"
Setting the bit depth to 1/4″

In my next post I do some more 3D printing, both good and bad.

Dog Weight Scale Part 10: 3D Printing Load Sensor holders

In my previous post I soldered the weight scale parts to a proto-board.  In this post, I design and 3D-print the part that keeps the Load Sensors from slipping.

The Load Sensor is an oddly-shaped thing that has a few tricky constraints: the T-shaped part in the middle must be free to bend downward (my wooden mounts take care of that), and I don’t want it to slide out of place horizontally or tilt off of its position when I’m putting the top plywood piece on the scale.

I’ve tried a couple ideas – wood holders, washers and bolts – but nothing seemed to work well. So this week I decided to learn how to design and print 3D parts.

After a few false starts I designed a basic part using FreeCAD. I like FreeCAD because it’s a powerful, Open Source CAD package capable of sophisticated work.  Some people find it difficult because, unlike SketchUp it’s Parametric – everything is done through setting parameters on lines, surfaces, and solids.

We have a Lulzbot Taz 5 3D printer at work. A friend at work helped me get started with it, and printed my first part for me.

My very first 3D printed part
My very first 3D printed part

This was a great start, and really got me fired up.  All I had to do next was fix a few details in the model, and I’d be done – what could go wrong?

First I installed the missing piece of the toolchain: the Lulzbot edition of Cura, a 3D print preparation application.  Then I edited my model in FreeCAD, exported it to .stl format, read it with Cura and… woops.

My lovely CAD model
My lovely CAD model
the "transporter malfunction" result in Cura
the “transporter malfunction” result in Cura

For some reason the model didn’t export/import properly: the bolt holes were missing, the little cutouts at the front were gone, and the tabs at the top turned into strange triangular blocks.  Not Good.

So I experimented and searched. The problem seems to be that Cura is (properly) confused by internal edges, so I should Fuse the parts of the model before exporting to Cura.  I haven’t yet found how to do that (education opportunity!), but I did manage to redesign the part so that it happily made it into Cura.  The problem seems to be aggravated by using Pockets (subtracting material), so my redesigned model has no pockets – it’s all just adding parts together.

second try: no Pockets
second try: no Pockets
Successfully imported into Cura
Successfully imported into Cura

A very short time later (ok, 45 minutes), I had a printed part!

Cutting the thin supports away with a hobby knife
Cutting the thin supports away with a hobby knife
Lucky me - it fits perfectly!
Lucky me – it fits perfectly!

In my next post, I drill the right depth of holes in the plywood.