[{"id":5305,"name":"8.10 Color sorter","moduletypeid":951,"content":"<p style=\"margin: 0px; text-indent: 0px; line-height: 1.75em;\"><br\/><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: Arial; background: rgb(0, 255, 255); font-size: 16px;\">Note: Please use the double-headed data cable provided by us to connect the Micro:bit board and expansion board to the computer, otherwise it will not be possible to drive the servo due to insufficient power.<\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\"><strong><span style=\"font-family: Arial; font-size: 16px;\">1. Learning target<\/span><\/strong><\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: Arial; font-size: 16px;\">In this lesson, we will use micro:bit board, building blocks and sensor modules to build a color sorter. It can distinguish red, green, blue three colors.<\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\"><span style=\"font-family: Arial; font-weight: bold; font-size: 16px;\">2. <\/span><strong><span style=\"font-family: Arial; font-size: 16px;\">Servo calibration<\/span><\/strong><\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\">Before assembling the building blocks, we need to use code to calibrate the servo to a fixed angle. <\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\">If calibration is not calibrated before using, it is easy to jam the servo during use and cause the steering gear to stall and damage the servo.<\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\">Calibration method:<\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\">2.1 Connect the brown line of the servo to GND (black), the red line of the servo to VCC (red), and the yellow line of the servo to IO on expansion board. <\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\">The left servo is connected to P1, the right servo is connected to P2. As shown below.<\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; text-align: center; line-height: 1.75em;\"><img src=\"\/public\/ueditor\/php\/upload\/image\/20210806\/1628250982744628.png\" title=\"1628250982744628.png\" alt=\"image.png\"\/><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\"> <\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\">2.2 Then connect the computer to the Micro:bit board and expansion board through the double-head micro USB cable we provided.<\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\"><span style=\"font-family: Arial; font-size: 16px;\">2.3 Download the servo calibration code (<\/span><strong><span style=\"font-family: Arial; color: rgb(0, 0, 255); font-size: 16px;\">Servo-calibration-color-sorter.py<\/span><\/strong><span style=\"font-family: Arial; font-size: 16px;\">) to the micro:bit board.<\/span><\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\">2.4 When a \"0\" pattern is displayed on the dot matrix of the Micro:bit board, it means the servo be calibrated successfully.<\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\"><span style=\"font-family: Arial; font-weight: bold; font-size: 16px;\">3. <\/span><strong><span style=\"font-family: Arial; font-size: 16px;\">Building blocks assembly<\/span><\/strong><\/span><\/p><p style=\"margin-right: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\">Please follow the steps we provide to assemble the building block models.<\/span><\/p><p style=\"margin-right: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\">Pay attention to the installation direction of the servo when assembling, otherwise the servo will be damaged due to the wrong angle of the servo after running the program.<\/span><\/p><p style=\"margin-right: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\">After the assembly is completed, please check the wiring of the servo as shown below.<\/span><\/p><p style=\"margin-right: 0px; text-align: center; line-height: 1.75em;\"><img src=\"\/public\/ueditor\/php\/upload\/image\/20210806\/1628250987508422.png\" title=\"1628250987508422.png\" alt=\"image.png\"\/><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\"> <\/span><\/p><p style=\"margin-right: 0px; text-align: center; line-height: 1.75em;\"><img src=\"\/public\/ueditor\/php\/upload\/image\/20210806\/1628250992663574.png\" title=\"1628250992663574.png\" alt=\"image.png\"\/><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\"> <\/span><\/p><p style=\"margin-right: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\"><strong><span style=\"font-family: Arial; font-size: 16px;\">4. About wiring<\/span><\/strong><\/span><\/p><p style=\"margin-right: 0px; text-align: center; line-height: 1.75em;\"><img src=\"\/public\/ueditor\/php\/upload\/image\/20210806\/1628250996454895.png\" title=\"1628250996454895.png\" alt=\"image.png\"\/><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\"> <\/span><\/p><p style=\"margin-right: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\"><strong><span style=\"font-family: Arial; font-size: 16px;\">5. About code<\/span><\/strong><\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; background: rgb(231, 230, 230); line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\"><\/span><\/p><pre class=\"brush:python;toolbar:false\"># -*- coding: utf-8-*-# Encoding cookie added by Mu Editor\r\nfrom microbit import *\r\nimport WOM_Sensor_Kit\r\n \r\ndisplay.off()\r\nWOM_Sensor_Kit.WOM_servo360(pin1, 190)\r\nWOM_Sensor_Kit.WOM_servo360(pin2, 190)\r\n \r\nwhile True:\r\n    if WOM_Sensor_Kit.WOM_color(WOM_Sensor_Kit.WOM_red) == 255:\r\n        if (WOM_Sensor_Kit.WOM_color(WOM_Sensor_Kit.WOM_green) < 20) and (WOM_Sensor_Kit.WOM_color(WOM_Sensor_Kit.WOM_blue) < 20):\r\n            WOM_Sensor_Kit.WOM_rgb(1023, 0, 0)\r\n            sleep(1000)\r\n            WOM_Sensor_Kit.WOM_rgb(0, 0, 0)\r\n            WOM_Sensor_Kit.WOM_servo360(pin1, 220)\r\n            WOM_Sensor_Kit.WOM_servo360(pin2, 220)\r\n            sleep(1000)\r\n            WOM_Sensor_Kit.WOM_servo360(pin1, 190)\r\n            WOM_Sensor_Kit.WOM_servo360(pin2, 190)\r\n            sleep(1000)\r\n    elif WOM_Sensor_Kit.WOM_color(WOM_Sensor_Kit.WOM_blue) == 255:\r\n        if (WOM_Sensor_Kit.WOM_color(WOM_Sensor_Kit.WOM_red) < 20) and (WOM_Sensor_Kit.WOM_color(WOM_Sensor_Kit.WOM_green) < 20):\r\n            WOM_Sensor_Kit.WOM_rgb(0, 0, 1023)\r\n            sleep(1000)\r\n            WOM_Sensor_Kit.WOM_rgb(0, 0, 0)\r\n            WOM_Sensor_Kit.WOM_servo360(pin1, 220)\r\n            WOM_Sensor_Kit.WOM_servo360(pin2, 150)\r\n            sleep(1000)\r\n            WOM_Sensor_Kit.WOM_servo360(pin1, 190)\r\n            WOM_Sensor_Kit.WOM_servo360(pin2, 190)\r\n            sleep(1000)\r\n    elif WOM_Sensor_Kit.WOM_color(WOM_Sensor_Kit.WOM_green) == 255:\r\n        if (WOM_Sensor_Kit.WOM_color(WOM_Sensor_Kit.WOM_red) < 20) and (WOM_Sensor_Kit.WOM_color(WOM_Sensor_Kit.WOM_blue) < 20):\r\n            WOM_Sensor_Kit.WOM_rgb(0, 1023, 0)\r\n            sleep(1000)\r\n            WOM_Sensor_Kit.WOM_rgb(0, 0, 0)\r\n            WOM_Sensor_Kit.WOM_servo360(pin1, 160)\r\n            WOM_Sensor_Kit.WOM_servo360(pin2, 150)\r\n            sleep(1000)\r\n            WOM_Sensor_Kit.WOM_servo360(pin1, 190)\r\n            WOM_Sensor_Kit.WOM_servo360(pin2, 190)\r\n            sleep(1000)<\/pre><p style=\"line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\"><strong><span style=\"font-family: Arial; font-size: 16px;\">6<\/span><\/strong><strong><span style=\"font-family: Arial; font-size: 16px;\">.Writing and download code<\/span><\/strong><\/span><\/p><p style=\"background: rgb(255, 255, 255); line-height: 1.75em;\"><span style=\"font-family: Arial; font-size: 16px;\">6.1 You should open the Mu software, and enter the code in the edit window, , as shown below.<\/span><\/p><p style=\"background: rgb(255, 255, 255); line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\"><strong><span style=\"font-family: Arial; color: rgb(237, 125, 49); font-size: 16px;\">Note! All English and symbols should be entered in English, use the Tab key (tab key) to indent and the last line must be a space.<\/span><\/strong><\/span><\/p><p style=\"line-height: 1.75em;\"><span style=\"font-family: Arial; font-size: 16px;\">6.2 You can click the “Check” button to check if our code has an error. <\/span><\/p><p style=\"line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\">If a cursor or underline appears on a line, it indicates a syntax error, please check and modify. If there is no error in the program, the bottom left of the interface will prompt that there is no problem in detection.<\/span><\/p><p style=\"text-align: center; line-height: 1.75em;\"><img src=\"\/public\/ueditor\/php\/upload\/image\/20210806\/1628251001694732.png\" title=\"1628251001694732.png\" alt=\"image.png\"\/><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\"> <\/span><\/p><p style=\"line-height: 1.75em;\"><span style=\"font-family: Arial; font-size: 16px;\">6.3 Click the ‘REPL’ button to check whether the WOM_Sensor_Kit Python library has been downloaded. <\/span><\/p><p style=\"line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\">If not, please refer to [Preparation before class] --> [Python Programming Guide] .<\/span><\/p><p style=\"text-align: center; line-height: 1.75em;\"><img src=\"\/public\/ueditor\/php\/upload\/image\/20210806\/1628251005574737.png\" title=\"1628251005574737.png\" alt=\"image.png\"\/><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\"><strong><span style=\"font-family: Arial; color: rgb(237, 125, 49); font-size: 16px;\"> <\/span><\/strong><\/span><\/p><p style=\"line-height: 1.75em;\"><span style=\"font-family: Arial; font-size: 16px;\">6.4 After the program is written, use a micro USB cable to connect the computer and the micro:bit board. Please click the ‘Flash’ button to download the program to the micro:bit motherboard (You need to click the ‘REPL’ button again to close the function of importing library files before you download the program).<\/span><\/p><p style=\"text-align: center; line-height: 1.75em;\"><img src=\"\/public\/ueditor\/php\/upload\/image\/20210806\/1628251009931365.png\" title=\"1628251009931365.png\" alt=\"image.png\"\/><span style=\"color: rgb(51, 51, 51); font-family: arial, helvetica, sans-serif; font-size: 16px;\"> <\/span><\/p><p style=\"line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\"><span style=\"font-family: Arial; font-size: 16px;\">6.5 If the download failed, please confirm whether the micro:bit is connected to the computer through the micro USB data cable, and confirm whether the <\/span><strong><span style=\"font-family: Arial; font-size: 16px;\">WOM_Sensor_Kit<\/span><\/strong><strong><span style=\"font-family: Arial; font-size: 16px;\"> <\/span><\/strong><strong><span style=\"font-family: Arial; font-size: 16px;\">Python library<\/span><\/strong><span style=\"font-family: Arial; font-size: 16px;\"> has been imported.<\/span><\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\"><strong><span style=\"font-family: Arial; font-size: 16px;\">7. Experimental phenomena<\/span><\/strong><\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: Arial; font-size: 16px;\">After the program is downloaded successfully. We control UFO catcher movement and Gripping-release by rocker module.<\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\">We can place red, green, and blue blocks on the color sorter to allow the machine to sort. <\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\">Place a red block under the color recognition module on the platform. The color sorter will tilt to the left and the blocks will fall. <\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\">Place a green block under the color recognition module on the platform. The color sorter will tilt to the right and the blocks will fall. <\/span><\/p><p style=\"margin-right: 0px; margin-left: 0px; text-indent: 0px; line-height: 1.75em;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 16px;\">Place a blue block under the color recognition module on the platform. The color sorter will tilt to the front and the blocks will fall. <\/span><\/p><p><br\/><\/p>","videotype":2,"videoname_1":"``http:\/\/www.yahboom.net\/xiazai\/WOM_Kit_Microbit\/Python\/Creative\/Servo-calibration-color-sorter.py","videoname_2":"``http:\/\/www.yahboom.net\/xiazai\/WOM_Kit_Microbit\/Python\/Creative\/Color-sorter.py","videoname_3":"``","videoname_4":"``","videoname_5":"``","videoname_6":"``","newimg":0,"dataurl":"","customurl":"","documentation_switch":"","classificationid":0,"paixu":0,"adddate":"1628251052"},[["","","http:\/\/www.yahboom.net\/xiazai\/WOM_Kit_Microbit\/Python\/Creative\/Servo-calibration-color-sorter.py","Servo-calibration-color-sorter.py"],["","","http:\/\/www.yahboom.net\/xiazai\/WOM_Kit_Microbit\/Python\/Creative\/Color-sorter.py","Color-sorter.py"]]]