Close
0%
0%

Lucy's Toy

A beeper toy for a blind dog.

Similar projects worth following
A sophisticated beeper to aid Lucy in her quest to find her toy after it is tossed.

Lucy is my Border Collie & Schipperke mix dog. At nine years old, Lucy is blind now. She has Progressive Retinal Atrophy which has slowly taken her sight from her. But she still loves to chase after her stuffed toys or balls when they are tossed a few feet away. Unfortunately, she has trouble locating it if the toy takes an unexpected bounce. We purchased a chime ball to see if that would help. The ball must be switched on manually and emits a chiming sound every five seconds until it is switched off. Lucy can find the chime ball easily, but doesn't like it when the ball sounds off in her mouth.

I've designed a beeper to insert inside one of Lucy's stuffed toys. It will have a small LiPo battery for power. A LIS3DH accelerometer detects a free-fall condition when her toy is tossed into the air and begins emitting a tone to let her know where the toy is. After a few seconds the tone will stop until the toy is tossed again. At least that's the plan.

The LIS3DH accelerometer requires a microcontroller to program it, via a SPI interface after power is applied, otherwise it won't do anything. I chose a PIC16F18313 for the µC for the following reasons:

  1. Low power dissipation. Less than 0.1µA in sleep mode, and less than 30µA when running at 32kHz.
  2. Built-in SPI interface.
  3. 10-bit ADC to measure battery voltage.
  4. Wide power supply range - 2.3VDC to 5VDC
  5. SOIC8 package is pretty small.

After adding a MCP73832 battery charger and a few discrete components the circuit looks like this.:

At the last minute I lost my nerve and added D1 to level shift the VDD voltage down to a max of around 3.6V. The LIS3DH has an absolute maximum VDD = 4.8V, but only specifies VDD=3.6V otherwise. If it can survive 4.2V, then D1 can be shorted out.

The PCB design is complete and measures 15mm x 15mm...the same dimensions as the 120mAh LiPo battery. I decided against using a lithium coin cell because I did not think that it could be attached well enough to survive the expected treatment. The LiPo will be attached with two small leads and a micro JST connector. It will probably be glued to the component side of the PCB. A micro USB jack, for charging, and a small buzzer completes the module.

Current Status:

At this point I have been able to program the PIC to configure the accelerometer to detect a free fall event, with appropriate delay, and trigger an interrupt input on the PIC. The PIC will then use the buzzer to emit a series of beeps for a couple of seconds and then a short 100ms beep every 2 seconds for 10 seconds. After that it goes to sleep and waits for another free fall event. 

The PIC is using < 1µA during sleep mode. The LIS3DH is supposed to consume about 12µA when sampling at 25Hz. I figure that the 120mAh LiPo will need to be recharged about once per year.

LucyToy.X.zip

This is the Microchip MPLABX project for programming the PIC16F18313.

Zip Archive - 51.59 kB - 12/07/2020 at 01:42

Download

LucyToy_gerber.zip

Gerber files for the PCB. You can upload this file to OSH Park to have PCBs made.

Zip Archive - 16.28 kB - 12/07/2020 at 01:33

