## Introduction: Easy Micro:Bit Rover

In this lesson, we are using a BBC Micro:Bit to drive and control a GiggleBot with MakeCode.

Before jumping into this, the GiggleBot is an easy-to-use platform that's really great for going straight into robotics without requiring prior knowledge about programming, robotics, mechanics and so on.

One of the ways to program it is with MakeCode, which is an environment where the BBC Micro:Bit can be visually programmed by drag-n-dropping blocks. This allows you to program the rover in a Lego-like fashion, which is very entertaining and fun.

So, nuff said, now let's get down to it!

## Step 1: Components Required

You are going to need the following hardware components:

1. A DexterIndustries GiggleBot.
2. A BBC micro:bit board.
3. 3 AA batteries.
4. USB A to MicroUSB cable - this one generally comes withing the micro:bit's package.

## Step 2: Putting the Hardware Together

Now, let's prepare the rover for programming it in MakeCode:

1. Put the batteries into the GiggleBot.
2. Plug in the BBC micro:bit into the GiggleBot.
3. Connect the BBC micro:bit to your computer with the provided USB cable.

## Step 3: Creating a MakeCode Project

Go to MakeCode and click on the "New Project" button. This will open up a new project for the BBC Micro:Bit board where we are going to program our GiggleBot visually, with blocks.

Now, let's load the pxt-giggle package. Press on the cogwheel on the top right, then click on Extensions, search for giggle and add the package called pxt-giggle.

## Step 4: Creating Our First Program in MakeCode

The program in this step makes the GiggleBot describe a square the moment button A is pressed on the BBC micro:bit.

Since turning to the left/right at exactly 90 degrees depends on various factors such as the surface type, battery level, load on the motors and so on, it's best to experiment with the values for the spin left for x ms block: in my case, 540 ms seems to be right value.

Also, if your GiggleBot does not go straight when commanded so, it is recommended to use the correct towards left/right by x block found in the More section of the GiggleBot package to adjust that.

Furthermore, if you don't want to reproduce the code by looking at the above screenshot, you can just copy paste the following Javascript alternative, then go in MakeCode and click on the Javascript button (next to the Blocks button) on the top of the page and put the code in there. Next, switch back to the block-based view of the code and click on Download to download the firmware.

```<p>input.onButtonPressed(Button.A, function () {<br>    lights.smileShow(NeoPixelColors.Orange)
for (let i = 0; i < 4; i++) {
gigglebot.driveMillisec(gigglebotWhichDriveDirection.Forward, 1000)
gigglebot.spinMillisec(gigglebotWhichTurnDirection.Left, 540)
}
lights.smileShow(NeoPixelColors.Blue)
})
gigglebot.stop()
lights.smileShow(NeoPixelColors.Blue)
gigglebot.setSpeed(gigglebotWhichMotor.Both, gigglebotWhichSpeed.Normal)
basic.forever(function () {

})</p>```

## Step 5: Flashing the Firmware

Now, let's flash the firmware onto the BBC micro:bit board. To do that, press on the Download button that sits on the bottom left side of the screen in MakeCode and save the hex file on your computer.

Next, copy-paste that hex file over to your BBC micro:bit board. Provided you have the board connected to your computer as we did in one of the first steps, you'll see there's a virtual filesystem to which you can copy-paste files - that's exactly where the firmware (or hex file) has to be copied to.

When copying the file, you'll be able to see the BBC micro:bit's status LED flashing intermittently. When the writing process is done, the virtual filesystem will temporarily disappear only to appear again in just a few seconds.

Once that happens, disconnect the USB cable from the micro:bit board and proceed to the next step.

## Step 6: Turn on the GiggleBot

Now, all we have left to do is turn on the GiggleBot.

Right next to the BBC micro:bit board on the GiggleBot, there's a little black slider switch with 2 states: ON and OFF. Switch it to the ON state and let the NeoPixel LEDs come to life!

## Step 7: Let It Run ... Let It Run!

To make things more interesting, I placed a whiteboard marker down in the center of the GiggleBot to make it draw a square while it's running. You can do that too! Go and grab one and start drawing with your rover.

And who said things have to stay unchanged? Go on and think outside the box, pun intended, and make your GiggleBot draw various shapes by tweaking the blocks in Step 4. Change the number of turns to say 8, reduce the time it spins on the spot to something like 350 ms and see what comes out of this.

Sky's the limit!