Table of Contents

Making a Pixy2 Mobile Robot

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:

Assemble the Pixy2 pan tilt

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.


Test your pan-tilt

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.

Assemble the Zumo base

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.

Test the Zumo base

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.

It's easy to hook the Zumo motors up backwards. This program will help you determine if your Zumo is working correctly. If something isn't right, none of the Zumo demos will work! So it's good to give this test a whirl…

#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

Making the cable is probably the most challenging step. It requires some decent maker skills.

  1. Start by measuring 9 inches of 10-conductor ribbon cable and cut to length.
  2. Crimp the 10-pin IDC header on one end of the cable, paying close attention to the pin number 1 triangle marking on the header and the red wire on the cable (wire number 1). Refer to the picture below. Crimping IDC cables isn't difficult, but if you haven't done it before, refer to some Youtube videos to become more familiar.
  3. On the other side of the cable, cut the cable as shown in the picture below.
  4. Strip wire 10 of the cable and crimp a female socket pin onto it as shown using needle-nose pliers, crimper or soldering in place. This wire is where Pixy2 will get its power (approximately 7V).
  5. Crimp the 6-pin connector onto the wires 1 through 6 as shown with the red wire on the left.
  6. Cut wire number 2 on the ribbon cable close to the 10-pin connector, being careful not to cut the adjacent wires. Cutting wire 2 prevents the 5V regulator on Zumo from fighting with the 5V regulator on Pixy2. Refer to the picture below.

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!

Putting it all together

  1. Clip a single pin from a 0.1” breakaway header and solder into the Vin hole on the Zumo as shown. Vin is labeled in Zumo's silkscreen. Be careful to choose the right pin (3 holes from the right, 3 holes up from the edge). Vin is a 7V (or close) power rail provided by a boost converter on Zumo.
  2. Plug the cable into Pixy and route the cable between the base plate of the pan-tilt and the Arduino, then plug the Arduino's ICSP connector in as shown.
  3. Plug the Pixy2/pan-tilt/Arduino assembly on top of the Zumo via the I/O connectors. If all is correct, Pixy should be facing forward (away from the Zumo power switch and LEDs). Note, because of the thickness of the Arduino cable connector, the Arduino won't be able to fully engage with the I/O connectors on the Zumo. There will be about 0.050 inch gap, but it's no biggee.
  4. The extra pin plugs into the Vin pin.

When all is done, your robot should look like this:

Power-on test

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.

Running the Zumo chase demo

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.

Troubleshooting

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.

  1. With the robot on its “lift” (so it doesn't run off) verify that Pixy2 is detecting your object. You should see Pixy2's LED illuminate the color of your object when the object is in view. If the LED is intermittent or dim, or if the LED stays on when you move the object out of view, bring up PixyMon and verify that Pixy2 has a good “lock” on the object. Refer to this guide to improve Pixy2's detection accuracy.
  2. With the robot on its “lift” (so it doesn't run off) move the object and see how the pan-tilt moves. Does it track the object well? If not, refer to our troubleshooting guide.
  3. With the robot on its “lift” (so it doesn't run off) hold the object directly in front of the robot, centered, about a foot from Pixy2's lens. Both of Zumo's treads should be moving forward. Move the object to the right. Zumo's left tread should accelerate. Move the object to the left. Zumo's right tread should accelerate. If one or more of the treads moves incorrectly or doesn't move at all, inspect the motor connections to Zumo's PCB, and use the Zumo test program (above) to better characterize how the motion is incorrect.

Running the line demo

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.

The code

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.

Troubleshooting

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.

  1. With the robot on its “lift” (so it doesn't run off), place the robot on top of the line you drew. Verify that Pixy2 is detecting and tracking the line. Do this by plugging in a USB cable into Pixy2 and running PixyMon. Is Pixy2 detecting the line and displaying the Vector? (Be sure to run the line_tracking program while testing.) The picture below shows a line being successfully tracked.
  2. If Pixy2 isn't detecting the line and displaying the Vector reliably, the line could possibly be too narrow or not dark enough. Although pencil will work, a black marker is recommended as it provides better contrast and tends to be thicker. In general, a line of 1/16 inch is plenty wide.
  3. From PixyMon, also verify that Pixy2's field of view is fully consumed by the ground in front of it. If Pixy2 can see the “horizon” (beyond the paper), what it sees might confuse it. Adjust the tilt angle further down by removing the tilt servo-horn and adjusting its angle such that Pixy2 is looking down more.
  4. With the robot on its “lift” (so it doesn't run off), move the robot so the line is centered in front of it and pointing straight away from the robot. The robot's treads should both be moving forward. Next, move the robot to the right, so the line is toward the left side of Pixy2's field of view. The right tread should accelerate. Next, move the robot to the left, so the line is toward the right side of Pixy2's field of view. The left tread should accelerate. If one or more of the treads moves incorrectly or doesn't move at all, inspect the motor connections to Zumo's PCB, and use the Zumo test program (above) to better characterize how the motion is incorrect.
  5. If after running the above tests, nothing appears to be wrong, try reducing the speed by reducing the ZUMO_FAST constant to a smaller value.

Happy tinkering!

Let us know how it goes – send us pictures and videos! And if you need help, don't be bashful.