===== Objective ===== This first lesson will show you how to assemble the PiBot. It will then show you how to configure and use the Raspberry Pi to control the PiBot with a simple Python program. Finally it will describe how the electronics work together to control the PiBot. ===== Parts Required ===== The parts below are required to complete this lesson. Note that all parts except the Raspberry Pi board and optional hardware are included in the [[https://www.amazon.com/OSOYOO-Raspberry-Educational-Ultrasonic-Obstacle/dp/B08JLS3J7Q|OSOYOO kit]] that can be purchased on Amazon. - Raspberry Pi 4 or 3B board - OSOYOO Top & Bottom Chassis Plates - OSOYOO Motors and wheel x2 - OSOYOO universal wheel - OSOYOO Model Pi motor driver board - OSOYOO PCA9685 compatible module - OSOYOO Voltage Meter - 18650 Battery box - 18650 batteries x2 - Jumper wires & Hardware - Optional Hardware - M2.5x5mm Hex Cap Screws - M2.5 Plastic Washers - M2.5x5mm+6mm Hex Brass Pillars - M2.5 Hex Nuts ===== Hardware Assembly ===== When handling any of the circuit boards make sure to wear your ESD wrist strap and have it connected to an earth ground point When installing items with multiple screws or nuts, leave them loose until all are installed and then tighten to ensure that you can get them all inserted When installing a board using the M2.5x5mm+6mm pillars, attach the pillars to the board with the screws and then install on the chassis with the nuts - Remove the protective film on the top and bottom car chassis plates\\ \\ Each chassis plate has only one protective film {{ :pibot:lesson1:h1.png |Remove protective film}} - Install the Metal Motor Holders from the hardware kit on the motors as shown below\\ \\ {{ :pibot:lesson1:h2.png |Install motor holders}} - Install the motors on bottom car chassis with M3x10mm screws from the hardware kit as shown below\\ \\ The M3x10mm screws are in the metal motor holder bag {{ :pibot:lesson1:h3.png |Install motors}} - Install the OSOYOO Model Pi motor driver module on bottom car chassis with with 4pcs M2.5x5mm screws, M2.5x5mm+6mm pillars, and M2.5 nuts from the hardware kit as shown below\\ \\ Make sure the OSOYOO Model Pi motor driver module is installed in the correct direction as shown on the right below If using brass pillars insert an M2.5 plastic washer between the Model Pi motor driver module and each pillar {{ :pibot:lesson1:h4.png |Install Model Pi}} - Install the PCA9685 compatible board on the bottom chassis with 4pcs M2.5x5mm screws, M2.5x5mm+6mm pillars, and M2.5 nuts from the hardware kit as shown below\\ \\ If using brass pillars insert an M2.5 plastic washer between the PCA9685 compatible board and each pillar {{ :pibot:lesson1:h5.png |Install PCA9685}} - Install the voltage meter board on the bottom chassis with 2pcs M2.5x5mm screws, M2.5x5mm+6mm pillars, and M2.5 nuts from the hardware kit as shown below\\ \\ If using brass pillars insert an M2.5 plastic washer between the voltage meter board and each pillar {{ :pibot:lesson1:h6.png |Install voltage meter}} - Install the universal wheel on the bottom chassis with 2pcs M3x10mm screws and M3 nuts from the hardware kit as shown below\\ \\ {{ :pibot:lesson1:h7.png |Install universal wheel}} - Install 4pcs M3x45mm brass pillars from the hardware kit on the bottom chassis with 4pcs M3x10mm screws and M3 plastic washers from the hardware kit as shown below\\ \\ {{ :pibot:lesson1:h8.png |Install brass pillars}} - Connect the wires between the boards on the bottom chassis as described below - Connect the 2pin 20cm and 3pin 20cm female to female cables to the PCA9685 compatible board as shown below - Connect the 6pin flying lead cable between the Model Pi motor driver board and the PCA9685 compatible board as shown below - Connect the motors to the Model Pi motor driver board as shown below - Connect the 3pin 15cm female to female between the voltage meter and the Model Pi motor driver board as shown below - Connect the USB cable to the Model Pi motor driver board as shown below\\ \\ Create loops in the wires by wrapping them around your finger to keep the wiring neat Use the USB-A to USB-C cable for the Raspberry Pi 4. Use the USB-A to USB-micro B cable for the Raspberry Pi 3B. {{ :pibot:lesson1:h9.png |Install Cables}} {{ :pibot:lesson1:wire1.png |PCA9685 wires}} {{ :pibot:lesson1:wire2.png |Model Pi control wires}} ^ Model Pi Motor Driver Board ^ PCA9685 Module ^ Raspberry Pi Board ^ | @-black:ENA | PWM 0 | --- | | @-purple:IN1 | --- | Pin 16 (GPIO 23) | | @-green:IN2 | --- | Pin 18 (GPIO 24) | | @-yellow:IN3 | --- | Pin 13 (GPIO 27) | | @-lightgrey:IN4 | --- | Pin 15 (GPIO 22) | | @-red:ENB | PWM 1 | --- | {{ :pibot:lesson1:wire3.png |Model Pi motor wires}} {{ :pibot:lesson1:wire4.png |Voltage Meter wires}} ^ Model Pi Motor Driver Board ^ Voltage Meter ^ | @-red:VIN | VT | | @-red:5V | VCC | | @-black:GND | GND | {{ :pibot:lesson1:wire5.png |USB power cable}} - Install the Raspberry Pi board on the top chassis with 4pcs M2.5x5mm screws, M2.5x5mm+6mm pillars, and M2.5 nuts from the hardware kit as shown below\\ \\ If using brass pillars insert an M2.5 plastic washer between the Raspberry Pi board and each pillar {{ :pibot:lesson1:h10.png |Install Raspberry Pi}} - Install the 18650 battery box on the top chassis with 4pcs M3x10mm flat screws and M3 nuts from the hardware kit as shown below\\ \\ {{ :pibot:lesson1:h11.png |Install 18650 battery box}} - Install the top chassis on the bottom chassis with 4pcs M3x10mm screws and M3 plastic washers as shown below\\ \\ Feed the wires from the bottom chassis through the holes on the top chassis before screwing it down {{ :pibot:lesson1:h12.png |Install top chassis}} - Connect the 18650 battery box to the Model Pi board as shown below\\ \\ {{ :pibot:lesson1:wire6.png |18650 Battery wires}} - Connect the PCA9685 compatible board to the Raspberry Pi board as shown below\\ \\ Create loops in the wires by wrapping them around your finger to keep the wiring neat {{ :pibot:lesson1:wire7.png |PCA9685 wires}} ^ PCA9685 Module ^ Raspberry Pi Board ^ | @-red:V+ | Pin 2 (5V) | | @-red:VCC | Pin 4 (5V) | | @-blue:SDA | Pin 3 (GPIO 2) | | @-red:SCL | Pin 5 (GPIO 3) | | OE | --- | | @-black:GND | Pin 9 (GND) | - Connect the Model Pi board flying leads to the Raspberry Pi board as shown below\\ \\ {{ :pibot:lesson1:wire8.png |Model Pi control wires}} ^ Model Pi Motor Driver Board ^ PCA9685 Module ^ Raspberry Pi Board ^ | @-black:ENA | PWM 0 | --- | | @-purple:IN1 | --- | Pin 16 (GPIO 23) | | @-green:IN2 | --- | Pin 18 (GPIO 24) | | @-yellow:IN3 | --- | Pin 13 (GPIO 27) | | @-lightgrey:IN4 | --- | Pin 15 (GPIO 22) | | @-red:ENB | PWM 1 | --- | - Connect the Model Pi board USB to the Raspberry Pi board as shown below\\ \\ {{ :pibot:lesson1:wire9.png |USB power cable}} - Install the wheels on the motors with 2pcs M2.2x22mm self-tapping screws as shown below\\ \\ The wheels are very snug fitting to the motor shafts and may require significant force. Brace the opposite side of the motor shaft when pushing them on. {{ :pibot:lesson1:h13.png |Install wheels}} ===== Software ===== Select the appropriate link below for instructions to setup the software on the PiBot and an exploration of how it works. * [[:pibot:lesson1:softwaremac|MacOS]] * [[:pibot:lesson1:softwarewin|Windows]] ===== Electrical Description ===== The OSOYOO Model Pi motor driver board is the heart of the PiBot. It is an improved L298N module which can power the motors and the Raspberry Pi at the same time. This board supports all the features of the L298N DC motor drive and also has a USB 5V output port which provides a stable voltage to the Raspberry Pi board up to 2.4A. It is fully compatible with the L298N control input signals ENA, IN1, IN2, IN3, IN4, and ENB. Each channel has two output sockets, K1 and K2 for the right side motors and K3 and K4 for the left side motors. The input power source can be any voltage between 7.5V and 24V. Recommended battery configurations are 2pcs tandem 18650 batteries, 6pcs tandem AA batteries, or 2pcs parallel 9V batteries. The ENA input to the Model Pi board gets a PWM signal from the PCA9685 compatible board which is controlled by the Raspberry Pi. This creates an analog current through the motor using the L298N H-bridge. The higher the PWM value from the Raspberry Pi, the more current will go through the motor, and the faster the motor will spin. The ENA input controls the K1 and K2 outputs which are connected to the right side motors. The ENB input to the Model Pi board gets a separate PWM signal from the PCA9685 compatible board. This creates an analog current through the motor using the L298N H-bridge in the same way that the ENA input works. The ENB input controls the K3 and K4 outputs which are connected to the left side motors. The IN1 and IN2 inputs to the Model Pi board get digital signals from the Raspberry Pi. These inputs control the L298N H-bridge to determine the direction that the motor rotates. When IN1=HIGH(1) and IN2=LOW(0) the motor moves forward. When IN1=LOW(0) and IN2=HIGH(1) the motor moves backward. The IN1 and IN2 inputs control the K1 and K2 outputs which are connected to the right side motors The IN3 and IN4 inputs to the Model Pi board get separate digital signals from the Raspberry Pi. These inputs control the L298N H-bridge to determine the direction that the motor rotates in the same way that the IN1 and IN2 inputs work. The IN3 and IN4 inputs control the K3 and K4 outputs which are connected to the left side motors The PCA9685 compatible board connects to the Raspberry Pi I2C bus. The Raspberry Pi can send commands to the PCA9685 compatible board to create the PWM signals used for the ENA and ENB signals to the Model Pi board. The PCA9685 compatible board has 16 PWM outputs, but the PiBot only use two of them, PWM0 and PWM1. The Raspberry Pi is the brains of the PiBot. It runs the Python programs which send the commands to the Model Pi board in order to make the PiBot do what you want it to do. It also can receive status from sensors that tell it where it is and allow it to make decisions about what to do without you. This capability will be explored in the following lessons. [[:pibot:start|Return to Main PiBot page]]