I’m starting an automatic pet feeder project. At first I just want a way to give the cats a snack at 5am so they stop waking us up. Depending on how that goes I might expand it further.
Right now my BOM consists of the following
- 1x Cereal Dispenser
- 1x Ramps 1.6 Board
- 5x A4988 motor drivers
- 1x Arduino Mega
- Just a normal one for now, but I have one with an integrated ESP32 on order
- 4x Nema17 17HS4023 Stepper Motors
The RAMPs parts came before the Arduino, so I designed and 3D printed a shaft for the auger and a mount to hold the motor in place where the knob used to be:
Now I have the Arduino, so I have to figure out how to wire it up and start driving it. I’m hoping to be able to leverage existing firmware, but that will remain to be seen.
The jumpers under each driver dictate the resolution of steps the motor can make. By putting a jumper on, it brings a pin on driver high. If it’s missing, an internal pull down resister keeps it low. Depending on which jumpers you install you get between a full step and a sixteenth step resolution. I put all jumpers on so I should be capable of 1/16 micro steps.
Then plug in each driver, ensure that the markings for each pin aligns with the markings on the RAMPs board. For the A4988 the pot should be facing away from the Power terminal blocks.
I don’t have a proper power supply right now (I ordered a 12V 5A one from amazon). In the meantime I’m using a 12V 1A wall wart that I had in my power supply drawer, hopefully it’ll get good enough for testing.
I think I’m going to hook the motor attached to the cereal dispenser as Extrude 0, which is the top left motor driver. The pins for these are labels 2B 2A 1A 1B; the A and B reference the stepper coils and I think the 2 is negative and 1 is positive. It doesn’t really matter which way you plug in the motor, it might be spin in the opposite direction as expected. I wired it with the red wire going to 2B and the black wire going to 1B, see below:
I think that’s it for now, next up is getting this motor moving so onto the firmware.
To get things moving, I downloaded the newest version of Marlin, uncommented out the line for E0 and pushed the firmware onto the Arduino Mega. Since I don’t have g-code for this, I tested it with a program called Pronterface. It connects to the Arduino over the COM port and basically acts like the interface that would normally be attached to a 3D printer.
Unfortunately because Marlin has smarts built into it, it won’t let me drive the extruder cold. I went back and uncommented the X axis, uploaded the new code, and plugged the motor into the X axis. Now I can tell Pronterface to move the x axis in intervals of 1, 10, or 100 in either direction. At first the motor wouldn’t turn the cereal dispensor. I suspected the torque was too high, so I attached a motor on its own instead and it moved just fine.
The problem is likely that the drivers aren’t tuned to the motors.
Tuning Motor Drivers
This is where things get tricky. The drivers that I bought are knock-off A4988. If I had proper parts, I could use the formula below based on the current limit (0.7 A) of my motors and know what ref voltage to tune the drivers to.
Vref = Imax * 8 * Rsense
Unfortunately these knock offs are known to have many different sense resistor values. I don’t have a micro-ohm meter, so I can’t measure what’s actually on my board, and the layout is different from any others I can find online, so I don’t even know which resistor to measure.
The table below has the possible values of the sense resistor and the associated ref voltage and whether or not it turns the dispenser.
|Sense Resistor (ohm)||Ref Voltage (V)||Turns Dispenser?|
Not being certain where I should actually set this, I dialed it back until it worked consistently, that was around 0.70 V. This isn’t a 3D printer, as in it won’t be running for hours at a time, so I’m going to risk it for now. Worse case I burn out a $2 driver or a $20 motor; lets hope the former.
So as of right now, I have a cereal dispenser that I can at great inconvenience make it turn.
One of my long term goals if this takes off is to have automated lids for the food bowls with RFID readers. That way if one cat walks away without finishing, they can come back later rather than another cat eating all of their own food plus the remains of everyone else’s. To support that possibility, I think I will need to write my own code more or less from scratch, rather than being able to make use of stock Marlin.
Next time I’ll see what I can do write some proper code to control this thing all on it’s own.