// Program button.c
//
#include <wiringPi.h>
#include <stdio.h>
// One side of the button is placed on GPIO 0
// The other side is on 5V
#define BtnPin 0
int
main(
){
wiringPiSetup();
pinMode(BtnPin,INPUT);
for(;;)
{
if(0==digitalRead(BtnPin))
{
printf("\nButton is NOT Pressed\n");
}
if(1==digitalRead(BtnPin))
{
printf("\nButton is Pressed\n");
}
}
return(0);
}
Thursday, November 19, 2015
Tuesday, November 10, 2015
DC Motor Control using PWM for Speed Control
In this exercise, we use DC Motor control using PWM for speed control. The electronic driver is called an H-Bridge that will allow the motor to turn either way if hooked up properly. That will be shown in a follow-on Blog entry.
We us a 31162MP H-Driver as hooked up to the Raspberry Pi 2B as shown:
https://www.dropbox.com/s/c0xvxc32x4q75tn/hDrivePi.pptx?dl=0
The specification for the 31162MP H-Driver board is:
https://www.dropbox.com/s/m2cym0tm2e7c2f4/31162mp-Hdriver.pdf?dl=0
Test code using a single speed is shown below. The speed can be set depending on the PWM pulse width of 0-1023. Below a value of about 150, the motor may not turn.
https://www.dropbox.com/s/p5e6wjhjwrra2s2/pwmtest1.c?dl=0
We us a 31162MP H-Driver as hooked up to the Raspberry Pi 2B as shown:
https://www.dropbox.com/s/c0xvxc32x4q75tn/hDrivePi.pptx?dl=0
The specification for the 31162MP H-Driver board is:
https://www.dropbox.com/s/m2cym0tm2e7c2f4/31162mp-Hdriver.pdf?dl=0
Test code using a single speed is shown below. The speed can be set depending on the PWM pulse width of 0-1023. Below a value of about 150, the motor may not turn.
https://www.dropbox.com/s/p5e6wjhjwrra2s2/pwmtest1.c?dl=0
Continuous Temperature Sensor with LED Indicator Program
Continuous Temperature Sensor with LED Indicator Program using linked compile for the functions.
The main program: tempmain.c
GPIO Setup program (function): setupPi.c
LED Off program (function): leds_off.c
Read Temperature Sensor program (function): readTemp.c
Turn on LED Corresponding to Temperature (I used 3 temperature ranges): led_temp_on.c
To compile:
gcc tempmain.c setupPi.c leds_off.c readtemp.c led_temp_on.c -lwiringPi
Single Pass Example Temperature Sensor with LED Indicator Program
SINGLE PASS Example Temperature Sensor with LED Indicator Program using linked compile for the functions.
The main program: tempmainEx.c
GPIO Setup program (function): setupPiEx.c
LED Off program (function): leds_offEx.c
Read Temperature Sensor program (function): readTempEx.c
Turn on LED Corresponding to Temperature (I used 3 temperature ranges): led_temp_onEx.c
To compile:
gcc tempmainEx.c setupPiEx.c leds_offEx.c readtempEx.c led_temp_onEx.c -lwiringPi
You'll see on the display when certain entries and exits to and from functions occur.
Subscribe to:
Posts (Atom)
