mirror of
https://github.com/clockworkpi/WiringPi.git
synced 2026-03-19 02:12:43 +01:00
Synced to git.drogon.net
This commit is contained in:
committed by
Philip Howard
parent
dda3305ce1
commit
3fbc564d00
@@ -30,15 +30,15 @@ INCLUDE = -I/usr/local/include
|
||||
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
|
||||
|
||||
LDFLAGS = -L/usr/local/lib
|
||||
LDLIBS = -lwiringPi
|
||||
LDLIBS = -lwiringPi -lpthread -lm
|
||||
|
||||
# Should not alter anything below this line
|
||||
###############################################################################
|
||||
|
||||
SRC = test1.c test2.c speed.c lcd.c wfi.c \
|
||||
piface.c gertboard.c nes.c \
|
||||
pwm.c tone.c servo.c \
|
||||
delayTest.c serialRead.c okLed.c
|
||||
SRC = blink.c test1.c test2.c speed.c lcd.c wfi.c isr.c isr-osc.c \
|
||||
piface.c gertboard.c nes.c \
|
||||
pwm.c tone.c servo.c \
|
||||
delayTest.c serialRead.c serialTest.c okLed.c
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
@@ -49,6 +49,12 @@ all:
|
||||
@echo " $(BINS)" | fmt
|
||||
@echo ""
|
||||
|
||||
really-all: $(BINS)
|
||||
|
||||
blink: blink.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ blink.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
test1: test1.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ test1.o $(LDFLAGS) $(LDLIBS)
|
||||
@@ -69,21 +75,29 @@ wfi: wfi.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ wfi.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
isr: isr.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ isr.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
isr-osc: isr-osc.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ isr-osc.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
piface: piface.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ piface.o $(LDFLAGS) $(LDLIBS) -lpthread
|
||||
@$(CC) -o $@ piface.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
gertboard: gertboard.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ gertboard.o $(LDFLAGS) $(LDLIBS) -lm
|
||||
@$(CC) -o $@ gertboard.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
nes: nes.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ nes.o $(LDFLAGS) $(LDLIBS) -lm
|
||||
@$(CC) -o $@ nes.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
pwm: pwm.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ pwm.o $(LDFLAGS) $(LDLIBS) -lm -lpthread
|
||||
@$(CC) -o $@ pwm.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
delayTest: delayTest.o
|
||||
@echo [link]
|
||||
@@ -93,6 +107,10 @@ serialRead: serialRead.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ serialRead.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
serialTest: serialTest.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ serialTest.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
okLed: okLed.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ okLed.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
@@ -10,5 +10,9 @@ To compile an individual example, just type
|
||||
|
||||
make exampleName
|
||||
|
||||
Where exampleName is one of:
|
||||
To really compile everything:
|
||||
|
||||
make really-all
|
||||
|
||||
The individual tests are:
|
||||
|
||||
|
||||
50
examples/blink.c
Normal file
50
examples/blink.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* blink.c:
|
||||
* Standard "blink" program in wiringPi. Blinks an LED connected
|
||||
* to the first GPIO pin.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <wiringPi.h>
|
||||
|
||||
// LED Pin - wiringPi pin 0 is BCM_GPIO 17.
|
||||
|
||||
#define LED 0
|
||||
|
||||
int main (void)
|
||||
{
|
||||
printf ("Raspberry Pi blink\n") ;
|
||||
|
||||
if (wiringPiSetup () == -1)
|
||||
return 1 ;
|
||||
|
||||
pinMode (LED, OUTPUT) ;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
digitalWrite (LED, 1) ; // On
|
||||
delay (500) ; // mS
|
||||
digitalWrite (LED, 0) ; // Off
|
||||
delay (500) ;
|
||||
}
|
||||
return 0 ;
|
||||
}
|
||||
30
examples/blink.rtb
Normal file
30
examples/blink.rtb
Normal file
@@ -0,0 +1,30 @@
|
||||
// blink.rtb:
|
||||
// Blink program in Return to Basic
|
||||
//
|
||||
// Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
//**********************************************************************
|
||||
// This file is part of wiringPi:
|
||||
// https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
//
|
||||
// wiringPi is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// wiringPi is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
//
|
||||
PinMode (0, 1) // Output
|
||||
CYCLE
|
||||
DigitalWrite (0, 1) // Pin 0 ON
|
||||
WAIT (0.5) // 0.5 seconds
|
||||
DigitalWrite (0, 0)
|
||||
WAIT (0.5)
|
||||
REPEAT
|
||||
END
|
||||
37
examples/blink.sh
Normal file
37
examples/blink.sh
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# blink.sh:
|
||||
# Standard "blink" program in wiringPi. Blinks an LED connected
|
||||
# to the first GPIO pin.
|
||||
#
|
||||
# Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
#######################################################################
|
||||
# This file is part of wiringPi:
|
||||
# https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
#
|
||||
# wiringPi is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# wiringPi is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
#######################################################################
|
||||
|
||||
# LED Pin - wiringPi pin 0 is BCM_GPIO 17.
|
||||
|
||||
LED=0
|
||||
|
||||
gpio mode $PIN out
|
||||
|
||||
while true; do
|
||||
gpio write $PIN 1
|
||||
sleep 0.5
|
||||
gpio write $PIN 0
|
||||
sleep 0.5
|
||||
done
|
||||
@@ -1,3 +1,27 @@
|
||||
/*
|
||||
* delayTest.c:
|
||||
* Just a little test program I'm using to experiment with
|
||||
* various timings and latency, etc.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* gertboard.c:
|
||||
* Simple test for the SPI bus on the Gertboard
|
||||
@@ -10,6 +9,24 @@
|
||||
* copy this value to D/A port 1 and use a 'scope on both D/A ports
|
||||
* to check all's well.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
23
examples/header.h
Normal file
23
examples/header.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* file.c:
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
118
examples/isr-osc.c
Normal file
118
examples/isr-osc.c
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* isr-osc.c:
|
||||
* Wait for Interrupt test program - ISR method - interrupt oscillator
|
||||
*
|
||||
* How to test:
|
||||
*
|
||||
* IMPORTANT: To run this test we connect 2 GPIO pins together, but
|
||||
* before we do that YOU must make sure that they are both setup
|
||||
* the right way. If they are set to outputs and one is high and one low,
|
||||
* then you connect the wire, you'll create a short and that won't be good.
|
||||
*
|
||||
* Before making the connection, type:
|
||||
* gpio mode 0 output
|
||||
* gpio write 0 0
|
||||
* gpio mode 1 input
|
||||
* then you can connect them together.
|
||||
*
|
||||
* Run the program, then:
|
||||
* gpio write 0 1
|
||||
* gpio write 0 0
|
||||
*
|
||||
* at which point it will trigger an interrupt and the program will
|
||||
* then do the up/down toggling for itself and run at full speed, and
|
||||
* it will report the number of interrupts recieved every second.
|
||||
*
|
||||
* Copyright (c) 2013 Gordon Henderson. projects@drogon.net
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <wiringPi.h>
|
||||
|
||||
|
||||
// What GPIO input are we using?
|
||||
// This is a wiringPi pin number
|
||||
|
||||
#define OUT_PIN 0
|
||||
#define IN_PIN 1
|
||||
|
||||
// globalCounter:
|
||||
// Global variable to count interrupts
|
||||
// Should be declared volatile to make sure the compiler doesn't cache it.
|
||||
|
||||
static volatile int globalCounter = 0 ;
|
||||
|
||||
/*
|
||||
* myInterrupt:
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void myInterrupt (void)
|
||||
{
|
||||
digitalWrite (OUT_PIN, 1) ;
|
||||
++globalCounter ;
|
||||
digitalWrite (OUT_PIN, 0) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************
|
||||
* main
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int myCounter = 0 ;
|
||||
int lastCounter = 0 ;
|
||||
|
||||
if (wiringPiSetup () < 0)
|
||||
{
|
||||
fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)) ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
pinMode (OUT_PIN, OUTPUT) ;
|
||||
pinMode (IN_PIN, INPUT) ;
|
||||
|
||||
if (wiringPiISR (IN_PIN, INT_EDGE_FALLING, &myInterrupt) < 0)
|
||||
{
|
||||
fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
printf ("Waiting ... ") ; fflush (stdout) ;
|
||||
|
||||
while (myCounter == globalCounter)
|
||||
delay (1000) ;
|
||||
|
||||
printf (" Done. counter: %6d: %6d\n",
|
||||
globalCounter, myCounter - lastCounter) ;
|
||||
lastCounter = myCounter ;
|
||||
myCounter = globalCounter ;
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
99
examples/isr.c
Normal file
99
examples/isr.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* isr.c:
|
||||
* Wait for Interrupt test program - ISR method
|
||||
*
|
||||
* How to test:
|
||||
* Use the SoC's pull-up and pull down resistors that are avalable
|
||||
* on input pins. So compile & run this program (via sudo), then
|
||||
* in another terminal:
|
||||
* gpio mode 0 up
|
||||
* gpio mode 0 down
|
||||
* at which point it should trigger an interrupt. Toggle the pin
|
||||
* up/down to generate more interrupts to test.
|
||||
*
|
||||
* Copyright (c) 2013 Gordon Henderson.
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <wiringPi.h>
|
||||
|
||||
|
||||
// What GPIO input are we using?
|
||||
// This is a wiringPi pin number
|
||||
|
||||
#define BUTTON_PIN 0
|
||||
|
||||
// globalCounter:
|
||||
// Global variable to count interrupts
|
||||
// Should be declared volatile to make sure the compiler doesn't cache it.
|
||||
|
||||
static volatile int globalCounter = 0 ;
|
||||
|
||||
|
||||
/*
|
||||
* myInterrupt:
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void myInterrupt (void)
|
||||
{
|
||||
++globalCounter ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************
|
||||
* main
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int myCounter = 0 ;
|
||||
|
||||
if (wiringPiSetup () < 0)
|
||||
{
|
||||
fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)) ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
if (wiringPiISR (BUTTON_PIN, INT_EDGE_FALLING, &myInterrupt) < 0)
|
||||
{
|
||||
fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno)) ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
|
||||
for (;;)
|
||||
{
|
||||
printf ("Waiting ... ") ; fflush (stdout) ;
|
||||
|
||||
while (myCounter == globalCounter)
|
||||
delay (100) ;
|
||||
|
||||
printf (" Done. counter: %5d\n", globalCounter) ;
|
||||
myCounter = globalCounter ;
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
@@ -1,3 +1,26 @@
|
||||
/*
|
||||
* nes.c:
|
||||
* Test program for an old NES controller connected to the Pi.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* okLed:
|
||||
* okLed.c:
|
||||
* Make the OK LED on the Pi Pulsate...
|
||||
* Copyright (c) 2012 gordon Henderson, but please Share and Enjoy!
|
||||
*
|
||||
* Originally posted to the Raspberry Pi forums:
|
||||
* http://www.raspberrypi.org/phpBB3/viewtopic.php?p=162581#p162581
|
||||
@@ -10,6 +9,24 @@
|
||||
* e.g. by putting it in /etc/rc.local and running it in the
|
||||
* background &
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -17,6 +34,7 @@
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <wiringPi.h>
|
||||
#include <softPwm.h>
|
||||
|
||||
@@ -1,9 +1,27 @@
|
||||
|
||||
/*
|
||||
* piface.c:
|
||||
* Simple test for the PiFace
|
||||
* piFace.c:
|
||||
* Simple test for the PiFace interface board.
|
||||
*
|
||||
* Read the buttons and output the same to the LEDs
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <wiringPi.h>
|
||||
|
||||
@@ -1,3 +1,27 @@
|
||||
/*
|
||||
* pwm.c:
|
||||
* Test of the software PWM driver. Needs 12 LEDs connected
|
||||
* to the Pi.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
|
||||
/*
|
||||
* serialRead.c:
|
||||
* serial.c:
|
||||
* Example program to read bytes from the Serial line
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
75
examples/serialTest.c
Normal file
75
examples/serialTest.c
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* serialTest.c:
|
||||
* Very simple program to test the serial port. Expects
|
||||
* the port to be looped back to itself
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <wiringPi.h>
|
||||
#include <wiringSerial.h>
|
||||
|
||||
int main ()
|
||||
{
|
||||
int fd ;
|
||||
int count ;
|
||||
unsigned int nextTime ;
|
||||
|
||||
if ((fd = serialOpen ("/dev/ttyAMA0", 115200)) < 0)
|
||||
{
|
||||
fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
if (wiringPiSetup () == -1)
|
||||
{
|
||||
fprintf (stdout, "Unable to start wiringPi: %s\n", strerror (errno)) ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
nextTime = millis () + 300 ;
|
||||
|
||||
for (count = 0 ; count < 256 ; )
|
||||
{
|
||||
if (millis () > nextTime)
|
||||
{
|
||||
printf ("\nOut: %3d: ", count) ;
|
||||
fflush (stdout) ;
|
||||
serialPutchar (fd, count) ;
|
||||
nextTime += 300 ;
|
||||
++count ;
|
||||
}
|
||||
|
||||
delay (3) ;
|
||||
|
||||
while (serialDataAvail (fd))
|
||||
{
|
||||
printf (" -> %3d", serialGetchar (fd)) ;
|
||||
fflush (stdout) ;
|
||||
}
|
||||
}
|
||||
|
||||
printf ("\n") ;
|
||||
return 0 ;
|
||||
}
|
||||
@@ -1,3 +1,27 @@
|
||||
/*
|
||||
* servo.c:
|
||||
* Test of the softServo code.
|
||||
* Do not use this code - use the servoBlaster kernel module instead
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
@@ -1,8 +1,26 @@
|
||||
|
||||
/*
|
||||
* speed.c:
|
||||
* Simple program to measure the speed of the various GPIO
|
||||
* access mechanisms.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <wiringPi.h>
|
||||
|
||||
@@ -1,7 +1,27 @@
|
||||
|
||||
/*
|
||||
* test1.c:
|
||||
* Simple test program to test the wiringPi functions
|
||||
* This is a sequencer to make a patter appear on 8 LEDs
|
||||
* connected to the GPIO pins.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <wiringPi.h>
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
|
||||
/*
|
||||
* test2.c:
|
||||
* Simple test program to test the wiringPi functions
|
||||
* PWM test
|
||||
* This tests the hardware PWM channel.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <wiringPi.h>
|
||||
|
||||
@@ -1,3 +1,27 @@
|
||||
/*
|
||||
* tone.c:
|
||||
* Test of the softTone module in wiringPi
|
||||
* Plays a scale out on pin 3 - connect pizeo disc to pin 3 & 0v
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
@@ -6,15 +30,13 @@
|
||||
#include <wiringPi.h>
|
||||
#include <softTone.h>
|
||||
|
||||
#define RANGE 100
|
||||
#define NUM_LEDS 12
|
||||
#define PIN 3
|
||||
|
||||
int scale [8] = { 262, 294, 330, 349, 392, 440, 494, 525 } ;
|
||||
|
||||
int main ()
|
||||
{
|
||||
int i, j ;
|
||||
char buf [80] ;
|
||||
int i ;
|
||||
|
||||
if (wiringPiSetup () == -1)
|
||||
{
|
||||
@@ -22,14 +44,14 @@ int main ()
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
softToneCreate (3) ;
|
||||
softToneCreate (PIN) ;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
for (i = 0 ; i < 8 ; ++i)
|
||||
{
|
||||
printf ("%3d\n", i) ;
|
||||
softToneWrite (3, scale [i]) ;
|
||||
softToneWrite (PIN, scale [i]) ;
|
||||
delay (500) ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,17 @@
|
||||
* wfi.c:
|
||||
* Wait for Interrupt test program
|
||||
*
|
||||
* Copyright (c) 2012 Gordon Henderson.
|
||||
* This program demonstrates the use of the waitForInterrupt()
|
||||
* function in wiringPi. It listens to a button input on
|
||||
* BCM_GPIO pin 17 (wiringPi pin 0)
|
||||
*
|
||||
* The biggest issue with this method is that it really only works
|
||||
* well in Sys mode.
|
||||
*
|
||||
* Jan 2013: This way of doing things is sort of deprecated now, see
|
||||
* the wiringPiISR() function instead and the isr.c test program here.
|
||||
*
|
||||
* Copyright (c) 2012-2013 Gordon Henderson.
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
@@ -33,9 +43,8 @@
|
||||
#define COUNT_KEY 0
|
||||
|
||||
// What BCM_GPIO input are we using?
|
||||
// GPIO 0 is one of the I2C pins with an on-board pull-up
|
||||
|
||||
#define BUTTON_PIN 0
|
||||
#define BUTTON_PIN 17
|
||||
|
||||
// Debounce time in mS
|
||||
|
||||
@@ -63,13 +72,11 @@ PI_THREAD (waitForIt)
|
||||
int debounceTime = 0 ;
|
||||
|
||||
(void)piHiPri (10) ; // Set this thread to be high priority
|
||||
digitalWrite (18, 1) ;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (waitForInterrupt (BUTTON_PIN, -1) > 0) // Got it
|
||||
{
|
||||
|
||||
// Bouncing?
|
||||
|
||||
if (millis () < debounceTime)
|
||||
@@ -80,7 +87,6 @@ PI_THREAD (waitForIt)
|
||||
|
||||
// We have a valid one
|
||||
|
||||
digitalWrite (17, state) ;
|
||||
state ^= 1 ;
|
||||
|
||||
piLock (COUNT_KEY) ;
|
||||
@@ -89,7 +95,7 @@ PI_THREAD (waitForIt)
|
||||
|
||||
// Wait for key to be released
|
||||
|
||||
while (digitalRead (0) == LOW)
|
||||
while (digitalRead (BUTTON_PIN) == LOW)
|
||||
delay (1) ;
|
||||
|
||||
debounceTime = millis () + DEBOUNCE_TIME ;
|
||||
@@ -108,11 +114,9 @@ void setup (void)
|
||||
{
|
||||
|
||||
// Use the gpio program to initialise the hardware
|
||||
// (This is the crude, but effective bit)
|
||||
// (This is the crude, but effective)
|
||||
|
||||
system ("gpio edge 0 falling") ;
|
||||
system ("gpio export 17 out") ;
|
||||
system ("gpio export 18 out") ;
|
||||
system ("gpio edge 17 falling") ;
|
||||
|
||||
// Setup wiringPi
|
||||
|
||||
@@ -120,9 +124,8 @@ void setup (void)
|
||||
|
||||
// Fire off our interrupt handler
|
||||
|
||||
piThreadCreate (waitForIt) ;
|
||||
piThreadCreate (waitForIt) ;
|
||||
|
||||
digitalWrite (17, 0) ;
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +150,7 @@ int main (void)
|
||||
piLock (COUNT_KEY) ;
|
||||
myCounter = globalCounter ;
|
||||
piUnlock (COUNT_KEY) ;
|
||||
delay (5000) ;
|
||||
delay (500) ;
|
||||
}
|
||||
|
||||
printf (" Done. myCounter: %5d\n", myCounter) ;
|
||||
|
||||
Reference in New Issue
Block a user