Getting Started with the Red Hat Co.Lab Robot

Contributors: D___Run___, Gina Likins
Favorited Favorite 1

Test (and fix any problems)

If your code is loaded and your robot is assembled, it’s time to take your robot for a spin.

  1. Unplug the USB cable (you don’t want to drag your computer off the table)
  2. Make sure you have plugged in the barrel power jack (and that you have batteries installed).
  3. Make sure the STOP/RUN MOTORS switch on the moto:bit set to RUN
  4. Put your robot on the floor (it would stink to have your cool, new robot drive right off the edge of a table!)
  5. Buckle your seatbelt and fasten your helmet and press Button A.

What we expect will happen is that your robot will drive forward for 1 second, pivot, and then drive forward for another second before stopping.

What might happen is that your robot drives backward instead of forward or it might spin in a circle! -- what!?

No, you didn’t do anything wrong; sometimes wiring is weird.

If you want to go ahead and fix it skip down to the fixing motor issues section. (No judgement!)

If you’d like to learn a little more about how motors work (and how engineering happens) before fixing it, read on:

Motors work by sending current around a coil of wire, creating a magnetic field (30-sec video showing this in action). This then interacts with magnets in the motor, causing a push / pull effect. If you do that with proper spacing and timing, then you can spin a shaft. (Check out the Resources section for a longer video on how motors work.)

When we hooked up the motors to the moto:bit board, we did so with the assumption that the red wire is the positive (+) and the black wire is the negative (-), which is the standard (also called the “convention”) and that the current would flow through the coil inside the motor from the positive (+) red end to the negative (-) black end. That would cause the shaft to spin in one direction (clockwise, normally). The motor also has a gearbox that both turns the clockwise spin 90° (so the drive shaft sticks out the side of the motor rather than the front -- much more handy for mounting wheels) and turns a very fast, but fairly weak spin into the slower but more powerful spin that’s needed to make your robot go.

So, what happens if:

  • the factory occasionally makes a batch of motors with the black positive (+) and the red negative (-) -- and yes, this sometimes happens! and
  • you wire the motors following the markings on the moto:bit board (which was engineered based on the standard red is always positive (+) and black is negative (-)), and
  • you run the code as written?

In this case, your robot won't behave as expected, but that’s ok, because we can fix it!

Diagnosing Motor Issues

If your robot is driving backwards, it means you got two “reverse” motors.

If your robot is spinning in a circle (which is kind of cute, but not what we’re looking for), then you got one normally wired motor and one “reverse” motor.

Either way, you have to compensate for the “reverse” motor(s), which you can do in the software or in the hardware.

We’ll look at both (and you can try them both), but if I have a choice, I’ll usually try to find a hardware fix that I can use on a permanent basis because there’s less chance that it will interfere with something else I might want to do in my code later on.

But what if you’re not sure whether there’s a reverse-motor situation happening? (Or you're not sure which motor is reversed...)

That's where the software fix comes in handy. You can make the necessary fix in the software, test that, then if it turns out that you have (one or more) reverse motors, you can make a more permanent fix with hardware. Because it’s useful to diagnose a problem before making fixes, we’re going to look at the software fix first.

Reversed-Motor Software Fix

If you closed it, open your MakeCode window again. Let's look at that first block of the sample code with the set ____ motor invert to ____ in it.

alt text

Here's how we described what was happening in that block:

On Start

The code starts by setting each motor channel in the on start code block. Depending on how the motors are wired to the moto:bit, your micro:bot may drive in the opposite direction than what you would expect. The set set ____ motor invert to ____ provides the option to switch the motor wires in code without physically rewiring the motors to the moto:bit. Set the left or right motor that you would like to invert. If you want the motor to drive in the opposite direction relative to your setup, select either true or false.

But what do you do if your robot is...

Spinning in a Circle

Here's my first test run:

  1. Try setting either of the two motors to true instead of false. It doesn’t matter which you choose.
  2. Download the code and transfer it to your micro:bit like you did before.
  3. Press the A button and see what happens. If your robot now goes backwards then your random choice of which motor to change was the wrong one. In other words, you reversed the motor that was correctly wired. :-) Like I did here (test run #2):
  4. No problem, though, just repeat the process, returning that motor to false and setting the other motor to true. Then download your code to the robot and try it out. Here's my test run #3:
  5. Hopefully your robot is now driving in the right direction?
  6. Congratulations! You correctly identified the reversed motor, and you can (if you’d like) fix the motor in the hardware. Don’t forget to change the software back to its original state!

Running in Reverse

If your robot is running backwards:

  1. Try setting both motors to true instead of false.
  2. Download the code and transfer it to your micro:bit like you did before.
  3. Press the A button and see what happens.
  4. Hopefully your robot is now driving in the right direction?
  5. If so, congratulations -- you got two reversed motors, and you figured it out!
  6. Now you can (if you’d like) fix the motors in the hardware. Don’t forget to change the software back to its original state!

Reversed-Motor Hardware Fix

Once you've used the software fix to figure out which motor(s) are reverse-wired, then you can make the change more permanently by changing the way the wires are connected.

Example: Let’s say your robot was spinning, and you used the software fix to figure out that your left motor is reversed. To fix it in the hardware, you’d plug the red wire into the pin that’s labeled black on the moto:bit on the left side and the black wire into the pin labeled red on the moto:bit on the left side. (Don’t forget to go back into your code and reset the left motor invert to false. Then you would download your new code and re-test it.)

If your robot is driving backwards, it’s the same process as for the spinning robot, only you have to reverse the sets of wires on both the right and left sides of the moto:bit (and change, re-download, and test your code).

NOTE: If you have to switch the wiring for either of your motors, it's a good idea to use a piece of tape to mark that on the moto:bit board in case the motor wires get disconnected (it happens!).

Here's my recap of the entire testing process and final run:

NOTE: For other troubleshooting tips and information about changing the battery, see Troubleshooting.

Project checklist

☑ Read Requirements and Assemble Tools

☑ Read the Instructions

☑ Identify the Parts

☑ Build Your Project

☑ Testing

☐ Show it off!

Congratulations! You have an amazing Co.Lab robot -- we can’t wait to see what you do with it.

What’s next?

More fun things to do with your Co.Lab robot kit (we’re going to use those Line Sensors you installed)!

Keep an eye on this space as we’ll be releasing more activities over time!