Difference between revisions of "Chapter 9 of KitiBot-Microbit"

From Waveshare Wiki
Jump to: navigation, search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
==2.4G Communication==
 
==2.4G Communication==
 +
You need at least two micro:bit for 2.4G testing
  
 +
First we should add the package for 2.4G, note that its package could not be used with Bluetooth at the same time.
  
 +
[[File:add package for radio.png|600px]]
  
 +
There are three types of radio blocks. Send, receive and initial
 +
 +
note: you should set the boards to the same wireless group for normal communication
 +
 +
[[File:radio class.png|600px]]
 +
 +
===Buttons===
 +
---
 +
 +
[[File:radio code.gif]]
 +
 +
[[File:radio code-1.png|500px]]
 +
 +
Press button A or B of one micro:bit, and another will show characters A or B on LED matrix
 +
 +
===Radio control KitiBot===
 +
----
 +
[[File:joystick board.png|600px]]
 +
 +
We have learned how to use radio above, here we learn to use radio to control KitiBot by the module [https://www.waveshare.com/wiki/Joystick_for_micro:bit Joystick for micro:bit].
 +
 +
To use the Joystick for micro:bit, you need to install WSJoyStick package.https://github.com/waveshare/JoyStick
 +
 +
[[File:add package for joystick microbit.gif]]
 +
 +
The block in WSJoyStick package are:
 +
 +
JoyStickInit: Should be used on start for initailization
 +
 +
Key P Press: This block is used to detect if buttons are pressed
 +
 +
DIR Dir None: Used to judge direction of joystick.
 +
 +
[[File:blocks in joystick package.png|500px]]
 +
 +
Let's go to write the sender code of Joystick by modifying the last project.
 +
 +
[[File:Joystick sending microbit.gif]]
 +
 +
Add JoystickInit to on start, DIR block is used to detect if the joystick is pressed to up. If joystick is pressed to up, sending character "U" and display arrow North on matrix. Here we use if...then..., with this structure, micro:bit will sending "U" when button is pressed and "N" when released. We also put a loop block while to waiting for button being released,make sure micro:bit only send one message when pressing and one message when releasing.
 +
 +
[[File:joystick sending microbit2.png|400px]]
 +
 +
Same settings for other buttons: Make micro:bit sending characters "U", "D", "L" and "R" when up, download, left and right joystick are pressed separately.
 +
 +
[[File:joystick sending microbit3.gif]]
 +
 +
[[File:joystick sending microbit4.png|400px]]
 +
 +
And the receiver code: Makes robot move according to the characters received."U" to upward, "D" to backward, "L" to turn left, "R" to turn right and "N" to stop.
 +
 +
[[File:joystick receive microbit.gif]]
 +
 +
[[File:joystick receive microbit2.png|400px]]
 +
 +
===Control steering gear===
 +
 +
Sender code: Sending characters: "1", "2", "3" and "4" when four color buttons are pressed, and "N" when released.
 +
 +
[[File:joystick_botton sending microbit.gif]]
 +
 +
[[File:joystick_botton sending microbit2.png|400px]]
 +
 +
Receiver code: Similar to Bluetooth codes, use variable "step" for rotate angle, "pos" for current angle. If step isn't equal to 0, button is pressed, steering gear rotate for certain angle, stop when released.
 +
 +
 +
[[File:joystick_botton receiver microbit.gif]]
 +
 +
[[File:joystick_botton receiver microbit2.png|600px]]
 +
 +
===Control RGB LED===
 +
Sender code is same as last project. What we need to do is to add RGB LED controll to receiver code. Similar to Bluetooth code
 +
 +
[[File:joystick_RGB receiver microbit.gif]]
 +
 +
[[File:joystick_RGB receiver microbit.png|600px]]
 +
 +
===Gestures===
 +
Projects we makes above are all use buttons to control, sending signal by 2.4G to control robot when button pressed. According to Chapter 3 Sensor, we know accelerometer has beed integrated on micro:bit. With the accelerometer, we can control robot via status of micro:bit instead of button.
 +
 +
We only need to addd gestures control to sender code.
 +
 +
[[File:gesture sending microbit.gif]]
 +
 +
[[File:gesture sending microbit.png|600px]]
 +
 +
Robot move when micro:bit (joystick for micro:bit) tilt, and stop when it keeps horizontally.
 
{{Chapters of Kitibot micro:bit}}
 
{{Chapters of Kitibot micro:bit}}

Latest revision as of 09:00, 30 September 2018

2.4G Communication

You need at least two micro:bit for 2.4G testing

First we should add the package for 2.4G, note that its package could not be used with Bluetooth at the same time.

Add package for radio.png

There are three types of radio blocks. Send, receive and initial

note: you should set the boards to the same wireless group for normal communication

Radio class.png

Buttons

---

Radio code.gif

Radio code-1.png

Press button A or B of one micro:bit, and another will show characters A or B on LED matrix

Radio control KitiBot


Joystick board.png

We have learned how to use radio above, here we learn to use radio to control KitiBot by the module Joystick for micro:bit.

To use the Joystick for micro:bit, you need to install WSJoyStick package.https://github.com/waveshare/JoyStick

Add package for joystick microbit.gif

The block in WSJoyStick package are:

JoyStickInit: Should be used on start for initailization

Key P Press: This block is used to detect if buttons are pressed

DIR Dir None: Used to judge direction of joystick.

Blocks in joystick package.png

Let's go to write the sender code of Joystick by modifying the last project.

Joystick sending microbit.gif

Add JoystickInit to on start, DIR block is used to detect if the joystick is pressed to up. If joystick is pressed to up, sending character "U" and display arrow North on matrix. Here we use if...then..., with this structure, micro:bit will sending "U" when button is pressed and "N" when released. We also put a loop block while to waiting for button being released,make sure micro:bit only send one message when pressing and one message when releasing.

Joystick sending microbit2.png

Same settings for other buttons: Make micro:bit sending characters "U", "D", "L" and "R" when up, download, left and right joystick are pressed separately.

Joystick sending microbit3.gif

Joystick sending microbit4.png

And the receiver code: Makes robot move according to the characters received."U" to upward, "D" to backward, "L" to turn left, "R" to turn right and "N" to stop.

Joystick receive microbit.gif

Joystick receive microbit2.png

Control steering gear

Sender code: Sending characters: "1", "2", "3" and "4" when four color buttons are pressed, and "N" when released.

Joystick botton sending microbit.gif

Joystick botton sending microbit2.png

Receiver code: Similar to Bluetooth codes, use variable "step" for rotate angle, "pos" for current angle. If step isn't equal to 0, button is pressed, steering gear rotate for certain angle, stop when released.


Joystick botton receiver microbit.gif

Joystick botton receiver microbit2.png

Control RGB LED

Sender code is same as last project. What we need to do is to add RGB LED controll to receiver code. Similar to Bluetooth code

Joystick RGB receiver microbit.gif

Joystick RGB receiver microbit.png

Gestures

Projects we makes above are all use buttons to control, sending signal by 2.4G to control robot when button pressed. According to Chapter 3 Sensor, we know accelerometer has beed integrated on micro:bit. With the accelerometer, we can control robot via status of micro:bit instead of button.

We only need to addd gestures control to sender code.

Gesture sending microbit.gif

Gesture sending microbit.png

Robot move when micro:bit (joystick for micro:bit) tilt, and stop when it keeps horizontally.

Related Pages