An automated pet feeder to keep my fat cat out of my skinny cat's food.
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
InitialDataTestv3.inoIdeally, the arduino would get 10 initial values on startup and use that to create a baseline. Then it uses the baseline to determine when the magnet is near, because the baseline changes. This is the sketch that alternates between good data and mystery numbers every other read. Modified from Sparkfun's magnetometer sample code.ino - 2.61 kB - 09/30/2016 at 02:19 |
|
|
FatCatv3.inoTesting the magnetometer to see if it can get sensible data. This is the sketch which gets good data, which changes sensibly when you move a magnet closer, but never returns to baseline when you remove the magnet. Modified from Sparkfun's magnetometer sample code.ino - 2.16 kB - 09/30/2016 at 02:18 |
|
I've been messing with this for a bit, and here's the current state of affairs:
I'm having 2 main problems with the data.
First, if I just use the example code for the magnetometer and leave it alone, I get consistent baseline data. If I move a magnet close to it, the data changes in the appropriate way. But when I remove the magnet, the data never returns to baseline. To be honest I'm having trouble coming up with possible causes for this problem. If it was a strong magnet or if it was there for a long time, it may magnetize nearby metal to cause this, but it's a weak magnet only near it for a few seconds.
Second problem: I want to establish a baseline, poll the data every 1-2 seconds, then use a simple if statement to move the servo motor if the data deviates from the baseline. To do this I need to get multiple readings and compare them. Every time I write a sketch where it reads the data more than once, I get a pattern: first read gets good data, second read gets mystery numbers that are NOT real data, third read good data, and it alternates like that. It does this even if I use different variable names for the first and second sets of data. It does this even if I reset the variables to 0 before the end of the loop. Pretty sure this has to do with bit math, somehow, which I'm 100% ignorant of.
Next steps: Learn more about the raw data that the magnetometer sends, learn more about the bit math it uses to convert it into the serial output I see, probably find out what 'registers' are because that seems important.
Create an account to leave a comment. Already have an account? Log In.
Become a member to follow this project and never miss any updates
Great initiative with your project! Your magnetometer might be dealing with residual magnetism, which could be causing the data anomaly post-magnet removal. A 'self-calibration' routine may be helpful. The inconsistent readings might be a timing issue - you might want to add a delay in your loop.
Understanding the raw data and the bit math will surely help you advance in the right direction! Wishing you the best of luck. For those who are curious about cat behaviors, particularly why some tabby cats tend to become overweight, you might find this article informative: Why Are Tabby Cats Fat?. Keep learning and pushing forward!