The Official Raspberry Pi Projects Book - Projects_Book_v4

(singke) #1

Tutorial


raspberrypi.org/magpi The Official Raspberry Pi Projects Book 115


and an automatic download of the JSON key should
begin. Keep track of this file! You should now use
an FTP program (such as FileZilla) or Samba (see
our tutorial at youtu.be/CEYwYqkAPfA) to move
the JSON file over to your Raspberry Pi. Place the
JSON file in the home directory /home/pi.

>STEP-08
Prepare the Raspberry Pi
We need to run a few commands to prepare the
Raspberry Pi. We only need to do this one time.
In the command line, run the following commands:

EMPATHYBOT


Above This project really only works well on non-bearded
humans. Beards interfere with the software

Above This project was tested on babies
and it works just fine on them too



STEP-04
Attach the sensors
We use the button sensor to give us an easy way to start
the robot up once the code is running, and the distance
sensor to judge how far we are from the human. Hang
the ultrasonic distance sensor from the front of the
GoPiGo, using small zip ties, and attach the button
to the top of the GoPiGo, also using zip ties.




STEP-05
Setup a free Google Cloud Vision account
You can use your Gmail or Google account to set this up.
At the time of publication, Google offers a 60-day free
account – magpi.cc/2hAk0tI.




STEP-06
Create a new project
This is an abbreviated version of the setup process.
You can see a pictorial walkthrough of how to set
up a new project in Google Cloud Vision online
here: magpi.cc/2hAhHqc.
Create a new project called ‘vision1’. Enable the Cloud
Vision API for vision1.




STEP-07
Download and install your JSON credentials
Head back to the Console in Google Cloud. Find
the box titled ‘Use Google APIs’ and click ‘Enable
and manage APIs’. Click on Credentials and Create
Credentials. Credentials is on the left-hand side,
with a picture of a key next to it. Select ‘Create
a Service Account Key’. Under Service Account,
select New Service Account. We’ll call this ‘vision’.
Finally, create a role. We’ll give the new role full
access, so select Project and Owner to give the Pi
full access to all resources. A pop-up window should
appear telling you that you have created a new key,



Language
>PYTHON

DOWNLOAD:
magpi.cc/2hAgqiT

sudo pip install --upgrade pip
sudo apt-get install libjpeg8-dev
sudo pip install --upgrade google-api-python-client
sudo pip install --upgrade Pillow
sudo apt-get install python-picamera

Finally, make the credentials we downloaded in the
previous step available to Python:

export GOOGLE_APPLICATION_
CREDENTIALS=filename.json

Here, replace ‘filename’ with the name of your JSON file.

>STEP-09
Run the code
If you’ve taken the code from our GitHub repo, or typed
it out yourself, you can now run the code:

sudo python empathybot.py

Point the robot towards your human subject, press the
Grove button on the GoPiGo, and let your robot start
interacting with some humans!
Free download pdf