Having collected together all the parts I thought I needed to get started with my CatDogFoxBot Project14 effort for Remote Sensing and Control I happily sat down for a couple of hours using TinkerCAD to design some 3D printed parts to hold everything together. So far I have made the platform to hold the stepper motor and a widget to connect the Grideye PCB to the spindle of the stepper motor. For an initial design I am very happy with these parts as when combined with some metal pillars a compact and tidy module has been produced. I have left the designing of the holder for the Nano until a later time as I am not entirely sure how the structure will progress once I start to get it ready for going outside all night - in the cold, damp and possibly even rain. The video below illustrates this module just scanning the Grideye sensor backwards and forwards through 180 degrees.
The main part of the Nano programme is listed below. It is not complicated, just a for loop that scans one way through 180 degrees and then back again, inside a while loop set to run forever.
count = 0;
while(1)
{
if (count < scansteps / 2)
{
leftturnstep();
}
else
{
rightturnstep();
} /* if */
count++;
if (count > scansteps)
count = 0;
} /* while */
The stepper motors have four phases so a simple one phase on at a time output sequence is all that is needed. I use a function to create the four step sequence to activate each phase once. The for loop then uses these functions.
void leftturnstep(void)
{
digitalWrite(PhaseA, HIGH); // turn the Phase on (HIGH is the voltage level)
delay(stepdelay); // wait for a bit
digitalWrite(PhaseA, LOW); // turn the phase off and the next one on
digitalWrite(PhaseB, HIGH);
delay(stepdelay); // wait for a bit
digitalWrite(PhaseB, LOW); // turn the phase off and the next one on
digitalWrite(PhaseC, HIGH);
delay(stepdelay);
digitalWrite(PhaseC, LOW); // turn the phase off and the next one on
digitalWrite(PhaseD, HIGH);
delay(stepdelay);
digitalWrite(PhaseD, LOW); // turn the phase off and the next one on
} /* leftturnstep */
I originally decided that it would not need any form of calibrating limit switch for the stepper motor as I thought I could just manually move the stepper motor shaft to the correct initial position. I can do this but I hadn't really thought that the stepper motor will always think that the power-on position will be step zero and that will be the same stepper motor shaft position whenever it was powered off. The result is that every time I power off or reprogram the Nano the Grideye sensor starts from a new zero position. At present I hold the Nano reset button down and manually adjust the stepper motor shaft position until it is correct but that is not easy to do and not all that practical so I think I will have to add some sort of limit switch or sensor.
The scanner module also makes a 'noise' as it is scanning which is not going to be that helpful as it might scare away the cats I am trying to detect. I can step at a much slower speed which will reduce the noise but then I will not be able to track the cat as it is moving about. I might have to include some sound-proofing.
I have not yet made the connections to the Grideye sensor yet so that will be the next step. I will need to download the library for it and try out the example programme provided in order that I can start to understand what the Grideye can do and what the data will look like.
Dubbie
Top Comments