Difference between revisions of "MakaPython Audio"
(→Project_1: Text to speech) |
(→Project_1: Text to speech) |
||
Line 119: | Line 119: | ||
| align="center" | 0 | | align="center" | 0 | ||
|} | |} | ||
+ | Note: when GPIO12 set to LOW, the internal LDO (VDD_SDIO) output 3.3V; when GPIO12 set to HIGH, the internal LDO (VDD_SDIO) output 1.8V, so it may get fails when you download the firmware if you had insert the Makepython Audio. | ||
Step:<br> | Step:<br> | ||
− | 1. | + | 1. Connecting MakePython ESP32 to PC via microUSB cable.<br> |
− | 2. | + | 2. Open flash_download_tools_v3.6.8,Select ESP32 DownloadTool<br> |
− | [[File: | + | [[File:MakePython_Audio_06.png|500px]]<br> |
− | + | 3. Select the related COM port, baud rate 921600,erase the ESP32 first.<br> | |
+ | [[File:MakePython_Audio_07.png|500px]]<br> | ||
+ | Note: In my PC, there is COM272 that may different in your PC.<br> | ||
+ | 4. Find the firmware bin file esp32_tts.bin,address 0x1000<br> | ||
+ | [[File:MakePython_Audio_08.png|500px]]<br> | ||
+ | 5. Click the START to download the firmware.<br> | ||
+ | [[File:MakePython_Audio_09.png|500px]]<br> | ||
+ | Wait until it finished.<br> | ||
+ | [[File:MakePython_Audio_10.png|500px]]<br> | ||
+ | 6. Insert the ESP32 board to Makepython Audio<br> | ||
+ | [[File:MakePython_Audio_11.png|500px]]<br> | ||
+ | 7. Open uPyCraft, select com port from '''Tools->Serial'''<br> | ||
+ | [[File:MakePython_Audio_12.png|500px]]<br> | ||
+ | 8. Select esp32 from '''Tools->Board'''<br> | ||
+ | [[File:MakePython_Audio_13.png|500px]]<br> | ||
+ | 9. Connect the Makepython ESP32 board.<br> | ||
+ | [[File:MakePython_Audio_14.png|500px]]<br> | ||
+ | 10. Open main.py from '''File->Open''', you can get the code from here: [https://github.com/Makerfabs/MakePython-Audio main.py]<br> | ||
+ | [[File:MakePython_Audio_15.png|500px]]<br> | ||
+ | 11. Click DownloadAndRun Button to download the main.py file to Makepython ESP32. | ||
+ | [[File:MakePython_Audio_16.png|500px]]<br> | ||
+ | Input say("hello,world") it will speech hello world. | ||
+ | |||
+ | Or also, you can update the firmware via command terminal, such as: | ||
+ | esptool.py --chip esp32 --port COM272 erase_flash | ||
+ | esptool.py --chip esp32 --port COM272 write_flash --flash_mode dio -z 0x1000 esp32-tts.bin | ||
+ | |||
+ | Code Show | ||
<pre> | <pre> | ||
− | from machine import | + | from machine import I2S |
− | import | + | from machine import Pin |
− | import | + | import array |
− | + | import speech | |
+ | |||
− | + | bck_pin = Pin(26) | |
− | + | ws_pin = Pin(25) | |
− | + | sdout_pin = Pin(27) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | audio_out = I2S(I2S.NUM0, | |
− | + | bck=bck_pin, | |
− | + | ws=ws_pin, | |
− | + | sdout=sdout_pin, | |
− | + | standard=I2S.PHILIPS, | |
− | + | mode=I2S.MASTER_TX, | |
+ | dataformat=I2S.B16, | ||
+ | channelformat=I2S.ONLY_RIGHT, | ||
+ | samplerate=16000, | ||
+ | dmacount=16, | ||
+ | dmalen=512) | ||
− | + | a = bytearray(16000*8) | |
− | + | size = speech.say('Hello, wolrld', a) | |
− | + | audio_out.write(a[:size]) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | def say(text): | |
− | + | a = bytearray(16000*8) | |
− | + | size = speech.say(text, a) | |
− | + | audio_out.write(a[:size]) | |
− | + | ||
− | + | ||
− | + | def close(): | |
− | + | audio_out.deinit() | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</pre> | </pre> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
===Project_2: Display SMS message on OLED display=== | ===Project_2: Display SMS message on OLED display=== |
Revision as of 07:14, 2 July 2020
Contents
Introduction
The MakePython Audio board uses the uDA1334 digital to analog converter (DAC), which converts I2S (not be confused with I2C) audio to an analog signal to drive speakers. The I2S Audioboard converts the digital audio signals using the I2S standard to an analog signal.
Model: xxxxxxxx
Features
• NXP Low power Audio DAC: uDA1334
• Integrated digital filter plus DAC
• Supports sample frequencies from 8 to 100 kHz
• Automatic system clock versus sample rate detection
• Low power consumption
• I2S-bus and LSB-justified format compatible
• Digital de-emphasis for 44.1 kHz sampling rate
• Support Micro SD Card
• Working Temperature: -40 – 85℃
• Size: 70*32.6mm
Interface Function
①toggle switch
②toggle switch
③Audio IC:uDA1443
④D3: PWR LED
⑤microSD card
⑥D1:LED controlled by IO21
⑦audio jack(3.5mm)
Required Materials
1. Makepython ESP32
2. MakePython Audio v2.0
3. microUSB Cable
4. Speaker
5. PC
6. SD card
System diagram
Makepython Audio can’t worl alone, it need work with Makepython ESP32(Wrover).
Application
You can get Makepython ESP32(Wrover) from:
https://www.makerfabs.com/makepython-esp32.html
Note: Makepython ESP32 Wroom’s RAM is not enough for audio application, so you need Makepython ESP32(Wrover)
Usage
Warning: Don't operate when powered on in case of short circuit.
This guides help you how to use makepython Audio with Makepython ESP32 to fulfill text to speech(TTS). It’s very simple and easy to understand. It also can play music from SD card or Flash too.
Makepython ESP32(Wrover) used USB-to-UART(CP2104) to upload firmware, you can install the CP2102 driver from:
https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers
Indicator LED Status
Indicator LED | Status |
D3 | Light on when powered on, light off when powered off |
D1 | Light on when IO21 output low, light off when IO21 output High |
Project_1: Text to speech
The example uses MicroPython programming, very simple and easy to understand.
MakePython Audio board cannot work alone. It needs a microcontroller like ESP32(Wrover) to drive it. With Makepython ESP32(Wrover) and Makepython Audio, they can be directly combined to fulfill various functions about audio.
You can get MakePython ESP32 from here:
https://www.makerfabs.com/makepython-esp32.html
Hardware interface
I2S Interface | ESP32 PIN | Remark |
I2S_BCK | IO26 | |
I2S_LCK | IO25 | WS |
I2S_DIN | IO27 |
ESP32 Booting Mode:
PIN | Default | SPI Boot(Running Mode) | Download Boot(Download Mode) |
GPIO0 | Pull-up | 1 | 0 |
GPIO2 | Pull-down | Don’t care | 0 |
GPIO12(MTDI) | Pull-down | 0 | 0 |
Note: when GPIO12 set to LOW, the internal LDO (VDD_SDIO) output 3.3V; when GPIO12 set to HIGH, the internal LDO (VDD_SDIO) output 1.8V, so it may get fails when you download the firmware if you had insert the Makepython Audio.
Step:
1. Connecting MakePython ESP32 to PC via microUSB cable.
2. Open flash_download_tools_v3.6.8,Select ESP32 DownloadTool
3. Select the related COM port, baud rate 921600,erase the ESP32 first.
Note: In my PC, there is COM272 that may different in your PC.
4. Find the firmware bin file esp32_tts.bin,address 0x1000
5. Click the START to download the firmware.
Wait until it finished.
6. Insert the ESP32 board to Makepython Audio
7. Open uPyCraft, select com port from Tools->Serial
8. Select esp32 from Tools->Board
9. Connect the Makepython ESP32 board.
10. Open main.py from File->Open, you can get the code from here: main.py
11. Click DownloadAndRun Button to download the main.py file to Makepython ESP32.
Input say("hello,world") it will speech hello world.
Or also, you can update the firmware via command terminal, such as: esptool.py --chip esp32 --port COM272 erase_flash esptool.py --chip esp32 --port COM272 write_flash --flash_mode dio -z 0x1000 esp32-tts.bin
Code Show
from machine import I2S from machine import Pin import array import speech bck_pin = Pin(26) ws_pin = Pin(25) sdout_pin = Pin(27) audio_out = I2S(I2S.NUM0, bck=bck_pin, ws=ws_pin, sdout=sdout_pin, standard=I2S.PHILIPS, mode=I2S.MASTER_TX, dataformat=I2S.B16, channelformat=I2S.ONLY_RIGHT, samplerate=16000, dmacount=16, dmalen=512) a = bytearray(16000*8) size = speech.say('Hello, wolrld', a) audio_out.write(a[:size]) def say(text): a = bytearray(16000*8) size = speech.say(text, a) audio_out.write(a[:size]) def close(): audio_out.deinit()
Project_2: Display SMS message on OLED display
Please note that each text message may require some fees depending on your local GSM operator, make sure the SIM card is active, and leave enough money for this application.
This example also uses MakePython ESP32 for MicroPython programming.
Step:
1. Plug in the GSM antenna
2. Insert a mini SIM card(GPS does work without a SIM)
3. Plug to MakePython ESP32, connect the USB to the PC.
4. Sample code, or you can get it from here: A9G_GSM.py
from machine import UART,Pin,I2C import machine import ssd1306 import utime uart = UART(2, baudrate=115200, rx=21, tx=22,timeout=10) i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000) #Init i2c lcd=ssd1306.SSD1306_I2C(128,64,i2c) A9G_RESET_PIN = Pin(33, Pin.OUT) A9G_RESET_PIN.value(0) utime.sleep_ms(2000) A9G_PWR_KEY = Pin(27, Pin.OUT) A9G_PWR_KEY.value(0) utime.sleep_ms(2000) A9G_PWR_KEY.value(1) utime.sleep_ms(20000) p=0 def text(string,c=0,r=0): global p if p>80: p=0 lcd.fill(0) colum=int(len(string)/15)+2 i=0 for a in range(0,colum): lcd.text(string[i:i+15],c,a*8) i=i+15 lcd.show() if True: uart.write('AT+GPS=0\r\n')#1: turn on GPS 0:Turn off GPS utime.sleep_ms(1000) uart.write('AT+CCID\r\n') utime.sleep_ms(1000) uart.write('AT+CREG?\r\n') utime.sleep_ms(1000) uart.write('AT+CGATT=1\r\n') utime.sleep_ms(1000) uart.write('AT+CGACT=1,1\r\n') utime.sleep_ms(1000) uart.write('AT+CGDCONT=1,\"IP\",\"CMNET\"\r\n') utime.sleep_ms(1000) uart.write('AT+CSQ\r\n') utime.sleep_ms(1000) uart.write('AT+CPMS="SM","SM","SM"\r\n') utime.sleep_ms(1000) uart.write('AT+CMGF=1\r\n') utime.sleep_ms(1000) #uart.write('AT+CMGL="ALL"\r\n') #utime.sleep_ms(1000) while True: if uart.any(): lcd.fill(0) uart.write('AT+CMGR=1\r\n') utime.sleep_ms(1000) bin_data = uart.readline() print(bin_data) text(bin_data,0,0) lcd.show() utime.sleep_ms(2000)
4. The screen displays the phone number, time and information for sending SMS.
- Mobile phone to send SMS.
- Display the phone number and time of sending SMS
- Show received content
FAQ
You can list your questions here or contact with support@makerfabs.com for technology support.