Raspberry Pi [zero] talking encyclopedia
Raspberry Pi zero Encyclopedia is a testimony that Pi zero is far superior to other MCUs of same form factors.
Raspberry Pi zero talking Encyclopedia
Prelude: openai.com can answers various questions in it’s chatgpt terminal. It can write codes for you. Even if you ask him about a song of someone, except singing the song, it will bring the lyrics full for you because it cannot sing song! Here Raspberry Pi zero will emulate an automated terminal through voice interactions. The cost of the project will be INR:2500 [USD $30 only]
This feat is unthinkable on the MCU level boards like - Arduino, Arduino Mega 2560, ESP32 or others. Those who still works with Arduino or other MCUs like ESP32, Arduino MEGA 2560, Maixduino or Seeduino, I will tell them to start working with small SBCs like Raspberry Pi zero, Nano Pi zero, Banana Pi zero or Orange Pi zero because you can do more with same or even less form factor and almost for same or little more cost with giving more versatility to your projects! These boards are becoming smaller and smaller in the coming days. What more? you can straight way works on Python micro python or any other preferred languages on these boards. These small SBCs do not have on board ADC [analog to digital converter]. However, that can be overcome by adding inexpensive chips like -CP3008, ADS1115, or PCF8591 to their I2C or SPI ports. I can say if the Arduino fever is over now then the small computer cum MCU like boards like Pi zero, Orange Pi , Nano Pi, Banana Pi are poised to conquer the coming days!
Sound output on Pi Zero: There is no sound output on Pi-Zero board. One has to connect an HDMI device [in other words a TV ] on Pi-Zero to get sound. However, there are another easier way which is shown in the schematic. Any two of the four PWM GPIO pins [12,13,18,19] can be used to force audio output by adding just one single line in /boot/config.txt file - [dtoverlay=audremap,pins_18_13] .Just open the file and go to the bottom and add this line followed by a reboot. Next time you will be able to hear audio on those two GPIO pins. Just add a headphone on the IN-L & IN-R to get sound on the headphone. So simple! The PAM8403 amplifies the sound further for a speaker.
Schematic of audio output on Pi-zero:
This PAM8403 is rated for 5Volt but it works on 3.3 volt with a small speaker.
BOM of this project: source Alibaba.com01. Raspberry Pi zero 2W - USD $25 02. PAM8403 Amplifier - USD $103. 4OHM Speakers - 02 nos. USD $1 / piece04. USB microphone - USD $1 to $20 [depending on variety]05. OTG cable for connecting USB microphone - USD $1 or less
Project code: First you need to get your chatgpt api-key which is available for free from openai.com. Please register your email address and then get the api-key which need to be inserted in the api-key variable in vi_chatgpt.py code.
button_listener.py = This is a button press code, which monitors a GPIO button [17 here, you can change it]. Once the button is pressed, it will start a shell program - vi_chatgpt.sh.
vi_chatgpt.sh = This code will start the main code - vi_chatgpt.py. After making this code, this code is to be made executable by issuing a command like this.$> chmod +x vi_chatgpt.sh [+x means making it executable]
vi_chatgpt.py = Main project code which when finishes, will release control to button_listener.py again to monitor the next button press event.
Sequence of Operations: On boot of the Pi zero board, the button_listener.py program will start on background and waits for the button press signal. On pressing the button [which is also made bounce_free to avoid repeated running of same program], the device will ask you to speak the question. Once you complete the question within 10 seconds, the device will seek your confirmation through a yes or no audio response. On saying no, it will ask you to start all over again. If yes, it will ask chatgpt to provide the answer. Once it receives the answer, it will speak it out the entire answer for you. After the sequence, it will wait for button press! The loop goes endless!
Autostart on boot: To make the code fires up on every boot of Pi-zero, first ensure that the Pi zero logs automatically into console mode [or graphics mode], Then in home folder [/home/bera/] there is a .profile file, open that file using any editor like nano or vi.$> nano /home/bera/.profile , At the end of that file attach this line. Save it and close it.python /home/bera/button_listener.py &Next time you reboot, the program will start automatically and will wait for button press event!
Softwares: Some softwares you may need to install first.$> pip install open$> pip install speech_recognition$> pip install subprocessThe USB microphone is quite sensitive to catch sound from the corner of the room while the microphone is placed on the other end. The ceiling fan is to be avoided or can be run at slow speed.
Aftermath: It is possible to even replace the ‘button press’ event by a fixed audio command like - ‘Daisy start’ or ‘Daichi start’ etc. like in amazon Alexa ]. but it makes the Pi-zero operation distinctively slow but sure it will work better in Pi-4 or Pi-5.
Somnath BeraKolkata.
Prelude: openai.com can answers various questions in it’s chatgpt terminal. It can write codes for you. Even if you ask him about a song of someone, except singing the song, it will bring the lyrics full for you because it cannot sing song! Here Raspberry Pi zero will emulate an automated terminal through voice interactions. The cost of the project will be INR:2500 [USD $30 only]
This feat is unthinkable on the MCU level boards like - Arduino, Arduino Mega 2560, ESP32 or others. Those who still works with Arduino or other MCUs like ESP32, Arduino MEGA 2560, Maixduino or Seeduino, I will tell them to start working with small SBCs like Raspberry Pi zero, Nano Pi zero, Banana Pi zero or Orange Pi zero because you can do more with same or even less form factor and almost for same or little more cost with giving more versatility to your projects! These boards are becoming smaller and smaller in the coming days. What more? you can straight way works on Python micro python or any other preferred languages on these boards. These small SBCs do not have on board ADC [analog to digital converter]. However, that can be overcome by adding inexpensive chips like -CP3008, ADS1115, or PCF8591 to their I2C or SPI ports. I can say if the Arduino fever is over now then the small computer cum MCU like boards like Pi zero, Orange Pi , Nano Pi, Banana Pi are poised to conquer the coming days!
Sound output on Pi Zero: There is no sound output on Pi-Zero board. One has to connect an HDMI device [in other words a TV ] on Pi-Zero to get sound. However, there are another easier way which is shown in the schematic. Any two of the four PWM GPIO pins [12,13,18,19] can be used to force audio output by adding just one single line in /boot/config.txt file - [dtoverlay=audremap,pins_18_13] .Just open the file and go to the bottom and add this line followed by a reboot. Next time you will be able to hear audio on those two GPIO pins. Just add a headphone on the IN-L & IN-R to get sound on the headphone. So simple! The PAM8403 amplifies the sound further for a speaker.
Schematic of audio output on Pi-zero:
This PAM8403 is rated for 5Volt but it works on 3.3 volt with a small speaker.
BOM of this project: source Alibaba.com01. Raspberry Pi zero 2W - USD $25 02. PAM8403 Amplifier - USD $103. 4OHM Speakers - 02 nos. USD $1 / piece04. USB microphone - USD $1 to $20 [depending on variety]05. OTG cable for connecting USB microphone - USD $1 or less
Project code: First you need to get your chatgpt api-key which is available for free from openai.com. Please register your email address and then get the api-key which need to be inserted in the api-key variable in vi_chatgpt.py code.
button_listener.py = This is a button press code, which monitors a GPIO button [17 here, you can change it]. Once the button is pressed, it will start a shell program - vi_chatgpt.sh.
vi_chatgpt.sh = This code will start the main code - vi_chatgpt.py. After making this code, this code is to be made executable by issuing a command like this.$> chmod +x vi_chatgpt.sh [+x means making it executable]
vi_chatgpt.py = Main project code which when finishes, will release control to button_listener.py again to monitor the next button press event.
Sequence of Operations: On boot of the Pi zero board, the button_listener.py program will start on background and waits for the button press signal. On pressing the button [which is also made bounce_free to avoid repeated running of same program], the device will ask you to speak the question. Once you complete the question within 10 seconds, the device will seek your confirmation through a yes or no audio response. On saying no, it will ask you to start all over again. If yes, it will ask chatgpt to provide the answer. Once it receives the answer, it will speak it out the entire answer for you. After the sequence, it will wait for button press! The loop goes endless!
Autostart on boot: To make the code fires up on every boot of Pi-zero, first ensure that the Pi zero logs automatically into console mode [or graphics mode], Then in home folder [/home/bera/] there is a .profile file, open that file using any editor like nano or vi.$> nano /home/bera/.profile , At the end of that file attach this line. Save it and close it.python /home/bera/button_listener.py &Next time you reboot, the program will start automatically and will wait for button press event!
Softwares: Some softwares you may need to install first.$> pip install open$> pip install speech_recognition$> pip install subprocessThe USB microphone is quite sensitive to catch sound from the corner of the room while the microphone is placed on the other end. The ceiling fan is to be avoided or can be run at slow speed.
Aftermath: It is possible to even replace the ‘button press’ event by a fixed audio command like - ‘Daisy start’ or ‘Daichi start’ etc. like in amazon Alexa ]. but it makes the Pi-zero operation distinctively slow but sure it will work better in Pi-4 or Pi-5.
Somnath BeraKolkata.
Diskussion (0 Kommentare)