Skip to content

Instantly share code, notes, and snippets.

@kamilion
Created September 8, 2018 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamilion/655fafb7db1a564d96f09d9a3f0efdee to your computer and use it in GitHub Desktop.
Save kamilion/655fafb7db1a564d96f09d9a3f0efdee to your computer and use it in GitHub Desktop.
from machine import Pin, ADC
# Time to wait for bounce in MICROseconds
od_debounce = 6000 # 6 milliseconds
# Time to wait for button to be held in MICROseconds
od_hold = 50000 # 50 milliseconds
# Battery status
od_batt = ADC(36)
od_batt.atten(ADC.ATTN_11DB)
#LED
od_led = Pin(2, Pin.OUT)
def menu_callback(p):
if p.value() == 0:
print("Menu Callback")
def vol_callback(p):
if p.value() == 0:
print("Volume Callback")
# System Buttons
od_vol = Pin(0, Pin.IN, Pin.PULL_FLOAT, handler=vol_callback, trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, debounce=od_debounce, acttime=od_hold)
od_menu = Pin(13, Pin.IN, Pin.PULL_UP, handler=menu_callback, trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, debounce=od_debounce, acttime=od_hold)
# The DPad class
class DPad:
def __init__(self, x_axis_pin=34, y_axis_pin=35, btn_a_pin=32, btn_b_pin=33, btn_start_pin=39, btn_select_pin=27):
self.x_axis = ADC(x_axis_pin)
self.x_axis.atten(ADC.ATTN_11DB)
self.y_axis = ADC(y_axis_pin)
self.y_axis.atten(ADC.ATTN_11DB)
self.left = False
self.right = False
self.up = False
self.down = False
self.btn_a_io = Pin(btn_a_pin, Pin.IN, Pin.PULL_UP)
self.btn_b_io = Pin(btn_b_pin, Pin.IN, Pin.PULL_UP)
self.btn_a = False
self.btn_b = False
self.btn_start_io = Pin(btn_start_pin, Pin.IN)
self.btn_select_io = Pin(btn_select_pin, Pin.IN, Pin.PULL_UP)
self.btn_start = False
self.btn_select = False
def joy_read(self):
joyX = self.x_axis.readraw()
joyY = self.y_axis.readraw()
self.left = False
self.right = False
self.up = False
self.down = False
if joyX > 2048 + 1024:
self.left = True
elif joyX > 1024:
self.right = True
if joyY > 2048 + 1024:
self.up = True
elif joyY > 1024:
self.down = True
def btn_read(self):
self.btn_a = False
self.btn_b = False
self.btn_start = False
self.btn_select = False
if self.btn_a_io.value() == 0:
self.btn_a = True
if self.btn_b_io.value() == 0:
self.btn_b = True
if self.btn_start_io.value() == 0:
self.btn_start = True
if self.btn_select_io.value() == 0:
self.btn_select = True
def get_state(self):
self.joy_read()
self.btn_read()
return {
'left': self.left,
'right': self.right,
'up': self.up,
'down': self.down,
'btn_a': self.btn_a,
'btn_b': self.btn_b,
'btn_start': self.btn_start,
'btn_select': self.btn_select
}
@Avi-TelnT
Copy link

Hi
I am looking to hire an ESP32 Python programmer to help me to develop a firework interface for ESP32 I2S for a mic on I2S ICS-43434 IC and play wav using I2S MAX98357A IC. The target is work needed Google speech recognition and Google text to speech from ESP32.
The development environment must be https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo
If you have an experience on ESP32 MicroPython_ESP32_psRAM_LoBo Python please reply my email nissim@telnt.com
And call my Skype nissim.test
The work is milestone-based and payment will be as milestone below,
We will provide the hardware for that :

  1. Expose to LoBO Python the ESP32-IDE /MicroPython/Tools/esp-idf/components/driver/include/driver/I2S.H and I2S.C by integrate them in machine module so dir(machine) will show the I2S interface and commands to set I2S for recording and playing using the ESP32 DMA.
  2. Use the above machine.I2S to record and play a wav file a digital mic on
    I2S ICS-43434 IC and play wav using MAX98357A IC
  3. Make an audio PTT (Push-To-Talk) instead of PCB button. By detecting the rising level on the recorded audio level, ok voice keyword recognized.
  4. Doing above but record and play from ram with Flak encoding as needed by Google SR AND TTS. See https://cloud.google.com/speech-to-text/docs/encoding
  5. I need to use SR to get the recognized the Mic audio, as text returns from Google back to ESP32, modify the return text with meaningful information and send to be played by Google TTS. Like Siri. With ESP32.
    As:
    You Say to Mic I2S ICS-43434 “What is the temperature now?”
    Get back the text in ESP32 Python “What is the temperature now”
    ESP32 Send to TTS “The temperature now is 30 degree”
    The return wav or Flak been played to using MAX98357A over I2S
  6. So, I believe to expose I2S code from ESP32 C to Python will not be a big work.
    a. Google API use wav Audio Encoding name: FLAC Free Lossless Audio Codec 16-bit or 24-bit required for streams.
    b. So, FLAC can be done in C or Python. But interface must be from Python. See https://goo.gl/mtrwVN
  7. Maybe this is a good source for FLAC in C https://goo.gl/cCYFTh
    Contact :
    Nissim Zur
    nissim@telnt.com
    Skype: nissim.test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment