SkillAgentSearch skills...

PiBot

Raspberry Pi robot with iOS, Android app and web UI

Install / Use

/learn @shaqian/PiBot
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

中文文档

PiBot

Raspberry Pi robot with iOS, Android app and web UI.

Demo

App

UI

App

Vision

Assembly

Assembly

Parts list

  • Raspberry Pi v3 Model B

  • Camera: 8MP Raspberry Pi Camera v2

  • Micro SD Card

    8G or above.

  • USB Sound Card

    I'm using this.

  • Microphone

    3.5mm jack, I'm using this.

  • Speaker

    Mini speaker with 3.5mm jack.

  • Robot Car Kit: ZK-4WD

  • Motor driver: L298n

  • 5v Power Supply

    Powers the Raspberry Pi.

  • Battery Power Supply

    Two 18650 (3.7v) batteries with battery case. Powers the motor driver.

  • DC-DC Converter: LM2596S

    Converts 7.4v to 5v to power the servo.

  • Servo: SG90 9g

  • Servo Mount

    I'm using this (keyword: 2 Axis Servo Gimbal FPV Camera Platform), but with only 1 servo because there're only two unique channels of hardware PWM output and I need to reserve one for IR.

  • IR Transmitter

    Initially I used the IR module for Arduino: KY-005, but the range was short.

    Then I found this (keyword: 1/3W High Power IR Transmitter Module For Arduino) that can get several meters.

  • IR Receiver: KY-022 (IR Receiver for Arduino)

  • Bread Board: SYB-170

  • DuPont Line

    20 or 30cm male to female.

  • Resistors

    1/4W 1kΩ & 2kΩ.

Circuit Diagram

Motor Driver and Motors

The "9v" battery is actually two 3.7v 18650 batteries.

Motor Schematic

Motor BreadBoard

Servo

The "9v" battery is actually two 3.7v 18650 batteries.

Servo Schematic

Servo BreadBoard

Temperature and Humidity Sensor

Temperature and Humidity Sensor Schematic

Temperature and Humidity Sensor BreadBoard

IR Receiver

IR Receiver Schematic

IR Receiver BreadBoard

IR Transmitter

IR Transmitter Schematic

IR Transmitter BreadBoard

Set Up Raspberry Pi and Network Connection

1) Install OS (with a Mac)

  • (Optional) Format SD card

    1. Install SD Card Formatter.

    2. Open SD Card Formatter and choose Overwrite Format.

    3. Click Format.

  • Install Raspbian from image (Official doc)

    1. Download .zip file for RASPBIAN STRETCH WITH DESKTOP.

    2. Unzip the file to extract the image, ie: 2017-07-05-raspbian-jessie.img.

    3. Open a terminal and run diskutil list. You will see a list of all your disks.

    4. Connect the SD card reader with the SD card inside.

    5. Run diskutil list again, identify the disk (not the partition) of your SD card, e.g. disk3, not disk3s1.

    6. Unmount your SD card by using the disk identifier: sudo diskutil unmountDisk /dev/disk[n] (replacing [n] with the number of the disk, ie: /dev/disk3).

    7. Copy the image to your SD card: sudo dd bs=1m if=[path-to-the-image-file] of=/dev/rdisk[n] conv=sync (replacing [path-to-the-image-file] ie: ~/Downloads/2017-07-05-raspbian-jessie.img, and replacing [n] with the number of the disk, ie: /dev/rdisk3).

2) SSH to Raspberry Pi (Official doc)

  1. Enable SSH:

    For Raspbian released after the end of Nov 2016, SSH is disabled by default. It can be enabled by placing a file named ssh, without any extension, onto the boot partition of the SD card.

  2. Eject your SD card and insert it into the Raspberry Pi.

  3. Connect the Raspberry Pi to your home router with a ethernet cable, then power it using a micro USB charger.

  4. Determine the IP address of the Raspberry Pi. If you do not have access to the router, open a terminal and run sudo nmap -sP -PI -PT 192.168.1.0/24 to scan all the devices in your home network.

  5. Open a terminal, run ssh pi@[IP-of-Raspberry-Pi] (replacing [IP-of-Raspberry-Pi] with actual IP address, ie: 192.168.1.16), enter default password raspberry.

  6. (Optional) Change password: passwd pi.

3) (Optional) Configure Graphical Remote Desktop (Official doc)

  1. If VNC connect is not yet installed on your Raspberry Pi, run
sudo apt-get update
sudo apt-get install realvnc-vnc-server realvnc-vnc-viewer
  1. To enable VNC Server, run sudo raspi-config, navigate to Interfacing Options, scroll down and select VNC > Yes.

  2. Open VNC Viewer, enter your Raspberry Pi's IP address to connect.

