PiJuice Robotic Project

This project will show you how to use the PiJuice HAT to power separate device other than the Raspberry Pi. In this project we are going to use the PiJuice HAT to power a motor controller board, but you can use to power other devices such as MCU’s. In this project we are going to use the Ryantek motor controller board to control two DC motors on a robotic chassis. The PiJuice HAT will power both the Raspberry Pi and the motors using the built-in VSYS, which can provide power up to 500mA and 2100mA.

What you will need

You will need the following parts to build this project. Some optional parts are required for the initial setup on the Raspberry Pi:

  • Raspberry Pi Computer
  • 16GB MicroSD card with the latest Raspbian Lite installed
  • Power supply 2.5A (To charge the battery and initial setup)
  • PiJuice HAT
  • Robotic chassis
  • 2x DC motors
  • Male to Female jumper wires

Hardware Setup

Step 1 – First thing you will want to do is to assemble the PiJuice HAT on top of the Raspberry Pi. Simply add it over the Pi’s GPIO pins making sure that they align and then push firmly down all the way. Once inserted you will need to affix the PiJuice HAT to the Pi using the supplied screws and standoffs.

Step 2 – Once the PiJuice HAT is attached the Raspberry Pi you can now add the motor controller board on top of the PiJuice HAT’s GPIO pins. The motor controller board uses the old 26-pin GPIO connector but is still pin-for-pin compatible with the Raspberry Pi 40 way header for the first 26 pins. Simply slot it on top of the male GPIO pins on the PiJuice HAT, pushing down firmly.

Step 3 – Assemble your robotic chassis. Most low cost robotic chassis will come with a front roller ball and two DC motors either side for each wheel.

Step 4 – Affix your Raspberry Pi to the top of the robot chassis. In the case for this project there were plenty of whole but none that would line up with the Pi’s. Therefore I used some hook and loop tape to fix the Pi to the chassis, this way I could also easily remove it when I need to. Alternatively you can drill some new holes in the chassis.

Step 5 – Now take the motor wires (Black, Red) and connect them to the motor controller board by inserting them into the screw terminals MOTOR-1 and MOTOR-2. At this point it doesn’t matter too much which motor connects to which screw terminal as we can swap it around in the coding when doing a quick test. Connect the black wire on the left side and the red wire on the right hand side as per the image below.

Step 6 – Now we can go ahead and connect the power for the motors and motor controller from the PiJuice HAT to the screw terminal VCC2. There are a couple fo ways you can do this from the PiJuice HAT. you can use the female header P3 or you can use the dedicated male VSYS pins under the board. In this particular project I’am going to use the VSYS pins under the PiJuice HAT. For this you can use Female to Male jumper wires.

Software Setup

For this project we are going to use the latest version of Raspbian Lite OS and then access and control the robot using SSH and some commands from a terminal.

Step 1 – Download the latest version of Raspbian Lite from the Raspberry Pi website – https://www.raspberrypi.org/downloads/raspbian/

Once downloaded flash it to you micro SD card using a program like – https://www.balena.io/etcher/

Step 2 – Before we insert the micro SD card into the Raspberry Pi and power it up we can enable SSH for remote access and also connect to your local Wi-Fi for network/internet access. This is known as a headerless setup.

MAC OS

Open up a terminal window and run this commands:

touch /Volumes/boot/ssh

touch /Volumes/boot/wpa_supplicant.conf

Edit the wpa_suplicant.conf file and add the following lines whilst adding your Wi-Fi credentials:

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="NETWORK-NAME"
    psk="NETWORK-PASSWORD"
}

Windows

  • Run Notepad
  • In a new file put in one space and nothing more
  • Click File / Save As …
  • Be sure to set Save as type to All Files (so the file is NOT saved with a .txt extension)
  • Call the file ssh and save it
  • Close the file

 

  • Run Notepad
  • Paste in the contents above (adjusting for the name of your country code, network name and network password)
  • Click File / Save As …
  • Be sure to set Save as type to All Files (so the file is NOT saved with a .txt extension)
  • Call the file wpa_supplicant.conf and save it
  • Close the file

Step 3 – Now you can insert the micro SD card into your Raspberry Pi and boot it up by pressing the SW1 button on the PiJuice HAT. After a few minutes the Raspberry Pi will begin to connect to your local Wi-Fi as set in the wpa_supplicant.conf file. Once connected you can now remotely access it over SSH from your computer.

MAC OS

Open up a terminal window and type in the following command:

ssh [email protected]

Enter the default password (raspberry) when prompted.

Windows

In windows you can connect to the Raspberry Pi via a program called putty.

Step 4 – Once logged in we can now begin to install the PiJuice software and also the Ryanteck software to control the motor controller board. In the terminal session type in the following commands:

sudo apt update

sudo apt-get install pijuice-base

The above command will firstly update the system so we can grab the latest software versions and the second will install the PiJuice software that we require.

sudo apt-get install git

git clone https://github.com/PiSupply/Ryanteck.git

Here we install a program called git, which is where all the software is located for the motor controller board. Then we create a copy of that repository on the Raspberry Pi.

Finally reboot your Raspberry Pi:

sudo reboot

Step 5 – Log back into the SSH session and from the command line type in the following to access the PiJuice command line utility:

pijuice_cli

From the menu go and change the “Power Switch” to 500mAh.

Now the VSYS on the PiJuice is providing power to the motor controller board up to 500mA maximum current.

Note: After a reboot this system power switch is reset back to its default value of “off” as it is not stored in NV memory on the MCU. This may change in future updates.

Controlling your robot

Now we have everything installed and setup ready to go. Open up the command line through SSH and type in teh following command to run your robot:

cd Ryanteck/RTK\ Motor\ Controller/Software/basicPython/codeSamples/

sudo python cliController.py

Now you can use the WASD keys on your keyboard to control the robotic by holding them down in a Forward, Reverse, Turn Left and Turn Right direction.

Summary

This project is a great example of how to utilise the VSYS functionality of the PiJuice HAT. Giving you the ability to separately power external devices such as motors or even other devices such as an Arduino board or any other MCU.

First published at 1:42pm on November 26, 2019
Last updated at 10:49am on December 4, 2019