Google’s voice assistant has been around for a while now as well as when Amazon released its Alexa API as well as ported the PaaS Cloud code to the Raspberry Pi 2 it was just a matter of time before everybody else jumped on the quick train to maker kingdom. Google just did it in style.
Few understand that the Google assistant API for the Raspberry Pi 3 has been available for a long time now however when they decided to provide away a free set with the may 2017 problems of MagPi magazine, they made an perception on everyone. unfortunately the world has more makers as well as hackers as well as the number of copies of the magazine are limited.
In this writeup, I design the diy version of the AIY set for everybody else who wishes to talk to a cardboard box. I take a better look at the free kit, take it apart, put it together as well as replace it with diy magic. To make things more convenient, I likewise designed an enclosure that you can 3D print to total the kit. lets get started.
The Teardown
A shout out to my buddy [Shabaz] in the UK for sending me a copy of the MagPi. The “Google AIY jobs Voice Kit”(henceforth understood as the kit) contains two PCBs as well as a lot of other stuff. The Voice HAT which appears like a Sound-Card-On-A-Diet has extremely restricted number of components. I will detail each section as well as draw the KiCAD schematic for the exact same one by one
Servos
Starting from the left side, there are 6 sets of 3-pin headers that are labelled ‘Servos’. The meant servo manage is made possible utilizing the Raspberry Pi 3’s on-board PWM module. Each set has a GPIO pin, 5V as well as GND connection. The GPIO pin does not link directly to the Raspberry Pi 3’s header however rather with 220Ohm present limiting resistors (labelled R1-R6).
Power Supply
Just south of these are gadgets identified Q5 as well as Q6 which I am presuming are part of a power supply choice circuit. correct me if I am wrong however right here is my estimate. The working is simple where Q5 only turns ON when the input voltage is higher than the 5V from the USB port. A simple comparator should do so I am utilizing the LM393 for reference.
EDIT: [Raivsr] explained that this might be the equivalent of the Raspberry Pi ‘Ideal Diode’.
Communication Interfaces
North of the ‘Servo’ headers is J15 labelled I2C that directly link to the Raspberry Pi 3 header. That means these should not be linked to anything with 5V pull-ups. They are not being utilized on the board however we will discuss more on this later. right next to it is the SPI as well as 2-pin UART headers. once again these link directly to the primary header as well as serve only as a breakout.
The DAC as well as EEPROM
A bit lower as well as we show up at the boxed circuit with a 16-Pin QFN marked ‘AKK BDQ’. This is the Maxim MAX98357A(PDF) which is an I2S DAC with a class D amplifier. It drives the speaker directly nevertheless since there is only one output, it can only be mono or integrated stereo. It’s still pretty rocking for the budget.
The fascinating thing is the existence of JP6 which seems to have all the I2S connections from the Maxim MAX98357A as well as a few other choose lines. integrated with the two vias that link to the second speaker output, you might potentially in shape one more Maxim MAX98357A breakout board on top to get stereo sound. I am going to do the schematic as well as make it downloadable as well as if you want to provide it a shot let me understand the results. think about it optional homework.
Next to the DAC is an 8-pin SSOP which is a 24C32 (PDF) I2C EEPROM. It’s not linked to the I2C header I talked about earlier however rather to pins 27 as well as 28 of the Raspberry Pi 3 header. According to the Raspberry Pi Foundation’s blog.
“The EEPROM holds the board manufacturer information, GPIO configuration as well as a thing called a ‘device tree‘ fragment – basically a description of the connected hardware that enables Linux to immediately tons the needed drivers.”
So its got some additional sauce that makes things tick as well as I might utilize a BusPirate to Dump the data however I am not sure if Google considers it Intellectual residential or commercial property so I won’t. I have an alternate for it also so checked out on.
Drivers
Moving towards the right, we discover 4 headers marked ‘Drivers’. These are MOSFET circuits for controlling tons such as relays. [Shabaz] did a fantastic task tracing out the elements on this as well as the 3 pins are GPIO, 5V as well as Driver.
The MOSFETs can drive tons of as much as 500mA each thanks to a polyswitch nevertheless the GPIOs are offered for utilize directly as well. tons to be driven should be linked between the pins marked ‘+’ as well as ‘-‘. The header pin on the left is a direct gain access to to GPIOs header pins from the Raspberry Pi 3 as well as the schematic shows the same.
Use these to link LEDs or similar gadgets to suggest the operation of the relays or loads.
Microphone as well as Button Connectors
More fascinating stuff is happening on the right side’s upper right with a push button as well as two JST connectors. The 4 pin connector is meant for the push button that sits on top of the assembled enclosure. The little PCB mounted push button is wired in parallel with the outside switch as well as can be utilized in its location while setting up as well as testing. The 5 pin JST is for the microphone connector as well as has all the I2S pins.
The Microphones
Lastly, the microphone board is marked 432 QDF21G, as well as has Knowles SPH0645LM4H MEMs digital microphones that talk I2S directly.
That’s It!
That about wraps up the teardown as well as all the info needed to make your own AIY Kit. The KiCAD schematic data are offered for download from GitHub nevertheless I leave you with the fun part which is the design as well as routing.
Here is some food for thought. Some parts can be omitted as well as the size of the hat can be shrunk down to the Pi Zero pHat.
For simplicity reasons, I am utilizing the preconfigured OS picture from the Google AIY page. It is a tad short of 900MB as well as can be downloaded directly from Goolge (huge file).
Add A Shutdown Button
You most likely noticed the little golden button next to the huge eco-friendly button in the picture above as well as that is the very first part of the exercise. It is a shutdown button as well as is added since I don’t want to SSH to the box every time I want to turn it off safely.
Get the button you want to utilize as well as add two wires with female headers. This bit works even without the Voice Hat so feel free to try it out. next if you have a voice hat, add male headers to the I2C part. You may select any type of other pins as well as it will still work. link the button to the SDA or GPIO 2 as well as boot the Pi 3 up.
Open up your favourite text editor as well as copy-paste the complying with code into it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/python
# simple script for shutting down the raspberry Pi at the press of a button.
# by Inderpreet Singh
import RPi.GPIO as GPIO
import time
import os
# utilize the Broadcom SOC Pin numbers
# configuration the Pin with interior pullups enabled as well as PIN in reading mode.
GPIO.setmode(GPIO.BCM)
GPIO.setup(02, GPIO.IN, pull_up_down = GPIO.PUD_UP)
# Our function on what to do when the button is pressed
def Shutdown(channel):
os.system("sudo shutdown -h now")
# add our function to execute when the button pressed event happens
GPIO.add_event_detect(02, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)
# now wait!
while 1:
time.sleep(1)
Save the data in your /home/pi folder as shutdown.py
In a terminal type the complying with commands
1
chmod +x shutdown.py python shutdown.py &
This should make the script run in the background. If you press the button, the Pi should shutdown immediately. You may select to add a delay by uncommenting the sleep phone call in the example code. Alternatively, you may likewise modification the GPIO by replacing the appropriate number in the python script.
Cool! now we can shutdown by pressing a button.
Add a USB noise Card
The obvious alternate to the Google AIY Voice Hat is to utilize any type of USB noise Cards that are offered from a number of sources. The easiest method is to just plug one in as well as configure the software application to utilize that instead of the Hat however when there two drivers installed, the python scripts requirement to be reconfigured to make whatever seamless.
Once you plug in the soundcard, the very first thing to do is inspect if it was acknowledged or not. In the terminal window, type in:
1
aplay – l
‘aplay’ is utilized by the scripts to speak out the replies so you should be able to see two noise devices. note that the onboard noise has been disabled from within the config.txt (see gadget tree reference) and can be enabled if you plan to utilize a USB microphone instead of the noise card. The windows output should look like the picture below.
I would like to set the USB noise card as the default audio, as well as for that we requirement to customize the /etc/asound.conf .
1
sudo nano /etc/asound.conf
Delete the existing material as well as replace it with text as shown below. though this sets the default input as well as output gadget to the USB device, there is one more step to make things work. (To exit nano, utilize Ctrl+x, y, return)
Next we edit to audio.py data that handles all the audio playing as well as recording functionality. For that, open up the data in your favourite text editor; mine is nano:
1
sudo nano /home/pi/voice-recognizer-raspi/src/audio.py
Scroll down to the part thatstates ‘arecord’ which is in the __init__ function. obviously there is a devoted process that keeps the recorder running as I will show in the video. For now, we want to edit the arguments to ensure that it utilizes the USB Card to catch audio instead of the original Voice Hat. A simple adjustment to utilize ‘-D’, ‘sysdefault:CARD=1’ should suffice as shown in the picture below.
A similar modification is need for the aplay function a bit further in the code.
With that, the hack is complete! double click the ‘test_audio.py’ to inspect if audio works. We are missing just one part of the puzzle though — the ‘listen’ button! So just cable a push button between GPIO23 as well as the adjacent ground pin as well as then run ‘src/main.py’ to begin playing with a diy Google AIY.
A Demo
A little video demo of the suggested hack with a USB noise card, outside speaker as well as a inexpensive microphone.
An Enclosure
The 3D printed enclosure is designed in Fusion360 as well as the STL data are part of the GitHub repository. You can utilize the exact same enclosure for a number of jobs since there are standoffs for the Raspberry Pi as well as the ports are brought out for convenience. There is a great deal of area inside to add hats as well as extra circuits.
I made the enclosure split from the middle to ensure that it becomes simple to gain access to the GPIOs. The whole thing will press in shape including the top cap which has holes for three buttons. I though it would make sense to have smaller buttons since the result is expected to be tougher than cardboard. There is ample area for the speaker should you select to include one that is somewhat different.
I have not had a possibility to print one out as well as will update this page when there is any type of development in the topic. right here is the render of the design.
Summary
Google has already had their APIs available to the public, however the preconfigured Raspbian picture will assist a great deal of people to get started. I have tried to design the fundamentals of the noise card in addition to provide out the plans for an equivalent card if you want to make one. For others the choice to utilize an outside noise card is explained as well as demonstrated as well as I hope it influences people to truly get into such projects. The world needs more AIY as well as right here is your possibility to get started, so what are you waiting for? get hacking.