a1tQ20000095cAjIAI

Course: AI LAB- Level 1
8. Magic Box to Magic Box Bluetooth Handshaking

  • 6-12 grade
  • Beginner

Lesson Description:

These activities have shown you that you can handshake without hardware and do it through software with variables and broadcasting.

There is still yet one more way to make two Dobot’s communicate with one another. This is through Bluetooth. Bluetooth is a short-range wireless communication protocol that will allow two devices, such as robots to communicate wirelessly across a room.

In this activity, signals will be sent wirelessly between two magic boxes. The 2-Button Input module will be the input and the LED module will be the output.


KEY VOCABULARY

  • Input
  • Output
  • Broadcast
  • Magic Box
  • LED Module
  • Signal
  • Handshake
  • Bluetooth
  • 2-Button input
  • Variables


EQUIPMENT & SUPPLIES

  • 2 Dobot Magic Boxes
  • Digital – 2-Button Input Module
  • LED Module
  • 2 Separate Computers
  • DobotLab software
  • 2 × 12 V Power Cable and Supply
  • 4 × Common Sensor Cables
  • 2 × USB-C to A Cable

image description

Lesson Modules


Teaching Tips:

Caution: NEVER wire anything to the Magic Box while it has power on. ALWAYS shutdown the BOX before making connections or damage to the controller could occur. Be sure to ask your instructor if you have any questions.

Caution: MAKE SURE THE TAB IS PRESSED DOWN ON THE WHITE CONNECTOR WHEN DISCONNECTING ALL SENSORS FROM THE MAGIC BOX! It is very easy to damage the sensors if the white connector is pulled or tugged on without pressing down the small white tab to release the cable from the sensor housing.

SECTION 1 – SETUP BOTH ROBOTS

SECTION 2 – WIRING the MAGIC BOX AND SENSORS – 1st SETUP

Setup #1

  1. For this activity, you will need:
    • 2× Magic Box
    • 2× USB-A to USB-C Cable
    • 2× AC/DC Power Adapter (12 V)
    • 4× Common Sensor Cables
  2. Wire the Magic Box as shown below
    • 1× Dual Button – PORT 2
    • 1× LED Module – PORT 4
Snapping suction cup

SECTION 3 – CONNECTING MAGIC BOXES to the COMPUTER & DOBOTLAB

  1. Connect both Magic Boxes to separate computers using their included USB cables.
  2. Open up DobotBlock Lab in the downloaded software on your computer.
  3. Once all of the wiring is done (sensors connected), power ON the Magic Box.
  4. Follow the same process from previous activities to add the Magic Box as a device and connect the software to it (establish communication).
  5. Click on “+ Add extension” for the AI SENSOR KIT.
ROBOT1 program screenshot ROBOT1 program screenshot ROBOT1 program screenshot ROBOT1 program screenshot

SKILL BUILDER 1 – SEND A SIGNAL THROUGH BLUETOOTH

The setup for sensing a signal between Magic Boxes is done with a few tools.

SET UP BLUETOOTH GROUP is the block that allows the program to send signals on a unique Bluetooth network. Each device must run this block at the beginning of the program.

A unique group (Street Name) should be chosen for each group of Magic Boxes that are to communicate (6 digit number (000001 – 999999)).

Each device is then given a specific device ID (House Number). The number can be any number from 0-255.

WHEN RECEIVING INFORMATION – Work similar to BROADCASTING MESSAGES. This block can replace the WHEN STARTED FLAG event header to start an operation each time a signal is received.

RECEIVE INFO FROM DEVICE – Can be set to a variable. Both numerical and string values can be received.

SEND INFO TO DEVICE – Block used to send numeric and string values to a specific device in the group.

Bluetooth blocks in Blockly Bluetooth blocks in Blockly Bluetooth blocks in Blockly Bluetooth blocks in Blockly

Bluetooth group # must be 6 digits long. For example: if you want to use the Bluetooth group # 1234, as in this activity, you must type in the leading two 0’s: 001234!

