
Week 19
Week 19 Assignment:
What tasks have been completed, and what tasks remain?
The tasks that have been completed:
The design and structure of the Kitty Matic are built. There board and parts have been made and soldered on to run the motor. The motor and the board have been installed and there is power running to the board. In testing the machine does turn manually and will feed food to the cats.
The tasks that remain:
I need to be able to program the board with the correct code. The Kitty Matic need to turn counter clockwise in order to have food rotate through the wheel and feel the cats. I need to run a 12 hour test to see if the code that I will be working on runs. I also need to find a way to seal the crack between the slope in the hopper and the side of the acrylic. It did not seal the first time I tried so I need to find a better way to close that area. Finish the presentation mp4 with the final video if multiple feeds.
What has worked?
The design of the feeder has worked. I am also very excited about the exterior design of the project. The addition of the hinges that I made were very exciting and the design of the vinyl to make the product aesthetically pleasing was also working for me. 3D printing certain parts has also been a great help. I was able to make things that I wouldn’t have been able to with any other tool.
What hasn't?
So far the code has not worked. I am honestly a bit perplexed by coding, but am ready to dive in head first to try to understand what I need to do. The top slope at this point also did not completely seal so the food could drop down the side of the machine.
What questions need to be resolved?
How many ticks does the motor need to rotate 90 degrees? What math do I need to figure out to convert seconds into the 12 hours? Will the code be able to do what I am asking it to do? Can I add just another piece of acrylic to the slope and use the adhesive to bond those pieces together? Will that close the gap and hold the cat food in?
What will happen when?
On Thursday I will be addressing the slope issue, I can laser cut the acrylic I need and then use the adhesive to combine the pieces. This should take no longer than 30 minutes total.
On Saturday I will be spending the whole day working on code. I plan to read further into the books that I have gotten and do more research online as to how to write the code. In the afternoon I will start actually playing with the code, adding and deleting things on the Linux machine and flashing the board.
By Sunday afternoon I am hoping to have the code completely finished and then just start working on my record keeping. From Sunday to Monday I plan to run the 12 hour test from 7 PM to 7 AM. This way if there is anything that needs to be fixed I will have time to run another 12 hour test on Monday night and still have time to make changes to my video for the presentation.
What have you learned?
I can’t even begin to tell you what I have learned….but I will try! I have learned how to design, mill and solder parts to a circuit board. I have learned how to use Linux to flash the board with a makefile and c code. I have learned how to adjust the makefile to contain the Atmel Ice as the programmer. I have learned how to complete the math to make the wheel have 4 quadrants that are each ¼ cup of cat food. I have learned how to make a gear with a drive gear attached to a motor. I have learned how to create a parametric press fit box and how to use the vinyl cutter in order to detail it. I have learned how to add power to a circuit board, what the pinouts mean on the microcontroller, and how to make a header to attach the motor to the board. I have learned how to design and 3D print a hinge system.
Documentation of week 19 work:
This week was devoted to me finishing the Kitty Matic. The biggest thing I needed to do was write the C code and to do testing with the actual motor and board that I designed. Please see the testing below.
Testing/writing code for the Kitty Matic:
I started by using the c code for the stepper motor that was provided for us:
hello.stepper.44.half.c
I did A LOT of testing as I have little to no experience with coding, so the process was long and all over the place.
I started with editing the main loop.
I needed the motor to turn clockwise so I took out the step_ccw(); from both lines.
Since I am using the same board as I used in week 10 I made a duplicate for testing purposes. I am also using the same files on my Linux computer so I just copied them into a new folder/directory called: kitty.matic
I then opened the terminal and typed: cd ~/Desktop/kitty.matic, then: make (made sure my make file included the atmel_ice as usual), then: make program-ice
I made sure to unplug the power before disconnecting the programmer and then plugging in the motor. Then plugged back in the power. I was excited to see the Kitty Matic motor/wheel turn…it worked great….except it was going the wrong direction!
So back to the programing. And this time I took out all of the step_cw();
This was a success.
Then it was on to trying to figure out how to change the “//main loop”. So I pretty much started from scratch. I tool out the i/j. The “for” loops variable were to count and not needed yet. Frankly I didn’t understand them either so it was good to start at the bottom and work my way up. I also removed the line: stratic uint8_t i, j; where they were defined. Then I made sure the loops were closed with the { } brackets back in the right places.
I had a friend helping me at this point that has done coding in other programs before just not C, so this was a great help because they understood the process at least.
We tried adding #include <stdio.h> and put sleep(2); in the loop. This didn’t work.
We then tried #define off/on delay (1000) to see it move more slowly. It was great to see a change, but I didn’t need it to be slower….so we changed that back.
Then we moved back to the loop added _delay_ms (1000); which by changing the delay to ms we were using milliseconds instead of us which is microseconds. Then we tried (2000) and then (12000) – 1 second, 2 second, 12 seconds between each step. This was fantastic! Finally getting to stepping the motor in a controlled way.
This is when we realized we were going to need to put back in the line stratic uint8_t i, j; and start to define variables in the main loop. Since this is the Kitty Matic and my name starts with a K, I decided that should be our first variable. stratic uint8_t k;
With the 1 second test we counted how many steps the motor took to turn 90 degrees. It was 50.
Some of the things I learned about code:
The “while” loop runs forever when closed {}.
“while (1)” is always true.
The “for” loop k < (50) will step the motor 50 times.
K < (50) will step 90 degrees.
_delay_ms (10000) is 10 seconds.
At this point we got the Kitty Matic to turn the 50 steps and then stop at 90 degrees to feed!
We used the code below to try to make the Kitty Matic turn 1 tick every 4 hours with a full dump of food at 12 hours.
Here is the math:
_delay_ms(30000) delaying 30 seconds
There are 3600 seconds in an hour.
3600 x 12 hours = 43200 seconds in 12 hours.
43200/30 = 1440 delays of the “for” loop @ 30 seconds
Our first 12 hour test was coded with 10 seconds of delay – 1440 times before it turned 90 degrees (50 steps).
In theory this would have worked, but after being plugged in from 6:35 pm – 6:35 am I was very disappointed. It seems the clock on the attiny44 did not like the waiting.
So now that I understood code a bit more, and the brackets and how the parts really come together I went back to the drawing board.
I did many tests on time, to see how long of time the motor and board could keep. I decided on 5 minutes. It kept pretty accurate time (only a few seconds off when tested over and over which wouldn’t matter in the long run for the cat feeder).
Test #1
1440 times at 10 seconds. Failed
Test #2
I added a variable which was t and added another “for” loop.
t < 6 and then the delay was (300000) roughly 5 minutes = 30 minutes
This worked! Success. The motor moved at 28 minutes and 40 seconds time and time again. I left this running over night and it was still running in the morning.
Test #3:
This time I wanted to see if I could get the code to step once every 30 minutes (to see progress) for the 12 hours (24) and then at 12 hours step the other 26 to complete the 50 (90 degrees) and feed the cats.
Code 1 - WRONG
Code 2 - WRONG
Code 3 - CORRECT!!
TEST 3 WAS A SUCCESS!!!!
The motor stepped once every 30 minutes as coded. Then after 24 steps (12 hours) it stepped 26 times to complete the 50 steps (90 degrees). The cat feeder is complete!!
See Final Project page for final code.
Week 19 Photos


