Pixy2 Quick Links
Basics
Connecting Pixy2 to…
Pixy2 Modes / Programs
Software and Support
Basics
Connecting Pixy2 to…
Pixy2 Modes / Programs
Software and Support
The robot in the Pixy2 video is something you can assemble yourself with some additional robot parts. It makes a fun little robot that is capable of useful tasks, such as, uh, chasing things and following lines. Its controller is a standard Arduino. And since it's an Arduino, you can easily modify our examples to make the robot do whatever you want.
What's required:
For the cable between Pixy and the Arduino/Zumo:
And various tools:
The assembly docs can be found here. You will be mounting the pan-tilt mechanism on top of your Arduino as shown below, so pay attention to which holes in the base-plate to use for the stand-offs. The stand-offs should align with the Arduino's mounting holes.
Once you've attached the stand-offs to the base plate, go ahead and mount the pan-tilt on your Arduino with 4 more of the 2-56 fasteners that came with the pan-tilt kit. Refer to the picture below. Notice how the Arduino headers are facing down.
If you haven't done so already, you should test your pan-tilt before proceeding by running the pan-tilt demo. If you run into any problems, refer to the pan-tilt troubleshooting guide.
Assembly docs for Zumo can be found here. The Zumo base assembly requires a soldering iron, and I (personally) found it somewhat challenging. The “sumo blade” (bumper) isn't necessary but doesn't hurt things either.
After you assemble the Zumo base, run a simple Arduino program to test the motors and buzzer. Below is a simple Arduino program you can cut and paste into the Arduino IDE. Note, the files ZumoMotors.h and ZumoBuzzer.h are part of the Pixy2 Arduino library (found here). Install the Pixy2 Arduino library if you haven't already.
#include <ZumoMotors.h> #include <ZumoBuzzer.h> ZumoMotors motors; ZumoBuzzer buzzer; void setup() { Serial.begin(115200); Serial.print("Starting...\n"); } void loop() { Serial.println("Left forward"); motors.setLeftSpeed(200); motors.setRightSpeed(0); delay(2000); Serial.println("Right forward"); motors.setLeftSpeed(0); motors.setRightSpeed(200); delay(2000); Serial.println("Left reverse"); motors.setLeftSpeed(-200); motors.setRightSpeed(0); delay(2000); Serial.println("Right reverse"); motors.setLeftSpeed(0); motors.setRightSpeed(-200); delay(2000); Serial.println("Buzzer"); motors.setRightSpeed(0); buzzer.playFrequency(500, 500, 15); delay(1000); }
Left, right, forward and reverse are with respect to an imaginary (and tiny) driver-person sitting on the Zumo and facing forward. The Zumo's power switch and LEDs are at the back of the Zumo, so the imaginary driver will face opposite (looking away from) the power switch and LEDs.
Make sure the Zumo motors move as described in the above program. Don't forget to insert batteries and turn the Zumo power switch on before running the test.
Making the cable is probably the most challenging step. It requires some decent maker skills.
You can test the cable with an ohmmeter if you would like to make sure the cable connections are correct. Inspect the cable picture below. Compare it to your cable. Are the connectors in the same orientation? Is the red wire on the ribbon cable doing the same thing? If one of the connectors or cables is flipped, you may damage your Pixy2!
Go ahead and switch on your Zumo by flipping the switch in the back. Pixy's LED should initially flash and turn off, which means Pixy is getting power. This is an excellent sign because it means that your cable is likely good.
If your Pixy doesn't come on, check the cable and its connections, and make sure the Vin pin is in the correct location. Is the Zumo powering on? (Check the Zumo LEDs.) If Zumo isn't powering on, make sure the batteries are inserted correctly. Then perhaps unplug Pixy from the cable and retry.
The chase demo is a good program to run first to test and possibly debug your robot. It's shown in the Pixy2 Youtube video.
Choose an object that you want your robot to chase such as a colored ball, and teach Pixy the object by plugging Pixy into your computer's USB port and running PixyMon.
Upload the ccc_zumo_chase program into the Arduino by plugging your Arduino into your computer's USB port and running the Arduino IDE. The ccc_zumo_chase program is part of the Pixy Arduino library which you can find here. Once the Pixy2 library is installed, you can find the ccc_zumo_chase program in File➜Examples➜Pixy2 from the Arduino IDE.
Unplug the USB cables and switch on your robot. Hold the object in front of the robot. If all goes well, Pixy2's LED will illuminate indicating that it has detected the object, and the robot will begin chasing the object, while tracking the object with the pan-tilt.
If your robot doesn't seem to be working, put the robot on something (e.g. a stack of quarters) to lift its treads off the ground, so that its treads are free to move, and you can more easily see what's going on without the robot running away.
The line demo is a fun demo – the same one shown in the Pixy2 Youtube video. If you haven't tried the chase demo (described above), we recommend running it first to test and possibly debug your robot.
Upload the line_zumo_demo program into the Arduino by plugging your Arduino into your computer's USB port and running the Arduino IDE. The line_zumo_demo program is part of the Pixy Arduino library which you can find here. Once the Pixy2 library is installed, you can find the line_zumo_demo program in File➜Examples➜Pixy2 from the Arduino IDE.
On a large piece of paper, or several pieces of paper taped together, draw an oval or a figure-8 with a black marker. When drawing curves, try to make the curves have a radius no smaller than 10 inches.
Place the robot on the line that you drew and turn it on. After initializing, Pixy2 should turn on its lamp and look down (with its tilt axis) and start following the line.
You can print the turn signs, cut them out and use them to direct your robot to execute turns at intersections (like in the video) if you like. It's pretty fun!
If all is working well, the robot will skillfully follow the line, beeping when it sees an intersection or a barcode. And executing turns if directed to do so by the turn signs.
If you look at the code for line_zumo_demo, you'll notice that it's surprisingly simple for what it does.
There is some interesting logic for setting the wheel velocities (setLeftSpeed() and setRightSpeed()). Sure, there is a PID loop wrapped around the robot heading. But in particular, if the Vector is pointing down (or down-ish), i.e., the y1 value of the Vector is greater than the y0 value – if so, the robot will actually need to back-up to keep the line in view. You can see this happen in the video when the robot makes a left-turn, because of the shape of the intersection.
As an exercise to the reader (don't you love those?), use the barcode images and your favorite drawing program to make a “U-turn” sign. Then modify the program to deal with a U-turn sign, such that when it sees it, the program issues a reverseVector() command, flipping the Vector. What do you expect will happen? Discuss with your lab partner.
If your robot doesn't seem to be working, put the robot on something (e.g. a stack of quarters) to lift its treads off the ground, so that its treads are free to move, and you can more easily see what's going on without the robot running away.
Let us know how it goes – send us pictures and videos! And if you need help, don't be bashful.