I made voice controlled robot car using Amazon Alexa, Node-RED and micro:bit.
ConstitutionReturn the speech response to Amazon Echo via Node-RED Alexa Home Skill Bridge to Node-RED on Raspberry Pi Zero W, and send a signal to micro: bit on BLE. Micro:bit is mounted on the extended mini robot car Maqueen and receives signals to move it.
Create a virtual Alexa device to create an account for Node - RED Alexa Home Skill Bridge and control the robot car.
Go to the following and click Resister.https://alexa-node-red.bm.hardill.me.uk/
Device registration
After registration, select the Devices tag and click Add Device.
We have created a device for Alexa "Rotation" for turning the robot car's motor forward and backward.
Name: Device name "Rotation" input
Description: A brief description of the device
Actions: Select the operation type of the device.
Here we select On and Off. Advance with On, Off in reverse.
Likewise, we created two additional devices, "Turn" to make the robot car right and left, and "Stop" to stop it.
Enable Node-RED skill in Alexa application of smartphone and link Alexa service to Node-RED Alexa Home Skill Bridge.
When you enable skills, it will switch to the account entry screen of Node - RED Alexa Home Skill Bridge, so enter the registered user name and password.
If there is no problem, it shifts to the device detection screen.
You can find the device that you created by clicking Discover Device.
To customize the utterance to start up the created device, edit the routines with the Alexa smartphone application.
I set it as follows.
"Alexa, move forward": Device "Rotation" On
"Alexa, go backwards": Device "Rotation" Off
"Alexa, right turn": Device "turn" On
"Alexa, left turn": Device "turn" Off
"Alexa, Stop": Device "Stop" On
Install the node for Alexa Home Skill Bridge in Node - RED and receive a speech so that BLE can send a string to micro: bit. I used Node-RED from Raspberry Pi Zero W here.
installing nodes
Install node-red-contrib-alexa-home-skill.
In the configuration palette installation node-red-contrib-alexa-home-skill is searched and "install" is clicked to add the node.
In order to use BLE, install the following as well. node-red-contrib-generic-ble
Node-RED flowAlexa-home Node
Place three virtual Alexa devices "Rotate", "Turn" and "Stop" created.
After placing the node, first enter the user name and password you registered with Node-RED Alexa Home Skill Bridge.
Select the device. Here, select "Rotation".
Likewise we will also place nodes for "turn" and stop.
true / false Branch function node
"Rotate" and "turn" devices will return true and false by utterance, so we will branch at the function node.
Character string for BLE transmission Function node
Place a function node that generates a character string for BLE transmission corresponding to utterance application of On / Off of "Rotation" and "Turn" and On of "Stop".
In Advance ("Rotating" device On) the character string "1:" is being transmitted.micro: bit Specify the UUID for writing of BLE and the hexadecimal character string.
Send each of the following character strings.
Advance ("Rotation" device On): "1:"
Backward ("Rotation" device Off): "2:"
Rightward ("Turn" device On): "3:"
Leftward ("Turn" device Off): "4:"
Stop ("Stop" device On): "5:"
Generic BLE out Node
Place the Generic BLE out node and click on the pencil mark.
Check Select from scan result and select BBC micro: bit.
It receives a character string from Node - RED via BLE with micro: bit and controls mini robot car.
In this case, block coding with MakeCode and write to micro: bit. https://makecode.microbit.org/
How to add Maqueen block
- Please access below and click "New Project"https://makecode.microbit.org/
- Click the setting icon -> Extension
- Enter the following library link and click Search
https://github.com/jhlucky/maqueen
Click on maqueen to install
Maqueen's block is added.
You can now code Maqueen with MakeCode.
How to add bluetooth block
Select bluetooth with extended function. Since it can not coexist with the radio block, a radio block deletion message is issued. Please delete it.
Block for bluetooth will be added.
Change the BLE pairing setting of micro: bit. Click the setting icon -> project settings and select "No Paring Required" at the top. Communication is now possible without pairing.
1. Initial setting
When the variable state is initialized and Bluetooth is connected with Node-RED (Raspberry Pi Zero W), the Nico Nico mark is displayed on the micro: bit LED matrix.
2. Receive string
Receives a character string from Node-RED and substitutes the character before the colon ":" into the variable state.
3. Forward and backward control
Advance with the reception of the character string "1:", move backward by "2:" reception. Also change the LED matrix display.
4. Rightward control
Turn 90 ° to the right when receiving the character string "3:". In the LED matrix, display the arrow in the turn direction and make the right side of the red LED indicator on the front of Maqueen blink like a blinker. After the turn, it stops all.
5. Leftward control
Turn 90 ° to the left with the character string "4:" received. The arrow on the turn direction is displayed on the LED matrix and the left side of the red LED indicator on the front of Maqueen is blinking like a blinker. After the turn, it stops all.
6. Motor stop
When the character string "5:" is received, the motor stops and the display of the LED matrix disappears.
MakeCode JavaScriptThe entire JavaScript code is described below.
let state = ""
bluetooth.onBluetoothConnected(function () {
basic.showIcon(IconNames.Happy)
})
bluetooth.onBluetoothDisconnected(function () {
basic.showIcon(IconNames.Sad)
})
bluetooth.onUartDataReceived(serial.delimiters(Delimiters.Colon), function () {
state = bluetooth.uartReadUntil(serial.delimiters(Delimiters.Colon))
})
state = "0"
bluetooth.startUartService()
basic.showIcon(IconNames.Sad)
basic.forever(function () {
if (state == "4") {
basic.showArrow(ArrowNames.East)
maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CCW, 20)
maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CW, 20)
for (let i = 0; i < 3; i++) {
maqueen.writeLED(maqueen.LED.LEDLeft, maqueen.LEDswitch.turnOn)
basic.pause(200)
maqueen.writeLED(maqueen.LED.LEDLeft, maqueen.LEDswitch.turnOff)
basic.pause(200)
}
maqueen.motorStop(maqueen.aMotors.M1)
maqueen.motorStop(maqueen.aMotors.M2)
basic.clearScreen()
state = "0"
}
})
basic.forever(function () {
if (state == "3") {
basic.showArrow(ArrowNames.West)
maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CW, 20)
maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CCW, 20)
for (let i = 0; i < 3; i++) {
maqueen.writeLED(maqueen.LED.LEDRight, maqueen.LEDswitch.turnOn)
basic.pause(200)
maqueen.writeLED(maqueen.LED.LEDRight, maqueen.LEDswitch.turnOff)
basic.pause(200)
}
maqueen.motorStop(maqueen.aMotors.M1)
maqueen.motorStop(maqueen.aMotors.M2)
basic.clearScreen()
state = "0"
}
})
basic.forever(function () {
if (state == "1") {
basic.showIcon(IconNames.SmallDiamond)
maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CW, 20)
maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CW, 20)
}
if (state == "2") {
basic.showIcon(IconNames.No)
maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CCW, 20)
maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CCW, 20)
}
})
basic.forever(function () {
if (state == "5") {
maqueen.motorStop(maqueen.aMotors.M1)
maqueen.motorStop(maqueen.aMotors.M2)
basic.clearScreen()
}
})
Operation
Comments