User Tools

Site Tools


pibot:lesson1:softwarewin

Software Setup

  1. Use the Raspberry Pi Imager utility to program the Raspberry Pi OS image to the microSD card as shown below.
    1. Insert the microSD card in the microSD card reader and plug the microSD card reader into the computer

      Insert microSD card

    2. Open the rpi-imager app from the Applications\Raspberry Pi Imager folder on the Flash drive

      If it ask “Do you want to allow this app to make changes to your device?” click the “Yes” button

    3. Select the “CHOOSE OS” button

      Initial Screen

    4. Select the “Raspberry Pi OS (other)” option from the list

      Selecting Image Type

    5. Select the “Raspberry Pi OS Lite (32-bit)” option from the list

      Selecting Image File

    6. Select the “CHOOSE STORAGE” button

      Main Screen

    7. Select the microSD card

      The size of the microSD card should be approximately 16GB

      If the microSD card already has an image on it then it will show Mounted as /Volumes/boot

      Selecting microSD card

    8. Hold down the Shift + Control + X keys at the same time to open the Advanced options window
    9. Click the box next to the “Set hostname:” option and change the value to “pibot##” where the ## comes from the label on the PiBot

      Use the Backspace key to delete the value already there

      Advanced options - Hostname

    10. Click the box next to the “Enable SSH” option and set the password for the pi user to “DogsAndCatsAreNice2.”

      Advanced options - SSH

    11. Scroll down, click the box next to the “Configure wifi” option and type the SSID, password, and select the Wifi country for your Wifi network

      The SSID and password for will be filled in by default based on the network your computer is connected to

      Click the box next to the “Show password” option to see the Wifi password

      If your wireless network doesn't have a password, skip this step and follow the instructions here after finishing the steps below to write the SD Card

      If you are outside the United States then use the Wifi country code with the appropriate ISO 3166 alpha-2 country code

      Advanced options - Wifi

    12. Scroll down, click the box next to the “Set locale settings” option and select the Timezone and Keyboard settings for your location

      The Timezone and Keyboard will be filled in by default based on your computer settings

      If you are outside the United States then use the Timezone with the appropriate TZ Database Time Zone

      Advanced options - Locale

    13. Click the Save button to close the Advanced options window and return to the main window
    14. Select the “WRITE” button

      Final Screen

    15. Click the “YES” button when asked if you want to continue

      If asked for your password to continue, enter it to give permission to write to the microSD card

      Confirmation Prompt

    16. When the Raspberry Pi Imager utility has finished, click the “CONTINUE” button and close the Raspberry Pi Imager utility
    17. Remove the microSD card reader from the computer
  2. Remove the microSD card from the microSD card reader and plug it into the Raspberry Pi board as shown below

    Insert microSD card

  3. Install charged 18650 batteries in the 18650 battery box and slide the switch to the “ON” position
  4. Wait 3-5 minutes for the green light to stop flashing
  5. Open the putty app from the Applications\PuTTY\<version> folder on the Flash drive

    The <version> folder will be something like “0.75”. Use the latest version available.

  6. Type “pibot##” in the Host Name (or IP address)“ box where the ## comes from the label on the PiBot.

    PuTTY Configuration

  7. Click the “Open” button to connect to the Raspberry Pi terminal via SSH

    PuTTY Open Connection

  8. If a “PuTTY Security Alert” window pops up, click the “Accept” button\

    PuTTY Security Alert

  9. Type “pi” at the “login as:” prompt and press Enter

    The password to enter when prompted is “DogsAndCatsAreNice2.” without the quotes. The '.' at the end is important!

    PuTTY Login

  10. Perform the following steps to enable the I2C interface on the Raspberry Pi board
    1. Type the following command and press enter to run the Raspberry Pi configuration utility

      sudo raspi-config
    2. Use the up and down arrow keys to select the “Interfacing Options” menu item and then press the enter key

      Main Menu

    3. Use the up and down arrow keys to select the “I2C” menu item and press the enter key

      Interface Menu

    4. Use the left and right arrow keys to select the “Yes” option and press the enter key

      I2C Enable

    5. Select the “Ok” option and press the enter key

      I2C Confirmed

    6. Use the left and right arrow keys to select the “Finish” option and press the enter key

      Exit

  11. Type the following commands and press enter after each line to install the rpi.GPIO library and the PIP3 application

    Answer “yes” or “y” when asked to install extra packages or continue

    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install python3-rpi.gpio python3-pip
  12. Type the following command and press enter to install the Adafruit-pca9685 library

    sudo pip3 install adafruit-pca9685
  13. Type the following commands and press enter to create a directory for the PiBot code

    mkdir -p ~/pibot
    cd ~/pibot
  14. Type the following command and press enter to download the Python code for this lesson

    wget http://osoyoo.com/driver/picar/picar-basic.py
  15. Place the PiBot on the floor in an area that is free of any obstacles
  16. Type the following command and press enter to make the PiBot move

    python3 picar-basic.py
  17. Type the following command and press enter to close the SSH connection

    exit

