-
Notifications
You must be signed in to change notification settings - Fork 0
License
chenphilip888/rpi4b-python-i2samp
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Python i2s experiments on Raspberry PI 4B board. The following 10 tests are included: ( see below for tests summary ) 1. speech_recog.py 2. sound_recorder.py 3. i2s_wavefile.py 4. i2s_lcd.py 5. i2s_servo.py 6. piano.py 7. littlestar.py 8. playmidi.py 9. kusc_fmradio.sh 10. youtube_audio.sh ------------------------------------------------------------------- To compile and flash to sd card: cd rpi4b-python-i2samp Download OS: wget https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2020-12-04/2020-12-02-raspios-buster-armhf-lite.zip unzip 2020-12-02-raspios-buster-armhf-lite.zip Use balenaEtcher to burn img to sd card. eject sd card. Plugin sd card to PC. To enable I2S add dtparam=i2s=on in /boot/config.txt sudo cp config.txt /media/$USER/boot sync sudo umount /media/$USER/boot eject sd card. Plugin the sd card to Raspberry PI 4B board. Connect gpio Pin 8 to serial USB cable TX. Connect gpio pin 10 to serial USB cable RX. Connect gpio pin 39 to serial USB cable ground. Type "script ~/outputfile.txt" on PC. Plugin serial USB cable to PC. Type "sudo screen /dev/ttyUSB0 115200" on PC. Power on Raspberry PI 4B board. It should prompt login message. user pi password raspberry sudo raspi-config set password, wifi, locale, timezone, peripheral etc. vi nosleep.sh ( add following line to disable sleep feature ) sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.ta rget ./nosleep.sh sudo dmesg -n 1 sudo vi /etc/rc.local ( add sudo dmesg -n 1 ) sudo ifconfig sudo apt-get update sudo apt-get upgrade sync sudo reboot ./nosleep.sh sudo apt-get install python-dev python-pip python-setuptools python3-dev python3-pip python3-setuptools dnsutils apache2 vsftpd ftp pavucontrol libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev libasound2-dev flac python-smbus ffmpeg mpg123 libffi-dev python-pygame vlc sync Because pulseaudio cannot work with i2smic we need to remove pulseaudio. sudo apt-get remove --purge pulseaudio sudo apt autoremove \rm -rf ~/.config sudo pip install pyaudio sudo pip install SpeechRecognition sudo pip install sounddevice sudo pip install soundfile sudo pip install numpy sudo pip install youtube_dl vi /etc/asound.conf sudo \rm /etc/alsa/conf.d/* sudo vi /usr/share/alsa/alsa.conf ( commented out pcm.cards and 21 lines below it ) sudo pip3 install --upgrade adafruit-python-shell curl -sS https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/i2samp.sh | bash ( enter y N y y ) reboot sudo vi /boot/config.txt ( delete dtoverlay=hifiberry-dac ) sync sudo umount /boot sudo reboot wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/i2smic.py sudo python3 i2smic.py ./nosleep.sh lsmod git clone https://github.com/chenphilip888/rpi4b-python-i2samp.git sudo cp ~/rpi4b-python-i2samp/asound.conf /etc/asound.conf sudo /etc/init.d/alsa-utils restart sudo cat /proc/device-tree/soc/i2c@7e804000/status sudo cat /proc/device-tree/soc/pwm@7e20c000/status sudo cat /proc/device-tree/soc/i2s@7e203000/status ls /sys/class/pwm sudo apt-get install i2c-tools sudo i2cdetect -y 1 Download gpio library on Raspberry PI 4B board: wget https://project-downloads.drogon.net/wiringpi-latest.deb sudo dpkg -i wiringpi-latest.deb gpio -v ( make sure it's v2.52 or above ) gpio readall sudo reboot ------------------------------------------------------------------------- Here are the summary of the tests: See GPIO-Pinout-rpi4b.png and https://www.raspberrypi.org/documentation/usage/gpio These tests used Seeed Grove-LCD RGB Backlight V3.0 JHD1313M2, Analog Servo, Adafruit SPH0645 I2S Mic and Adafruit MAX98357 I2S Class-D Mono Amp. To use Adafruit SPH0645 I2S Mic see https://learn.adafruit.com/adafruit-i2s-mems-microphone-breakout/overview To use Adafruit MAX98357 I2S Class-D Mono Amp see https://learn.adafruit.com/adafruit-max98357-i2s-class-d-mono-amp I2S_Mic: Connect gpio pin 35 to LRCL. Connect gpio pin 38 to DOUT. Connect gpio pin 12 to BCLK. Connect gpio pin 9 to GND. Connect gpio pin 1 to 3V. I2S_AMP: Connect gpio pin 35 to LRC. Connect gpio pin 40 to DIN. Connect gpio pin 12 to BCLK. Connect gpio pin 9 to GND. Connect gpio pin 2 to Vin. Connect 8 ohm speaker to screw-terminal. I2C_LCD: Connect gpio pin 3 to lcd display SDA. Connect gpio pin 5 to lcd display SCL. Connect gpio pin 2 to lcd display 5V. Connect gpio pin 6 to lcd display ground. Servo: Connect gpio pin 33 to servo control. Connect gpio pin 4 to servo 5V. Connect gpio pin 14 to servo ground. 1. speech_recog.py When prompt "say something", speak to Microphone for 3 seconds. It will print what you said. 2. sound_recorder.py When prompt "recording...", speak to Microphone for 3 seconds. It will save sound to 'file.wav'. 3. i2s_wavefile.py It will read 'file.wav' and print what you said in 'file.wav'. Then you can type "aplay file.wav" to hear what you said. 4. i2s_lcd.py When prompt "say stop to exit", speak to Microphone for colors of your choice. It will display colors of your choice to LCD background color. 5. i2s_servo.py When prompt "say stop to exit", you can command servo to turn right, turn left or stay in the middle by speaking to Microphone. 6. piano.py Push keyboard 'z'-'.', 'a'-'l', 'q'-'o', '1'-'9', esc to quit. 7. littlestar.py Play little star song. 8. playmidi.py Play midi song. 9. kusc_fmradio.sh Play real time KUSC FM Radio station. 10. youtube_audio.sh Play youtube audio. ----------------------------------------------------------------------------- Here are the procedure to test the above 10 tests: I2S_Mic: Connect gpio pin 35 to LRCL. Connect gpio pin 38 to DOUT. Connect gpio pin 12 to BCLK. Connect gpio pin 9 to GND. Connect gpio pin 1 to 3V. I2S_AMP: Connect gpio pin 35 to LRC. Connect gpio pin 40 to DIN. Connect gpio pin 12 to BCLK. Connect gpio pin 9 to GND. Connect gpio pin 2 to Vin. Connect 8 ohm speaker to screw-terminal. To clean alsamixer settings: sudo \rm /var/lib/alsa/asound.state sudo chmod -x /usr/sbin/alsactl sudo reboot cat /proc/asound/cards arecord -l aplay -l sudo chmod +x /usr/sbin/alsactl repeate following steps twice: arecord -D dmic_sv -c2 -r 44100 -f S32_LE -t wav -V mono -v file.wav alsamixer ( adjust PCM volume to 86 % and Capture volume to 75%, then press F5 ) sudo /etc/init.d/alsa-utils restart arecord -c2 -r 44100 -f S32_LE -t wav -V mono -v file.wav aplay file.wav sudo reboot arecord -c2 -r 44100 -f S32_LE file.wav aplay file.wav aplay /usr/share/sounds/alsa/Front_Center.wav mpg123 http://ice1.somafm.com/u80s-128-mp3 cd ~/rpi4b-python-i2samp chmod 755 *.py *.sh ./speech_recog.py ./sound_recorder.py ./i2s_wavefile.py ./i2s_lcd.py ./i2s_servo.py sudo ./piano.py sudo ./littlestar.py ./playmidi.py ./kusc_fmradio.sh ./youtube_audio.sh When done all tests: sudo shutdown -h now Power off Raspberry PI 4B board. Unplug serial USB cable from PC. Type "exit" on PC. ------------------------------------------------------------------------------
About
No description, website, or topics provided.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published