Welcome to Morpx Documents

MU Vision Sensor 3 Introduction

MU Vision Sensor 3(MU 3) is an intelligent vision sensor that can recognize many kinds of objects with deep-learning algorithm inside. For example, it can detect color blocks, balls, human body and cards.Its detect result can be transmitted through UART or I2C interface. MU 3 is compact, low power consumption, process all algorithms locally, and can be widely used in intelligent toys, AI+STEAM lessons, creators and other products or fields.

_images/MUVS3_main.png

Hardware Setup

1. Set Communication Mode

MU supports 4 kinds of communication modes: UART,I2C,WIFI,image transmission . Change mode by switching Output switch on left side of MU.

After choosing mode, communication mode in program should be same as switch to make the codes working. Choose communication mode before coding, and then set other parameters.Every time changing communication mode, MU must be restarted.

output mode

switch

number

LED indicate

UART

FUNC00

00

flash red

I2C

FUNC01

01

flash green

WiFi

FUNC10

10

flash yellow

image transmission

FUNC11

11

flash purple

2. Set Address

MU supports 4 address: 0x60 (default), 0x61 , 0x62 , 0x63 . Address should be changed when conflicted with other sensors. In I2C modes, several MU sensors can work together with different address.

Note

Use default address 0x60 normally.

device address

switch

number

device address

switch

number

0x60

FUNC00

00

0x61

FUNC01

01

0x62

FUNC10

10

0x63

FUNC11

11

3. Wire Connection

UART/WiFi/image transmission modes

MU

RX

TX

G

V

controller

TX

RX

GND

5V

I2C modes

MU

SCL

SDA

G

V

controller

SCL

SDA

GND

5V

Software Setup

Check detailed instructions among platforms below.

Special modes introduction

WiFi/image transmission mode network distribution

In WiFi/iamge transmission mode, distribute network by sending AT command to MU. Default serial baudrate is 9600.

Send following command to know all AT commands:

AT+HELP

Attention

all commands should end with "\r\n" or ' ' .

MU supports AP and STA modes to connect to network. Here is difference between two ways:

AP mode

AP mode is default WiFi mode of MU. In this mode, MU will establish a WiFi hotspot for user to connect. When WiFi connect successfully,LED of MU will turn off.

Default hotspot name is MORPX-MU-AB .

Note

A stands for initial word of LED color on the left, and B stands for initial word of LED color on the right.

