Raspberry Pi - makerforgetech/modular-biped GitHub Wiki

Once assembled, the software can be installed on the Raspberry Pi and run with the following steps.

Note: You may not need all steps if you do not have all the hardware components.

Clone the repository

This project uses github for version control. Clone the repository to your Raspberry Pi.

git clone https://github.com/dmt-labs/modular-biped.git

In your terminal, navigate to the cloned directory and select the branch you would like to use. The main branch is the most stable and up to date. The dev branch is used for development and may not be stable.

git checkout main

The following commands assume you are using a terminal and are in the project directory.

Coral TPU Accelerator (optional)

If you'd like to use the Googla Coral USB Accelerator, first flash the Pi SD card with the image found in the AIY Maker Kit (Download as of 2022-08-05)

(I attempted to install the required software from the coral getting started guide but I was unable to get past an error relating to grpico "GLIBC_2.29' not found")

Alternatively, set Config.vision.tech to opencv for the original (slower) facial recognition. I am not updating this anymore so you may find some integration issues.

Installation

An installation bash script is available. Grant execute permissions and run.

chmod 777 install.sh
./install.sh

Configuration

All general and feature specific configuration can be added to the config file config.py in the project modules directory.

Each item in the configuration must match your hardware setup.

To run on startup, add a call to the ./startup.sh script to /etc/rc.local

Servos

The servo ranges are defined in both the modules/config.py file and the arduino_sketch/Config.h file. These must match your hardware setup.

Once the servos have been initialised, the arduino software prevents the servos to move outside of these ranges. This is to prevent damage to the servos and robot.

Important: this does not apply to the initialisation positions, so be careful which values you set here.

For more information see the Arduino page.

Running

./startup.sh

Testing

PyTest is used for testing. To run all tests:

python3 -m pytest --cov=modules --cov-report term-missing

Test classes are sparse at the moment, but will be added as the project progresses.

Feature specific configuration

Auto shutdown

Add the startup command to the boot file on the pi (edit /etc/rc.local) This can then be stopped by running the ./stop.sh command in the project directory.

GPIO 26 is also wired to allow shutdown when brought to ground via a switch.

Guide: https://howchoo.com/g/mwnlytk3zmm/how-to-add-a-power-button-to-your-raspberry-pi

Script:

#!/usr/bin/env python

import RPi.GPIO as GPIO
import subprocess

GPIO.setmode(GPIO.BCM)
GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.wait_for_edge(26, GPIO.FALLING)

subprocess.call(['pkill', '-f', 'main.py'], shell=False) # kill main script safely
subprocess.call(['shutdown', '-h', 'now'], shell=False)

Neopixel

For the Pi 5 and latest PCB, the neopixels are connected via a driver board (see bill of materials). This allows the neopixels to be controlled via the I2C bus.

WS1820B support can be included via the Pi GPIO pin 12 on the Pi 4 and earlier versions. Unfortunately this blocks audio output. (see the discussion)

sudo vim /boot/config.txt
#dtparam=audio=on

The application must be executed with sudo if neopixels are used.

For these reasons the Neopixel eye is being replaced with an RGB alternative.

https://learn.adafruit.com/neopixels-on-raspberry-pi/python-usage

Buzzer

A buzzer is connected to GPIO 27 to allow for tones to be played

Motion Sensor

An RCWL-0516 microwave radar sensor is equipped on GPIO 13

Stereo i2s MEMS Mics

GPIO 18, 19 and 20 allow stereo MEMS microphones as audio input. This involves additional configuration steps to enable.

Mic 3V to Pi 3.3V
Mic GND to Pi GND
Mic SEL to Pi GND (this is used for channel selection, connect to either 3.3V or GND)
Mic BCLK to BCM 18 (pin 12)
Mic DOUT to BCM 20 (pin 38)
Mic LRCL to BCM 19 (pin 35)

https://learn.adafruit.com/adafruit-i2s-mems-microphone-breakout/raspberry-pi-wiring-test

sudo apt-get -y update
sudo apt-get -y upgrade

Reboot

cd ~
sudo pip3 install --upgrade adafruit-python-shell
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/i2smic.py
sudo python3 i2smic.py

Test

arecord -l arecord -D plughw:0 -c2 -r 48000 -f S32_LE -t wav -V stereo -v file_stereo.wav

Note: See below for additional configuration to support voice recognition

Speech Recognition

