I am modifying a pedal pi (link here). I split the input program from the output program. For simplicity right now, that all it does. The standard out from my input program is being fed to the standard in of my output program using a pipe and it prints the value to the screen:
sudo ./input | sudo ./output
I have to use sudo because the bcm2835 requires me to be in root.
My problem is,that there is like a 3 second delay between when I strum the strings on the guitar, and when the output program prints the values. When I just print the values from the input program, there is no delay, So I am guessing that the delay is caused by the pipe.
I researched it, and some forums said I could use sudo unbuffer ./input | sudo ./output
but using that still has the same delay.
Is there a setting I have to tweak to get rid of this delay?
Input code:
#include <stdio.h>
#include <bcm2835.h>
#include <inttypes.h>
uint32_t read_timer=0;
uint32_t input_signal=0;
int main(int argc, char **argv)
{
if (!bcm2835_init())
{printf("bcm2835_init failed. Are you running as root??\n"); return 1;}
if (!bcm2835_spi_begin())
{printf("bcm2835_spi_begin failed. Are you running as root??\n"); return 1;}
bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default
bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_64); // 4MHz clock with _64
bcm2835_spi_chipSelect(BCM2835_SPI_CS0); // The default
bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); // the default
uint8_t mosi[10] = { 0x01, 0x00, 0x00 }; //12 bit ADC read channel 0.
uint8_t miso[10] = { 0 };
while(1)
{
bcm2835_spi_transfernb(mosi, miso, 3);
input_signal = miso[2] + ((miso[1] & 0x0F) << 8);
printf("%d \n", input_signal);
}
bcm2835_spi_end();
bcm2835_close();
return 0;
}
Output code:
#include <stdio.h>
#include <bcm2835.h>
#include <inttypes.h>
uint32_t input_signal=0;
int main(int argc, char **argv)
{
// Start the BCM2835 Library to access GPIO.
if (!bcm2835_init())
{printf("bcm2835_init failed. Are you running as root??\n"); return 1;}
// Start the SPI BUS.
if (!bcm2835_spi_begin())
{printf("bcm2835_spi_begin failed. Are you running as root??\n"); return 1;}
bcm2835_gpio_fsel(18,BCM2835_GPIO_FSEL_ALT5 ); //PWM0 signal on GPIO18
bcm2835_gpio_fsel(13,BCM2835_GPIO_FSEL_ALT0 ); //PWM1 signal on GPIO13
bcm2835_pwm_set_clock(2); // Max clk frequency (19.2MHz/2 = 9.6MHz)
bcm2835_pwm_set_mode(0,1 , 1); //channel 0, markspace mode, PWM enabled.
bcm2835_pwm_set_range(0,64); //channel 0, 64 is max range (6bits): 9.6MHz/64=150KHz PWM freq.
bcm2835_pwm_set_mode(1, 1, 1); //channel 1, markspace mode, PWM enabled.
bcm2835_pwm_set_range(1,64); //channel 0, 64 is max range (6bits): 9.6MHz/64=150KHz PWM freq.
while(1)
{
scanf("%d", &input_signal);
printf("%" PRIu32 "\n", input_signal);
bcm2835_pwm_set_data(1,input_signal & 0x3F);
bcm2835_pwm_set_data(0,input_signal >> 6);
}
//close all and exit
bcm2835_spi_end();
bcm2835_close();
return 0;
}
When I just print the values
, function used for that ?and when the output program prints the values
? values printed into the terminal with your printf function exactly , not a 'sound lag' ?