Welcome to Tiny:bit Robot Car repository
当製品の日本語版マニュアル資料は、こちらからご取得ください。
11.Ultrasonic
Learning goal:
This lesson learns how to use ultrasonic sensor by Python programming.
Code:
1) Import the library needed for this lesson from micro:bit, display is used for dot matrix display, Image calls the built-in image, and tinybit controls the car.
2) display.show(Image.HAPPY): Display a smile on micro:bit dot matrix.
3) a = tinybit.ultrasonic(): Read the ultrasonic data and save it to variable a;
4) print(a):Print the data a detected by the ultrasonic wave through the serial port.
According to the hardware interface reference manual, the ultrasonic sensor connect to P15,P16 of micro:bit.

Programming and downloading:
1.You should open the Mu software, and enter the code in the edit window, , as shown below.
Note! All English and symbols should be entered in English, and the last line must be a space.
2.You can click the “Check” button to check if our code has an error. If a line appears with a cursor or an underscore, the program indicating this line is wrong.
3.Click “REPL” button,check whether the tinybit library has been downloaded. If not, please refer to the [preparation before class]---> [Python programming]
4.Click the “Flash” button to download the program to micro:bit board.
If the program is wrong or the experimental phenomenon is wrong after downloading, please confirm whether you have downloaded the Buildingbit libraryhex file we provided to the micro: bit board.
For the specific method of adding library files, please refer to 【1.Preparation before class】---【Python programming】
Experimental phenomena:
After download is complete. You can see the smiling face on the LED dot matrix screen. Open the serial port assistant, select the corresponding serial port, set the baud rate to 115200, and click to open the serial port, you can see the ultrasonic data.