Download

  • Final Product

    Bud Bennett12/07/2020 at 00:54 0 comments

    The toy is essentially done, and working properly. I encased it into a baltic birch enclosure, with lots of hot glue and CA glue.

    The openings are for the buzzer and the micro-USB charger. I was surprised that it was nearly too large to fit inside the opening in her new toy -- a Kong Comfort Kiddos Bear:

    Lucy is always enthralled with any new toy. This one is no different. I think it will remain #1 for a while.

    At this point I think the project is completed. Good enough. I'll post the gerber files and the MPLABX project in the files section.

  • PIC programming modifications

    Bud Bennett12/04/2020 at 01:02 0 comments

    I made a mistake programming the LIS3DH accelerometer. The INT1 duration register was not addressed properly, so the accelerometer would not delay the interrupt output when detecting a free-fall event. I discovered the error and made changes to the PIC code to change the free-fall duration to 320ms, along with increasing the free-fall threshold to 320mg (from about 100mg). 

    Results:

    • Previously, when Lucy dropped her toy from a few inches off the floor the toy would beep. Now, the toy does not beep until it is dropped about 3 feet in height. It also does not beep when she shakes it or a human shakes it. 
    • You still must be careful tossing the toy so that is doesn't rotate (revolve?) or the accelerometer won't generate an interrupt. Lucy has a lot of trouble locating the toy now if it doesn't beep.

    The PIC code is very close to complete. My wife thinks it should be able to discriminate between a rotating toy and a non-rotating toy, but perfection is hard to achieve and I'm satisfied with the performance so far.

  • First Pass Prototypes

    Bud Bennett11/13/2020 at 16:11 0 comments

    The PCBs arrived a couple days ago. I had a lot of trouble getting the accelerometer soldered properly. The technique that worked on the accelerometer was to create small solder bumps both on the PCB and the LIS3DH, use a good amount of flux paste, and solder it to the PCB before other components were mounted. This allowed me to test the connections using a diode checking function on the DVM to make sure that all the traces going to the PIC were properly soldered. Without this check there was a high probability that at least one connection (usually the INT1 pin) was open. 

    I did not populate the 1N4148 diode. The LIS3DH operates just fine with a 4.2V supply. I should have implemented an option for a shorting resistor across the diode, but just put a short solid wire across it instead.

    With a working PCB, I measured the following:

    Supply Current at idle = 12.2µA

    Charging current = 75mA (including the LED current)

    This idle current is pretty close to that expected for the system using the following conditions:

    1. The PIC idle current is around 0.7µA during sleep with the watchdog timer running.
    2. The LIS3DH is running at 25Hz and expected to consume 6uA @ VDD = 3.3V. But the current nearly doubles when VDD is increased to 4.2V.
    3. The battery charger IC contributes less than a few hundred nA of leakage current drain on the battery.

    I was expecting to have the LIS3DH run at 10Hz and draw only 4µA, but increased the ODR to 25Hz and the duration of the interrupt event to 400ms to lessen the chance of a false free fall detection. Even so, with 12µA idle current I expect the 120mAh battery to last about 1 year between recharges, depending upon how often it is tossed.

    It's a pretty small package -- even with the battery attached. The battery is contained temporarily with a couple of small rubber bands. Hot glue will probably be the permanent attachment method. I've tossed it a few times. It doesn't always trigger the beeper. The package is so small by itself that the unit tends to revolve in flight and might not drop below the free fall threshold. There have been quite a few false triggers as well. I'm hesitant about removing the PIC and reprogramming it with different parameters for the accelerometer. Every time I have desoldered the PIC I have been unable to reprogram it -- no idea why at this point. Perhaps the better approach would have been to use a DIP with a socket for experimentation and then switch to an SOIC after getting the parameters right.

    The first testing of the unit in one of Lucy's existing plush toys did not go well. Lucy regarded the beeper as a violation of one of her favorite toys and wanted nothing to do with it. I ordered a different plush toy, with a velcro pouch to hold the beeper. Hopefully, Lucy will respond better to a new toy with the beeper installed. I'll add a new log with those results when the new toy arrives.

  • The Code

    Bud Bennett10/27/2020 at 20:22 0 comments

    The PIC program is written in assembler. It is pretty straightforward and can be explained in three flow charts.

    The chart above shows the steps necessary to configure the PIC and the accelerometer. Most of the peripheral modules are disabled. The only modules needed are the FVR, ADC, and MSSP (for the SPI interface). Then the modules are configured. The watchdog timer (WDT) is set to overflow after 264 seconds. The ADC is set to run on its own RC clock and place the 10-bit result so that the 8LSbs occupy the low byte of the two byte ADC result register. The SPI is set to match the protocol required by the accelerometer and is set to master mode since it controls the SPI clock (SCK). The I/O ports are set to digital with required input/output assignment. Lastly, the 8-byte ADC rolling average is zeroed out as a precaution.

    The accelerometer is configured via the SPI interface to set an interrupt pin, INT1, when a free-fall event is detected. This sequence is right out of the application note for the LIS3DH, with a few parameters modified for this purpose. The peripheral clock is disabled to save power since it is only needed for the SPI interface. 

    The interrupts are enabled and the PIC goes to sleep, consuming only a fraction of 1µA. There are two ways to wake it from sleep: a WDT overflow every 264 seconds, or a interrupt on INT.

    When the external INT pin is asserted the above routine wakes the PIC from sleep and executes. The beeper is exited in a series of 20 beeps (50ms on, 50ms off) for 2 seconds. Then there will be a 2 second pause and a 100ms beep, which repeats TBD times. After that the SPI is used to read data from the accelerometer to clear the interrupt event and unlatch the INT1 pin. PIC peripheral clocks are again disabled, the PIC interrupt flag is cleared and general interrupts are enabled. The routine returns to the running program -- most likely back to sleep.
    The WDT wakes up the PIC every 264 seconds. This routine counts out 24 hours before it checks the battery voltage. If the battery voltage is above 3.3V then the 24 hour timer is reset and the cycle begins again. If the battery voltage is below 3.3V then the PIC will beep 5 times (so as not to get it confused with a smoke detector) and go back to sleep until the WDT wakes it again to repeat the battery voltage check. I'm hoping that it won't do this at 2:00am.

    I will post the entire MPLABX project to the files section when it is solidified.

  • Breadboarding

    Bud Bennett10/26/2020 at 19:56 0 comments

    Normally, I would use a simulator to verify the correctness of the design, but Microchip's simulator for the PIC16F18313, that runs under its MPLABX IDE, doesn't implement the Master Synchronous Serial Port peripheral. I have a PicKit4 programmer/debugger (not a clone). I thought that it would be easier to work with DIP parts than SOICs using a ZIF socket, so I purchased 4 PIC16F18313 DIPs from Digikey. 

    The PicKit4 blew up the first 3 parts that I tried to program. All the program was supposed to do was toggle an output pin at a 1 second rate after configuring all of the peripherals. This was a problem that I was familiar with -- my previous work-around was to use low voltage programming. But all of the pins on this chip were being used as I/O and LVP was not allowed if the MCLRE config bit was not set.

    I finally trolled the internet to see if others were having this problem and found this YouTube video. The guy that posted the video said that Microchip had posted a technical note for a fix to the PicKit4 on it website -- ETN #37 MPLAB® PICkit 4 VPP Overshoot Modification. I was going to implement the suggested mod, but something was fishy between the provided schematic and the photo of the mod on the PCB:

    The schematic seems OK to me, but the image shows that they disconnected the gate of Q3 from R54 and connected R142. This doesn't match the schematic. It seemed to me that they could not have properly tested the fix if the implementation was incorrect. I contacted Microchip, told them about the ETN issue and the YouTube video, and asked them to send a replacement for my PicKit4 (serial #BUR18XXXXX). In the meantime I implemented the 120Ω resistor at the VPP pin of my old PicKit4, which was recommended by the guy in the YouTube video. While this purported fix allowed me to program the PIC with the correct function, the current drain after programming increased from an expected 20µA to between 16mA and 60mA. Something still wasn't right and now all of my PIC16F18313 DIPs were gone. I had a PIC16F18323, which is just a 313 with 14 pins. When the new PicKit4 arrived I was able to program the 14pin DIP without damaging it. It's the only DIP part that I have left.

    Microchip requested that I send the defective PicKit4 back to them at my expense...FAT CHANCE!

    The Breadboard:

    The LIS3DH accelerometer is mounted on an Adafruit breakout board. The passives are just bypass caps and a current limit resistor for the LED, which substitutes for the buzzer.

    I hot glued a 15400 battery holder for the li-Ion power source allow the entire unit to be tossed for testing. At this point I have enough code working to configure the LIS3DH to detect a free-fall event lasting 400ms and assert an interrupt to the PIC. The PIC then activates the buzzer in this pattern: 20 50ms bursts lasting 2 seconds, then a 100ms burst every 2 seconds over the remaining 10 seconds. Then the PIC goes back to sleep until interrupted by the accelerometer and the cycle repeats. The buzzer pattern may change after observing Lucy's pursuit timeline with her chiming ball.

    Next step is to add a battery monitor to announce when the battery requires recharge.