Software Explanation

  1. To view the code that makes the PiBot run perform the following steps
    1. Open the VSCode from the Applications directory on the flash drive
    2. Click on the small green square in the bottom left corner of the screen

      VSCode Main Screen

    3. Select the “Remote-SSH: Connect Current Window to Host…” option

      VSCode Remote-SSH

    4. Type “pi@pibot##” and press enter

      Replace the text “pibot##” with the label on the PiBot

      If a “Windows Security Alert” window pops up, click the “Allow access” button

      It may take a couple of minutes while it installs some files on the PiBot

      VSCode Remote Connection

    5. Select “Linux” for the platform of the remote host

      If it asks “are you sure you want to continue” select “continue” to finish connecting

      The password to enter when prompted is “DogsAndCatsAreNice2.” without the quotes. The '.' at the end is important!

      It may take a couple of minutes while it installs some files on the PiBot

      VSCode Remote Connection

  1. Click the “Open Folder” button

    VSCode Open Folder

  2. Select the “pibot” folder and click the “OK” button

    The password to enter when prompted is “DogsAndCatsAreNice2.” without the quotes. The '.' at the end is important!

    If it asks “Do you trust the authors of the files in this folder?” click the “Yes, I trust the authors” button

    VSCode Browse

  3. Select the picar-basic.py file in the list on the left

    If it asks to install the recommended extensions, click the install button

    The password to enter when prompted is “DogsAndCatsAreNice2.” without the quotes. The '.' at the end is important!

    VSCode picar-basic.py

  4. Find line 20 in the picar-basic.py file. What is the name of the variable? What value is assigned to the variable? What do you think this value controls on the PiBot?

    The line numbers are displayed to the left of each line of text and are a feature of the Visual Studio Code editor

    Variables are short “words” that can hold values. They allow you to change the value in one place and have it updated in multiple places in the code. They also allow the code to change the value of the variable.

    Values are assigned to variables using the '=' character

  5. Find the other places in the code where this variable is used. How many of them are there?
    \\

    When you see some text followed by a '(' with some more text and then a ')' that is a function call. The text before the '(' is the function name. The text between the '(' and ')' are parameters that get passed to the function. What the function does is defined by a 'def' in front of the function name somewhere in the code.

    Functions allow a common set of steps to be used in many places in the code without having to type in all of those steps each time.

  6. Find the definition of the function that uses the variable. What does the function do?

    In the definition of the function, the text between the '(' and ')' may be different from when it is called. When the function is called, the variable that is passed to it replaces the name from the definition.

    See the Electrical Description section on the previous page for a description of what the pwm does

  7. How would you change the code to make the PiBot move faster? How about to make it move slower? Make one of those changes to the code and save it using File→Save.
  8. Open a terminal in Visual Studio Code from the Terminal→New Terminal menu
  9. Type the following command and press enter to make the PiBot move with your changes

    python3 picar-basic.py
  10. Try out the other change to the code following the same steps
  11. When you're finished testing out your changes type the following command in the terminal and press enter to shutdown the PiBot

    sudo shutdown -h now
  12. Click on the small green rectangle in the bottom left corner of the screen and select “Close Remote Connection”
  13. Wait 3-5 minutes for the green light on the Raspberry Pi to stop flashing and turn off the switch on the PiBot battery

Return to Lesson 1

"O LORD, how manifold are your works! In wisdom have you made them all; the earth is full of your creatures. - Psalm 104:24"
pibot/lesson1/softwarewin.txt · Last modified: 2022/10/20 21:53 by 127.0.0.1