lukasmaximus89
Published © MIT

M5Stack RFID Face Wav Playing Flashcard Program

After I recently discovered how to play WAV files on the M5Stack, I thought it would be perfect to make a flashcard system.

IntermediateFull instructions provided2 hours499
M5Stack RFID Face Wav Playing Flashcard Program

Things used in this project

Hardware components

M5Stack FIRE IoT Development Kit (PSRAM 2.0)
M5Stack FIRE IoT Development Kit (PSRAM 2.0)
×1
M5 Faces Pocket Computer with Keyboard/PyGamer/Calculator
M5Stack M5 Faces Pocket Computer with Keyboard/PyGamer/Calculator
×1
RFID Module (Generic)
×1

Software apps and online services

MicroPython
MicroPython

Story

Read more

Code

RFID Wav player code

MicroPython
Plays wav files and reads rfid cards (copy to m5stack with ampy, copy and paste into python tab in uiflow or upload via vscode)
from machine import I2S
import os, uos, wave
import face

#initialize the I2S device
i2s = I2S(  mode = I2S.MODE_MASTER | I2S.MODE_TX | I2S.MODE_DAC_BUILT_IN,
            rate = 16000,
            bits = 16,
            channel_format = I2S.CHANNEL_ONLY_RIGHT,
            data_format = I2S.FORMAT_I2S_MSB)

faces_rfid = face.get(face.RFID)

#uncomment the following line if you have issues mounting the sd
uos.sdconfig(uos.SDMODE_SPI,clk=18,mosi=23,miso=19,cs=4)

#create a function to play the wav
def wav_player(fname):
    wav = wave.open(fname)
    i2s.set_dac_mode(I2S.DAC_RIGHT_EN)
    i2s.sample_rate(wav.getframerate())
    i2s.bits(wav.getsampwidth() * 8)
    i2s.nchannels(wav.getnchannels())
    i2s.volume(20)

    while True:
        data = wav.readframes(1024)
        if len(data) > 0:
            i2s.write(data)
        else:
            wav.close()
            break

# Playing WAV audio file
lcd.clear()
lcd.print('working',0,0,0xffffff)

try:
    uos.mountsd()
except:
    os.mountsd()
    lcd.print('sd card not mounted',0,50,0xffffff)
    pass

while True:
    if (faces_rfid.readUid()) == 'insert your cards uid here':
        wav_player('/sd/baboon2.wav')
        i2s.stop()
    if (faces_rfid.readUid()) == '1a9dbb1529':
        wav_player('/sd/bark.wav')
        i2s.stop()
    if (faces_rfid.readUid()) == 'aedf48fdc4':
        wav_player('/sd/Tiger7.wav')
        i2s.stop()

Credits

lukasmaximus89

lukasmaximus89

39 projects • 6 followers
I'm Luke from Manchester, UK. I've been living in shenzhen for 6 years. I do 3D design, Basic Electronics, Casting and other cool stuff.

Comments