Open Slavok47 opened 1 year ago
I test it using Arduino IDE, you have to flash your chip with bootloader first to accept Arduino codes, I'll try to update the README file and the wiki with all details soon. Anyway, this is tutorial on Arduino website regarding this https://create.arduino.cc/projecthub/akarsh98/using-a-stm32-like-an-arduino-tutorial-stm32f103c8-1073cb
the kernel for STM32 is installed and working for me, it is your code that does not work
Can you tell me what's that didn't work? Is pcm-stm32f103.ino
compiled/uploaded correctly ?
BTW, you have to put hex.h on the same directory with pcm-stm32f103.ino
files , and you can create hex.h using Audacity or FFmpeg to create PCM unsigned 8-bit
on Audacity [ref]
Open the audio file File -> Export ... In the window that pops up, select the file format as "Other uncompressed files" Select "Options" Select the "Header" as "RAW (header-less)"
or FFmpeg
ffmpeg 'source.mp3' -t 10 -acodec pcm_u8 -ac 1 -ar 8000 song.wav
and convert it to hex here http://tomeko.net/online_tools/file_to_hex.php?lang=en
But you need to use my hex.h hex file first to make sure it will work
pin number will be PA8
Your hex.h file is too big and causing compile error, I reduced the file but PA8 output is only 32kHz PWM signal. only hiss in the speaker
I reduced the file
After you cut off the hex file, you should change quack_wav_len
value according to number of hex digit on that file (e.g use notepad++ to count it )
something I have a problem with converting to HEX, the sound file is 4 seconds long, after conversion it has a large size of 302884 bytes
I have a problem with converting to HEX,
Ok, first have you test the file I provided, does it work. And to making it work for new sound file you should use Audacity as I mentioned above
I figured out Audacity, everything worked fine, but another problem appeared, it does not work simultaneously with the SSD1306 display, separately everything works, but together only information is displayed on the display, but there is no sound
void loop() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10,0);
display.println("OK");
display.display();
sound();
}
void sound(){
char sample = pgm_read_byte(&quack_wav[p++]);
pwmWrite(PA8, sample) ;
if (p == quack_wav_len) {p=0;}
delayMicroseconds(120);
}
separately everything works, but together only information is displayed on the display, but there is no sound
Please upload the .ino
.hex
files you're using, and tell me by detail what did work and didnt work .
Anyway this code were made precisely for specified clock cycle and uses
pwmWrite
, I think using any other function in the loop will cause it to have unpredicted delays and the wave will be out of sync
you can either debug it by changing pwmtimer2.setPrescaleFactor( )
to lower value or delayMicroseconds( );
I redid the function a little and everything worked, I will continue to test
void sound() {
for (int i = 0; i <= sizeof(quack_wav); i++) {
char sample = pgm_read_byte(&quack_wav[p++]);
pwmWrite(PA8, sample);
if (p == sizeof(quack_wav))
{
p = 0;
}
delayMicroseconds(120);
}
}
I redid the function a little and everything worked, I will continue to test
Good to hear that, BTW I create this project to test/learn about composite video on the STM32F103c8t6 black pill ,
Even there already been projects doing it, but I want it to be learning experience for me and others, if you are interested about this please let me know to contact each other, it's not necessary to start soon, anytime you have spare time .
yes, it's interesting, still, increase the volume, on one transistor it's still not enough volume
yes, it's interesting, still, increase the volume, on one transistor it's still not enough volume
To increase the volume, you have to use amplification circuits, on the YT video I use simple PNP transistors(in parallel) to amplify the audio
It works in Arduino IDE?