Using Object Recognition and AI with the HaloCode

Using Object Recognition and AI with the HaloCode

In this tutorial, we will be showing you how to use AI and object recognition with your HaloCode. For this tutorial you will need:

Plugging In

The HaloCode can connect to your PC or Mac via a USB A to micro B cable. Plug USB A end into your devices USB Port and plug the micro B end into the micro-USB port on the bottom of the HaloCode. Plug USB A end into your devices USB Port and plug the micro B end into the micro-USB port on the bottom of the HaloCode.

Software

The mBlock software for the HaloCode comes in two different versions, the online version can be used within any internet browser (Chrome is recommended) and an offline version which is available for download on PC and Mac OS.

Using Object Recognition and AI with the HaloCode

If you are using the online version you will also need to install the browser plug-in in order for the software to communicate with the HaloCode.

Using Object Recognition and AI with the HaloCode

When you first load the software, the device setup for coding will default to the Codey Rocky. Follow the four steps below in order to change the device to the HaloCode.

  1. In the Devices tab, click on the blue plus symbol in the white box next to the Cody.
  2. In the new window that opens, double click on the HaloCode icon.
  3. When it has finished loading, click on the Codey again in the Devices tab. With Codey selected click on the white x in the blue circle
  4. You should be left with just the HaloCode in the Devices tab.
 Using Object Recognition and AI with the HaloCode Using Object Recognition and AI with the HaloCode Using Object Recognition and AI with the HaloCode Using Object Recognition and AI with the HaloCode
1 2 3 4

Within the coding software, you can quickly switch between using Block programming and Python by clicking on the button in the top right of the screen.

Using Object Recognition and AI with the HaloCode Using Object Recognition and AI with the HaloCode
Block Programming Mode Python Mode

 

For this tutorial, make sure you are in Blocks Mode.

Setting Up the Extension

Click on the Sprites tab on the left-hand side of the screen.

Using Object Recognition and AI with the HaloCode

At the bottom of the block code categories, click the EXTENSION button.

Using Object Recognition and AI with the HaloCode

Navigate the screen till you find the Teachable Machine extension and click the add button.

Using Object Recognition and AI with the HaloCode

Setting Up the Object Recognition

Setup your camera and objects that you wish to use for the recognition.

Using Object Recognition and AI with the HaloCode

From the TM category, select the Training Model option at the top of the screen.

Using Object Recognition and AI with the HaloCode

With your image in place, you can teach the program up to 3 different objects. In our example, we are only going to use two. Press the Learn button in the first category, taking multiple images of your object from different angles.

Using Object Recognition and AI with the HaloCode

Repeat this process with the second and third objects that you wish to use.

Using Object Recognition and AI with the HaloCode

Give each category a name and press the Use This Model button to save the images and go back to the main coding screen.

Using Object Recognition and AI with the HaloCode

From the TM category, press the Open Recognition Window button, to load a view of what the camera is currently seeing along with the object it has matched it against.

Using Object Recognition and AI with the HaloCode

Coding the Sprite

From the EVENTS category, drag the When I Receive Message1 block onto the workspace.

Using Object Recognition and AI with the HaloCode

Click on the word message1 to bring up the dropdown menu, click on New Message to create your own.

Using Object Recognition and AI with the HaloCode

In the popup window that opens, give the message a new name, for this example, as it is going to be used to start the object recognition we are going to call it Start

Using Object Recognition and AI with the HaloCode

On the CONTROL category, drag the If Then Else statement block and attach it to the bottom of the When I Receive block you just added.

Using Object Recognition and AI with the HaloCode

From the OPERATORS block, drag the Blank = 50 comparison block into the dark orange space in the if statement.

Using Object Recognition and AI with the HaloCode

Go to the TM category and drag the Recognition Result block into the left-hand side of the comparator block that you just added. In the right-hand side of the comparator, change the value to your first object recognition category. In our example the first one was MakeyMakey.

Using Object Recognition and AI with the HaloCode

Click on the EVENTS category and drag the broadcast block into the top half of the if statement. Rename this to match the object recognition name, in this example it is MakeyMakey.

Using Object Recognition and AI with the HaloCode

Right-click anywhere on the orange if statement block and select duplicate.

Using Object Recognition and AI with the HaloCode

Place this copied block into the bottom part of the original if statement.

Using Object Recognition and AI with the HaloCode

In the new, if statement, change the right-hand side of the operator and the message being broadcast to match the second result.

Using Object Recognition and AI with the HaloCode

Lastly, from the EVENTS tab, drag the broadcast block to the empty gap in the second if statement, creating a new name for it.

Using Object Recognition and AI with the HaloCode

Coding the HaloCode

Click back to the HaloCode by selecting the Device tab.

Using Object Recognition and AI with the HaloCode

From the EVENTS category, drag the When Button Is Pressed block onto the workspace.

Using Object Recognition and AI with the HaloCode

Again, from the EVENTS category, drag the broadcast block underneath it, changing the message to Start from the drop-down menu.

Using Object Recognition and AI with the HaloCode

From the EVENTS category, drag the When I Receive block, using the drop-down menu to select one of your options, in our example it is the Makey Makey. Click on the LIGHTING category and drag the All LEDs Light Up block underneath it, changing it to your choice of colour.

Using Object Recognition and AI with the HaloCode

Right-click on the When I receive block and select duplicate.

Using Object Recognition and AI with the HaloCode

Make the following changes to the copied version, change the message received to the second option (our example is the MoveBuggy) and change the LEDs colour to another one of your choosing.

Using Object Recognition and AI with the HaloCode

Repeat this step again for the message Nothing.

Uploading Code to HaloCode

Click the blue Connect button at the bottom of the screen, in the popup box that opens, press the Connect button.

Using Object Recognition and AI with the HaloCode

Once connected, make sure that you are in Upload mode

Using Object Recognition and AI with the HaloCode

Click on the upload button at the bottom of the screen to upload the code.

 

Running the Program

Switch the Software back to Live mode

Using Object Recognition and AI with the HaloCode 

Press the go button (green flag) on the program, place an object in front of the camera and press the button on your HaloCode.

Extra Additions!

The software allows you to add audio outputs quickly and easily, navigate back to the Sprite by clicking on the Sprites tab and click on the EXTENSION button again. In the extensions window, you are looking for Text to Speech option, click the add button.

Using Object Recognition and AI with the HaloCode

Navigate to the TEXT TO SPEECH category and Speak Hello blocks after each broadcast blocks within the if statement, changing the word hello to what you wish the program to say.

Using Object Recognition and AI with the HaloCode

Restart your program by pressing the red stop button and then the go button (green flag) on the program, place an object in front of the camera and press the button on your HaloCode.

Previous Next