OS: BPI-M3 Ubuntu15.10 (Kernel3.4) Version: 1.0 HDMI
Buzzer Power - Pin 7 - GPIO4
Buzzer GND - Pin 9 - GND
Step 1: Download WiringPI
$ git clone https://github.com/BPI-SINOVOIP/BPI-WiringPi.git -b BPI_M3 $ cd BPI-WiringPi $ chmod +x ./build $ sudo ./build
Step 2 : Copy smaple code to Buz_pwm.c file
$ sudo vi Buz_pwm.c
Step 3 : Compile Buz_pwm.c
$ gcc -o Buz_pwm Buz_pwm.c -l wiringPi -lpthread
Step 4 : Run Buz_pwm
$ sudo ./Buz_pwm
Video Demo:
Sample Code:
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include<wiringPi.h>
#include<softPwm.h>
int buz=7;
int pwm,pwmmax=50,count;
int main(){
if (wiringPiSetup() < 0)
{
fprintf (stderr, "Unable to open device: %s\n", strerror (errno)) ;
return 1 ;
}
if(softPwmCreate(buz,pwm,pwmmax)<0)
{
fprintf (stderr, "Unable to open pwm device: %s\n", strerror (errno)) ;
return 1 ;
}
for(count=0;count<100;count++)
{
softPwmWrite(buz,count);
delay(50);
}
/*
pinMode(7,OUTPUT);
while(1)
{
digitalWrite(0,LOW);
delay(2000);//0.5 second or sleep(1)=1 second
digitalWrite(0,HIGH);
delay(300);//0.5 second
}
*/
}