4) Connect to Wifi (Official doc)

  1. Run cat /etc/network/interfaces. Make sure you have:
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
  1. Run sudo vi /etc/wpa_supplicant/wpa_supplicant.conf. Go to the bottom of the file and add the following:
network={
    ssid="{Name-of-the-Wifi}"
    psk="{Password-of-the-Wifi}"
}
  1. Run sudo service networking restart to take effect. Now you can unplug the ethernet cable and use wifi only.

Install Prerequisites

1) Python 3.x

If which python3 returns nothing, run sudo apt-get install python3.

2) NodeJs 8.x

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt install nodejs
node -v

3) Nginx Server

Install the nginx package sudo apt-get install nginx and start the server sudo /etc/init.d/nginx start.

4) Audio & Video related

Install the library for ALSA applications development files: sudo apt-get install libasound2-dev. If you got 404 Not Found, run sudo apt-get upgrade --fix-missing.

avconv is needed for converting recorded videos to .mp4 format: sudo apt-get install libav-tools

mpg123 is used for playing .mp3 format music: sudo apt-get install mpg123

5) Clone the repo

cd ~
git clone https://github.com/shaqian/PiBot.git

Set up and Test Hardware Components

1) Motor driver and motors

Do not install the wheels when testing.

  1. Refer to the circuit diagram and connect the wires.

  2. Install rpio, run npm install rpio.

  3. Start node, run node.

  4. Initialize output:

var rpio = require('rpio');
rpio.open(29, rpio.OUTPUT, rpio.LOW);
rpio.open(31, rpio.OUTPUT, rpio.LOW);
rpio.open(38, rpio.OUTPUT, rpio.LOW);
rpio.open(40, rpio.OUTPUT, rpio.LOW);
  1. Go forward:
rpio.write(29, rpio.LOW);
rpio.write(31, rpio.HIGH);
rpio.write(38, rpio.LOW);
rpio.write(40, rpio.HIGH);
  1. Go backward:
rpio.write(29, rpio.HIGH);
rpio.write(31, rpio.LOW);
rpio.write(38, rpio.HIGH);
rpio.write(40, rpio.LOW);
  1. Stop:
rpio.write(29, rpio.LOW);
rpio.write(31, rpio.LOW);
rpio.write(38, rpio.LOW);
rpio.write(40, rpio.LOW);

2) Servo

  1. Refer to the circuit diagram and connect the wires.

  2. Run:

cd ~/PiBot/PiBotServer/bin
chmod +x direct.py
  1. The position is controlled by duty cycle, normally ranges from 2.5 to 11.5. Go to middle position:
./direct.py 7
  1. Full left:
./direct.py 2.5
  1. Full right:
./direct.py 11.5

3) Temperature and Humidity Sensor

  1. Refer to the circuit diagram and connect the wires.

  2. Run:

cd ~/PiBot/PiBotServer/bin/temp_hum
chmod +x getTemp.py
chmod +x getHum.py
  1. Get temperature:
./getTemp.py
  1. Get humidity:
./getHum.py

4) IR Receiver

I use IR Receiver to read IR signal from remote controls of home appliances, then emulate the remote control by sending the same signal from Raspberry P.

I borrowed the code from this repo but changed the ports as well as the value of ST_BASE which was 0x20003000 for older Raspberry Pi but should be 0x3F003000 for Raspberry Pi 3 (BCM2837).

  1. Refer to the circuit diagram and connect the wires.

  2. Run gpio -v to check if wiringPi is already installed. If not, install Wiring Pi.

  3. Run cd ~/PiBot/PiBotServer/bin. Compile the code and generate the binary:

gcc ir_decode.c -lwiringPi -o decode.out
chmod +x decode.out
  1. Run sudo ./decode.out. It would print [0] every one second when no IR signal is received.

  2. Point the remote control to the IR receiver and press the button. The decoded IR signal is a series of hex numbers, ie: 0xb2,0x4d,0x1f,0xe0,0x98,0x67,[48].

  3. Repeat the same for "ON" button and "OFF" button, and note down the IR signals.

5) IR Transmitter

Disconnect the IR Receiver as we are done with IR decoding.

  1. Refer to the circuit diagram and connect the wires.

  2. Run the following to duplicate the ir_encode code.

cd ~/PiBot/PiBotServer/bin
cp ir_encode.c on.c
cp ir_encode.c off.c
  1. Run vi on.c, and change the hex string in line 166 to what you have decoded, ie:
char data[6] = {0xb2,0x4d,0x1f,0xe0,0xd8,0x27};
  1. Run vi off.c, and change the hex string in line 166 to what you hav

Related Skills

View on GitHub
GitHub Stars76
CategoryDevelopment
Updated5mo ago
Forks38

Languages

JavaScript

Security Score

97/100

Audited on Nov 4, 2025

No findings