DEVICE 1

  1. Drag over a SETUP BLUETOOTH and a SEND BLUETOOTH from the WIRELESS category in the block toolbox.
  2. Create the program to the right on one computer.
    • Set up a unique group number for both devices.
    • This device will be DEVICE ID 1.
    • Send the STRING HELLO to DEVICE 2 in a loop every three seconds.
Device 1 Bluetooth code

DEVICE 2

  1. On the second computer, create a new variable (BLUE).
  2. Drag over a SETUP BLUETOOTH and a RECEIVE INFO from the WIRELESS category in the block toolbox.
  3. Create the program to the right on one computer.
    • Use the same group number from the 1st device.
    • This device will be DEVICE ID 2.
    • Set the VARIABLE BLUE to the information RECEIVED from device 1.
Device 2 Bluetooth code

Run both programs. The STRING hello should briefly appear and disappear in the BLUE variables box.

Device 2 Bluetooth code

If your set up did not work correctly the first time, what did you have to do to make it work?

SKILL BUILDER 2 – CONTROL A DEVICE THROUGH BLUETOOTH

Now that a signal can be both sent and received through Bluetooth, use this signal to control one device from another. The following program will use a button press (DUAL BUTTON) from Magic Box 1 to turn ON and OFF the LED MODULE from Magic Box 2.

DEVICE 1

  1. Drag over a SETUP BLUETOOTH and a SEND BLUETOOTH from the WIRELESS category in the block toolbox.
  2. Create the program to the right on one computer.
    • Keep the same GROUP and ID numbers.
    • Drag over an IF/ELSE Statement from the Control toolbox.
    • IF BUTTON RED is pressed, send the STRING LED ON else LED OFF.
Device 1 button code

DEVICE 2

  1. Drag over a SETUP BLUETOOTH and a RECEIVE BLUETOOTH from the WIRELESS category in the block toolbox.
  2. Create the program to the right on computer 2.
    • Start the program by turning off all of the LEDs.
    • Keep the same GROUP and ID numbers.
    • Set the variable BLUE to the info received from device 1.
    • Drag over two IF Statements from the Control toolbox.
    • IF variable BLUE = LED ON, turn ON LED 1 (RED).
    • IF variable BLUE = LED OFF, turn OFF LED 1 (RED).
Device 2 LED code

Run both programs.

Helpful tip lock button NOTE: There will be a small delay in the LED turning ON and OFF. Be patient, the delay may be 1 to 2 seconds.

Why do you think there is a delay?

If your set up did not work correctly the first time, what did you have to do to make it work?

The program can be simplified further by using the WHETHER RECEIVED instead of setting a variable to the value received.

  1. Create the program to the right on computer 2.
    • Keep the same GROUP and ID numbers.
    • The variable (BLUE) can be removed completely from the program.
    • Drag over a WHETHER RECEIVED and place one in each IF Statement.
    • IF variable BLUE = LED ON, turn ON LED 1 (RED).
    • IF variable BLUE = LED OFF, turn OFF LED 1.
Device 2 LED code Device 2 LED code

Run both Programs.

If your set up did not work correctly the first time, what did you have to do to make it work?

CHALLENGE – SECTION 4 – PASS the LED SIGNALS (HOT POTATO)

Create a program that will allow BOTH Magic Boxes to cross communicate.
Program both Magic Boxes with the same program.

  1. The BLUE and RED DUAL BUTTONS control LED 1 and LED 2 from the opposite Magic Boxes.
  2. The RED BUTTON turns LED 1 RED.
  3. The BLUE BUTTON turns LED 2 BLUE.

If your set up did not work correctly the first time, what did you have to do to make it work?


Teaching Tips:

CONCLUSION

  1. List two advantages to wireless communication between devices.

    A.  ____________
    B.  ____________
  2. List two disadvantages to wireless communication between devices. Did you experience any?

    A.  ____________
    B.  ____________
  3. How could wireless communication in an industrial, or factory type setting?

GOING BEYOND

  • Use My Blocks to make the challenge above simpler.
  • Make one LED come on when the other Magic Box’s button is pressed, and another come on when it is not.
  • Make the challenge above work with two different LEDs back and forth, on both magic boxes.

Teacher Initials _________