Tour de Taiwan for Mechatronics: 2019 New Taipei City Information Technology Project Exhibition

by Ted-Lee

The following are some information and takeaway from the event, mainly regarding mechatronics.

Project detail

1. Participants line up in the waiting area before entering the site.

2. A team consists of no more than 3 players, each of whom wearing a Watch:bit.

3. Players complete the mission of touring around the Taiwan-map sites within the time limit. The total number of steps from each group will be shown on the light bar at the display rack.

4. After the task, the total score will be displayed on the LCD leaderboard, with the top ten teams refreshed regularly.

Design

台灣地圖設計稿

Project structure

As shown in Figure 7, Watch:bit A-C (transmitting end) worn by 1 to 3 players send the readings of step counts back to the micro:bit R (receiving end) via 2.4G Hz radio broadcast. The summed scores is displayed via the LED WS2812B strip light (display 1). After the one-minute countdown is over, the final results of each group will be settled, and the top ten records will be displayed on the LCD screen (display 2).

Hardware

The client–server model was adopted to facilitate mechatronic engineering, as it is used for wiring the circuit of the display rack, as shown in Figure 8. There are the wireless transmission and the wired transmission:

1. Client side: three Watch:bits are used as the carrier for transmission of front-end data collected. The three Watch:bits are each worn by one player to obtain the number of steps taken.

2. Server side: The step counts of the three participants are all sent to the micro:bit R fixed at the back of the display rack to be summed up. As shown in Figure 9, on the server side, a dual power supply (3/5V) connected to the same ground and a 213-piece strip light WS2812B are used to display the players’ progress in touring around Taiwan. In addition, the micro:bit R is connected to a laptop via a USB cable. In addition to power supply for the micro:bit R, the cable allows transmission of the summed step counts collected from Watch:bit A-C via radio broadcast to the laptop through mbed serial port driver (https://reurl.cc/pW8M4e). Lastly, the final results on an Excel leaderboard are shown on an LCD screen.

Mechatronics programming

The programming of this project is divided into four parts: Watch:bit, micro:bit R, strip light display, and Excel leaderboard.

1. Watch:bit AC: (https://reurl.cc/QjNW69; https://reurl.cc/rQkZ14; https://reurl.cc/12l0oV). As shown in the red circles in Figure 11, the three watches share the same programming, and only the corresponding codes require modification. The codes for JavaScript and MakeCode are shown in the following table and Figure 12.

• Reset: Before the game started, all players press button A and B to reset the Watch:bit.

• Start: Pressing button A to start the pedometer, and the Watch:bit counts steps at every move.

• Stop: When the time is up, all players press button B to end the count, which was transmitted to micro:bit R. via broadcast.

// 啟動計步器

input.onButtonPressed(Button.A, function () {

    basic.showNumber(0)

    start = true

})

// 計步

input.onGesture(Gesture.Shake, function () {

    if (start) {

        no = no + 1

        radio.sendValue(“A”, no)

        basic.showNumber(no)

    }

})

radio.onReceivedValue(function (name, value) {

    if (name == “AA”) {

        ack = 0

        music.playTone(262, music.beat(BeatFraction.Whole))

    }

})

// reset

input.onButtonPressed(Button.AB, function () {

    ack = 0

    no = 0

    start = false

    basic.showString(“A”)

})

// stop

input.onButtonPressed(Button.B, function () {

    ack = 1

    start = false

})

let no = 0

let start = false

let ack = 0

radio.setGroup(168)

basic.showString(“A”)

ack = 0

basic.forever(function () {

    if (ack) {

        radio.sendValue(“SA”, no)

        basic.pause(0)

    }

})

2. micro:bit R: (https://reurl.cc/44YXdR). As shown in the red circles in Figure 13. The codes for MakeCode and JavaScript are shown in the following table and Figure 14.

• Reset: Pressing button A and B to for the micro:bit R to return to its beginning state.

• Broadcast reception: Micro:bit R receiving the pedometer readings from Watch:bit A-C via broadcast, as shown in Figure 15.

// 歸零

input.onButtonPressed(Button.AB, function () {

    basic.showString(“R”)

    led_sum = 0

    initStrip()

})

radio.onReceivedValue(function (name, value) {

    if (name == “SA”) {

        a = value

        radio.sendValue(“AA”, a)

    } else if (name == “SB”) {

        b = value

        radio.sendValue(“AB”, b)

    } else if (name == “SC”) {

        c = value

        radio.sendValue(“AC”, c)

    }

    if (name == “RA” || name == “RB” || name == “RC”) {

        basic.showString(“R”)

        led_sum = 0

        initStrip()

    } else {

        // stop

        if (name == “SA”) {

            a = value

            led_sum = a + (b + c)

            sa = 1

            radio.sendValue(“AA”, 0)

            basic.pause(0)

        } else if (name == “SB”) {

            b = value

            led_sum = a + (b + c)

            sb = 1

            radio.sendValue(“AB”, 0)

            basic.pause(0)

        } else if (name == “SC”) {

            c = value

            led_sum = a + (b + c)

            sc = 1

            radio.sendValue(“AC”, 0)

            basic.pause(0)

        }

        if (sa && (sb && sc)) {

            basic.showLeds(`

                . # # # .

                # . . # #

                # . # . #

                # # . . #

                . # # # .

                `)

            basic.showNumber(led_sum)

            serial.writeString(“Data,”)

            serial.writeNumber(led_sum)

            serial.writeLine(“”)

            sa = 0

            sb = 0

            sc = 0

        } else {

            if (name == “A”) {

                a = value

            } else if (name == “B”) {

                b = value

            } else if (name == “C”) {

                c = value

            }

            led_sum = a + (b + c)

            basic.showNumber(led_sum)

            basic.pause(0)

            if (led_sum <= led_no) {

                showStrip(led_sum)

            }

        }

    }

})

function showStrip (num: number) {

    for (let i = 0; i <= num – 1; i++) {

        strip.setPixelColor(i, strip_color)

        strip.show()

        // 這裡不pause一下下就會出錯,hen鳥…

        basic.pause(200)

    }

}

function initStrip () {

    strip_color = neopixel.colors(NeoPixelColors.Yellow)

    a = 0

    b = 0

    c = 0

    sa = 0

    sb = 0

    sc = 0

    strip.clear()

    strip.show()

}

let strip_color = 0

let sc = 0

let sb = 0

let sa = 0

let c = 0

let b = 0

let a = 0

let strip: neopixel.Strip = null

let led_no = 0

let led_sum = 0

radio.setGroup(168)

basic.showString(“R”)

led_sum = 0

// start from 0

led_no = 213

// 初始化灯條

strip = neopixel.create(DigitalPin.P1, led_no, NeoPixelMode.RGB)

strip.clear()

strip.show()

initStrip()

3. Strip light shows the progress of players touring around Taiwan, as shown in the red circles in Figure 12.

4. Excel leaderboard: As shown in the red circles in Figure 17, we also refer to this article (https://reurl.cc/bkeGWl) and download PLX-DAQ (Parallax Data Acquisition tool; https://reurl.cc/6EXLqd), an Excel plug-in. After testing (https://reurl.cc/9O01Da), it is successful. As shown in Figure 18, the micro:bit R transmits players step counts to the relay laptop through the serial port, and then the PLX-DAQ plug-in, written using Visual Basic for Applications (VBA), receives the data to be put down in the leaderboard. The Excel leaderboard adopts RANK() frank to rank the top ten player scores. The leaderboard image is also displayed on the LCD screen in real time in the exhibition hall for players to check.

分享到社群

vMaker編輯

The share account of vmaker editors. Send your work to us:contact@vmaker.tw