Skip to content

MU vision sensor, specifically designed for the AI education.

License

Notifications You must be signed in to change notification settings

mu-opensource/pxt-muvision

Repository files navigation

MU Vision Sensor 3

The MU Vision Sensor is a sensor module for micro:bit and other hardware platform that support UART or I2C communication protocols.

Basic usage

  • Get vision result
// Initialized MU with I2C port
muvision.begin(MuId.Mu00, MuVsMode.kI2CMode)
// Vision begin
muvision.visionBegin(MuId.Mu00, MuStatus.Enable, MuVsMessageVisionType.kVisionBall)
basic.forever(function () {
    // Get vision status first
    if (muvision.detected(MuId.Mu00, MuVsMessageVisionType.kVisionBall)) {
        // If vision detected, print vision result
        serial.writeValue("x", muvision.visionValue(MuId.Mu00, muvision.VisionType.VisionBallDetect, muvision.Params.Horizontal))
        serial.writeValue("y", muvision.visionValue(MuId.Mu00, muvision.VisionType.VisionBallDetect, muvision.Params.Vertical))
        serial.writeValue("w", muvision.visionValue(MuId.Mu00, muvision.VisionType.VisionBallDetect, muvision.Params.Width))
        serial.writeValue("h", muvision.visionValue(MuId.Mu00, muvision.VisionType.VisionBallDetect, muvision.Params.Height))
    }
})
  • Get light sensor result
muvision.begin(MuId.Mu00, MuVsMode.kI2CMode)
muvision.lsBegin(MuId.Mu00, MuStatus.Enable, MuLsType.LsProximity)
muvision.lsBegin(MuId.Mu00, MuStatus.Enable, MuLsType.LsAmbientLight)
basic.forever(function () {
    serial.writeValue("proximity", muvision.lsReadProximity(MuId.Mu00))
    serial.writeValue("als", muvision.lsReadAmbientLight(MuId.Mu00))
})
  • Read WiFi data(AP mode)

Before you use this function, you need to set the FUNC switch to 10(WiFi AT mode) or 11(video transmission mode).

serial.redirect(
    SerialPin.P12,
    SerialPin.P13,
    BaudRate.BaudRate9600
)
// Wait for serial initialization to complete
basic.pause(500)
// Show local IP on the screen
basic.showString(muvisionAT.wifiSIP())
basic.forever(function () {
    basic.showString(String.fromCharCode(muvisionAT.wifiRead()))
})
  • Read WiFi data(STA mode)

Before you use this function, you need to set the FUNC switch to 10(WiFi AT mode) or 11(video transmission mode), and your device and MU must be connected to the same network.

serial.redirect(
SerialPin.P12,
SerialPin.P13,
BaudRate.BaudRate9600
)
// Wait for serial initialization to complete
basic.pause(500)
muvisionAT.wifiSet("your_ssid", "your_password", MuAtMode.ModeSTA)
basic.showIcon(IconNames.Heart)
// Check connect
if (muvisionAT.wifiCon(true)) {
    basic.showIcon(IconNames.Yes)
    // Show local IP on the screen
    basic.showString(muvisionAT.wifiSIP())
    // Set target IP
    muvisionAT.wifiUDP("your_target_ip", "3333")
} else {
    basic.showIcon(IconNames.No)
}
basic.forever(function () {
    basic.showString(String.fromCharCode(muvisionAT.wifiRead()))
})

License

MIT

Supported targets

  • for PXT/microbit

What about other libraries for the MU Vision Sensor?

For more information

Check out the official site http://www.morpx.com/zn.index.html for links to documentation, issues, and news