Building Line Following Robot Using Maker Pi Pico, Maker Drive and Maker Line

Building Line Following Robot Using Maker Pi Pico, Maker Drive and Maker Line

OVERVIEW

Raspberry Pi Pico is the 1st Microcontroller Development Board from Raspberry Pi Foundation. It is also based on the 1st Microcontroller IC/Silicon - RP2040, designed and produced by Engineers from the Raspberry Pi team too.

Maker Pi Pico is Raspberry Pi Pico's extension board developed by Cytron Technologies. Maker Pi Pico gives you access to all Raspberry Pi Pico's pins on two 20 ways pin headers, with clear labels. Each GPIO is coupled with an LED indicator for convenient code testing and troubleshooting. The bottom layer of this board even comes with a comprehensive pinout diagram showing the function of each pin. 

Maker Drive is a easy and beginner-friendly motor driver.  Maker Drive is designed for simplicity and with the beginner in mind.  Maker Drive is designed to be compact, roughly the size of a passport photo. Maker Drive has 4 Test Buttons (2 for each channel), 4 Indicator LEDs (2 for each channel). 

Maker line is a easy and beginner-friendly line sensor. Maker Line also supports dual outputs: 5 x digital outputs for the state of each sensor independently which is similar to conventional IR sensor, but you get the benefit of easy calibration; One analog output where its voltage represents the line position. Analog output also offers higher resolution compared to individual digital outputs. 

HARDWARE SETUP

 

Parts

Wiring & Assembly

 

Solder the wires to the motors.

 

 

 

Mount motors to robot chassis. 

 

 

 

Pass the wires through the chasis hole as shown below.

 

Tighten a 5mm PCB Stand on the chasis with the screw to mount Maker Drive.

  

Tighten a 5mm PCB Stand to Maker Drive.

  

Mount Maker Drive on the chasis. Only one PCB Stand is screwed to chasis.

 

Connect the wires to Maker Drive and mount the wheel to the motors. 

 

Tighten a screw on the chasis as shown below to mount Maker Pi Pico later.

 

Stick a double-sided tape on the chasis and place battery holder (with battery) on it.

 

Connect the battery wires to Maker Drive and check the motors are running correctly.

Img 20210310 161128

Turn on the switch on battery holder and  press button M1A & M2A on Maker Drive, the motors should be moving forward. Swap the wires if the motors are moving in wrong directions.

Img 20210310 161128 768x1024

 

Place 15mm and 10mm PCB Stand together (or use 25mm PCB Stand) and tighten it to chasis.

Img 20210310 161659

Screw Maker Pi Pico with the PCB Stand.

Img 20210315 115239

Add PCB Stand to the remaining 3 sides of the Maker Pi Pico.

  

Connect the wires as shown below to power up Maker Pi Pico.

  

Connect wires from Maker Pi Pico to Maker Drive.

  

Tighten two 5mm PCB Stand at the bottom of chasis.

 

Install Maker Line with 10mm PCB Stand.

 

 

Connect wires from Maker Pi Pico to Maker Line.

 

Install ultrasonic sensor into the ultrasonic bracket.

 

Install ultrasonic sensor with bracket into the chasis.

 

Connect wires from Maker Pi Pico to ultrasonic sensor.

 

SOFTWARE SETUP

 

Installing MicroPython

Step 1: Hold down the ‘BOOTSEL’ button on the top of your Pico; then, while still holding it down connect a micro USB cable into the micro USB port on your Pico and computer. Count to three, then let go of the ‘BOOTSEL’ button.

Step 2: Pico appear as a removable drive, as though you’d connected a USB flash drive or external hard drive. You’ll see two files on your Pico - INDEX.HTM and INFO_UF2.TXT. Point the mouse cursor at the first file - INDEX.HTM and double-click it to open it in your browser.

1

 

Step 3: When the browser opens, click on the MicroPython tab to load the MicroPython-specific section of the page. Click on the ‘Download UF2 file’ button to download the MicroPython firmware.

2

 

Step 4: Copy the downloaded file to Pico’s removable storage drive.

3

 

Step 5: After a few seconds you’ll see your Pico disappear from File Manager.

Installing Thonny

Step 1: Open your web browser, visit thonny.org, and click the download link at the top of the page to download the Thonny installer.

Step 2: Open the Thonny software, with your Pico connected to your computer, click on the word ‘Python’ followed by a version number at the bottom-right of the Thonny window. In the list that appears, look for MicroPython (Raspberry Pi Pico) and click on it. If you can’t see it in the list, double-check that your Pico is properly plugged in to the micro USB cable and that the micro USB cable is properly plugged in to your computer.

4

 

CODING

 

Move Around

In this part, we will be learning on how to code the robot to move forward, reverse, turn left and turn right.

Add Library

Step 1: Download the library file (motor_driver.py) from here

Step 2: Launch Thonny application and open the library file

11

 

Step 3: Save the library file into the Raspberry Pi Pico

12

13

 

Step 4: Save the library with the same name you downloaded with (motor_driver.py) Must add .py at the back

14

 

Step 5: Click OK and the library is added to your Pi Pico

 Get the library documentation here

Move Forward

Step 1: Open a new empty file.

Step 2: Copy & paste these code into your Thonny IDE.

Step 3: Save the file in Raspberry Pi Pico.

1 2

Step 3: Save the file as 'main.py' and click OK. Must add .py at the back.

3

Turn on the robot by using the switch at battery holder. The robot will move forward.

Move Backward

Follow the steps from "Move Forward" and add the code below.

Turn Left

Follow the steps from "Move Forward" and add the code below.

Turn Right

Follow the steps from "Move Forward" and add the code below.

Aadgif

Brake

Follow the steps from "Move Forward" and add the code below.

Example codes to drive the motors are here

Detect Object

In this part, we will be learning on how to code the robot to read ultrasonic sensor.

Follow the steps from "Move Forward" and add the code below.

 

This program will print ultrasonic distance in the unit of cm on the Thonny shell.
Example code to read ultrasonic is here

Line Following

In this part, we will be learning on how to code the robot to read line sensor and follow the line.

Follow the steps from "Move Forward" and add the code below.

This program will print line sensor analog value on the Thonny shell.


Follow the steps from "Move Forward" and add the code below.

.

This line follow example is the combination of the three program above .