Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8037

Interfacing (DSI, CSI, I2C, etc.) • Re: Need help with pigpiod

$
0
0
Thank you @redvli

I notice you're using pigpio, not the daemon pigpiod, so I thought I'd give that a try again. I had abandoned that early on because it proved a problem to run my program with root (sudo); it doesn't have a keyboard, but I could see on the screen that it wanted me to enter a password when it tried to execute sudo piSoundTest.

For background, I have this display...
https://www.pishop.ca/product/4-3inch-c ... e-800-480/

I made an Alarm Clock/Radio with it. The "radio" is actually a music player that uses gstreamer to randomly play a song from my NAS server. It detects when a paired/trusted Bluetooth headphone or speaker comes online, and automatically starts playing. It stops playing when the headset/speaker disconnects. This all works fine. Now I just wanted to use some simple monotonic songs for the alarm clock. I had done something similar with a pico, and it worked fine. I foolishly assumed it would not be such a major pain to do it on the pi4..... HA!

So, the 'meat' of the program is changed to...

Code:

gpioCfgClock(2, 0,0 );if ((hPigpio = gpioInitialise()) != PI_INIT_FAILED){if ( (range = gpioSetPWMrange(PWM_PIN, PIGPIO_100_PERCENT_DUTY)) > 0){// set the modes for gpio pinsgpioSetMode(SCOPE_TRIGGER, PI_OUTPUT);} else hPigpio = PI_INIT_FAILED;for (octave = 0; octave < 8; octave++){gpioWrite(SCOPE_TRIGGER,0);// trigger the logic analyser for each octaveusleep(25000);gpioWrite(SCOPE_TRIGGER,1);usleep(25000);printf("Octave %d\n", octave);for (i = 0; i < 12; i++){freq = frequencies[i] * (1 << octave);freq = round(freq);if ( ( ifreq = gpioSetPWMfrequency(PWM_PIN, freq ) ) > 0 ){usleep(500000);// .5 secgpioPWM(PWM_PIN, PIGPIO_50_PERCENT_DUTY );printf("   Note %4s Requested Freq = %5.0f Given Freq = %d\n", pstrNotes[i], freq, ifreq);usleep(500000);// .5 secgpioPWM(PWM_PIN, 0 );} else printf("gpioSetPWMfrequency() Octave %d, note %d (freq %f) failed.. rc= %d\n", octave, i, freq, ifreq);}usleep(500000); // .5 sec}//gpioTerminate();} else hPigpio = PI_INIT_FAILED;
The output from each note is displayed as...

Code:

Octave 3   Note    C Requested Freq =   131 Given Freq = 125   Note   Db Requested Freq =   139 Given Freq = 125   Note    D Requested Freq =   147 Given Freq = 125   Note   Eb Requested Freq =   156 Given Freq = 125   Note    E Requested Freq =   165 Given Freq = 200   Note    F Requested Freq =   175 Given Freq = 200   Note   Gb Requested Freq =   185 Given Freq = 200   Note    G Requested Freq =   196 Given Freq = 200   Note   Ab Requested Freq =   208 Given Freq = 200   Note    A Requested Freq =   220 Given Freq = 200   Note   Bb Requested Freq =   233 Given Freq = 250   Note    B Requested Freq =   247 Given Freq = 250Octave 4   Note    C Requested Freq =   262 Given Freq = 250   Note   Db Requested Freq =   277 Given Freq = 250   Note    D Requested Freq =   294 Given Freq = 250   Note   Eb Requested Freq =   311 Given Freq = 250   Note    E Requested Freq =   330 Given Freq = 400   Note    F Requested Freq =   349 Given Freq = 400   Note   Gb Requested Freq =   370 Given Freq = 400   Note    G Requested Freq =   392 Given Freq = 400   Note   Ab Requested Freq =   415 Given Freq = 400   Note    A Requested Freq =   440 Given Freq = 400   Note   Bb Requested Freq =   466 Given Freq = 500   Note    B Requested Freq =   494 Given Freq = 500
Now, it went from bad to worse. Although all the notes do play, none of them are what I asked for. :(

I tried different settings for gpioCfgClock() and range. I haven't found any settings yet that make this work.

At this point, I'm ready to give up on playing tunes, and just do a boring beep beep beep at a frequency that works!

As far as using the built-in audio, I disabled it because I only want pulseaudio to find BT devices, and also don't want more wires connected to the box, just power.

Statistics: Posted by ronter — Thu Mar 27, 2025 6:57 pm



Viewing all articles
Browse latest Browse all 8037

Trending Articles