Trigger word for voice recognition (currently not used): https://snowboy.kitt.ai/

Speech recognition is enabled whenever a face is visible. Ensure that the device_index specified in modules/speechinput.py matches your microphone. (see below).

See scripts/speech.py to list input devices and test. See below for MEMS microphone configuration

MEMS Microphone configuration for speech recognition

By default the Adafruit I2S MEMS Microphone Breakout does not work with speech recognition.

To support voice recognition on the MEMS microphone(s) the following configuration changes are needed.

sudo apt-get install ladspa-sdk

Create /etc/asound.conf with the following content: (On the line slave.pcm "plughw:0", replace the 0 with the index of your card from arecord -l)

pcm.pluglp {
    type ladspa
    slave.pcm "plughw:0"
    path "/usr/lib/ladspa"
    capture_plugins [
   {   
      label hpf
      id 1042
   }
        {
                label amp_mono
                id 1048
                input {
                    controls [ 30 ]
                }
        }
    ]
}

pcm.lp {
    type plug
    slave.pcm pluglp
}

This enables the device 'lp' or 'pluglp' to be referenced in voice recognition. Shown with index 18 in the example below. Note: The module will automatically detect the device with the name lp or pluglp and use the correct index.

Sample rate should also be set to 16000

mic = sr.Microphone(device_index=18, sample_rate=16000)

I would also advise setting the default device to pluglp:

sudo vim /etc/asound.conf

then modify slave.pcm within the pcm.!default entry:

pcm.!default {
    type    plug
    slave.pcm   "pluglp"
}

And save. This allows the MEMS microphone to be used as the default mic.

References:

Serial communication with Arduino

In order to use the Raspberry Pi’s serial port, we need to disable getty (the program that displays login screen)

sudo raspi-config -> Interfacing Options -> Serial -> "Would you like a login shell to be accessible over serial" = 'No'. Restart

Connection via serial pins

Connect the Pi GPIO 14 & 15 (tx & rx) to the arduino tx & rx (tx -> rx in both directions!) via a logic level shifter, as the Pi is 3v3 and the arduino is (most likely) 5v.

Upload to Arduino over serial pins

The sketch on the arduino can be updated directly from the Raspberry Pi using the Arduino IDE. For more information see the Arduino page.

PCB Layout

A custom PCB has been designed to connect to the Raspberry Pi. This is available in the circuits folder.

The Pi 5 PCB is the latest completed version that supports the Raspberry Pi. Take a look at the discussion for more information on this build.

There is also an earlier version built for the Pi 3b+ available. See below.

To print the PCB, upload the gerber files to a PCB printing service such as PCBWay.

Pi 5 PCB

See the full schematic for more information (click to enlarge):

PCB layout

PCB Files.

Pi 5 head gerber zip for printing

There are details of the PCB build process in the playlist

Pi 3b+ PCB

Version 3 is a simpler version that supports the Raspberry Pi. PCB layout

PCB Files

Pi 3b+ head gerber zip for printing

The following shows the pins in use on the Raspberry Pi using the custom PCB. See the wiki for more information on the features.

The PCBs connect to the Arduino PCB (see the Arduino page for details on the Arduino PCB pinout).

LLC+MEMS+I2C - 3V3  (1) (2)  5V - Power
         I2C GPIO2  (3) (4)  5V
         I2C GPIO3  (5) (6)  GND
             GPIO4  (7) (8)  GPIO14 - TX/RX
      Ground - GND  (9) (10) GPIO15 - TX/RX
            GPIO17 (11) (12) GPIO18 - MEMS
   Buzzer - GPIO27 (13) (14) GND
            GPIO22 (15) (16) GPIO23
               3V3 (17) (18) GPIO24
            GPIO10 (19) (20) GND
             GPIO9 (21) (22) GPIO25
            GPIO11 (23) (24) GPIO8
               GND (25) (26) GPIO7
             GPIO0 (27) (28) GPIO1
             GPIO5 (29) (30) GND
             GPIO6 (31) (32) GPIO12
   Motion - GPIO13 (33) (34) GND
     MEMS - GPIO19 (35) (36) GPIO16
 Shutdown - GPIO26 (37) (38) GPIO20 - MEMS
        MEMS - GND (39) (40) GPIO21

Problems?

This project is a work in progress. If you have issues or questions please raise an issue on github and myself or one of the contributors can help.