View all 5 project logs

Enjoy this project?

Share

Discussions

D. E. wrote 12/14/2020 at 14:45 point

Depending on the type of buzzer, some buzzer manufacturers recommend a free-wheeling diode connected to the buzzer pins.

Measuring the voltage on the buzzer pins while it is buzzing can give more insights.

https://www.murata.com/en-us/support/faqs/products/sound/sounder/char/sch0001

  Are you sure? yes | no

Bud Bennett wrote 12/14/2020 at 16:50 point

I put a scope on the buzzer output pin and did not see any untoward voltage spikes. It's pretty small, around 9mm diameter, and doesn't draw much current -- maybe 10mA. It is also an active buzzer, so that might not require diode protection.

  Are you sure? yes | no

Simon Merrett wrote 12/13/2020 at 11:34 point

Great project! With those low currents, you will be able to run it off a small suoercap battery and run them between the extremes of the PIC's operating voltage range. Might be a safety upgrade if the battery is ever deemed to become vulnerable to the chewing. But I suppose that's on a dog-by-dog basis! 

  Are you sure? yes | no

Bud Bennett wrote 12/13/2020 at 15:39 point

I’ve been thinking about that lately too. The PIC will reset below about 2.3V, I think. A single supercap charged to 2.7V doesn’t give up a lot of energy between 2.7-2.3V. Not sure the beeper would work well at those low voltages. Plus, there aren’t many supercap chargers out there, and it would be a significant design change. Stacking 2 supercaps would complicate the charger and require a voltage regulator (more current).  But it would be safer.