(For enample: left LED is R ed, right LED is **Y**ellow, then default WiFi name is MORPX-MU-RY

Send following AT command to change WiFi name:

AT+WIFISET=<yourSSID>,<yourPassword>,AP
AT+WIFICON=1

If succeed, returns:

OK
wifi ap mode starting...
OK
STA mode

STA mode means MU and another device should connect to the same WiFi to get each connected. Send following commands to configure:

AT+WIFISET=<yourSSID>,<yourPassword>,STA
AT+WIFICON=1

Attention

<yourSSID><yourPassword> should be an available WiFi(case sensitive), or connection failed.

If set successfully, return:

OK
wifi sta mode connecting...
OK

Watch image in image transmission mode

Set MU to image transmission mode and complete WiFi connect , images can be watched through website 192.168.4.1 .

Wireless Transmission

MU can transmit data in WiFi/image transmission modes.Complete WiFi connect and then take following steps:

Note

TCP/UDP software are different in PC or mobile devices, here are some common definition:

  • local IP : IP address of MU

  • target IP : IP address of target device that MU send to

  1. Open TCP/UDP software, choose UDP, and change mode to Unicast

  2. Search local IP by sending command to MU:

AT+WIFISIP

Return MU local IP.

  1. Set TCP/IP to MU local IP, and port is 3333

Note

In STA mode router will distribute a random address for MU and target device. Take following steps:

  1. Search target IP (Most TCP/IP software will show local IP address)

  2. Send command to MU:

AT+WIFIUDP=<targetIP>,3333

Return:

OK

Now WiFi configuration is finished, and all the data from TCP/UDP software will show on MU serial port, and all data from MU serial port will show on TCP/UDP software.

MU 3 Mixly Programming Guide

This passage introduces how to use MU Vision Sensor 3 with Arduino board and Mixly IDE.

Import Mixly Library for MU Vision Sensor 3

Open Mixly and choose controller.For example, choose Arduino Uno. If you use MoonBot controller, choose Arduino Mega(atmega 1280) and choose the available COM port.

_images/MUVS3_Mixly_hardware.png

Click ‘Import’.

_images/MUVS3_Mixly_import.png

Locate the ‘MuVisionSensor3.xml’ file , select and open it.

_images/MUVS3_Mixly_file.png

Then the nether information window prompts” import custom Library successfully ”, and you will find ‘MuVisionSensor3’ library in the ‘Blocks’ window.

_images/MUVS3_Mixly_imported.png

Connect to Arduino

MU Vision Sensor 3 periphrals and ports:

_images/MUVS3_pinout3.png

Serial Mode*

  1. Output Protocol Switch: set both switchs downward.

  2. Connect the output RX pin of MU to TX pin of Arduino and TX pin of MU to RX pin of Arduino.

  3. Change the UART address of MU sensor by resetting Address Switch. Both switches are downwards and the address is 0x60 on default. (Changing this setting is not recommended)

Arduino UNO cannot send messages to PC when MuVisionSensor is running in hardware serial mode, due to a communication conflict.

AT Command Mode (For firmware after V1.1.5)

  1. Output Protocol Switch: set switch 1 upwards and switch 2 downwards.

  2. Connect the output RX pin of MU to TX pin of Arduino and TX pin of MU to RX pin of Arduino.

Image Transmission Mode (For firmware after V1.1.5)

  1. Output Protocol Switch: both switchs are upwards.

  2. Connect the output RX pin of MU to TX pin of Arduino and TX pin of MU to RX pin of Arduino.

Block Introduction

Setting Blocks

Initialization
  1. Hardware Serial Mode: Vision sensor uses serial mode to initialize the main control when connecting the main control hardware serial port. The serial port is the serial communication between the main control and the computer. When it is used for vision sensor, computer printing characters will be disordered or communication abnormalities.

_images/Mixly_block_serial_init.png

  1. Software Serial Mode: Vision sensor uses serial mode, and the main controller is initialized when connecting the main control software serial port. The main controller can customize RX and TX pins. The speed of soft serial port in real environment may be too fast and unstable. The baud rate is not recommended to exceed 9600.

_images/Mixly_block_softserial_init.png

  1. Hardware I2C Mode: The vision sensor uses I2C mode to initialize the main controller when connecting the main controller I2C pins.

_images/Mixly_block_i2c_init.png

Enable Vision Algorithms

_images/Mixly_block_enable_algorithm.png

Algorithm performance level

_images/Mixly_block_algorithm_performance.png

Enable/Disable the High FPS Mode

In high FPS mode, detect speed and power consumption will increase.

_images/Mixly_block_highFPS.png

Set White Balance Mode

Adjust the image bias caused by the change of external light source.

_images/Mixly_block_setWB.png

LED Settings

_images/Mixly_block_setLED.png

Restore Default Settings

Disable all algorithms and restore hardware default settings.

_images/Mixly_block_setdefault.png

Get Result Blocks
  1. Ball/Body Detection

_images/Mixly_block_ball_detect.png

  1. Card Detection

_images/Mixly_block_card_detect.png

  1. Color Block Detection

_images/Mixly_block_color_recognition.png

  1. Color Recognition

_images/Mixly_block_color_block.png

Light Sensor Blocks

Enable Light Sensor

Enable light sensor functions. Gesture detect function can not work together with other functions.

_images/Mixly_block_ls_begin.png

Set Sensitivity

Set light sensor sensitivity, only working in Proximity/Ambient Light Detect.

_images/Mixly_block_ls_set_sensitivity.png

Get Proximity Value

Read proximity value. Closer the distance, bigger the value.

_images/Mixly_block_ls_read_proximity.png

Read Ambient Light Value

Lighter the ambient light, bigger the walue.

_images/Mixly_block_ls_read_als.png

Read Detected Gesture or Not

Read whether detected gesture. If not detected, return 0.

_images/Mixly_block_ls_detect_gesture.png

Judge Detected Gesture

Judge type of the detected gesture.

_images/Mixly_block_ls_read_gesture.png

WiFi Module Blocks

WiFi AT command Settings

Blocks below only works in image transmission or AT command mode.

WiFi Initialization

Initial WiFi port and baudrate.

_images/Mixly_block_wifi_begin.png

Configure WiFi

Set account and password of WiFi.

_images/Mixly_block_wifi_config.png

Connect/Establish WiFi

Try connect to WiFi or establish WiFi and return conncetion result.

_images/Mixly_block_wifi_connect.png

Disconnect WiFi

_images/Mixly_block_wifi_disconnect.png

Set target IP

_images/Mixly_block_wifi_set_target_ip.png

Read target IP

_images/Mixly_block_wifi_read_target_ip.png

Read local IP

Get IP of MU.

_images/Mixly_block_wifi_read_local_ip.png

WiFi Read

Get data that target IP sent to MU.

_images/Mixly_block_wifi_read.png

WiFi Write

Send data to target IP.

_images/Mixly_block_wifi_write.png

Examples

Color Recognition

_images/Mixly_example_color_recognition.png

Ball Detection

_images/Mixly_example_ball_detect.png

Card Detection

_images/Mixly_example_card_detect.png

Light Sensor - Gesture Detect

_images/Mixly_example_ls_gesture_detect.png

Light Sensor - Proximity/Ambient Light Detect

_images/Mixly_example_ls_als_proximity_detect.png

Connect to WiFi through AT Command

_images/Mixly_example_AT_wifi_set.png

FAQs

  1. Q: What should I do if I can’t open programming blocks or blocks are black boxes?

A: Please download the latest Mixly program file and import the library again.

  1. Q: What should I do when I import the library and download the examples correctly, but the vision sensor doesn’t respond and the serial port output nothing?

A: Check whether the cable is correctly and tightly connected .

Check whether the white light on the back side is on. If this light is not on ,this means something wrong with power supply.

Check whether the output mode switch and address switch are correctly setted.

It takes MU sensor a period of time to initialize after power-on , we suggested to add a delay of not less than 500 ms before calling ‘setup’ block in your program.

After reset, the two LEDs on the front side of MU vision sensor will flicker once. Red light indicates that the current mode is serial mode, green light indicates that the current mode is I2C mode. If the color does not go with the setting of output mode switch, please reset this switch.

  1. Q: What should I do if I download the program and the serial port output correctly, but the LED does not light?

A: When the color recognition algorithm runs, the LED lights will be shut down in order not to interfere with the recognition results.

Calling the LED setting block and alter the brightness parameter with non-zero number.

  1. Q: Why there are some fuctions which can be found in the datasheet while are not listed in Mixly library?

A: In order to make the library easy to understand and operate, some uncommon functions are removed from the Mixly library, and some parameter setting methods are simplified. If these functions are needed, please email to support@morpx.com.

  1. Q: Why the previously downloaded recongnition algorithms have impact on the current running program? For example download ball detection algorithm after running color recognition algorithm ,you will find the LEDs are still on even if the ball is not recognized, but this will not occur when only ball recognition algorithm was downloaded.

A: Because the previous algorithm is not terminated even if the program ends, you can add ‘setDefault’ block when calling ‘setup’ block or restart MU vision sensor.

MU 3 Arduino Programming Guide

This passage introduces how to use MU Vision Sensor 3 with Arduino board and Arduino IDE.

Import Arduino Library for MU Vision Sensor

Download Arduino IDE at Arduino official website

https://www.arduino.cc/en/Main/Software

Download latest MU Vision Sensor library in github

https://github.com/mu-opensource/MuVisionSensorIII

Install the Arduino IDE, and third-part library is located in “Documents\Arduino\libraries”. Unzip the MU Vision Sensor library and drag it into the libraries file to finish importing the library.

Open Arduino IDE, choose “Tools - Board” to change the development board. Arduino Uno is a popular board. If you use the MoonBot controller board, you should choose Arduino Mega 2560, and choose the processor ATmega 1280. Then connect the board and choose the right COM port.

If the library is successfully imported, the examples of MU is shown in ”File - Examples - Mu Vision Sensor III”. Open an example and verify it to check wether the library can be compiled.

_images/MUVS3_Arduino_library_en.png

Connect to Arduino

MU Vision Sensor 3 periphrals and ports:

_images/MUVS3_pinout.png

Serial Mode*

(1) Output Protocol Switch: set both switchs downward.

(2) Connect the output RX pin of MU to TX pin of Arduino and TX pin of MU to RX pin of Arduino.

(3) Change the UART address of MU sensor by resetting Address Switch. Both switches are downwards and the address is 0x60 on default. (Changing this setting is not recommended)

Arduino UNO cannot send messages to PC when MuVisionSensor is running in hardware serial mode, due to a communication conflict.

AT Command Mode (For firmware after V1.1.5)

  1. Output Protocol Switch: set switch 1 upwards and switch 2 downwards.

  2. Connect the output RX pin of MU to TX pin of Arduino and TX pin of MU to RX pin of Arduino.

Image Transmission Mode (For firmware after V1.1.5)

  1. Output Protocol Switch: both switchs are upwards.

  2. Connect the output RX pin of MU to TX pin of Arduino and TX pin of MU to RX pin of Arduino.

Examples

ball

body

colorDetect

colorRecognition

getTargetPosition

numberCard

shapeCard

trafficCard

arduino_base_interface

MU 3 MakeCode Programming Guide

This passage introduces how to use MU Vision Sensor 3 with Micro:bit board and MakeCode IDE.

Import Extensions

Run MakeCode (open https://MakeCode.microbit.org/ in the web browser or use an offline version of MakeCode, which can be downloaded from Microsoft MakeCode website https://www.microsoft.com/en-us/makecode). Start a new project, find Extensions in Advanced menu.

_images/MUVS3_Makecode_extension.png

Search muvision or mu to find ‘muision’ from the results list. (former link mu-opensource/pxt-MuVisionSensor3 is abandoned) Click to import the extension into MakeCode.

_images/MUVS3_Makecode_extension_MU.png

_images/MUVS3_Makecode_imported.png

Connect to Micro:bit

MU Vision Sensor 3 periphrals and ports:

_images/MUVS3_pinout1.png

Serial Mode

(1) Output Protocol Switch: both switchs are downwards

(2) Connect the output Pin1(RX) to Pin13(TX) of Micro:bit and Pin2(TX) to Pin16(RX) of Micro:bit

(3) Change the UART address of MU sensor by resetting Address DIP Switches. By default, both switches are downward and the address is 0x60. (Changing this setting is not recommended)

*Micro:bit cannot send messages to PC when MuVisionSensor is running in serial mode, due to a communication conflict.

*The default communication baud rate is 9600 and cannot be modified.

AT Command Mode (For firmware after V1.1.5)

  1. Output Protocol Switch: set switch 1 upwards and switch 2 downwards.

  2. Connect the output Pin1(RX) to Pin13(TX) of Micro:bit and Pin2(TX) to Pin16(RX) of Micro:bit.

Image Transmission Mode (For firmware after V1.1.5)

  1. Output Protocol Switch: both switchs are upwards.

  2. Connect the output Pin1(RX) to Pin13(TX) of Micro:bit and Pin2(TX) to Pin16(RX) of Micro:bit.

Block Introduction

MUvision

Initialization

(1)Serial Mode:In serial mode, two pins are defined as TX & RX respectively, according to the hardware connection to the MU Vision Sensor,P12 and P13 as example。

_images/Makecode_block_serial_init.png

(2)I2C Mode

_images/Makecode_block_i2c_init.png

Enable Vision Algorithms

Seven recognition algorithms are integrated in current firmware(Version A).For detailed information please refer to the datasheet of MU vision sensor.

_images/Makecode_block_enable_algorithm.png

Set Performance Level

Algorithm performance differs in accuarcy and speed. Performance settings can be changed to fit in certain applications.

Default setting: Balance level.

_images/Makecode_block_algorithm_performance.png

Enable/Disable the High FPS Mode

The camera is in high FPS mode by default,which has a higher speed than normal mode.High FPS mode can be turned off to save power.

_images/Makecode_block_highFPS.png

Set White Balance Mode

Ambient light will influence the detect result of the vision sensor, especially color detection and recognition. In complex light environment or in color recongnition mode, it is recommended to lock white balance.

Reset the vision sensor, and put it in front of a white paper to measure brightness. A few seconds later, white balance will be locked.

_images/Makecode_block_setWB.png

Set Digital Zoom Level

Larger digital zoom level means longer detectable distance, and view sight is narrower meanwhile.

To get a better detect results, set a proper zoom level for the algorithm and test it.

_images/Makecode_block_setzoom.png

On-board LED Settings

Two on-board LED lights can be programmed to shine different colors when The sensor has detected an object or not.

Default setting: When undetected objects , two lights are red and when detected they are blue.

_images/Makecode_block_setLED.png

Restore Default Settings

_images/Makecode_block_setdefault.png

Enable light sensor functions

If light sensor enabled, gesture function can not be used with other functions in the mean time.

_images/Makecode_block_ls_begin.png

Set Light Sensor Sensitivity

_images/Makecode_block_ls_set_sensitivity.png

Light sensor read proximity value

_images/Makecode_block_ls_read_proximity.png

Light sensor read brightness value

_images/Makecode_block_ls_read_als.png

Light sensor read gesture value

_images/Makecode_block_ls_gesture_status.png

Light sensor get gesture result

_images/Makecode_block_ls_gesture_value.png

MUvisionAT

WiFi Configure Module can only be used in WiFi and image transmission modes.

Read local IP

Read IP of MU.

_images/Makecode_block_wifi_read_sip.png

Read target IP

Read IP of target device.

_images/Makecode_block_wifi_read_cip.png

WiFi Configuration

Configure WiFi account, password and mode.

_images/Makecode_block_wifi_set.png

Configure target IP through WiFi

Only working when successfully connected to WiFi.

_images/Makecode_block_wifi_udp.png

WiFi read transmission data

Read data from target device through WiFi.

_images/Makecode_block_wifi_read.png

Get Result Examples

Ball/Body Detection

Setup program: Init I2C connection, and set algorithm to ball detect. Other settings are default.

Loop program: If MU detected a ball, it will send data to Micro:bit through I2C interface. And PC get the data from Micro:bit through USB serial port.The data contains position and size of the ball.

Actual result: After resetting MU and Micro:bit, LED lights flash red. When MU detected a ball, LED lights flash blue and Makecode console will display the data.

_images/Makecode_example_ball_detect.png

Card Detection

Setup program: Init I2C connection, and set algorithm to traffic card. Other settings are default.

Loop program: If MU detected traffic card, it will send data to Micro:bit through I2C interface. And PC get the data from Micro:bit through USB serial port.The data contains position, size and type of the traffic card.

Actual result: After resetting MU and Micro:bit, LED lights flash red light. When MU detected a traffic card, LED lights flash blue and Makecode console will display the data.

_images/Makecode_example_card_detect.png

Color Recognition

Setup program: Init I2C connection, and set algorithm to color recognition. Lock the white balance to get a higher accuracy.Other settings are default.

Loop program: If MU detected color at (50,50), it will send data to Micro:bit through I2C interface. And PC get the data from Micro:bit through USB serial port.The data contains RGB channel and type of the color.

Actual result: After resetting MU and Micro:bit, LED lights are off. Makecode console will display the data.

_images/Makecode_example_color_recognition.png

Color Block Detection

Setup program: Init I2C connection, and set algorithm to color block. Lock the white balance to get a higher accuracy. Other settings are default.

Loop program: If MU detected a color block, it will send data to Micro:bit through I2C interface. And PC get the data from Micro:bit through USB serial port.The data contains position, size and type of the color block.

Actual result: After resetting MU and Micro:bit, LED lights flash red light. When MU detected a color block, LED lights flash blue and Makecode console will display the data.

_images/Makecode_example_color_block.png

Serial Mode Example

Change the output protocol switch to serial mode and connect MU to Micro:bit through serial port.In this mode PC cannot communicate with Micro:bit, so the led dot screen of the Micro:bit is used to display the data directly.

Setup program: redirect the serial port to P14 and P13, and select ‘Number Card’algorithm. Other settings are default.

Loop program: If MU detects one number card, it will send data to Micro:bit through serial interface. The Micro:bit LED screen shows the number.

Actual result: After resetting MU and Micro:bit, LED lights flash red light. When MU detected a number 1 card, LED lights flash blue and Micro:bit screen shows 1.

_images/Makecode_example_serial.png

MU 3 MicroPython Programming Guide

This passage introduces how to use MU Vision Sensor 3 with Micro:bit board and MicroPython language.

Preparations before Coding

If you want to use Micro:bit to control the MU Vision Sensor, you need to import the MicroPython firmware that contains the ‘MuVisionSensor’ module. Please follow the steps below:

(1) Download the firmware:

GitHub: https://github.com/mu-opensource/MuVisionSensor3-MicroPython

Official Website: http://mai.morpx.com/page.php?a=sensor-support

(2) Flash the firmware:

Connect the micro:bit to computer via USB cable,and drag the downloaded frimware “microbit-micropython-MuVisionSensor-0.8.0.hex” to MICROBIT disk. Micro:bit will flash the new firmware and restart.

(3) Download and install Mu Editor:

Mu Editor is a simple Python code editor for beginner programmers with friendly GUI.

It can be downloaded in the main page: https://codewith.mu/

(4) Import module

Open Mu Editor, change the mode to BBC micro:bit,and click the”REPL”button to enter serial reply mode.The micro:bit will send firmware version at first. Type the code below and press enter to run

>>> from MuVisionSensor import *

Now you can call all the public APIs in ‘MuVisionSensor’

Key words auto-completion fuction is only available in REPL mode.

_images/MicroPython_imported.png

Connect to Micro:bit

MU Vision Sensor 3 periphrals and ports:

_images/MUVS3_pinout2.png

I2C Mode

(1)Output Mode DIP Switch: set switch 1 downwards and switch 2 upwards

(2)Connect the output Pin1(SDA) to the Pin20 of Micro:bit, and Pin2(SCL) to Pin19 of Micro:bit. Also connecting the ground pin and 3.3v power pin to micro:bit.

(3)Change the I2C address of MU Vision Sensor by resetting Address DIP Switch. In default both switches are downward and the address is 0x60. (Changing this setting is not recommended)

Only I2C mode is supported now.

You may need a shield to connect MU to Micro:bit, as is shown below:

_images/MUVS3_microbit_connect1.png

Usage of APIs

Initialize MU Vision Sensor

Two steps to initialize this sensor:

Step1. Call the ‘MuVisionSensor(‘address’)’ to create an object , the value of ’address’ should be consistent with the setting of Address DIP Switch (default is 0x60);

Step2. Call the ‘begin()’ function to start this sensor;

Enable Algorithms

API

MuVisionSensor.VisionBegin(vision_type)

All available ‘vision_type’s as follows:

VISION_COLOR_DETECT

VISION_COLOR_RECOGNITION

VISION_BALL_DETECT

VISION_BODY_DETECT

VISION_SHAPE_CARD_DETECT

VISION_TRAFFIC_CARD_DETECT

VISION_NUM_CARD_DETECT

VISION_ALL

Example

from MuVisionSensor import *  #import the library
.... #
mu.VisionBegin(VISION_COLOR_DETECT)  #
mu.VisionBegin(VISION_SHAPE_CARD_DETECT | VISION_BALL_DETECT) #enable card detect and ball detect algorithms

Set Performance Level

API

MuVisionSensor.VisionSetLevel(vision_type, level)

‘level’ can be set to:

LevelDefault

LevelSpeed

LevelBalance

LevelAccuracy

Example

mu.VisionSetLevel(VISION_BALL_DETECT, LevelSpeed)
Get Performance Level

API

mu.VisionSetLevel(vision_type)

The return value is between 0~3, which represents the 4 levels

Enable High FPS Mode

API

MuVisionSensor.CameraSetFPS(mode)

‘mode’ can be set to:

FPSNormal

FPSHigh

Get FPS Mode

API

MuVisionSensor.CameraGetFPS()

return ‘0’(FPSNormal) or ‘1’(FPSHigh)

Set White Balance Mode

Adjust the color cast caused by the changes of external light sources.

API

MuVisionSensor.CameraSetAwb(mode)

‘mode’ can be set to:

AutoWhiteBalance

LockWhiteBalance

WhiteLight

YellowLight

Get White Balance mode

API

MuVisionSensor.CameraGetAwb()

The return value is between 0~3,which represents the 4 WB modes.

Set Digital Zoom Ratio

API:

MuVisionSensor.CameraSetZoom(mode)

‘mode’ can be set to:

ZoomDefault

Zoom1

Zoom2

Zoom3

Zoom4

Zoom5

Get Digital Zoom Ratio Setting

API

MuVisionSensor.CameraGetZoom()

The return value is between 0~5, which represents the 6 zoom levels.

LED Settings

API

MuVisionSensor.LedSetColor(led, detected_color, undetected_color, level)

Explanations of these parameters:

led: the LED you want to configure, the available values

Led1

Led2

detected_color: colors which are detected, the available values as follows

LedClose

LedRed

LedGreen

LedYellow

LedBlue

LedPurple

LedCyan

LedWhite

undetected_color: colors which are not detected, same available values as detected_color.

level: set the brightness level; an integer between 0 and 15; the larger the brighter.

Restore Default Settings

API

MuVisionSensor.SensorSetDefault()

Restart

API

MuVisionSensor.SensorSetRestart()

Get Results of Detection

API

MuVisionSensor.GetValue(vision_type, object_inf)

The available values of ‘vision_type’ are as mentioned above.

object_inf can be set to:

Status 0 means undetected, 1 means detected

XValue

YValue

WidthValue

HeightValue

Label

RValue

GValue

BValue

MU Vision Sensor Resource

Technical Information

Thanks for purchasing MU Vision Sensor 3, and we would like to provide continuous updating service, please check to our website: www.morpx.com regularly. Updates are subject to change without notice. You can get the latest technical information from the following websites:

Product Support: http://mai.morpx.com/page.php?a=sensor-support

GitHub: https://github.com/mu-opensource/

3D Printing Bracket

For customers bought bare MU board, we provide 3D printing cover and foldable bracket.It can be fixed anywhere and can be adjusted to any angle. Please print by yourself if you have a 3D printer.

MU3 3D Printing Bracket

_images/bracket_foldable_MU.png

MU Vision Sensor Application

Auto Cannon

Introduction

This project is an auto shoot cannon based on direnjie kit and MoonBot structure parts. MU vision sensor 3 is fixed on top of the cannon that can recognize the coordinates of the target. So that the controller can control the servos and water gun to aim and shoot the target until clear.

Contents

  • A water gun

  • Servo gimbal

  • MU vision sensor 3

  • Handbit controller

  • Lipo battery + 18650 Power Li battery

  • Target with MU number cards

_images/MUVS3_Auto_Shoot.png

This is the auto cannon. The hardware is from direnjie kit and structure is from MoonBot Kit. Other bracket parts can be 3d printed. Number cards are sticked to the original electric target so that the target can be recognized by MU.

Program Example

  • Initial Settings

Firstly the peripherals should be set, including servos and MU.

_images/Mixly_Auto_Shoot_1.png

  • Search Function

Move servos in horizontal direction to search card in the vision sight.

_images/Mixly_Auto_Shoot_2.png

  • Aim Function

When MU find a card, the program turns into aim function. Move servos slowly to adjust the position between cannon and card.

_images/Mixly_Auto_Shoot_3.png

  • Shoot Function

Simply control the P7 pin to shoot for 0.5 seconds. Time can be modified to save the bullet.

_images/Mixly_Auto_Shoot_4.png

  • Loop Program

Combine the above functions and make the program repeatly.

_images/Mixly_Auto_Shoot_5.png

  • Remote Control

Cannon can be settled by Blynk app through BLE. Put the loop program to blynk blocks. When touch the button on the phone, auto shoot program can be launched.

_images/Mixly_Auto_Shoot_6.png

War Game

Firstly, servos move to central position. The cannon moves from left to right and scan the target in the mean time. When meeting the number card, program turns into aim function. When verify the target position is within 48 to 52 position, shoot for 2 seconds and return to search function again.

MoonBot Kit Introduction

MoonBot Kit is a STEAM education kit produced by Morpx. The kit contains various hardware modules, sheet metal parts and plastic shells, used to build all kinds of robots. With programming software in telephone and computer, teenagers can make AI robots ,learn STEAM lessons and take steps towards excellent engineers in the future.

_images/MoonBot_Kit_assembled.png _images/MoonBot_Kit_main.png

MoonBot Kit Hardware Instruction

MoonBot Kit contains 9 kinds of hardware modules. Users can programme to control modules through Mixly or Arduino platform, or design interactive program after building certain structures. In instructions below, we provide pinout graphs and sample programs of every single module to help users get started with the kit.

Detailed software instructions at:

MoonBot Kit Mixly Instruction

Download all hardware programs here:

MoonBot Kit hardware examples

Controller Module

Brief Introduction

_images/render_controller.png

Controller Module is the programming core of the robot. The main chip is ATmega1280, which is Arduino compatible. On-board servo, motor and GPIO ports can be used to connect to other devices. And there are on-board keys, LED lights, buzzer and IMU that can be used to fast programme.

Specification

Size: 53 x 53 x 17.6 mm

Processor: ATmega1280

Ports: 4 servos, 2 motors, 9 GPIOs

On-board Resources: keys, LED, buzzer, IMU

Pinout

_images/pinout_controller.png

Usage

LED and Button Example

Button and LED light are basic IO device, and can be used to test other devices.So firstly we introduce these to help test others. The following example shows how to control 2 on-board RGB LED lights with 2 programmable buttons.

Code introduction: Loop detect the status of button A and B. LED1 turns red when button A is pressed, while LED2 turns green when button B is pressed. When both of the buttons are pressed, both LEDs turns blue.By default, both LEDs are off.

_images/Mixly_example_controller_LEDbutton.png

Photo:

_images/photo_LEDbutton.png

Buzzer Example

This code shows the way to programme buzzer on controller.Use two methods to make the buzzer beep.

Code introduction: Set the buzzer BPM(beats per minute) to 120, which means 1 beat is 0.5 second. Buzzer can directly play a tone like high G, or play a certain frequency like 194 Hz. A delay should be added when play the frequency, or it will be skiped immediately. Loop play 5 times and end playing.End the whole code by adding an end block or it will play repeatly.

_images/Mixly_example_controller_buzzer.png

IMU Example

IMU(Inertial Measurement Unit) contains one or more of gyroscope, accelerator and compass. It is usually used to measure the posture of copters and robots. This IMU on contorller contains accelerator, compass and temperature compensation. Use the feedback to know while the robot is falling, droped or shaking.

Code introduction: Initialize the compass and adjust the LEDs of controller at first. Loop judge the 4 directions defined by compass and accelerator and show them on LEDs.

Phenomenon: Reset the controller and draw ∞ in the air to calibrate the compass. The calibration finishs when LEDs shine. Put the controller horizontally and 180° means the right South. yaw it to the left/right and the left/right LED turns on. Pitch up/down and LED turns green/red.

_images/Mixly_example_controller_IMU.png

Vision Module

Brief Introduction

_images/render_MUVS3_2.png

Vision module is a intelligent vision sensor containing AI algorithms.

Vision module can be connected to controller by serial interface, and controlled by pregrammed instructions. It can also be controlled by mobile phone app through wifi.

Specification

Size: 37 x 37 x 15 mm

Processor: ESP32

Camera: OV7725

Sight: 85°

On-board Resources: keys, LED

Communications: UART、wifi

Connector: PH2.0 4P

Pinout

_images/pinout_MUVS3_2.png

Usage

Serial Communication Example

Vision module can be connected to controller module and receive instructions through serial port.

Hardware connection: Connect the vision module to P9 port, as a UART3 serial port device.

Code introduction: In initial part, Serial 3 is opened and default baudrate is set to 115200. Vision mudule is connected to serial3 and ball detect algorithm is enabled. In loop part, Controller LEDs are set same as vison module LEDs. That is, LEDs turn blue when detected ball, and turn red when undetected.

Phenomenon: Press the reset button of vision module, wait it to be in receiving status when LEDs turn on. Then reset the controller,and it will send instructions to vision module. Then the vision module is in ball detect mode, and LEDs flash red.The controller will get the data from vision module and show red too. When detect a ball, all LEDs turn blue.

_images/Mixly_example_MUVS3_balldetect.png

Photo:

_images/photo_MUVS3.png

Pay attention that the vison module is a little different from MU 3. Due to wifi function, vision module can only be connected to controller through serial port, and be developed by Arduino IDE or Mixly.The initial code is shown above.

In order to show the connect and initial progress, this program is easy. Learn more blocks and examples at

MU 3 Mixly Programming Guide

Connect to App through Wifi

Vision mudule contains wifi unit, so it can be connected directly to MU Bot App. Programme or remote control it, please check

MoonBot Kit MU Bot App Tutorial

Battery Module

Brief Introduction

_images/render_battery.png

Battery module is used to power controller module, driving actuators and sensors.

It contains battery voltage converter, electricity management, overload protect and rechagre unit. It can be charged directly by USB port(Not for communication).

Specification

Size: 67.6 x 56 x 33.7 mm

Battery Type: Polymer lithium battery

Output Power: 5V 2.8A max

Charging Power: 5V 1A max

Charging Period: 3.5h

Charging Port: USB type-C

Pinout

_images/pinout_battery.png

Usage

  • Short press power button to turn on battery and long press 3 seconds to turn off. Automaticly turn off when unconnected for 30 seconds.

  • Orange light on the top is charge indicator,while white light is power indicator and red light indicates USB connected.4 blue lights indicates remaining capacity.

  • Battery module power the controller module through PH2.0 5P wire. It can drive high-power actuators like servos and motors.The max output power is 5V 2.8A.

  • Battery module can be charged through USB-C port(Not for communication), with 1A max charge current. Whole charge time is about 3.5 hours.It is recommended to use standard charger, while computer USB port can usually provide only 0.6A.

Attention

  • Battery module can only be connected to controller module.Do not modify and disassemble it.

  • Battery module contains circuit protect unit to prevent overloading.Manually control the output power can maintain a longer battery lifetime.

  • LiPo battery is a Flammable and explosive product, so protect it from pressure, falling, water, heat and metal parts.

  • Control the remaining power to 50% for long time storage. Prevent touching the button to open it.

Motor Module

Brief Introduction

_images/render_motor.png

Motor module contains a gear motor and an encoder inside.The active wheel is connected to gear motor, while the passive wheel is connected with screw and bearings.

The wheels are attached to track, and two whole motor modules are enough to build a Chassis.

Specification

Size: 109 x 40 x 39.1 mm

Reducer: 120:1

Unloaded Speed: 100rpm

Unloaded Current: 150rpm

Rated Speed: 70rpm

Rated Current: 300mA

Encoder: photoelectric encoder

Connector: PH2.0 2P + PH2.0 4P

Pinout

_images/pinout_motor.png

Usage

Chassis Control

Under structures as MoonRover, MoonBot and MoonMech, chassis can be controlled to go forward , go back and turn around. Run the following program to test it.

Hardware connection: Connect the motors and encoders to the controller. Motor port M1 corresponds to encoder port P4, and M2 corresponds to P6. Motor module is a high-power device and controller should be connected to battery to drive motor. The controller can be connected to battery and USB at the same time and uses battery as power source.

Code introduction: In setup part, the direction of chassis is set, bias of direction, distance and turning radius is corrected. In loop part, Chassis goes forward, back, turns left and right.Conrtol the distance and angle by setting motor speed. End the program at last.

_images/Mixly_example_motor_tankbase.png

Photo:

_images/photo_motor.png

Single Motor Control

Except for controlling the whole chassis, motor 1 or 2 can be directly controlled.

Hardware connection: Same as above.

Code introduction: In initialize code, serial port is opened to send encoder data. Write value and control motor voltage through PWM for 2 seconds. Then write motor speed with encoder feedback for 2 seconds. And the controller send encoder data through serial port.Write 0 to stop the motor.

_images/Mixly_example_motor_single.png

Servo Module

Brief Introduction

_images/render_servo.png

Servo is an angle-control actuator based on PWM signal.It contains DC motor, reducer,feedback circuit and current control circuit.

Specification

Size: 54 x 20 x 47.2 mm

Servo Type: 55g metal-gear servo

Torque: 9.4kg.cm

Rated Current: 250mA

Blocked Circuit: 1A

Connector: PH2.0 3P

Usage

Servo Calibration

Servo can rotate from 0 to 180 degree. Degree increases clockwise and decreases CCW. Initial degree is 90 degree, with a red mark pointing forward.

Servo is an angle-control device and it uses potentiometer to get the degree. Servo initial degree may has a devistion due to precision of the potentiometer,usually smaller than 10 degrees. Just programme to calibrate the servo.

Code introduction: In initial part,Servo is initialize to 90 degree.Check the actual degree and change the correct value to set the servo to right angle.

Pay attention that this value is the correct value of servo rather than port S1. If the servo changes port, and programme should be changed too.

_images/Mixly_example_servo_calibrate.png

Servo Rotation

There are two ways to rotate servo.One for setting degree and time, and the other for setting degree and speed and moving together. The first way is often used for single servo rotation, and the second is for multiple servos.

Code introduction: In initial part, servo is calibrated and direction is set. In loop part, control degree and time to move servo for 30 degrees, and then move servos fastly to 150 degree.

_images/Mixly_example_servo_move.png

Photo:

_images/photo_servo.png

Speaker Module

Brief Introduction

_images/render_speaker.png

Speaker module is a mp3 player controlled by serial intruction. Put sound files to in and control it with controller module.

Specification

Size: 48 x 48 x 11.6 mm

Charging Power: 1W

Supported File: mp3

Memory Space: 16MB

Pinout

_images/pinout_speaker.png

Usage

Code Introduction:Let the speaker play music, and use the controller button to pause or play.

Connect the speaker to P2 of controller, set play mode to random play and define speaker volume. Detect the state of button A. If it is pressed, play or pause.

_images/Mixly_example_speaker.png

Photo:

_images/photo_speaker.png

Eyes Module

Brief Introduction

_images/render_eyes.png

Eyes module contains 12 serial RGB LED lights.

Specification

Size: 64 x 32 x 12 mm

LED Type: serial LED

LED number: 12

Color: 16 million colors

Pinout

_images/pinout_eyes.png

Usage

Multiple Control

Code introduction: Connect the eyes module to P1 of main controller and define brightness of eyes. Let 12 LEDs show appointed color for 5 seconds, show happy for 5 seconds, and turn off.

_images/Mixly_example_eyes.png

Photo:

_images/photo_eyes.png

Single Control

Code introduction: Set LEDs one by one and control the RGB value of every light for 1 second.

_images/Mixly_example_eyes_single.png

Touch Module

Brief Introduction

_images/render_touch.png

Touch module is a single touch button.

Specification

Size: 34 x 32 x 9.6 mm

Touch Type: Non-self-locking single touch

Touch Area Size: diameter 14mm

Pinout

_images/pinout_touch.png

Usage

Code introduction: Connect the touch module to P1 of controller.Detect the mudule state. Controller LED turn red when touch module is touched, otherwise turn off.

_images/Mixly_example_touch.png

Photo:

_images/photo_touch.png

Infrared Module

Brief Introduction

_images/render_infrared.png

Infrared module has 2 infrared switch inside, used to detect certain obstacle.

It has short and long modes, which can be used in following line or aoviding obstacle.

Specification

Size: 34 x 32 x 12 mm

Infrared Type: 2 reflective switchs

Detect Distance:

short mode 10mm

long mode 110mm

Pinout

_images/pinout_infrared.png

Usage

Code introduction: Connect the infrared module to P3 of controller module and detect 2 switchs state.

When both switchs detect the obstacle, 2 LEDS of controller turn red. When only one switch detect, turn on 1 LED instead.

_images/Mixly_example_infrared.png

Photo:

_images/photo_infrared.png

MoonBot Kit Structure Instruction

MoonBot Kit contains 3 official structures, including MoonRover, MoonMech and MoonBot. Every structure has unique functions, and all parts are packaged in the standard and educational version.

Programme through Mixly, Arduino and MU Bot App, or directly remote control, or even express creative ideas and design your own robot.

MoonRover Instruction

Introduction

MoonRover is made of sheet metal body and hardware modules.It is drived by track chasis. The controller module is fixed on top of it, and connected to other devices with wires. Infrared module and vision module can be fixed on front or bottom of the body, and battery is fixed backwards.

MoonRover can be used to learn applications like avoiding obstacles, following line, auto driving and so on.

_images/render_MoonRover.png

Specification

Size: 177 x 157 x 87 mm

Functions

Motion: head, chassis

Sense: vision, infrared, encoder

Build Manual

Download pdf manuals of MoonRover

MoonRover get started guide

MoonRover extended manual

Or watch video guide on youtube

MoonRover video guide

Program Examples

Download MoonBot Mixly examples

MoonRover Examples

Avoid Obstacles

MoonRover becomes a obstacle avoiding car when 2 infrared modules are fixed in front.

Hardware connection: Build the MoonRover with the manual. Infrared sensor on the left is connected to P3 of the controller, and the other is connected to P7. Both sensors should be set to long distance mode.

Code introduction: In initial part, Two infrared sensors are set to the ports, and chassis is calibrated. In loop part, there are three status.When the left/right sensor detect obstacles, the chassis turn right/left.Go forward by default.

_images/Mixly_MoonRover_avoidObstacle.png

Auto Drive

MoonRover becomes a auto driving car when using vision module to navigate.

Hardware connection: Build the MoonRover with the manual.The vision module is connected to P9 of the controller.

Code introduction: In initial part, vision module is connected to serial 3(P9 port), algorithm is set to traffic card and chassis is calibrated. In loop part, vision module detect traffic card.5 traffic card refer to 5 status, and MoonRover will move as the card shows.

Phenomenon: After downloading the program, turn on battery. Vision module will shine red after setup. Put a Forward card in front of MoonRover for about 20 centimeters and MoonRover will recognize it and go forward. Change card to change its status. Put different cards on the road to let MoonRover auto drive.

_images/Mixly_MoonRover_autoDrive.png

MoonMech Instruction

Introduction

MoonMech is a movable mechanical arm. Its body is made by plastic shell and sheet metal frame. The track chasis is drived by motor module, and mech arm is drived by servos. The claw on top of the arm can catch various objects with vision feedback.

MoonMech can be used to learn competitive applications like transpotation and playing basketball.

_images/render_MoonMech.png

Specification

Size: 271 x 137 x 244 mm

Functions

Motion: mech arm, claw, chassis

Sense: vision, encoder

Build Manual

Download pdf guide of MoonMech

MoonMech build guide

Or watch video guide on youtube

MoonMech video guide

Program Examples

Download MoonMech Mixly examples

MoonMech Examples

Catch Ball

This example shows how to catch ping-pong ball recognized by vision module.

Code introduction: In initial part, vision module and servos are set to their ports. Vision algorithm is set to ball detect, and servos are set to initial position. In loop part, vision module will detect ball and judge the x offet and move the chassis.Then judge the y offset and move servos. Use the ball width to estimate the distance. When the width is above 27, the claw will close and catch the ball.

Phenomenon: Turn on MoonMech and it will open claw and look forward, with vision module LEDs shining red. Put a ping-pong ball in front of the claw, and the LEDs turn blue. Adjust the position of ball until the claw catch it.

_images/Mixly_MoonMech_grab_ball.png

MoonBot Instruction

Introduction

MoonBot is a semi-humanoid robot with abundant sense and interaction. Its body is made by plastic shell and sheet metal frame. The track chasis is drived by motor module.Head and hands are drived by servos. Eyes and speaker can interact with others with touch, vision and position feedback.

MoonBot can be used to learn service robot applications like reception and patrol.

_images/render_MoonBot.png

Specification

Size: 150 x 137 x 216 mm

Functions

Motion: head, hands, chassis

Interaction: eyes, speaker

Sense: vision, touch, encoder

Build Manual

Download pdf guide of MoonBot

MoonBot build guide

Or watch video guide on youtube

MoonBot video guide

Program Examples

Download MoonBot Mixly examples

MoonBot Examples

Shake Body

MoonBot has servos in head and hands, and motors in chassis.Just program to make MoonBot dance.

Code introduction: In initial part, servos are set to head and hands.In loop part, use robot blocks to make MoonBot to move chassis and lands slowly.

_images/Mixly_MoonBot_shake.png

Follow people

MoonBot can use vision module to recognize people, and always face people with chassis and head.

Code introduction: In initial part, servos are connected to ports and are adjusted direction according to actual position. Vision module is connected to seiral 3(P9), and the algorithm is set to human body. In loop part, when detect human body, MoonBot will move chassis according to x offset of human body, and move head according to y position.

Phenomenon: After downloading the program, put MoonBot on desk and stand in front of it. MoonBot will detect upper body and vision module shines blue when detected. Walk around and MoonBot will rotate to keep the face in front of you al the time.

_images/Mixly_MoonBot_followBody.png

MoonBot Kit MU Bot App Tutorial

This article introduces how to connect MoonBot Kit with MU Bot App on mobile phone or tablet.

MoonBot Kit APP Firmware Upgrade Guide

Programming with MoonBot Kit APP requires burning the specified firmware in the master control.

This article guides users how to upgrade MoonBot Kit master module to burn firmware needed for APP programming.

Preparation

Hardware:

  • MoonBot kit

  • PC (Windows,Linux,Mac OS)

Software:

Upgrade by burning HEX files

Upgrade Arduino source code by compiling Arduino IDE

  • 1.BuildingMoonBot Kit Arduino development environment

  • 2.DownloadMoonBot Kit Master remote control source code(Source.zip File)

  • 3.Open Arduino IDE,Click Project->Loading Library->Add.ZIP library`,Select the.Zip file downloaded in Step 2.

    _images/Earduino_add_zip_library.png

  • 4.Select the. zip file downloaded in step 2 and click OK to load the source code of MoonBot Kit master remote control

  • 5.Click Arduino File->Example>MoonBotRemote->RemoteWithDemo,Open Source code

    _images/Earduino_add_example_remote_with_demo.png

  • 6.Connet MoonBot Kit Master Control to Computer,Click Arduino Tool->Port,Selectthe corresponding MoonBot port.

  • 7.Click the Download button and wait for the download to complete

Test

  • 1.After restart, press the main control button A, close to the A key LED bright blue light and give a prompt sound.

  • 2.After restart, press the main control button B, close to the B key LED bright green light and give a prompt sound.

APP Remote Control

First select the remote controller, and then chooses the corresponding robot form.

Introduction to Controller Use

_images/MoonBot_App_C.jpg

1.WiFi Connection

Click on the combination of color blocks that match the color of the LED light of the VisionSensor to start the connection.

If the connection fails, press the visual module reset key to re-select the connection.

_images/EMoonBot_App_C1.jpg

_images/EMoonBot_App_C2.jpg

2.Robot form selection

Choose the corresponding form among the three.

3.Setting Function Button

Click on the Setup Function Key, the circle box below the Function Key is dotted.

Click on the dotted circle box to add, delete and replace each function into the circle box. Click on the Setup Function Key to complete the setup.

Setting Function Button.gif

4.Wheel control

When WiFi is connected, the motion of the robot can be controlled by the wheel disk.

5.Functional Button

Click on the set function key to make the robot act accordingly. Some functions can be turned on/off.

MoonBotCar:Visual Angle Up/Down,Tracking Ball,Obstacle Avoidance,Card Identification

_images/EMoonBot_App_C6.jpg

MoonBotMech:Arm up/Down,Visual Angle Up/Down,Open/Close Claw,Catch Ball,Shoot

_images/EMoonBot_App_C7.jpg

MoonBot:Left Arm Up/Down,Right Arm Up/Down,Head Angel Up/Down,Dancer1/2,Be cute

_images/EMoonBot_App_C8.jpg

6.LED Button and Sound Button

There will be lights/sounds when you click on the button.

APP Programing

_images/EMoonBot_App_P0.jpg

Introduction to Programming Use

1.WiFi Conncet

Click on the combination of color blocks that match the color of the LED light of the VisionSensor to start the connection.

If the connection fails, press the visual module reset key to re-select the connection.

_images/EMoonBot_App_C1.jpg

_images/EMoonBot_App_C2.jpg

2.Exit Button

3.The button to be updated

4.Help Button

Click on the button and there will be instructions for each button.

5.Share Button

Click to share the program with friends / QQ / Wechat / Wechat Friends Circle

6.Project Preservation Button

The program can be named and saved to my project.

7.My Program

Select your own saved project to open

8.Program Block

Contains various programming blocks

9.Play Button

Execute transmission

Example

Program.gif

APP Programming Block_Artificial intelligence

Artificial intelligence

_images/EMoonBot_APP_AI.jpg

Algorithm enable/Disable

_images/EMoonBot_APP_AI0.jpg

Algorithm: ball,body, shape card, traffic card, number card, color block detection, color recognition

Parameter: enable/Disable

Instructions

Ball Algorithm: Identify orange ping-pong (Label:1) and green tennis (Label:2)

Body Algorithm: Detection of upper body characteristics

Shape/Trafiic/Number Card: Identify specific cards

Color block detection: Setting a color and detecting its block area

Color recognition: Specify an area to detect its color

One or more algorithms can be open at the same time

_images/EMoonBot_APP_AI0_0.png _images/EMoonBot_APP_AI0_1.png

Setting Block Detection Colors

_images/EMoonBot_APP_AI1.jpg

Color: Black, white, red, yellow, green, cyan, blue, purple

Instructions

The color block detection algorithm detects red by default. It can change the color of detection by using this function block.

MoonBot/MoonBot_App/./images/EMoonBot_APP_AI1_0.png

Reading algorithm to detect parameters

_images/EMoonBot_APP_AI2.jpg

Algorithm: ball,body, shape card, traffic card, number card, color block detection, color recognition

Setting parameters: is detected, X , Y , width, height, label

Is detected:True when detected and False when not detected

X coordinate, Y , width, height:Quantify to (0-100)

Classification number:Label

MoonBot/MoonBot_App/./images/EMoonBot_APP_AI2_0.png

Seeing algorithm block

_images/EMoonBot_APP_AI3.jpg

Algorithm: ball,body, shape card, traffic card, number card, color block detection, color recognition

MoonBot/MoonBot_App/./images/EMoonBot_APP_AI3_0.png

Algorithm azimuth position block

_images/EMoonBot_APP_AI4.jpg

Algorithm: ball,body, shape card, traffic card, number card, color block detection

Setting parameters:center, up, down, left, right

MoonBot/MoonBot_App/./images/EMoonBot_APP_AI4_0.png

Algorithm size block

_images/EMoonBot_APP_AI5.jpg

Algorithm: ball,body, shape card, traffic card, number card, color block detection

Setting parameters: big, normal, small

Algorithmic area location block

_images/EMoonBot_APP_AI6.jpg

Algorithm: ball,body, shape card, traffic card, number card, color block detection

x:1/2/3/4/5

y:1/2/3/4/5

Shape card block

_images/EMoonBot_APP_AI7.jpg

Parameters: check, closs, circle, square, triangle

Trafiic card block

_images/EMoonBot_APP_AI8.jpg

Parameters: forward, left, right, turn around, park.

Number card block

_images/EMoonBot_APP_AI9.jpg

Parameters:0~9

Ball Recognition block

_images/EMoonBot_APP_AI11.jpg

Parameters: ping-pong (orange), tennis (green)

Color recognition block

_images/EMoonBot_APP_AI10.jpg

Parameters: black, white, red, yellow, green, cyan, blue, purple

Detection of gestures block

_images/EMoonBot_APP_AI12.jpg

Parameters: Up, Down, Left, Right, Any

Something Approaching to MU block

_images/EMoonBot_APP_AI13.jpg

Parameters: aany, far, middle, near.

Ambient luminance block

_images/EMoonBot_APP_AI17.jpg

Parameters: darkest, dark, good, bright, brightest

Set camera zoom block

_images/EMoonBot_APP_AI14.jpg

Parameters:1/2/3/4/5

Instructions

If the Zoom value is small, the field of vision is wide and the distance is close.

If the Zoom value is large, the field of vision is narrow and the distance is long.

White balance mode block

_images/EMoonBot_APP_AI15.jpg

Parameters: auto, lock, white light , yellow light .

Instructions

Automatic mode: suitable for use in environments with good lighting and low color requirements

Lock-in mode: suitable for the environment with high color requirement, let MU calibrate the white balance on the white paper,

then lock the white balance parameters, the color will not change with the change of the environment after lock-in.

White light mode: suitable for white light or overcast environment, this mode also belongs to automatic white balance mode;

Yellow light mode: suitable for use in yellow light or sunshine environment, this mode also belongs to automatic white balance mode.

Lighting settings for MU detection

_images/EMoonBot_APP_AI16.jpg

LED lamp color detected: close, blue, green, cyan, red, purple, yellow, white, random

LED lamp color undetected: ibid.

Lighting brightness: 1-10, the greater the value, the brighter

APP Programming Block_Input

Input

_images/EMoonBot_APP_Input.jpg

Read button pressed status

_images/EMoonBot_APP_Input0.jpg

Parameter:A,B,A+B

Return: button pressed / not pressed

Initialization of Touch Sensor Port

_images/EMoonBot_APP_Input1.jpg

Parameter:Port3,Port5,Port7,Port8

Initialize the infrared sensor port and read infrared sensors

_images/EMoonBot_APP_Input2.jpg

Port Parameter:Port3,Port5,Port7,Port8

infrared sensor IR1:IR2 Parameter:0:0,0:1,1:0,1:1

0 means undetected , 1 means detected

Read the compass toward(0~360°)

_images/EMoonBot_APP_Input3.jpg

Return: The compass faces the angle

Read acceleration value(1024/g)

_images/EMoonBot_APP_Input4.jpg

Parameter:X direction, y direction, Z direction, strength value

Return: Acceleration value

Reading rotation angle(°)

_images/EMoonBot_APP_Input5.jpg

Parameters: pitch (x), roll (y), read the main control tilt angle

Return: Angle value(-180°~+180°)

Read thermometer values

_images/EMoonBot_APP_Input6.jpg

Return: Temperature value

Read IMU actions

_images/EMoonBot_APP_Input7.jpg

Parameters: vibration, free falling, X-axis up, X-axis down, Y-axis up, Y-axis down, Z-axis up, Z-axis down, 3g, 6g, 8g

Calibration compass

_images/EMoonBot_APP_Input8.jpg

Compass calibration module, the main control in calibration needs to be flipped in the shape of ”∞“

APP Programming Block_Light

Light

_images/EMoonBot_APP_Light.jpg

Eye light setting block

_images/EMoonBot_APP_Light0.jpg

Eye parameters: all, left and right eyes

Color parameters: close, blue, green, cyan, red, purple, yellow, white, random

Luminance parameters: 1-10, the greater the value, the brighter

Expression block

_images/EMoonBot_APP_Light1.jpg

Parameters: happy, sad, angry, blink, turning, flashing, rainbow, closed eyes

Return: Show expression

Eye preset RGB value of each LED lamp

_images/EMoonBot_APP_Light2.jpg

LED light:1-12 and all lights

Red:0~255

Green:0~255

Blue:0~255

Show eye preset

_images/EMoonBot_APP_Light3.jpg

Main control LED lamp setting block

_images/EMoonBot_APP_Light4.jpg

Main LED parameters: all, 1, 2

Color parameters: close, blue, green, cyan, red, purple, yellow, white, random

Luminance parameters: 1-10, the greater the value, the brighter

MU LED light setting block

_images/EMoonBot_APP_Light5.jpg

MU LED lamp parameters: all, 1, 2

Color parameters: close, blue, green, cyan, red, purple, yellow, white, random

Luminance parameters: 1-10, the greater the value, the brighter

APP Programming Block_music

Music

_images/EMoonBot_APP_Music.jpg

Speaker Plays Sound block

_images/EMoonBot_APP_Music0.jpg

Play the specified sound:Animal Voice, Greetings, Piano, City, Drum, Custom Voice

Volume Selection Block

_images/EMoonBot_APP_Music1.jpg

Parameters: 0-10, the larger the value, the larger the volume.

Play mode block

_images/EMoonBot_APP_Music2.jpg

Parameters: single play, single loop

Speaker stop block

_images/EMoonBot_APP_Music3.jpg

Stop playing sound

Buzzer play block

_images/EMoonBot_APP_Music4.jpg

Buzzer to play scales in a set beat

Scales: aerial, do1-si7, Do1-Si7

Rhythm: 1/8-4 beats

Buzzer play sound block

_images/EMoonBot_APP_Music5.jpg

Play the specified sound

Parameters: key tone 1-4, alarm 1-2, sound effect 1-4, ambulance sound, siren sound

APP Programming Block_motion

motion

_images/EMoonBot_APP_Moving.jpg

Setting steering angle block

_images/EMoonBot_APP_Moving0.jpg

Steering port:steering1~steering4

Angle:0~180°

Read steering angle block

_images/EMoonBot_APP_Moving1.jpg

Read the specified steering angle

Parameters: steering gear 1-4

Forward

_images/EMoonBot_APP_Moving2.jpg

Distance set to advance at specified gear speed

Execution distance:0~999cm

Speed parameters: very fast, fast, medium, slow, very slow

Back off

_images/EMoonBot_APP_Moving3.jpg

Back-set distance at specified gear speed

Execution distance:0~999cm

Speed parameters: very fast, fast, medium, slow, very slow

Turn Left

_images/EMoonBot_APP_Moving4.jpg

Turn left at the specified gear speed and set the angle

Execution angle:0~999°

Speed parameters: very fast, fast, medium, slow, very slow

Turn right

_images/EMoonBot_APP_Moving5.jpg

Turn right at the specified gear speed and set the angle

Execution angle:0~999°

Speed parameters: very fast, fast, medium, slow, very slow

Stop Motion block

_images/EMoonBot_APP_Moving6.jpg

Writing speed of Motor block

_images/EMoonBot_APP_Moving7.jpg

Write a certain speed to the motor(-100~+100R/min)

Parameters: Motor 1, Motor 2

Read motor speed block

_images/EMoonBot_APP_Moving8.jpg

Parameters: Motor 1, Motor 2

Calibration of alignment migration block

_images/EMoonBot_APP_Moving9.jpg

Calibrate the alignment migration so that it does not migrate in a certain direction.

Parameters: 0-200, > 100 to the right and < 100 to the left

Calibration of alignment distance block

_images/EMoonBot_APP_Moving10.jpg

Calibrating the inaccuracy of the direct distance caused by external interference

Parameters: > 100 Increase Distance, < 100 Reduce Distance

Calibration of rotate angle block

_images/EMoonBot_APP_Moving11.jpg

Incomplete turning angle caused by calibration external interference

Parameters: > 100 Increase turning angle, < 100 Reduce turning angle

Calibration of steering angle block

_images/EMoonBot_APP_Moving12.jpg

Calibration of angle error in production and installation by rudder calibration module

Parameters: steering gear 1-4

Increase/decrease(-90~+90°)

APP Program Example

Touch Wave

MoonBot has steering engine in its hand and touch sensor in its head. Touch beckoning can be realized by programming.

Explain:Cyclic detection of touch sensor status, when the left side of the head is touched, the robot beckons the left hand.

When the right side of the head is touched, the robot waves its right hand.

_images/EMoonBot_APP_Touch.png

Simple Algorithm

MoonBot uses VisionSensor and LED Module.

Explain:Cyclic detection of the ball algorithm, when the ball is detected, the eyes turn around the expression, when not detected closed eyes.

_images/EMoonBot_APP_Ball.png

Examples of functional modules

MoonBot robot uses button speaker, LED lamp, actuator lamp and mathematic module.

Explain:Cyclic detection of buttonA/B status. The MoonBot robot makes sound and light arm movements when the button is pressed.

_images/EMoonBot_APP_AnJian.png

Search sb.

MoonBot Using VisionSensor and Motion Modules

Explain: Turn on Body Detection Algorithms,When the body is not detected, the VisionSensor LED flashes red light,

When the body is detected, the VisionSensor LED flashes blue light.

When the body is detected in the center, the robot stops moving, otherwise it turns left/right.

_images/EMoonBot_APP_Body.png

Barrier Avoidance Intelligent Vehicle

Install infrared sensors on left and right sides of intelligent vehicle car

Explain: Calibration chassis,Turn left when the right infrared sensor of the smart car detects obstacles,

turn right when the left infrared sensor detects obstacles, and go straight when none of them is detected.

_images/EMoonBot_APP_Car0.png

Traffic Intelligent Vehicle

Intelligent Vehicle Cooperative Traffic Card Algorithms

Explain: Calibration chassis,turn on the traffic card algorithm, set the camera zoom level

and set the white balance parameters according to the lights.

When traffic card is not detected, the VisionSensor LED flashes red light and blue light when the traffic card is detected.

_images/EMoonBot_APP_Car1.png _images/EMoonBot_APP_Car2.png

MoonBot Kit Mixly Tutorial

This article introduces MoonBot Kit developing tutorial with Mixly platform.

Visit Mixly official docs for basic tutorials: Mixly wiki

MoonBot Mixly Guidelines for Programming Construction

There are two ways to install MoonBot Mixly. Download the full package and unzip, or install independent library if you already installed Mixly.

Instructions are shown below.

Full Installation Package Download

Windows/Linux/Mac Full Edition MoonBot Mixly Package Download Link: https://drive.google.com/drive/folders/1L_FKMlQnddgi_rLnRiOYbA9o9q24RGEm?usp=sharing

Independent Library Installation

Import and upgrade Mixly-Arduino Library
  • 1.Start Mixly-Arduino

    • Windows

      Open {your_mixly_path}/arduino-1.8.5/arduino.exefile under the Mixly installation path,start Arduino

    • Linux

      Running Arduino files at the terminal,start Arduino

      $ cd {your_mixly_path}
      $ ./arduino-1.8.2-linux64/arduino
      
  • 2.Click on Project - > Load Library - > Manage Library', openLibrary Manager’.`

    _images/Earduino_lib_management_zh1.png

  • 3.Search library AsyncDelay, install the relevant library if not installed and update if the library is not the latest edition

    _images/Earduino_lib_download_zh1.png

  • 4.Install the library Software Wire ``Adafruit_NeoPixelServo’according to the installation method of the third step, ensure that the relevant library is installed to the latest version.

  • 5.Close Arduino,Complete the installation of the base library.

Import Mixly Library
  • 1.Click Download MoonBot/MuVisionSensor3 The latest version of Mixly Library Compression Pack

  • 2.Upzip the downloaded MoonBot/MuVisionSensor3compression package

  • 3.Open the Mixly interface, click the import button,find the files at the end of xmlunder the MoonBot/MuVision Sensor 3 folder path.

  • 4.Library installation completed

API Reference resources

The programming blocks of MoonBot Kit and MUVision Sensor 3 are customized in MoonBot Mixly. This article will explain the program blocks one by one, as well as some complex program examples. It can be combined with previous hardware module examples for learning.

Mixly Basic Tutorial in Mixly Help Document,will not repeat it here.

MU Vision Sensor 3 Course in : MU Vision Sensor 3 Mixly Guide

Input

Input include MoonBot Kit Touch Module Infrared Module Controller Module keys and pin mapping module

_images/1.png
Initialization of Touch Sensor
_images/2.png
Introduction

Initialize the touch sensor to the corresponding port.

Introduction
port
  • 1~9

Reading Touch Sensor
_images/3.png
Introduction

Read the value of the corresponding port of the touch sensor

Parameters
port
  • 1~9

Return
  • HIGH :Object Touch Sensor

  • LOW :Objectless Touch Sensor

Initialization of Infrared Sensors
_images/4.png
Introduction

Initialize touch sensor to corresponding port

Parameters
port
  • 1~9

Reading Infrared Sensor
_images/5.png
Introduction

Read the corresponding pin value of infrared sensor port

Parameters
Port
  • 1~9

Pin
  • 1~2

Return
  • HIGH :Infrared Sensor Triggered

  • LOW : Infrared sensor not triggered

Reading Button
_images/6.png
Introduction

Read button status

Parameters
button
  • A :Button A

  • B :Button B

  • A&B:Button A and B

Return
  • HIGH:The Button is pressed

  • LOW:The Button is not pressed

Port pin mapping
_images/7.png
Introduction

Reading the Arduino pin number corresponding to the MoonBot port

Parameters
Port
  • 1~9

Pin
  • 1~2

Return
  • Corresponding Arduino pin

Chassis Control

Chassis Control include drives MoonBot Kit Motor Module and driving of Encoder in Motor.

By calling these modules, the motor chassis can move.

_images/11.png
Reversal direction
_images/12.png
Introduction

The direction of motion of the flip motor.

Parameters
Reversal direction
  • true :Reversal direction

  • false :Default direction

Straight-line offset correction
_images/13.png
Introduction

Because of friction, installation deviation and other disturbances, the chassis will be offset in a certain direction when it goes straight.

Direct migration caused by external disturbance can be corrected by `direct migration correction `module.

Introduction
Straight-line offset correction(%)
  • 0~200 :>100 Correction to the right,<100 Correction to the left

Straight Distance Correction
_images/14.png
Introduction

Because of friction, installation deviation and other disturbances, chassis traveling a certain distance will have the situation of inadequate direct travel.

Through the `direct distance correction `module, the situation of the out-of-place direct distance caused by external disturbance can be corrected.

Before correcting the straight-line distance, it is suggested that straight-line migration correction’be carried out first.`

Introduction
Straight Distance Correction(%)
  • 0~+∞ :>100 Increased direct distance,<100 Straight distance decreases

Turning Angle Correction
_images/15.png
Introduction

Because of friction, installation deviation and other disturbances, chassis rotating at a certain angle will have the situation that the turning angle is not in place.

Through the `turning angle correction’module, the situation that the turning angle caused by external disturbance is not in place can be corrected.

Before correcting the turning angle, it is suggested that `straight-line offset correction’ and `straight-line distance correction’ should be carried out first.

Introduction
Turning Angle Correction(%)
  • 0~+∞ :>100 Increased turning angle,<100 Reduced turning angle

Forward
_images/16.png
Introduction

Control the chassis to move forward at a given speed until it stops at a given distance.

The module ** calls the encoder module ** to ensure that the corresponding encoder has been connected to the corresponding port

Parameters
Forward Distance(cm)
  • Distance value :Given straight distance,Unit: cm

speed
  • Speed Value :Given Speed of Direct Motor,Unit: RPM

Backward
_images/17.png
Introduction

The control chassis runs backwards at a given speed until it stops at a given distance.

The module ** calls the encoder module ** to ensure that the corresponding encoder has been connected to the corresponding port.

Parameters
Backward distance(cm)
  • Distance value :Given straight distance,Unit: cm

speed
  • Speed Value :Given Speed of Direct Motor,Unit: RPM

Left turn
_images/18.png
Introduction

Control the chassis to turn left at a given speed to a given angle and stop.

The module ** calls the encoder module ** to ensure that the corresponding encoder has been connected to the corresponding port.

Parameters
Left turn angle(°)
  • Angle value :Given a straight angle,Unit: °

speed
  • Speed Value:Given Speed of Direct Motor,Unit: RPM

Right turn
_images/19.png
Introduction

Control the chassis to turn right at a given speed to a given angle and stop.

The module ** calls the encoder module ** to ensure that the corresponding encoder has been connected to the corresponding port.

Parameters
Right turn angle(°)
  • Angle value :Given a straight angle,Unit: °

speed
  • Speed Value :Given Speed of Direct Motor,Unit: RPM

Stop
_images/110.png
Introduction

The chassis stops turning.

Motor write-in value
_images/111.png
Introduction

Write the analog to the motor at the corresponding port.

Parameters
Motor port
  • 1 :Motor port 1

  • 2 :Motor port 2

value
  • ±255 :Write the value of the analog,>0 Turn Forward,<0 Turn back,=0 Stop turning

Reading motor value
_images/112.png
Introduction

Read the analog value of the corresponding motor port.

Parameters
Motor port
  • 1 :Motor port 1

  • 2 :Motor port 2

Return
  • value :Value of motor analogue

Writing Speed of Motor
_images/113.png
Introduction

Write the speed to the motor at the corresponding port.

The module ** calls the encoder module ** to ensure that the corresponding encoder has been connected to the corresponding port.

Parameters
Motor port
  • 1 :Motor port 1

  • 2 :Motor port 2

value
  • ±60 :Write the value of the analog,>0 Turn Forward,<0 Turn back,=0 Stop turning,unit:RPM

Reading motor speed
_images/115.png
Introduction

Read the speed of the corresponding motor port.

Parameters
Motor port
  • 1 :Motor port 1

  • 2 :Motor port 2

Return
  • speed :motor speed ,unit:RPM

Steering engine

Steering engine include MoonBot Kit Servo Module drives,It can be used to drive the steering gear connected to the four rudder ports in MoonBot Kit.So the actuator with one or more ports can move simultaneously.

_images/21.png
Setting Angles
_images/22.png
Introduction

Write the angle to the steering gear connected to the specified steering port.

Parameters
steering gear port
  • 1~4

angel
  • 0~180°

Reading angel
_images/23.png
Introduction

Reads the current angle value of the specified steering port.

Parameters
steering gear port
  • 1~4

Presupposition angle
_images/24.png
Introduction

Preset the steering angle and speed of the specified steering gear port.

The module should be used in conjunction with the `synchronous movement of all steering gear to the preset angle `module.

Parameters
steering gear port
  • 1~4

speed
  • fast :Set the speed of steering gear to be fast(about150°/s)

  • mid :Set the steering gear running at medium speed(about 100°/s)

  • slow :Set the speed of steering gear to slow(about 50°/s)

Synchronize all steering gear to preset angle
_images/25.png
Introduction

Move all steering gear to the preset angle.

The module needs to be used in conjunction with the `preset angle’ module.

Reversal direction
_images/26.png
Introduction

The steering angle is reversed with 90 degree as the median value.

Parameters
  • false :Default Motion Direction

  • true :Turn the steering gear in the direction of motion

Correcting
_images/27.png
Introduction

Errors in production and installation of gears and steering gear disks may cause steering gear to fail to turn at specified angles.

The angle error caused by the above reasons can be corrected by the steering gear calibration module.

Parameters
  • ±90°

Music

Music include MoonBot Kit Controller Module buzzer drive and external Drive Speaker Module.

By calling these modules, you can control MoonBot Kit to play music.

_images/31.png
Speaker initialization
_images/32.png
Introduction

Initializes the speaker connected to the specified port.

Parameters
port
  • 2,7,9

Speaker Setting Play Mode
_images/33.png
Introduction

Set up the playback mode of the speaker.

Parameters
Play mode
  • Single Play :Stop playing after playing specified music

  • Single tune circulation :Play specified music in a loop

  • Play all :Play the next music in the music list automatically after playing the specified music

  • Random Play :Play one of the music lists randomly after playing the specified music

Speakers Play Music
_images/34.png
Introduction

Play music with a given name.

Parameters
Music Name
  • :the drop-down menu for the module

Speaker Plays Custom Music
_images/35.png
Introduction

Play music with the specified music name.

Users need to put corresponding custom music into loudspeakers before this operation.(How to save music?),The first four words of a musical name should be letters or numbers.

Parameters
Music Name
  • :Customize the first four characters of the music name,Support only ** English ** or ** Numbers **

Speaker Play Setting
_images/36.png
Introduction

Set the current speaker playback status.

Parameters
Play settings
  • Play/pause :Play or pause current music

  • Next song :Play the next music in the music list

  • Last song :Play the last music in the music list

  • Stop :Stop playing music

Loudspeaker set volume
_images/37.png
Introduction

Set the loudspeaker volume.

Parameters
volume
  • 0~32

Buzzer Plays Scales
_images/38.png
Introduction

Buzzer to play scales in a set beat

Parameters
Scale
  • High, middle and low levels

Rhythm
  • 1/16~4 beat :Single beat time can be set by buzzer.

Buzzer pauses play
_images/39.png
Introduction

The time when the buzzer pauses to play a given beat.

Parameters
Rhythm
  • 1/16~4 beat :Single beat time can be set by buzzer.

Buzzer Sets Play Rhythm
_images/310.png
Introduction

Set the number of beats per minute (BPM) of buzzer.

Parameters
beats per minute

Buzzer Play Frequency
_images/311.png
Introduction

Set up a buzzer to play music at a specified frequency at a given time.

Parameters
frequency
  • 0~65535 :Frequency Recommendation Setting in the Frequency Range acceptable to the Human Ear(20~20000Hz)

time
  • 0 :Continuous broadcasting

  • other :Stop playing for a specified length of time

Buzzer stop playing
_images/312.png
Introduction

The buzzer stopped playing sound.

IMU

IMU include MoonBot Kit Controller Module three-axis acceleration , drive of three-axis magnetometer and temperature sensor on board.

By calling these modules, you can get MoonBot Kit master control of current direction, tilt angle and state, etc.

_images/41.png
Compass calibration
_images/42.png
Introduction

When calibrating the compass, the master control needs to flip in the shape of ”∞“

Acquisition of compass angle
_images/43.png
Introduction

Read the angle between the current direction and the northward direction of the compass Y axis.

Return
  • 0~360°

Acquisition of acceleration value
_images/44.png
Introduction

Read the acceleration simulation of a given axis.

Parameters
Directional axis
  • X,Y,Z

Return
  • Acceleration analogue

Acquisition of acceleration angle
_images/45.png
Introduction

Acquisition the tilt angle of the master control

Introduction
Angle type
  • Elevation angle :The angle between Y axis and horizontal plane in the master control coordinates. When the main control tilts upward, the pitch angle is positive and vice versa.

  • Roll angle :The angle between X axis and horizontal plane in the master control coordinates. When the main control tilts to the right, the roll angle is positive and vice versa.

Return
  • ±180°

Read Temperature
_images/46.png
Introduction

Read the current temperature

Parameters
Unit of temperature
  • :Celsius degree

  • :Fahrenheit degree

Return
  • Temperature value

Read the current status
_images/47.png
Introduction

Read the current master control state.

Parameters
state
  • shock :Whether the master control is in vibration state or not

  • Free fall :Whether the master control is in free falling state

Return
  • true :The master control is currently in this state

  • false :The master control is not currently in this state

Light

Light include MoonBot Kit Controller Module Two on-board LEDs and 12 external LEDs Eyes Module drivers.

With these modules, you can easily set the color and brightness of the LED.

_images/51.png
Eye Initialization
_images/52.png
Introduction

Initialize the eye module to the specified port.

Parameters
port
  • 1~9

Eye display
_images/53.png
Introduction

Write the color value of the eye LED into the buffer and display it.

Introduction
colour
  • _images/LED_color.png
Eyes show expression
_images/54.png
Introduction

Eye LED displays facial movements.

Parameters
Expression
  • `` Module Dropdown Menu``

Master control LED display
_images/55.png
Introduction

Write the color value of the master LED into the buffer and display it.

Parameters
colour
  • _images/LED_color.png
LED Setting RGB Value
_images/56.png
Introduction

Write the RGB color value of a given LED lamp into the buffer.

Parameters
LED Type
  • Eye :eye LED

  • master control LED :master control LED

Lamp number
  • Eye: 0~11, master control LED : 0~1

R value
  • 0~255 :Red Channel Analog

G value
  • 0~255 :Green Channel Analog

B value
  • 0~255 :Blue Channel Analog

LED Setting HSV Value
_images/57.png
Introduction

Write the HSV color value of a given LED lamp into the cache.

Parameters
LED Type
  • Eye :Eye LED

  • master control LED :master control LED

Lamp number
  • Eye: 0~11, master control LED : 0~1

H value
  • 0~360°: Tone Value

_images/hue_color.jpeg
S value
  • 0~255 :Saturation value analogue

V value
  • 0~255 :Luminance value analogue

LED show
_images/58.png
Introduction

Show the color values in a given LED buffer

Parameters
LED Type
  • Eye :Eye LED

  • master control LED :master control LED

LED clear
_images/59.png
Introduction

Clear the cache of the specified LED.

Parameters
LED Type
  • Eye :Eye LED

  • master control LED :master control LED

LED brightness
_images/510.png
Introduction

Set the brightness of the given LED.

Parameters
LED Type
  • Eye :Eye LED

  • master control LED :master control LED

brightness
  • 0~255 : 0 darkest,``255`` brightest

Mech

Mech include mech Integrative Action in Morphology

By calling these modules, you can easily control the manipulator to catch the ball and so on.

_images/61.png
Initialization
_images/62.png
Introduction

Initialize the MoonMech manipulator port.

Parameters
MU adress
  • MU00 :MU address 0x60

  • MU01 :MU address 0x61

  • MU10 :MU address 0x62

  • MU11 :MU address 0x63

MU Port
  • 2,7,9

Mech claw Steering engine port
  • 1~4

Upper arm Steering engine port
  • 1~4

Lower arm Steering engine port
  • 1~4

Setting the position of catch ball
_images/63.png
Introduction

Setting up the position of the MoonMech manipulator to grasp the ball,The mechanical gripper can catch the ball by adjusting the X-Y value of the recognition ball.

When the ball is within the given X-Y value range, the mechanical claw closes to grasp the ball.

Parameters
X
  • 0~100 :Horizontal position of mechanical claw grip ball,The horizontal position of the mechanical claw relative to the ball can be adjusted by modifying this value.

Y
  • 0~100 :Vertical position of mechanical claw catching ball,The vertical height of the gripper can be adjusted by modifying this value.

Setting Shooting Conditions
_images/64.png
Introduction

Setting up the conditions of MoonMech mechanical claw shooting,The horizontal position X and width of the card can be adjusted to allow the manipulator to shoot accurately into the basket.

When the card within the given X-width range, the arm triggers the shooting action to shoot.

Parameters
X
  • 0~100 :Horizontal position relative to transverse coordinate X of card when shooting with mechanical claw,The horizontal position of the gripper relative to the card can be adjusted by modifying this value.

Width
  • 0~100 :The size of the card when the mechanical claw shoots,The distance between MoonMECH mechanical arm and basket (card) can be adjusted by modifying this value.

Claw movement
_images/65.png
Introduction

Set up mechanical claw action. This module can be used to control the horizontal or up-down translation of the mechanical claw.

Parameters
action
  • open :Open the mechanical claw(110°)

  • close :Close the mechanical claw(90°)

  • forward :The mechanical claw advances horizontally in a unit.

  • back :The mechanical claw retreats one unit horizontally

  • up The mechanical claw is vertically upward in a unit.

  • down :A vertical downward unit of a mechanical claw.

Find the ball
_images/66.png
Introduction

Control MoonMech manipulator to perform ball searching.

Return
  • true :Find the ball

  • false:No ball was found.

Catch the ball
_images/67.png
Introduction

Control MoonMech manipulator to perform catch action.

If the ball manipulator is not found during execution of this block, MoonMech will remain in place and return false

Return
  • true :Catch the ball

  • false:No ball was found.

Find the card
_images/68.png
Introduction

The MoonMech manipulator is controlled to perform the search basket (card) action.

Parameters
card type
  • shape card

  • traffic card

  • number card

Return
  • true :Find the given card

  • false:No given card was found

Shoot
_images/69.png
Introduction

Control MoonMech manipulator to execute shooting action.

If the ball manipulator is not found during execution of this block, MoonMech will remain in place.

MoonBot

MoonBot include MoonBot robot Integrative Action in Morphology.

By calling these modules, you can control the robot to perform nodding, waving and other actions.

_images/71.png
Initialization
_images/72.png
Introduction

Initialize the ports of the MoonBot robot.

Parameters
Head steering gear
  • 1~4

Left-handed steering gear
  • 1~4

Right-handed steering gear
  • 1~4

Wave
_images/73.png
Introduction

The arm that drives the robot waves.

Parameters
Arm
  • Left hand

  • Right hand

  • Both hands

deviation
  • 0~90 :Deviation Angle of Up and Down Waves of Robot

Speed
  • fast

  • mid

  • slow

Swing
_images/74.png
Introduction

The head and foot of the robot are swing at the same time.

Parameters
Motor
  • Left motor

  • Right motor

  • Dual motor

Speed
  • fast

  • mid

  • slow

Shake your body from side to side
_images/75.png
Introduction

Control the robot motor to sway left and right.

Parameters
Speed
  • fast

  • mid

  • slow

Time
  • 0~+∞ :Single shaking time of motor

Step Forward
_images/76.png
Introduction

Controlling the robot takes a step forward.

Parameters
Speed
  • fast

  • mid

  • slow

Time
  • 0~+∞ :The longer the motor takes a step forward, the bigger the step is.

Nod
_images/77.png
Introduction

The control robot nodded once.

Parameters
deviation
  • 0~90° :Nodding range

Speed
  • fast

  • mid

  • slow

MoonBot Kit Arduino Tutorial

This artical introduces developing MoonBot Kit with Arduino IDE.

MoonBot Kit Arduino Guidelines for Building Development Environment

MoonBot Kit(hereinafter referred to as MoonBot)provide Arduino library functions,Support for development programming on Arduino (ATmega1280)

This document aims to guide users to build MoonBot hardware development environment based on Aduino official IDE.

Preparation

Hardware:

  • MoonBot Developer Suite

  • PC (Windows,Linux or Mac OS)

Software:

Detailed installation steps

First step:MoonBot Import Arduino External Dependency Library
  • 1.Start Arduino official IDE

  • 2.Click on Project - > Load Library - > Manage Library',openLibrary Manager’.`

    _images/Earduino_lib_management_zh.png

  • 3.Search library `AsyncDelay’, install the relevant library if not installed, update if the library is updated

    _images/Earduino_lib_download_zh.png

  • 4.Install the library Software Wire'Adafruit_NeoPixel’ Servo according to the installation method in step 3, Ensure that the relevant libraries are installed in the latest version

Step 2: import MoonBot Arduino library
  • 1.Download the latest MuVisionSensor3 Arduino library andMoonBot Arduino library(Source code(zip))

  • 2.Click on the `Project - > Load Library - > Add. zip Library’, select the MounBot Arduino Library downloaded in the first step, complete the import of the library.

    _images/Earduino_add_zip_library1.png

  • 3.Repeat the previous step and import the MuVisionSensor3 Arduino library to complete the library import

Step 3: Connecting devices

Now connect your MoonBot to PC,Device connection and port configuration

  • 1.Click on Tool - > Development Board , select``Arduino/Genuino Mega or Mega 2569`

  • 2.Click on Tool - > Processor ,selectATmega1280

  • 3.Click on Tool - > Port`,Select the corresponding MoonBot port

    Generally, serial ports display different names under different operating systems:

    • **Windows Operating System: ** COM1 etc.

    • Linux Operating System: Start with `dev/tty’.

    • MacOS Operating System: Start with `dev/cu‘ .

Step 4: Compile routines
  • 1.Click on `File - > Example - > MoonBot’,select one of the routines

    _images/Earduino_open_examples.png

  • 2.Click on the upload button. If everything goes well, the development board will be reset and the corresponding routine will start running after the burning is completed.

API Reference

There are customized programming blocks in MoonBot Arduino used for MoonBot Kit and MU Vision Sensor 3. This article introduces every block, and shows some complicated program examples. Users can learn programming combining hardware modules.

Check MU Vision Sensor 3 documents here: MU Vision Sensor 3 Guide

Pin Map

Overview

MoonBot Kit Controller Module contains 9 GPIO ports, 4 servo ports, two motor ports and other on board resources. And in Arduino library we provide pin map livrary and relevant defined pin to guide users requiring corresponding pin number.

Through these functions and macros, we can easily get pin numbers of MoonBot Kit controller.

Get Keys Status

For example, turn on the on-board LEDs by getting button status.

#include <MoonBot.h>

int button_a = MOONBOT_PIN_BUTTON_A;        // Get button A pin number
int button_b = MOONBOT_PIN_BUTTON_B;        // Get button B pin number

void setup()
{
    LED.begin();        // On board LEDs begin
}

void loop()
{
    if ((!digitalRead(button_a) && !digitalRead(button_b))) {
        // If button A and B is pressed at mean time, LED 0 and 1 show cyan.
        LED.setPixelColor(0, 0x00ffff);
        LED.setPixelColor(1, 0x00ffff);
        LED.show();
    } else if ((!digitalRead(button_a))) {
        // If only button B is pressed, LED 0 show green
        LED.setPixelColor(0, 0x00ff00);
        LED.setPixelColor(1, 0x000000);
        LED.show();
    } else if ((!digitalRead(button_b))) {
        // If only button A is pressed, LED 1 show blue.
        LED.setPixelColor(0, 0x000000);
        LED.setPixelColor(1, 0x0000ff);
        LED.show();
    } else {
        // If buttons are not pressed, LEDs turn off.
        LED.setPixelColor(0, 0x000000);
        LED.setPixelColor(1, 0x000000);
        LED.show();
    }
}
Get LED Eyes Pin Number

Initialize LED by getting the status of Eyes Module on port 3.

moonbot_eyes.setPin(moonbotPortToPin(kPort3, kPortPin1));     // Set port 3 as the first pin of LED eyes.
moonbot_eyes.begin();         // Initialize LED eyes
Get Touch Module status

Read status of Touch Module on the GPIO ports.

#include <MoonBot.h>

// connect touch sensor 1 on port 1
uint8_t touch1 = moonbotPortToPin(kPort1, kPortPin1);
// connect touch sensor 2 on port 2
uint8_t touch2 = moonbotPortToPin(kPort2, kPortPin1);

void setup()
{
  // initialize touch sensor 1/2 as INPUT_PULLUP
  pinMode(touch1, INPUT);
  pinMode(touch2, INPUT);
}

void loop()
{
  Serial.println("=======================");
  Serial.print("touch sensor1: ");
  // read touch sensor 1 state
  if (digitalRead(touch1)) {
    Serial.println("on touch");
  } else {
    Serial.println("not touch");
  }
  Serial.print("touch sensor2: ");
  // read touch sensor 2 state
  if (digitalRead(touch2)) {
    Serial.println("on touch");
  } else {
    Serial.println("not touch");
  }
}
Get Infrared Module Status

We can use the same way to read the status of Infrared Module.

#include <MoonBot.h>

// connect ir sensor 1 on port 1
uint8_t ir1[2] = {
    moonbotPortToPin(kPort1, kPortPin1),
    moonbotPortToPin(kPort1, kPortPin2)
};
// connect ir sensor 1 on port 1
uint8_t ir2[2] = {
    moonbotPortToPin(kPort2, kPortPin1),
    moonbotPortToPin(kPort2, kPortPin2)
};

void setup()
{
  // initialize ir sensor 1/2 as INPUT_PULLUP
  pinMode(ir1[0], INPUT);
  pinMode(ir1[1], INPUT);
  pinMode(ir2[0], INPUT);
  pinMode(ir2[1], INPUT);
}

void loop()
{
  Serial.println("=======================");
  Serial.print("ir sensor1: ");
  // read ir sensor 1 state
  if (!digitalRead(ir1[0]) || !digitalRead(ir1[1])) {
    Serial.println("triggered");
  } else {
    Serial.println("not triggered");
  }
  Serial.print("ir sensor2: ");
  // read ir sensor 2 state
  if (!digitalRead(ir2[0]) || !digitalRead(ir2[1])) {
    Serial.println("triggered");
  } else {
    Serial.println("not triggered");
  }
}

Attention

Infrared module is in low level when touched, and pin mode is LOW; And it is not touched when level is HIGH.

API Reference - Pin Map
Header File
Enum
enum moonbot_servo_t
  • MoonBot Kit servo port

value:

kServo1=0

kServo2

kServo3

kServo4

kServoNum
  • servo port number

enum servo_pin_t
  • servo port type

value:

kSignal
  • servo signal pin

kShutDown
  • servo power pin

kState
  • servo status pin

enum moonbot_motor_t
  • MoonBot Kit motor port

value:

kMotor1=0

kMotor2

kMotorNum
  • motor port number

enum motor_pin_t
  • motor port type

value:

kDirection
  • motor direction pin

kSpeed
  • motor speed pin

enum moonbot_port_t
  • MoonBot Kit GPIO port

value:

kPort1=0

kPort2

kPort3

kPort4

kPort5

kPort6

kPort7

kPort8

kPort9

kPortNum
  • GPIO port number

enum port_pin_t
  • GPIO port type

value:

kPortPin1=0

kPortPin2

kPortPinNum
  • port pin number

Macro Definition
MOONBOT_PIN_LED
  • MoonBot Kit contrller on-board LED pin

MOONBOT_PIN_BUZZER_SIG
  • MoonBot Kit controller buzzer signal pin

MOONBOT_PIN_BUZZER_SHDW
  • MoonBot Kit controller buzzer power pin

MOONBOT_PIN_BUTTON_A
  • MoonBot Kit controller button A pin

MOONBOT_PIN_BUTTON_B
  • MoonBot Kit controller button B pin

Functions
uint8_t moonbotPortToPin(moonbot_port_t port_num, port_pin_t pin_num);
  • Get MoonBot Kit controller Arduino pin number of the GPIO port.

value
  • port_num: GPIO port

  • pin_num: port pin number

return
  • Arduino pin number of the port pin

uint8_t moonbotMotorToPin(moonbot_motor_t motor_num, motor_pin_t pin_type);
  • Get MoonBot Kit controller Arduino pin number of the motor port.

value
  • motor_num : motor port number

  • pin_type : motor pin type

return
  • motor port Arduino pin

uint8_t moonbotServoToPin(moonbot_servo_t servo_num, servo_pin_t pin_type);
  • Get MoonBot Kit controller Arduino pin number of the servo port.

value
  • servo_num : servo port number

  • pin_type : servo pin type

return
  • servo port Arduino pin

Motor

Overview

MoonBot Kit Motor Module includes motor and encoder. In Arduino library we provide motor library to drive single motor, and chassis control library to drive dual motors.

We can include MoonBot.h header file to call TankBase to drive motor chassis, or call Motor1 Motor2 to control single motor.

Chassis control

How to make the chassis move around? Check this simple example:

#include <MoonBot.h>

void setup()
{
  TankBase.begin();   // enable TankBase, use default setting
}

void loop()
{
  // forward 1s
  TankBase.write(100, 100);
  delay(1000);
  // backward 1s
  TankBase.write(-100, -100);
  delay(1000);
  // turn right 1s
  TankBase.write(100, -100);
  delay(1000);
  // turn left 1s
  TankBase.write(-100, 100);
  delay(1000);
}

Through TankBase.write() function, write motor speed of left and right motor can make the chassis move.

If you want to control the motor speed accurately, use TankBase.writeRpm() function instead.

// Chassis turn left, with left motor speed 30 RPM, and right -30 RPM.
TankBase.writeRpm(30, -30);

Note

Use functions that can control accurate speed of the motor like TankBase.write() TankBase.writeDistance() TankBase.writeAngle() ,

you need to connect the encoder to its port, and initialize function TankBase.begin() , and change the parameter enc_enable to true (default is true )

You can also make motor move certain angle or distance.

void loop() {
    TankBase.writeDistance(30, 20);     // Chassis move forward for 20 cm with the speed of 30 RPM
    while(TankBase.read(kLeftMotor) || TankBase.read(kRightMotor));     // Wait for the chassis to stop
    delay(100);
    TankBase.writeAngle(30, 180);       // Chassis turn right for 180 degrees with the speed of 30 RPM
    while(TankBase.read(kLeftMotor) || TankBase.read(kRightMotor));     // Wait for the chassis to stop
    delay(100);
}

Note

Because of fix devations or friction force, you will find chassis can not go straight. You can use following calibration functions to correct it.

void setup() {
    TankBase.rpmCorrection(82);           // Calibrate speed offset %
    TankBase.distanceCorrection(120);     // Calibrate distance offset %
    TankBase.wheelSpacingSet(100);        // Calibrate angle offset %
}
Control Single Motor

If you only want to control single motor, call Motor1 Motor2 to achieve.

Motor1.write(100);      // Set motor1 analog value to 100
Motor2.write(100);      // Set motor1 analog value to 100
Motor1.writeRpm(30);    // Set motor1 speed to 30 RPM
Motor2.writeRpm(30);    // Set motor1 speed to 30 RPM
API Reference - Motor
Header File
Enum Type
enum moonbot_motor_t
  • motor port type

value:

kMotor1=0

kMotor2

kMotorNum

Class
class Motor
  • Single motor driver

member function
Motor(moonbot_motor_t motor_type);
  • constructed function, define port type

parameter
  • motor_type

int begin(const bool reverse_dir = false, const bool enc_enable = true);
  • Initialize motor in the given port

parameter
  • reverse_dir : Reverse motor rotate direction, false by default

  • enc_enable : Enable encoder, true by default

return
  • 0 :Initailization succeed

  • -1 : Can not find the motor port

void write(int vol);
  • Write analog value

parameter
  • vol : Value of the voltage, with range of ±255 ,>0 means CW,<0 means CCW

int read(void);
  • Read the analog value

return
  • ±255 : Analog value

void writeStep(uint32_t step, int rpm = 30);
  • Drive motor with certain speed and steps and then stop.

  • This function will use encoder, and encoder must be opened in begin() function.

parameter
  • step : Rotation step, 240 steps per cycle

  • rpm : Motor rotation speed, 30 RPM per cycle

void writeRpm(int rpm = 30);
  • Write motor speed, unit: RPM

  • This function will use encoder, and encoder must be opened in begin() function.

parameter
  • rpm : Motor rotation speed, 30 RPM by default

int readRpm(void);
  • Read motor speed, unit: RPM

  • This function will use encoder, and encoder must be opened in begin() function.

return
  • Motor rotate speed

void writeDistance(int rpm, uint32_t distance_cm);
  • Drive motor with certain speed and distance and then stop. Because of the offsets, please use``distanceCorrection()`` function to calibrate.

  • This function will use encoder, and encoder must be opened in begin() function.

parameter
  • rpm : Motor rotation speed

  • distance_cm : Moving distance, unit: cm

uint32_t readEncoderPulse(void);
  • Read encoder value

  • This function will use encoder, and encoder must be opened in begin() function.

return
  • Current encoder value

void rpmCorrection(uint8_t percent);
  • Motors RPM calibration

parameter
  • percent : Calibration percentage. >100 means increase , <100 means decrease

void distanceCorrection(uint8_t percent);
  • Motors distance calibration

parameter
  • percent : Calibration percentage. >100 means increase distance, <100 means decrease

API Reference - Chassis Control
Enum Type
enum motor_type_t
  • motor type

value:

kLeftMotor=0
  • left motor

kRightMotor
  • right motor

Class
class MoonBotTankBase
  • Chassis dual motor driver

member function
MoonBotTankBase(Motor& left_motor, Motor& right_motor);
  • constructed function, define two motors to the port

parameter
  • left_motor

  • right_motor

int begin(const bool reverse_dir = false, const bool enc_enable = true);
  • Initialize chassis motors

parameter
  • reverse_dir : Reverse rotation direction, false by default

  • enc_enable : Enable encoder, true by default

return
  • 0 : Initialization succeed

  • -1 : Can not find the motor port

int begin(const bool left_reverse_dir, const bool right_reverse_dir, const bool enc_enable);
  • Initialize chassis motors

parameter
  • left_reverse_dir : Reverse left motor rotation direction

  • right_reverse_dir : Reverse right motor rotation direction

  • enc_enable : Enable encoder

return
  • 0 : Initialization succeed

  • -1 : Can not find the motor port

void write(int left_vol, int right_vol);
  • Write analog value to motors

parameter
  • left_vol : Left motor voltage, range of ±255 , >0 means CW, <0 means CCW

  • right_vol : Right motor voltage, range of ±255 , >0 means CW, <0 means CCW

int read(motor_type_t motor_type);
  • Read analog value from motors

parameter
  • motor_type

return
  • ±255 : Analog value

uint32_t readEncoderPulse(motor_type_t motor_type);
  • Read motor encoder value

  • This function call encoder, and should be opened after begin() function

parameter
  • motor_type

return
  • Current encoder value

void writeRpm(int left_rpm, int right_rpm);
  • Write motors speed, unit: RPM

  • This function will use encoder, and encoder must be opened in begin() function.

parameter
  • left_rpm : Left motor rotation speed

  • right_rpm : Right motor rotation speed

int readRpm(motor_type_t motor_type);
  • Read motors speed, unit: RPM

  • This function will use encoder, and encoder must be opened in begin() function.

parameter
  • motor_type

return
  • Motor rotation speed

void writeDistance(int rpm, uint32_t distance_cm);
  • Drive motors with certain distance and stop. Because of the offsets, please use rpmCorrection() and distanceCorrection() function to calibrate.

  • This function will use encoder, and encoder must be opened in begin() function.

parameter
  • rpm :Motor rotation speed

  • distance_cm : Moving distance, unit: cm

void writeAngle(int rpm, uint32_t angle);
  • Drive motors with certain distance and stop. Because of the offsets, please use rpmCorrection() and wheelSpacingSet() function to calibrate.

  • This function will use encoder, and encoder must be opened in begin() function.

parameter
  • rpm : Motor rotation speed

  • angle : Rotation angle, unit: degree(°)

void wheelSpacingSet(int correct, float space_cm = 0);
  • Set wheel spacing and calibrate turn angle. This function can calibrate that wheel can not turn the accurate angle

parameter
  • correct Correction value, >100 means angle increase, <100 means decrease

  • space_cm : Motor spacing

void rpmCorrection(int percent);
  • Calibrate the speed of left and right motor

parameter
  • percent : Calibration value, >100 means calibrate to right, <100 means calibrate to left

void distanceCorrection(int percent);
  • Calibrate moving distance

parameter
  • percent : Calibration value, >100 means increase distance, <100 means decrease

void forward(unsigned int step, unsigned int rpm = 30);
  • Chassis move forward for certain distance and stop

parameter
  • step : Forward distance, unit: cm

  • rpm : Motor rotate speed, 30RPM by default

void backward(unsigned int step, unsigned int rpm = 30);
  • Chassis move backward for certain distance and stop

parameter
  • step : Back distance, unit: cm

  • rpm : Motor rotate speed, 30RPM by default

void turnLeft(unsigned int step, unsigned int rpm = 30);
  • Chassis turns left for certain degrees and stop

parameter
  • step : Left turn angle, unit: degree(°)

  • rpm : Motor rotate speed, 30 RPM by default

void turnRight(unsigned int step, unsigned int rpm = 30);
  • Chassis turns right for certain degrees and stop

parameter
  • step : Right turn angle, unit: degree(°)

  • rpm : Motor rotate speed, 30 RPM by default

void stop(void);
  • Chassis stop moving

Music

Overview

MoonBot Kit provide two sound devices, buzzer on Controller Module and Speaker Module . We can use Arduino basic functions tone() and noTone() to control the buzzer. Use Speaker library to control the speaker.

By including MoonBot.h header file in program, we can call speaker driver to drive the speaker module.

On-board Buzzer Driver

We can use macro definition MOONBOT_PIN_BUZZER_SIG to get Arduino pin of the buzzer, and control the voltage of MOONBOT_PIN_BUZZER_SHDW to open or close the buzzer.

#include <MoonBot.h>

void setup()
{
    pinMode(MOONBOT_PIN_BUZZER_SIG, OUTPUT);        // Initialize buzzer signal pin to output mode
    pinMode(MOONBOT_PIN_BUZZER_SHDW, OUTPUT);       // Initialize buzzer power pin to output mode
    digitalWrite(MOONBOT_PIN_BUZZER_SHDW, LOW);     // Pull down buzzer power pin to open buzzer
    tone(MOONBOT_PIN_BUZZER_SIG, 1000, 2000);       // Let buzzer play with 1000Hz for 2000ms
}

Attention

In 7th line of the example:

7
digitalWrite(MOONBOT_PIN_BUZZER_SHDW, LOW);     // Initialize buzzer power pin to output mode

Pull MOONBOT_PIN_BUZZER_SHDW voltage LOW to open it, and HIGH to close.The default voltage is LOW.

Speaker Module Driver

MoonBot Kit Speaker Module use a WT2003S MP3 decoder chip. Call speaker library to control it as a MP3 player.

There is a simple MP3 player tutorial:

#include <MoonBot.h>

void setup()
{
    speaker.begin(Serial2);     // Initialize speaker module to Arduino serial port 2(MoonBot GPIO port 2)
    speaker.setPlayMode(0);     // Set play mode to single play, which means stop after playing a music
    speaker.setVolume(20);      // Set volume to 20. Max volume is 32
}

void loop()
{
    if ((!digitalRead(MOONBOT_PIN_BUTTON_A))) {
        // If button A is pressed
        speaker.playNext();     // Play the next music
    } else if ((!digitalRead(MOONBOT_PIN_BUTTON_B))) {
        // If button B is pressed
        speaker.playPrevious(); // Play the last music
    }
}

Check Official terminal MP3 player examples for more detailed information.

API Reference - Speaker
Class
class WT2003S
  • WT2003S MP3 player driver

Menber function
void begin(SoftwareSerial &serialPort);
  • Use software serial port to initialize speaker

parameter
  • serialPort : software serial port

void begin(HardwareSerial &serialPort = Serial);
  • Use hardware serial port to initialize speaker

parameter
  • serialPort : hardware serial port, Serial by default

uint8_t play(char* fileName);
  • play music with the file name

parameter
  • fileName : 4 bytes of the file name

return
  • 0 means the command is right, other return means wrong

uint8_t setVolume(uint8_t volumeLevel);
  • Set volume of the speaker

parameter
  • volumeLevel : volume level, with range of 0~32

return
  • 0 means the command is right, other return means wrong

uint8_t stop(void);
  • Stop playing current music

return
  • 0 means the command is right, other return means wrong

void pause(void);
  • Pause when playing, play when pausing

uint8_t playPrevious(void);
  • Play the last music. Play the final music when on the first

return
  • 0 means the command is right, other return means wrong

uint8_t playNext(void);
  • Play the next music. Play the first music when on the final

return
  • 0 means the command is right, other return means wrong

uint8_t setPlayMode(uint8_t mode);
  • Set play mode

parameter
  • mode :

    0

    single play

    1

    single cycle

    2

    list loop

    3

    randomplay

return
  • 0 means the command is right, other return means wrong

uint16_t getSongCount(void);
  • Get the music order number in the list

return
  • current music order number in the list

void getSongName();
  • Get first 9 bytes of the song name. Read WT2003S::songName[MP3_NUM_NAME_BYTES] to get the name

uint8_t playTrackNumber(uint8_t trackNumber);
  • Play music with the given order number

parameter
  • trackNumber : music order number in the list

return
  • 0 means the command is right, other return means wrong

uint8_t getVolume(void);
  • Get current volume level of the speaker

return
  • 0~32 : volume level of the speaker

uint8_t getPlayStatus(void);
  • Get the current play status

return

1

play

2

stop

3

pause

IMU

Introduction

MoonBot Kit Controller Module integrates three functions of triaxial magnetometer, triaxial acceleration and temperature sensor into IMU module. In the Arduino library, we also provide ref:IMU < api-ref-imu > library to facilitate users to access the master control of the current attitude, direction, temperature and other states.

By calling `IMU’, we can quickly obtain the current compass angle, pitch angle, roll angle, gravity acceleration, temperature and other state values.

Read master control current direction

By reading the angle of the compass, we can know the direction of the current master control:

#include <MoonBot.h>

void setup()
{
  IMU.enable();         // IMU Enable
  IMU.calibrateMag();   // IMU magnetometer calibration,the master control needs to flip in the shape of ”∞“
}

void loop()
{
  Serial.print("compass:");
  // Obtain the compass angle(0~360°).When pointing north, the value is 0 or 360
  Serial.println(IMU.getMagAngle());
}

Note

When the main control is flat, the return value is Y axis (see the master control front silk mark) and the northward clip.

When the main control is erected, the return value is the angle between Z axis and North direction.

Obtain Pitch angle or Rolling angle
// Obtain Pitch angle(±180°),When the main control is up, the angle is positive and the downward angle is negative.
int pitch = IMU.getAccAngle(kAccPitch);
// Obtain Rolling angle(±180°),The main control right deviation is positive and the left deviation is negative.
int roll = IMU.getAccAngle(kAccRoll);

Note

MoonBot Kit The main control direction is Y axis (see the main control front silk mark),Angles are calculated on this premise.。

Acquisition of current acceleration
// Acquisition of acceleration,unit:g,The value at rest is 1.0.
float acceleration = IMU.getAcceleration();
Obtain the current motion state
void loop()
{
    if (IMU.on(kIMUShake)) {
        // If the current master is shaking
        // bright red LED
        LED.setPixelColor(0, 0xff0000);
        LED.setPixelColor(1, 0xff0000);
        LED.show();
    } else if (IMU.on(kIMUFreeFall)) {
        // If the current master is in free fall
        // bright green LED
        LED.setPixelColor(0, 0x00ff00);
        LED.setPixelColor(1, 0x00ff00);
        LED.show();
    } else {
        // If the main control is stationary
        // close LED
        LED.setPixelColor(0, 0x000000);
        LED.setPixelColor(1, 0x000000);
        LED.show();
    }
}
API Reference - IMU
enumeration
enum lsm303_axes_t
  • IMU Directional axis type

value:

kDirX

kDirY

kDirZ

enum lsm303_acc_angle_t
  • IMU Attitude Angle Type。

value:

kAccRoll

kAccPitch

enum imu_state_t
  • IMU Special state type.

value:

kIMUShake
  • IMU Is it in a sloshing state

kIMUFreeFall
  • IMU Is it in a free falling state

Class
class LSM303AGR_IMU_Sensor
  • IMU Drive.

group function
int enable(void);
  • enable IMU

Return
  • 0 enable success, unable failure

int advGetMagAngle(lsm303_axes_t main_axes, lsm303_axes_t sub_axes);
  • Get the plane where the specified spindle and vice-spindle are located, and the angle between the spindle and the North side.

parameters
  • main_axes :Spindle

  • sub_axes :Countershaft

Return
  • Angle between the spindle and the North

int getMagAngle(void);
  • Obtain the compass angle,When the main control is placed horizontally, the angle between the positive direction of Y axis and the north is returned;

    when the main control is placed vertically, the angle between the positive direction of Z axis and the north is returned.

Return
  • Angle between the spindle and the North

int getAccAngle(lsm303_acc_angle_t angle_type);
  • Obtain the main control angle.

parameters
  • angle_type :angle type

Return
  • angle

float getAcceleration(void);
  • Acquisition of acceleration value。

Return
  • Acceleration value,unit:g

bool on(imu_state_t imu_state);
  • Get whether the master control is in some state。

parameters
  • imu_state :IMU state

Return
  • true IMU In this state,Otherwise, it is not in this state.

bool calibrateMag(void);
  • Calibration of Magnetometer

Return
  • Whether the calibration is completed or not

int16_t temperature(void);
  • Obtain the original temperature value

Return
  • Primitive value of temperature

float temperatureC(void);
  • Get the current temperature,unit:Celsius degree

Return
  • Current temperature,unit:Celsius degree

float temperatureF(void);
  • Current temperature,unit:Fahrenheit degree

Return
  • Current temperature,unit:Fahrenheit degree

group variable
LSM303AGR_ACC_Sensor Acc;
  • Acceleration drive

LSM303AGR_MAG_Sensor Mag;
  • Magnetometer drive

Servo

Overview

MoonBot Kit Controller Module can be connected up to four Servo Module 。 In Arduino library, we provide Servo library. Through this library, you can control one or more servos to move.

Servo library inherit Arduino basic servo driver class Servo. Except for basic Servo class function, we also provide functions like servo calibration, several servos move together. In MoonBot.h header file, we provide four variables m_servo[kServo1] m_servo[kServo2] m_servo[kServo3] m_servo[kServo4] to drive corresponding servo ports in controller module.

Basic Application

There is a basic application of servos.

#include <MoonBot.h>

int pos;

void setup() {
    m_servo[kServo1].attach(kServo1, true);          // attaches servo on servo port 1, and reverse directions
}
void loop() {
  for (pos = 0; pos <= 180; pos += 1) {     // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    m_servo[kServo1].write(pos);                     // tell servo to go to position in variable 'pos'
    delay(15);                              // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) {     // goes from 180 degrees to 0 degrees
    m_servo[kServo1].write(pos);                     // tell servo to go to position in variable 'pos'
    delay(15);                              // waits 15ms for the servo to reach the position
  }
}

Note

Initial function of servos is changed to attach(moonbot_servo_t servo_port, bool reverse), and original function uint8_t attach(int pin) is not supported anymore.

Servos move together

We provide void MoonBotServo::setTargetAngle() and MoonBotServo::moveAllServoToTarget() functions to make servos move togehther.

#include <MoonBot.h>

void setup() {
  for (int i = 0; i < kServoNum; ++i) {
    m_servo[i].attach((moonbot_servo_t)i);  // attaches servo
  }
}
void loop() {
  // in steps of 1 degree
  for (int i = 0; i < kServoNum; ++i) {
    m_servo[i].setTargetAngle(180, 1);      // set all servo to go to position in variable '180', speed 1 degree per pulse(20ms)
  }
  MoonBotServo::moveAllServoToTarget();     // move all servo to target angle
  for (int i = 0; i < kServoNum; ++i) {
    m_servo[i].setTargetAngle(0, 1);        // set all servo to go to position in variable '0', speed 1 degree per pulse(20ms)
  }
  MoonBotServo::moveAllServoToTarget();     // move all servo to target angle
}

Note

When using MoonBotServo::moveAllServoToTarget(); default parameter, the function will wait for all servos finish moving and stopping. When parameter is not 0, it will stop when time is over, and feed back whether moving is finished.

Function``bool isMoving(void);`` can be used every certain time to check the status.

while (!MoonBotServo::moveAllServoToTarget(0)) {
    // Check whether servos are moving.
    for (int i = 0; i < kServoNum; ++i) {
        if (!m_servo[i].isMoving()) {
            // when servos stop, print the status.
            Serial.print("Servo");
            Serial.print(i);
            Serial.println(" Stopped.");
        }
    }
}
Serial.println("All Servo Stopped.");

When using COM monitor, information will be received as below.

Servo1 Stopped.
...
Servo1 Stopped.
Servo2 Stopped.
...
Servo2 Stopped.
Servo3 Stopped.
...
Servo3 Stopped.
All Servo Stopped.
Servo Calibration

MoonBot Kit Servo library provide servo calibration function that can correct the offset of servos.

m_servo[kServo1].correction(-2);        //Calibrate servo 1 downwards for 2°
API Reference - Servo
Header File
Enum
enum moonbot_servo_t
  • servo port type

value:

kServo1

kServo2

kServo3

kServo4

kServoNum
  • servo port number

Class
class MoonBotServo
  • MoonBot Kit servo driver library

Member function
uint8_t attach(moonbot_servo_t servo_port, bool reverse = MOONBOT_SERVO_REVERSE);
  • Initialise servo to servo ports.

Parameter
  • servo_port

  • reverse

Return
  • NOT_A_PORT Servo port is invalid, and other initialization is right.

uint8_t attach(moonbot_servo_t servo_port, int min, int max, bool reverse = MOONBOT_SERVO_REVERSE);
  • Initialise servo to servo ports, and set its moving range.

Parameter
  • servo_port :servo port

  • min :minimum degree of servo

  • max :max degree of servo

  • reverse :reverse servo direction

Return
  • NOT_A_PORT Servo port is invalid, and other initialization is right.

void detach(void);
  • Detach servo and port

void write(int value);
  • Write servo angle

parameter
  • value :angle value range 0~180°

int read(void);
  • Read current servo degree

Return
  • current degree

void reverse(bool state);
  • Reverse servo direction

parameter
  • state: Status true Direction is reversed

void setTargetAngle(int angle, unsigned int speed = 1);
  • Initialise servos.It should be used together with``static bool moveAllServoToTarget()`` .

parameter
  • angle : Initialised angle

  • speed : degree of every pulse

void stop(void);
  • stop servos

void power(bool state);
  • open or close servo power.

parameter
  • state :status of servo power, true means open

void correction(int angle_offset);
  • Servo calibration

parameter
  • angle_offset :Calibrate the angle. Range: ±90°

bool isMoving(void);
  • Read moving status.

Return
  • true Servo is moving

bool isPowerOverload(void);
  • Detect whether current is overload.

Return
  • true Power is overload

Static member function
static bool moveAllServoToTarget(unsigned long timeToWait_ms = 0xFFFFFFFF);
  • Move all servo to set angle

Parameter
  • timeToWait_ms : Default time is infinite, until servo move to target angle.

Return
  • true Finish all movement.

static void stopAllServo(void);
  • Stop all servo movements.

Light

Overview

MoonBot Kit contains two sets of light modules,Respectively located Controller Module and Eyes Module 。 We can use Adafruit_NeoPixel library to drive these two sets of light modules.

We can drive two on-board LED lights by calling `LED’.Drive 12 LED eyes by calling `moonbot_eyes’.At the same time, through the call: ref: `LED eye movement < api-ref-led-action > ` let the eyes make a rich expression.

LED Foundation driven
#include <MoonBot.h>

void setup() {
    // enable main control LED
    LED.begin();
    moonbot_eyes.begin();
    //  clear LED color
    LED.clear();
    LED.show();
    moonbot_eyes.clear();
    moonbot_eyes.show();
}

void loop() {
    if (digitalRead(MOONBOT_PIN_BUTTON_A) == LOW
        && digitalRead(MOONBOT_PIN_BUTTON_B) == LOW) {
        // If A&B is pressed at the same time
        // LED and eye lights display cyan
        LED.fill(0x003030);
        LED.show();
        moonbot_eyes.fill(0x003030);
        moonbot_eyes.show();
    } else if (digitalRead(MOONBOT_PIN_BUTTON_A) == LOW) {
        // If key A is pressed
        // LED0,The right eye display green.
        LED.setPixelColor(0, 0x003000);
        LED.setPixelColor(1, 0);
        LED.show();
        moonbot_eyes.clear();
        moonbot_eyes.fill(0x003000, 0, 6);
        moonbot_eyes.show();
    } else if (digitalRead(MOONBOT_PIN_BUTTON_B) == LOW) {
        // If key B is pressed
        // LED1,The left eye display green.
        LED.setPixelColor(0, 0);
        LED.setPixelColor(1, 0x000030);
        LED.show();
        moonbot_eyes.clear();
        moonbot_eyes.fill(0x000030, 6, 6);
        moonbot_eyes.show();
    } else {
        // LED Eye lights off
        LED.clear();
        LED.show();
        moonbot_eyes.clear();
        moonbot_eyes.show();
    }
}
LED Eye Lighting Action

MoonBot Kit provides abundant Eye action to be used:

colorWipe(moonbot_eyes, 0x40, 200);         // LEDs turn green one by one
theaterChase(moonbot_eyes, 0xFF00, 50);     // Eyes turn around
MoonBotEyesCircle(moonbot_eyes, 50);        // Eyes turn around gradually
rainbow(moonbot_eyes, 5);                   // Eyes show rainbow color
rainbowCycle(moonbot_eyes, 5);              // Eyes show rainbow color one by one
API Reference - Adafruit_NeoPixel

Check Adafruit official website for detailed information: https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-use

API Reference - LED Eyes Action
Header File
Enum
enum moonbot_eyes_t
  • eyes type

value:

kEyesLeft
  • left eye

kEyesRight
  • right eye

kEyesBoth
  • both eyes

enum moonbot_look_t
  • direction that eyes look at

value:

kEyesLookUp
  • Eyes look up

kEyesLookDown
  • Eyes look down

kEyesLookLeft
  • Eyes look left

kEyesLookRight
  • Eyes look right

enum moonbot_eyes_scroll_t
  • eyes scroll type

value:

kEyesScrollUp
  • eyes scroll up

kEyesScrollDown
  • eyes scroll down

kEyesScrollLeft
  • eyes scroll left

kEyesScrollRight
  • eyes scroll right

Functions
void colorFade(Adafruit_NeoPixel& led, uint8_t r, uint8_t g, uint8_t b, uint8_t wait);
  • LED eyes turn to target color gradually

parameter
  • led : LED type

  • r : value of red channel

  • g : value of green channel

  • b : value of blue channel

  • wait : time to wait

void colorWipe(Adafruit_NeoPixel& led, uint32_t c, uint8_t wait);
  • LED change color one by one

parameter
  • led: LED type

  • c: REG color of the LED

  • wait: time to wait for action

void rainbow(Adafruit_NeoPixel& led, uint8_t wait);
  • LED light shine rainbow color

parameter
  • led : LED type

  • wait : time to wait

void rainbowCycle(Adafruit_NeoPixel& led, uint8_t wait) ;
  • LED change light of rainbow color gradually

parameter
  • led : LED type

  • wait : time to wait for changing

void theaterChase(Adafruit_NeoPixel& led, uint32_t c, uint8_t wait);
  • LED turn around with target color

parameter
  • led : LED type

  • c : RGB color of LED light

  • wait : time to wait for action

void MoonBotEyesLook(Adafruit_NeoPixel& led, moonbot_look_t look_tpye, uint32_t color);
  • LED eyes look to the direction

parameter
  • led : LED type

  • look_tpye : the direction that eyes looks to

  • color : eyes color

void MoonBotEyesScroll(Adafruit_NeoPixel& led, moonbot_eyes_scroll_t scroll_tpye, uint32_t color, uint8_t wait = 50);
  • LED eyes scroll to the direction

parameter
  • led : LED type

  • scroll_tpye : direction that eyes scroll to

  • color : LED color type

  • wait : time to wait, 50ms by default

void MoonBotEyesCircle(Adafruit_NeoPixel& led, uint32_t color, moonbot_eyes_t eyes_type = kEyesBoth, uint8_t wait = 50);
  • LED eyes turn around gradually

parameter
  • led : LED type

  • color : eyes color

  • eyes_type : eyes type

  • wait : circle time, 50ms by default

MoonBot Kit Extended Structures

Except for official structures, makers can use MoonBot Kit hardware modules and other common materials to build creative robots.

Lego Car

Hardware modules of MoonBot Kit can be connected to lego parts and used to build lego robots.

Basic connection: There two main types of lego parts: technic series and traditional series.Horizontally placed modules are compatible with traditional series, while vertically placed modules are compatible with technic series. Traditional parts needs to be transfered to a 2X2 lego block, and technic parts needs black bolts to connected to others, as is shown below.

_images/MoonBot_extension_lego_compatible.png

Demount the screw of active wheel, remove the active wheel and mount an adapter of TT motor to Lego. Then MoonRover can use Lego wheels to become a traditional two wheel car. And a universal wheel is needed to make the car horizontal, as is shown below.A big wheel will make the car drive twice faster than before.

_images/MoonBot_extension_lego_wheel.png

Biped Robot

MoonBot controller can be connected to 4 servos, and made a biped dancing robot with some sheet metal parts.

_images/MoonBot_extension_biped_robot.png

Shell Mod

Shell of MoonBot can be modified by yourself.Just use 3d printing, paper and wood boards to change shell or inside parts of MoonBot. For example, a cool dragon from Teacher Ma is shown below.

_images/MoonBot_extension_shell_mod.png

MoonBot Kit Firmware Upgrade Guide

This doc will guide users to upgrade firmware of MoonBot Kit Controller Module and Vision Module .

Preparation

Hardware:

  • MoonBot Kit

  • PC(Windows)

Software:

Upgrading Steps

Step One: Upgrade firmware of MoonBot Kit Controller

Refer to MoonBot Kit APP Firmware Upgrade Guide

Step Two: Upgrade firmware of MU Vision Sensor 3

1. Connect Vision Module to MoonBot Kit Controller Module port P9, and connect the controller to PC.

2. Press and hold function button of Vision Module on the left, and then press Reset button once. Then release function button, and the vision sensor is in upgrading mode now.

  1. Open MU Vision Sensor 3 upgrade software flash_download_tools_vx.x.x.exe

  2. Choose ESP32 DownloadTool

    _images/moonbot_upgrade_flash_loader.png
  3. Change Settings

    _images/moonbot_upgrade_setup.png

Note

  • SPI SPEED:40MHz

  • SPI MODE:DIO

  • FLASH SIZE:32Mbit

  • BAUD:115200

  • COM:connect to the right COM port, which can be found in Windows device manager.

    _images/moonbot_upgrade_find_com.png
  1. Choose ... button and choose firmware file, and choose to activate the file.

  2. Input address of the firmware behind @ , which is 0x10000.

Attention

Do not forget to input the address or modify it. Otherwise you will damage the firmware order of the vision sensor. If it happens, please contact to Morpx support to solve it.

Phone number: (0571)8195 8588

E-mail: support@morpx.com

8.Press START button on the left-bottom corner, and click continuously button B of MoonBot Kit Controller Module until the software start burning firmware. LED on the right side of the controller turns green.

9.When the software progress bar is full, and shows FINISH, firmware downloading is complete.

MoonBot Kit Resource

Technical Information

Thanks for purchasing MoonBot Kit, and we would like to provide continuous updating service, please check to our website: www.morpx.com regularly. Updates are subject to change without notice. You can get the latest technical information from the following websites:

Official Website: http://mai.morpx.com/page.php?a=moonbot-kit

GitHub: https://github.com/mu-opensource/

3D Assembly Models

MoonBot Kit 3D assembly files can be downloaded here:

MoonBot Kit 3D assembly

_images/model_3D_MoonBot.png

STP file is a universal 3D file format, which can be opened by popular CAD software like solidworks and CREO.

The models can be used to watch the details of each MoonBot Kit structure, measure dimension, render in Keyshot and so on.

Plastic and sheet metal parts in models are optimized for manufacturing, and are not recommended to be used for FDM 3D printing.

Projects

There are extended projects of MoonBot Kit. Watch the latest updates at https://www.hackster.io/tianli.

MU Self-driving Kit Introduction

MU无人驾驶套件是基于MU视觉识别技术而延伸的学习套件。套件包含了一台自动驾驶小车和模块化的路障、地图。

自动驾驶小车以Micro:bit作为主控,MU作为眼睛,通过红外、视觉、超声波等反馈引导小车自动驾驶; 另一块Micro:bit作为路障主控,通过交通灯、舵机控制等实现动态的交通指示,也可和小车进行无线通讯; 模块化的地图可拼搭成不同路线形式,模拟各类道路情况。

无人驾驶创客先行,快用MU无人驾驶套件体验未来交通吧。

_images/SelfDriving_main.png

MU Self-driving Kit Structure

交通装置拼装

麦昆小车扩展

MU Self-driving Kit MakeCode Tutorial

本文介绍MU无人驾驶套件在MakeCode环境中开发的教程。

MakeCode是一款由微软开发的可视化编程软件,适配Micro:bit、乐高 EV3等硬件平台。

MakeCode在线编程:MakeCode for micro:bit

基础教程

简介

micro:bit是一款全球流行的STEAM教育开发板,由英国BBC广播公司开发。 micro:bit本身集成了传感器和灯光显示等外部设备,接入电脑即可编程体验基础功能;当插入扩展板类产品如麦昆小车,可以有更多的控制电机、氛围灯等功能。

micro:bit官方采用MakeCode软件进行编程。编程页面:MakeCode在线编程

本教程围绕MakeCode软件进行编程块的教学,逐步加入AI内容,帮助用户入门并掌握自动驾驶套件的内容。

编程界面

在主页“我的项目”中新建一个项目,进入编程界面。

_images/mainPage.jpg

程序烧录

在编程界面中,最左侧是模拟器和下载按钮,部分程序可以直接模拟运行查看效果,所有程序编译完成后都可以下载到micro:bit上运行。

micro:bit连上电脑后显示一个模拟U盘,将程序编译后生成的hex文件放入U盘就会重启micro:bit运行该程序。

_images/download.jpg

编程块操作

界面中间是编程主界面,拖放可选择的编程块至右边即可编程,鼠标右键点击可重复、删除、显示帮助等操作,鼠标放置在编程块处会显示编程块的简单说明。

_images/blocks.jpg

添加扩展

除了基础编程块,套件还会用到外部设备的扩展编程块,打开高级-扩展,搜索”muvision”添加MU视觉传感器相关编程块,搜索“maqueen”添加麦昆小车相关编程块。其他第三方编程块导入同理。

_images/muvision.jpg

界面顶部可切换至代码编程,左侧会显示资源管理器,可查看程序相关源文件。本教程以可视化编程为主,代码仅做参考。

完整示例

拖动显示LED块到无限循环中,复制一个放到下方,将上方的LED灯点亮一个图案比如爱心,就是一个简单的闪动爱心的程序,在左边的模拟器可以看到模拟效果。

点击“下载”,编译生成hex文件,将micro:bit连接至电脑,将hex文件放入micro:bit模拟U盘。micro:bit将会自动重启,数秒后看到程序实际运行效果。

_images/heartBeat.jpg

Tips:默认块中,“当开机时”中的程序运行一次,然后进入“无限循环”中循环运行。

执行器类教程

执行器是接受控制信号并对受控对象施加控制运行作用的装置。作为输出类设备,通常用简单的从上至下的顺序控制就可以使执行器动起来。 通过相应的编程块来掌握以下执行器的直接控制。

电机控制

电机(motor)俗称马达,是常见的电能转换为机械能的装置。电机可划分为直流、交流,有刷、无刷,永磁、电磁等很多种类。小车常用直流减速电机作为车轮的驱动电机。 通过控制左右轮的速度、方向即可实现小车向各个方向的运动。

示例一:控制小车运动方向

程序说明:通过控制两个电机运动方向实现小车方向的变化,让小车分别前进、后退、左转、右转、停止,每个动作持续2秒。

_images/motorDirection.jpg

示例二:控制小车加减速

程序说明:使用循环控制电机速度依次增加,电机速度从0增加到200,再减到0,每次变化50. index循环中,每执行一次index加1,index乘以相应的倍数50作为电机速度,随循环次数而变化。

_images/motorAccelerate.jpg

舵机控制

舵机(servo)是一种简单的伺服电机,常用在车模、船模、机器人等产品,用于掌舵控制方向。 舵机内部采用直流电机驱动,多级齿轮减速器产生大扭矩,电位器确定当前角度。 用PWM信号控制舵机转到指定角度即可让舵机快速转到某个角度后保持不变。

示例:控制舵机摆动

程序说明:循环写入舵机角度,每0.1秒改变一次角度,舵机缓慢在0-180度范围摇摆。index乘以相应的倍数作为舵机角度。

_images/servoSweep.jpg

灯光控制

灯光是最基础的输出类设备,可作为装饰、照明、程序调试等功能。这里介绍几种不同的常用灯光和相应的控制。

单LED灯

麦昆小车前方有两个LED车灯,通过简单的打开和关闭控制两个灯的通断。

示例:LED交替闪烁

_images/lightFlash.jpg

micro:bit点阵

micro:bit自带的点阵由25个LED灯组成,可以形成丰富的图案和字符。基础示例中已展示绘制爱心,以下程序介绍LED滚动显示过程。

示例:显示滚动图像

程序说明:在LED高级块中图像,创建一个大图像,在无限循环中调用,每隔200ms偏移产生滚动动画。

_images/lightMatrix.jpg

串行灯

麦昆小车车底有4个氛围灯,这是一种特殊的带芯片的串行灯,通过发送一串数据可控制整串LED的RGB值,产生各种各样的颜色。 驱动这4个灯需要添加”neopixel”扩展。 通过车底丝印可以了解这些灯的连接引脚P15和串联顺序。

示例:流水灯

程序说明:通过控制每个灯的RGB值来点亮所有灯。初始化中配置灯的引脚P15,数量为4。 LED的灯号为0-3,每隔100ms依次亮红、绿、蓝灯,形成流水灯。

_images/lightNeo.jpg

音乐控制

micro:bit的P0脚可以接蜂鸣器,制作简单的音乐。打开小车上的蜂鸣器可以启用该音乐功能。 通过编程块播放内置的音效,或者用音调自制音乐。

示例:小星星

程序说明:通过编程块改变音调和节拍形成顺序的音乐段,以《小星星》的乐谱作示范。

_images/buzzerLittleStar.jpg

传感器类教程

传感器(sensor)是一种检测装置,能将测量到的信息,转换为电信号输出。对于主控来说传感器主要是输入设备,在自动控制中起重要作用。 传感器的类别非常多,功能和数据也各有不同。本教程通过micro:bit相关传感器的使用来表达反馈控制的过程,见微知著。

按键

按键是最简单的输入设备,也可以当做是一种传感器。按键主要有通断两种状态,对应程序中的真或假、0或1,通过两种状态的检测判断产生反馈,做出相应反应。 实际生产生活中还有触摸按键、红外按键、人体红外开关、限位开关等各类按键的变种,控制方式和普通按键也有很多类似之处。

示例一:获得按键状态

程序说明:通过条件逻辑检测按键的状态,如果按键A被按下则屏幕显示A,如果按键B被按下则屏幕显示B,否则不显示,每0.1秒检测一次。

_images/buttonStatus.jpg

示例二:中断事件

程序说明:中断是独立于初始化和无限循环的另一种状态,由某种状态触发,如本例中的当按键被按下。程序在执行完中断程序后会回到原来的位置。 本例中主程序为显示爱心,中断程序为A或B被按下时切换显示A或B,之后回到循环继续显示爱心。

_images/buttonInterrupt.jpg

指南针

指南针也称为地磁传感器,能够感应地球磁场并输出当前角度,得到方位信息。

示例:电子指南针

程序说明:通过micro:bit板载的指南针获得当前的角度,用屏幕显示东(E)西(W)南(S)北(N)。 将micro:bit平放转动即可看到角度。指南针初次使用需校准,翻转micro:bit将点阵全部点亮即可。

_images/compassDirection.jpg

程序扩展:加入东北、东南、西北、西南,使指南针更丰富。

加速度计

和指南针类似,加速度计也是一种惯性测量单元(IMU),可以测得当前多个方向的加速度值,也可以通过数据的累加、判断大小来获得速度、旋转角度、震动等信息。

示例:计步器

程序说明:类似于运动手环的计步功能,用变量step作为步数,屏幕显示当前步数。当震动时中断,step累加。

_images/accelerometerStep.jpg

程序扩展:如果在野外被五步蛇咬了怎么办?计步器试试计到4步就报警。

超声波传感器

超声波传感器是最常见的测距传感器,利用声波的发射和接收时差乘以声速获得距离信息,类似于蝙蝠的测距。超声波传感器测量距离可以达到0.04-4米。

示例一:超声波测距

程序说明:用变量distence记录超声波测距的值,并通过micro:bit的点阵显示该距离。

_images/ultrasonicDistance.jpg

示例二:避障小车

程序说明:超声波常用于小车避障,是一个典型的反馈控制过程。小车默认以100的速度直行,距离前方障碍小于20cm时,小车原地调头。

_images/ultrasonicAvoidance.jpg

程序扩展:尝试不同避障距离时有不同的避障路线。比如距离小于10cm则后退调头,距离20cm则右转90度。

红外传感器

红外传感器可以检测黑白色,本质是一对红外开关。一个红外灯发射红外光,遇到前方白色时反射,黑色吸收,另一个接收头检测是否接收到,产生0和1两种状态。 使用多组红外开关可以避障或巡线。

示例:红外巡线小车

程序说明:麦昆小车底部有两组红外传感器,可用于红外巡线。红外的0和1两种状态表示在黑线内还是黑线外,通过两对红外状态的判断让小车直行、左转还是停止,每50ms判断一次。

_images/infraredLineFollower.jpg

通讯类教程

在实际的设备与设备间、芯片与芯片间往往有各种通讯协议(protocol),用于传输复杂的数据,本质是按照预定的规则收发数据。 在可视化编程中部分收发规则已简化,配置了默认的引脚、格式,而内部的数据类型、字符的协议需要用户自己定义。

串口

串口通讯(Serial Communication)是设备间常用的串行通讯方式,比如micro:bit与电脑间就可以通过串口收发数据。 串口常用于程序的调试环节,可以将程序中的数据配合一些解释通过串口打印在电脑上。 串口设备接入电脑后会显示相应的COM口,在此电脑右键左侧设备管理器中可以找到。

示例:串口打印数据

程序说明:用串口替代micro:bit的点阵来显示超声波测距数据,打印在控制台上。 用变量distence记录超声波测距的值,串口打印描述性的语句和distance的值来显示数据,常用于程序的调试。 在编程界面左侧打开“显示控制台 设备”即可看到串口返回的信息。

_images/serialUltrasonic.jpg

无线

micro:bit主控芯片自带无线通讯功能,是一种分组广播的通讯形式,当两块micro:bit设定在同一分组时即可收发数据。

示例:无线遥控小车

程序说明:此程序需要两块micro:bit,一块发送,一块接收。

接收端程序:无线接收字符以触发相应的动作。开机时匹配无线组1,无限循环为空。 在接收到无线数据时产生中断,根据无线接收到的数据让小车对应运动。

_images/radioRx.jpg

发射端程序:通过按键A B触发无线发送。开机时设置无线组1,发射功率为7。循环检测按键状态,当A、B或A+B被按下时通过无线发出对应字符。

_images/radioTx.jpg

程序扩展:体感遥控小车,将发射端程序改为加速度计触发,倾斜micro:bit来控制小车。当手中的micro:bit前后左右倾斜时让小车对应运动。

_images/radioTxAccel.jpg

Tips:这里无线发射和接收就是一个简单的通信协议,用数字1、2、3、4表示左转、右转、前进、后退。熟练以后可以设计更多复杂的协议。

蓝牙

程序高级教程

本文系统性介绍程序的相关概念,较为理论,结合各类实际程序总结归纳。

基本(basic)

当开机时:初始化程序,开机时最先运行一次。一般将设备的初始化放在此内。

无限循环:主程序,简单程序的不断运行,或者复杂程序中调用函数。

暂停:维持当前状态一段时间,防止程序运行过快跳过某些动作。一般可用几十毫秒至数秒,过小或过大可能出错。

中断:独立于初始化和主程序,满足某种触发条件后执行内部程序,可以是按钮、振动、无线接收等各类外部触发条件,执行完毕后回到被中断的程序处继续运行。

循环(loop)

repeat循环:指定循环次数

while循环:当满足某个条件时循环。“无线循环”本质就是while true,表示一直循环。

for循环:使用index索引计数来循环,从0开始,每次加1,index可以被内部调用。

for of循环:以数组中的元素个数计数循环,用值(value)引用数组中的元素

逻辑(logic)

if条件:如果,否则如果,否则,否则如果可以有多个,将多种可能性的时间列举在内,常用于传感器的状态判断。

布尔运算:布尔值(Boolean)指正确true(1)或错误false(0)。布尔运算指且(and)或(or)非(not),常用在多种条件出现时的判断过程。 判断结果返回一个布尔值。

比较运算:数值或字符串间的大小对比。比较结果返回一个布尔值。

变量(value)

设置变量:新建一个变量,在程序的某些位置调用,变量名要具有可读性。

变量赋值:变量可以赋值为其他数值,或以n为幅度累加,x = x + n。

数学(math)

数学运算:加减乘除、取余、平方根、三角函数、四舍五入等常见数学运算。

随机数:指定某个区间内返回一个随机数,或返回随机布尔值。

函数(function)

编程中的函数是一个功能性的过程,也称为子程序,通常是进行一段运算或控制一段输入过程。当程序中的过程反复出现时,可以建立一个函数进行调用。

新建函数:建立一个能被调用的函数。可以带有文本、数值或布尔值的参数,在调用时对参数赋值。

数组(array)

一串数组中每个值都是一个变量,各变量的排序称为索引,从0开始。

改变数组中的值:获得目标值的索引,将该位置的值替换,不改变数组长度。

改变数组长度:从首、尾、中间移除或者添加值,重新建立索引,数组的长度改变。

文本(text)

在打印调试会用到文本来解释数据,而受到一串文本常需要从中解析数据。

文本解析:获取文本的长度,提取字符或字符串,文本间的比较。

文本转换:将文本转换为数字、整数,或将数字转换为文本。

硬件高级教程

在Makecode中很多默认硬件相关的编程已做简化,而在使用外接设备时,比如插入扩展板,就涉及到引脚的相关控制。 在使用麦昆小车时就会涉及到引脚的精确使用,如蜂鸣器接在P0脚。 通过硬件相关的系统学习,在使用micro:bit外接传感器或执行器时就能如鱼得水,自由设计。

GPIO

通用输入输出端口(GPIO)是主控芯片提供的可供编程的接口,对应着芯片上的各个引脚。 在micro:bit中有部分引脚已被系统使用,留出的引脚可供用户编程。在高级-引脚里可以看到引脚P0-P20中的部分可以使用。 而板载的按键、LED等外设(外部设备的简称)同样也用到了其中部分引脚。

micro:bit引脚图:

_images/microbit_pinout.jpg

可以看到micro:bit可用的引脚已经通过金色的金手指引出,在套件中配了一块扩展板,则能将金手指转换成排针,方便连接舵机、LED等外部设备。 蓝色的是引脚插口,红色是VCC,黑色是GND。扩展板可用圆形DC口或USB口供电(扩展板USB口只能供电,不能下载)。

扩展板接口图:

_images/IObit_front.jpg

示例:点亮红绿灯模块

程序说明:将红绿灯模块连接到扩展板的P15口,参考串行灯程序,用扩展板点亮红绿灯模块,程序下载完后用电池盒通过DC口供电,脱离USB线。

示例:GPIO输出

程序说明:将LED车灯示例用GPIO直接控制的方式来实现,在麦昆小车上找到车灯的引脚P8和P12,输出数字量1即可点亮,数字0关闭。

_images/GPIOOutput.jpg

程序扩展:试试按键示例用数字读取引脚的值来实现。

ADC与DAC

模拟量是在一定范围连续变化的变量,比如声音的大小。 数字量是时间上是不连续变化(离散)的量,比如开关的状态,只在0和1之间变化。

模拟量(Analog)与数字量(Digital)在电路中的转换过程称为ADC(模拟转数字)和DAC(数字转模拟)。 micro:bit中的ADC是指测量电压模拟量读取,用0-1024的数字返回结果,测得的电压为

Volt = 3.3 * (Value/1024)

可以看到模拟转换为数字时有一定的精度,电压被分为1024份,测得的数字量约等于输入的模拟量。

示例:加速度值

程序说明:通过串口查看加速度值。下载程序后打开控制台,左右倾斜micro:bit,查看绘制的模拟曲线和返回的数字值。

_images/GPIOADC.jpg

DAC则相反,指定0-1024的数字模拟写入,输出对应的电压值为

Volt = 3.3 * (Value/1024)

示例:呼吸灯

程序说明:麦昆自带的车灯模块并没有调节车灯亮度的功能,但可以通过控制输出引脚的电压改变车灯亮度。 用模拟写入0-1000的值,车灯就有逐渐变亮的呼吸效果。

_images/GPIODAC.jpg

PWM

PWM是指脉冲宽度调制,在指定的周期时间上输出一定比例的高电平脉冲来输出数字信号。 最常见的就是舵机的PWM信号,脉冲的周期是20ms,舵机角度0度对应高电平1ms,90度对应1.5ms,180度对应2ms。

示例:舵机PWM控制

程序说明:通过有引脚的PWM输出来控制舵机,向P1输出PWM信号。

_images/GPIOPWM.jpg

IIC SPI

提供了IIC、SPI等接口,在使用相应外设时可以调用接口进行通信。

MU3应用教程

了解MU3的基础编程块使用请查看MU3 MakeCode教程

深入视觉原理和复杂应用请查看MU视觉传感器3深度开发指南

光线传感器

Wifi通讯

PID算法

综合运用教程

单线道路自动驾驶

单线红外巡线

竖立路牌识别:交通卡片指示牌、数字卡片限速、颜色识别红绿灯

道路内自动驾驶

道路中颜色识别道路范围寻路

识别地上交通卡片,道路标识

遥控 巡线综合

遥控移动到指定位置后切换至自动运动

MU Self-driving Kit Resource

技术资料

在以下网址可获取最新的MU视觉传感器技术资料:

官网技术支持:http://mai.morpx.com/page.php?a=sensor-support

GitHub:https://github.com/mu-opensource/

亚克力支架

对于套件中的模块化亚克力板,需要增加数量的用户可自行用激光切割机切割2mm的亚克力板。

MU自动驾驶套件亚克力板

3D打印支架

对于购买MU裸板的用户,我们提供了3D打印的外壳和折叠支架文件,可以在小车等使用场景下固定和调节传感器的角度,有3D打印机的创客可自行打印。

MU3 3D打印支架

_images/bracket_foldable_MU1.png

平台链接

MU视觉传感器可以和各类开源软硬件配合使用,查看各类开源平台以学习其基础知识。

麦昆小车

麦昆小车资料 [wiki链接]http://wiki.dfrobot.com.cn/index.php?title=(SKU:ROB0148)_micro:Maqueen(V2.0)%E6%9C%BA%E5%99%A8%E4%BA%BA%E5%B0%8F%E8%BD%A6

Micro:bit教程

Micro:bit官网 https://microbit.org/zh-CN/

MakeCode在线编程 https://makecode.microbit.org/#

Technical Support

Thanks for purchasing our products, and we would like to provide continuous updating service, please check to our website: www.morpx.com regularly. Updates are subject to change without notice. You can get the latest technical information from the following websites:

Official Website: http://mai.morpx.com/page.php?a=moonbot-kit

GitHub: https://github.com/mu-opensource/

Wiki: http://wiki.morpx.com/index.php/Home

Phone Number: 0571-81958588

Email: support@morpx.com

Wechat ID

_images/QRcode_WeChat.png

QQ ID

_images/QRcode_QQ.png

关于本站/About

本网站为摩图科技出品的产品相关资料站,在电脑端和移动端均可打开。

This website is document of products produced by Morpx Inc. The website can be opened in computer and mobile devices.

页面使用说明/Page Usage Notes

点击左下角 Read the Docs 按钮打开边栏,可以看到包含的功能。

Click the Read the Docs button in the left-bottom corner to open the sidebar pannel. Functions are shown below.

_images/about_corner.png
  • 切换语言/Change Language

目前大部分文档有中文和英文两种语言的版本,英文版是由中文版翻译而来。若切换语言时显示页面不存在,则为无对应翻译页面。 建议点击左上角返回首页后切换语言。如有任何问题,请联系我们。

Most documents have Chinese and English version. English version is the translation of the Chinese. There is no corresponding page if the page does not exist when changing language. Just click the left-top button to return to the homepage and change again. If there is any problem, please let us know.

  • 版本控制/Version Control

文档最新版本为latest,有其他稳定发布版本时会显示。

The newest document is in latest branch.Other stable branch will be shown when published.

  • 指南下载/Download the Docs

目前有pdf、html和Epub文件可供下载,方便离线阅读。

There are pdf, html and Epub files available for downloading.

Product Copyrights

Software Licenses

Opensource Software

Arduino

  • Arduino is an open-source physical computing platform based on a simple I/O board and a development environment that implements the Processing/Wiring language. Arduino can be used to develop stand-alone interactive objects or can be connected to software on your computer (e.g. Flash, Processing and MaxMSP). The boards can be assembled by hand or purchased preassembled; the open-source IDE can be downloaded for free at https://www.arduino.cc/en/Main/Software

  • Arduino is an open source project, supported by many.

  • The Arduino team is composed of Massimo Banzi, David Cuartielles, Tom Igoe and David A. Mellis.

  • Arduino uses GNU avr-gcc toolchain, GCC ARM Embedded toolchain, avr-libc, avrdude, bossac, openOCD and code from Processing and Wiring.

  • Icon and about image designed by ToDo.

MicroPython

  • MicroPython is written in C99 and the entire MicroPython core is available for general use under the very liberal MIT license. Most libraries and extension modules (some of which are from a third party) are also available under MIT or similar licenses.

  • You can freely use and adapt MicroPython for personal use, in education, and in commercial products.

  • MicroPython is developed in the open on GitHub and the source code is available at the GitHub page, and on the download page. Everyone is welcome to contribute to the project.