Tag Archives: MagPi

A Google Assistant with the Raspberry Pi

This is the age of smart home assistants, but not the human kind. The last couple of years a fever pitch has been building up over these smart home assistants, and every manufacture is now offering their own version. While Apple offers Siri, Amazon presents Echo and Alexa, Microsoft wants us to use Cortana, and Google tempts us with Google Home Assistant, there are several more in the race. However, in this melee, Raspberry Pi (RBPi) enthusiasts can make their own smart speaker using the SBC.

Although you can buy Google Home, the problem is it is not available worldwide. However, it is a simple matter to have the Google Assistant in your living room, provided you have an RBPi3 or an RBPiZ. Just as with any other smart home assistant, your RBPi3 home assistant will let you control any device connected to it, simply with your voice.

The first thing you need to communicate with your assistant is a microphone and a speaker. The May issue MagPi, the official RBPi magazine, had carried a nice speaker set sponsored by Google. However, if you have missed the issue, you can use any speaker and USB microphone combination available. The MagPi offer is an AIY Voice Kit for making your own home assistant. AIY is an acronym coined from AI or Artificial Intelligence, and DIY or DO it Yourself.

The MagPi Kit is a very simple arrangement. The magazine offers a detailed instruction set anyone can follow. If you do not have the magazine, the instructions are available on their AIY projects website. The contents of the kit include Voice HAT PCB for controlling the microphone and switch, a long PCB with two microphones, a switch, a speaker, an LED light, a switch mechanism, a cardboard box for assembling the kit, and cables for connecting everything.

Apart from the kit, you will also require additional hardware such as an RBPi3, a micro SD card for installing the operating system, a screwdriver, and some scotch tape.

After collecting all the parts, start the assembly by connecting the Voice HAT PCB. It controls the microphones and the switch, and you attach it to the RBPi3 or RBPiZ using the two small standoffs. Take care to align the GPIO connectors on the HAT to that on the RBPi, and push them in together to connect.

The combination of the HAT board and RBPi will go into the first box. You will need to fold the box taking care to keep the written words on the outside. Place the speaker inside the box first, taking care to align it to the side with the holes. Now, connect the cables to the Voice HAT, and place the combination inside the box.

Next, assemble the switch and LED, inserting the combination into the box. Take care to connect the cables in proper order according to the instructions. As the last step, use the PCB with the two microphones, and use scotch tape to attach it to the box.

Now flash the SD card with the Voice Kit SD image from the website, and insert it into the RBPi. Initially, you may need to monitor the RBPi with an HDMI cable, a keyboard, and mouse.

Voice HAT for Raspberry Pi for Controlling a Motor

If you were one of the unlucky ones to miss out on the issue 57 of the MagPi, then the only option is to buy the Voice HAT from the AIY projects. The issue 57 had offered a free AIY projects Voice Kit, which Google had developed to make a Voice Assistant, and you could control a speaker with the voice HAT that attached on top of a Raspberry Pi Zero (RBPiZ).

Other tutorials in the MagPi show how to connect the Voice HAT hardware to simple circuits.  So far, the tutorials have dealt with LED lights and servomotors, but this project is somewhat more complex—using the Voice HAT to control a DC motor. Therefore, you will need a DC motor, four AA size batteries, breadboard, and jumper wires.

Usually, the RBPiZ draws its power from the power supply on the Voice HAT board. For this project, this connection has to be broken, else the motor may draw too much power from the RBPiZ and short it. On the Voice HAT board, locate the external power jumper marked JP1, and use a sharp knife to cut the track. If you later wish the power to be shared again between the board and the RBPiZ, re-solder the cut joint.

Power off the RBPiZ and the Voice HAT, and connect the positive terminal of the DC motor to Driver 0, middle pin, which is marked with a “+” symbol. Same way, the negative terminal of the DC motor connects to the “–“ pin of the Driver 0. As this pin connects to the GPIO4 pin, it allows the motor to be turned on and off.

The four AA battery pack connects to the +V and GND pins on the Voice HAT. This ensures the motor is supplied adequate power from the battery pack and the Voice HAT and does not crash the RBPiZ when it draws power. Now turn on the power to the Voice HAT, and then turn on the battery pack.

At this point, you are ready to turn on power to the RBPiZ. Boot into the AIY Projects software and enter the code from motor.py for testing the circuit. The control to the motor comes from the PWMOutputDevice from GPIO Zero, and this allows managing the speed of the motor.

The motor is controlled via a Pulse Width Modulation (PWM) method. The RBPiZ controls the power to the motor by controlling the on and off periods. If the on period is more than the off period, the motor receives more power and therefore, rotates faster.

To manage the speed of the motor, you control the variables .on() and .off() in the software.  Alternately, you may set the value of the instance variable to a value between 0.0 and 1.0 for controlling the speed. Here, 0.0 means the motor is a dead stop, while 1.0 sets the motor to a maximum speed. The motor.py uses both techniques and you can also use pwm.pulse() for pulsing the motor on or off. To integrate this with the Voice Assistant, enter the code from add_to_action.py to the relevant sections. You can now control the motor using voice commands.

Talk to your Raspberry Pi

The Raspberry Pi Foundation has tied up with Google for a project called the Artificial Intelligence Yourself or AIY. This is a Hardware on Top or HAT project for the Raspberry Pi 3 (RBPi3) to transform the single board computer into a virtual assistant. This is the first time that Google is offering something exclusively for hobbyists, and the kit comes free with the printed issue 57 of the MagPi—the official magazine of the Raspberry Pi.

The kit with the MagPi magazine consists of a Voice HAT board, a speaker, a stereo microphone board, a large arcade push button, and a set of wires. This is all one needs to add-in voice integration to the RBPi3, turning it into a personal Alexa alternative. Alexa is an intelligent personal assistant developed by Amazon. Intelligent personal assistants are capable of offering real time information, such as news, traffic, weather, apart from playing audiobooks, streaming podcasts, setting alarms, making to-do lists, playing back music, and most importantly, capable of voice integration.

The MagPi magazine contains all the build instructions for putting together the free hardware voice kit; you only need to add the RBPi3 to get it working. There is also a custom cardboard case to house the entire kit along with the RBPi3. Apart from the RBPI3, the AIY voice project will work with an RBPi2 and an RBPiZW as well. Once the hardware is assembled, you will need some software setup, with access to the Google Assistant SDK and Google Cloud Speed API.

The MagPi 57 issue offers several voice integration ideas for the AIY voice kit and you can enhance them or build your own projects. For instance, you can have a voice integration project to answer all your questions just as Alexa does. Alternately, you can create a voice-controlled robot. In fact, some owners of RBPi are building secret AIY projects at Hackster.

According to Billy Rutledge, Google’s director on the project, the AIY project demonstrates a practical method of starting and running a natural language recognizer in conjunction with the Google Assistant. Not only will you have all the functions of the Google Assistant, you can as well add your own pairs of questions and answers.

The Voice Kit and RBPi3 combination acts as a voice recognizer and uses the Google Assistant SDK to recognize speech. For evaluating local commands, it uses a local Python application. You can talk to the Google Assistant, which makes use of the Google Cloud Speech API to answer back. If you wish to use voice capabilities in your future projects, check out the Maker’s guide for more creative extensions.

The arcade style button has additional functions other than initiating the speech interaction. A bright LED mounted within the button signals to verify your device is running properly through different types of blinking. For instant, the LED pulses to indicate the device is just starting up, and the voice recognizer has not started functioning yet. Once the device is ready to be used, the LED blinks every few seconds. The LED glows steadily when the device is listening, and pulses if the device is thinking or responding.