Originally, I thought about using a rechargeable coin cell, but the mount was large and did not seem to secure the battery well enough for the expected abuse. 

I’m thinking about potting the whole thing in epoxy or polyester resin — that’s probably best option for protection. If the battery charging cycle is every year, or so, then the toy would last several dog generations.

Fortunately, Lucy doesn’t chew her toys. She licks them. She still has the very first stuffed toy that we gave her.

  Are you sure? yes | no

Simon Merrett wrote 12/13/2020 at 16:32 point

Ah, I assumed PICs were same as attinies in respect of operating voltage. I managed to get the latest version of #Yapolamp down to 1.6V.

I also have an undocumented project which is a beeper run from an ATtiny402 which uses a pair of tiny photovoltaic cells to charge a pair of stacked supercaps (very small) through a diode. It uses two blue LEDs in series with each other, parallel with the supercaps, to prevent the caps' voltage rising too high. The low relative current source of the pv cells and the miniscule beeper current (400 uA while driving the 16mm SMD piezo full push-pull, single uA sleep) makes this pretty safe, if you ask me - I have no need for resistors in series with the voltage limiting LEDs because the pv cells could not generate enough power for full rated current, let alone thermal runaway. 

The beeper runs on a 10% 1Hz duty for many tens of minutes with even a mild charge in the low 2.x volt range. Encasing in clear silicone or epoxy would certainly allow this to run without any external charging needs. Happy to share details with anyone interested (but appreciate this project is done!). 

Glad Lucy is a licker not a chewer! 

  Are you sure? yes | no

Bud Bennett wrote 12/13/2020 at 20:35 point

The blue LED charger sounds interesting, but I think that I would ditch the solar cells for a resistor and USB jack. Give me some links for the solar cells and the supercaps. 15mmx15mm is a pretty small space to work with. If I used the “L” spec’d PIC I could get to a POR of 1.6V, but it would have to run on only one super cap. I don’t use the SDI input of the SPI, so could get another pin for push-pull output to the buzzer. ...but my project is completed...

  Are you sure? yes | no

Bud Bennett wrote 11/15/2020 at 05:01 point

Lucy's pictures are located in the Halo For Lucy project. I don't have any new ones yet.

  Are you sure? yes | no

Jarrett wrote 11/14/2020 at 22:00 point

Okay but where are the pictures of Lucy

  Are you sure? yes | no

Debargha Ganguly wrote 11/15/2020 at 03:11 point

This. Is. What. We. Really. Want. To. See.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates