Making sounds
Re: Making sounds
Thanks @dhylands and @pythoncoder. I ended up using the hardware SPI, the clock output was good enough for what I needed.
Re: Making sounds
I just translated into esp/machine language your pyb_test. The rest is pretty portable...dhylands wrote:You may want to checkout: http://forum.micropython.org/viewtopic. ... 72&p=12291
It's a pity the 1000Hz limit of the PWM on ESP.
Besides I hope I've made it right. (The only audible song is TopGun Theme but it was fun!)
Code: Select all
# Port for ESP8266
from rtttl import RTTTL
import songs
import time
from machine import Pin, PWM
buz_tim = PWM(Pin(5))
def play_tone(freq, msec):
print('freq = {:6.1f} msec = {:6.1f}'.format(freq, msec))
if freq > 0:
buz_tim.freq(int(freq))
buz_tim.duty(50)
time.sleep_ms(int(msec * 0.9))
buz_tim.duty(0)
time.sleep_ms(int(msec * 0.1))
def play_song(s):
tune = RTTTL(songs.find(s))
for freq, msec in tune.notes():
play_tone(freq, msec)
allsongs = [ 'Super Mario - Main Theme', 'SMBtheme', 'SMBwater', 'SMBunderground', 'Picaxe', 'The Simpsons', 'Indiana', 'TakeOnMe', 'Entertainer', 'Muppets', 'Xfiles', 'Looney', '20thCenFox', 'Bond', 'MASH', 'StarWars', 'GoodBad', 'TopGun', 'A-Team', 'Flinstones', 'Jeopardy', 'Gadget', 'Smurfs', 'MahnaMahna', 'LeisureSuit', 'MissionImp', ]
for s in allsongs:
print('Playing ', s)
play_song(s)
Re: Making sounds
Following this and other discussions that show that a higher frequency can be achieved in toggling pin, I was just wondering why there is the 1khz limit on PWM for ESP8266. It is only the current implementation or there are other issues?
Thanks
Thanks