wiringpi 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/wiringpi/WiringPi/devLib/ds1302.c +240 -0
- data/ext/wiringpi/WiringPi/devLib/ds1302.h +44 -0
- data/ext/wiringpi/WiringPi/devLib/font.h +2577 -0
- data/ext/wiringpi/WiringPi/devLib/gertboard.c +164 -0
- data/ext/wiringpi/WiringPi/devLib/gertboard.h +45 -0
- data/ext/wiringpi/WiringPi/devLib/lcd.c +495 -0
- data/ext/wiringpi/WiringPi/devLib/lcd.h +52 -0
- data/ext/wiringpi/WiringPi/devLib/lcd128x64.c +673 -0
- data/ext/wiringpi/WiringPi/devLib/lcd128x64.h +39 -0
- data/ext/wiringpi/WiringPi/devLib/maxdetect.c +165 -0
- data/ext/wiringpi/{serial.h → WiringPi/devLib/maxdetect.h} +14 -15
- data/ext/wiringpi/WiringPi/devLib/piFace.c +112 -0
- data/ext/wiringpi/WiringPi/devLib/piFace.h +32 -0
- data/ext/wiringpi/WiringPi/devLib/piFaceOld.c +178 -0
- data/ext/wiringpi/WiringPi/devLib/piGlow.c +118 -0
- data/ext/wiringpi/WiringPi/devLib/piGlow.h +45 -0
- data/ext/wiringpi/WiringPi/devLib/piNes.c +113 -0
- data/ext/wiringpi/WiringPi/devLib/piNes.h +45 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/7segments.c +221 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/buttons.c +83 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/gertboard.c +96 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/record.c +60 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/temperature.c +78 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/voltmeter.c +73 -0
- data/ext/wiringpi/WiringPi/examples/Gertboard/vumeter.c +152 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/blink.c +59 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/buttons.c +103 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/ladder.c +337 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/metro.c +111 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/motor.c +120 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/reaction.c +194 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow0.c +51 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piGlow1.c +258 -0
- data/ext/wiringpi/WiringPi/examples/PiGlow/piglow.c +176 -0
- data/ext/wiringpi/WiringPi/examples/blink.c +48 -0
- data/ext/wiringpi/WiringPi/examples/blink12.c +111 -0
- data/ext/wiringpi/WiringPi/examples/blink12drcs.c +125 -0
- data/ext/wiringpi/WiringPi/examples/blink6drcs.c +115 -0
- data/ext/wiringpi/WiringPi/examples/blink8.c +57 -0
- data/ext/wiringpi/WiringPi/examples/clock.c +201 -0
- data/ext/wiringpi/WiringPi/examples/delayTest.c +107 -0
- data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
- data/ext/wiringpi/WiringPi/examples/header.h +23 -0
- data/ext/wiringpi/WiringPi/examples/isr-osc.c +118 -0
- data/ext/wiringpi/WiringPi/examples/isr.c +110 -0
- data/ext/wiringpi/WiringPi/examples/lcd-adafruit.c +347 -0
- data/ext/wiringpi/WiringPi/examples/lcd.c +286 -0
- data/ext/wiringpi/WiringPi/examples/lowPower.c +68 -0
- data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
- data/ext/wiringpi/WiringPi/examples/okLed.c +82 -0
- data/ext/wiringpi/WiringPi/examples/pwm.c +58 -0
- data/ext/wiringpi/WiringPi/examples/q2w/binary.c +79 -0
- data/ext/wiringpi/WiringPi/examples/q2w/blink-io.c +61 -0
- data/ext/wiringpi/WiringPi/examples/q2w/blink.c +50 -0
- data/ext/wiringpi/WiringPi/examples/q2w/bright.c +59 -0
- data/ext/wiringpi/WiringPi/examples/q2w/button.c +63 -0
- data/ext/wiringpi/WiringPi/examples/q2w/volts.c +62 -0
- data/ext/wiringpi/WiringPi/examples/rht03.c +69 -0
- data/ext/wiringpi/WiringPi/examples/serialRead.c +48 -0
- data/ext/wiringpi/WiringPi/examples/serialTest.c +75 -0
- data/ext/wiringpi/WiringPi/examples/servo.c +57 -0
- data/ext/wiringpi/WiringPi/examples/softPwm.c +89 -0
- data/ext/wiringpi/WiringPi/examples/softTone.c +54 -0
- data/ext/wiringpi/WiringPi/examples/speed.c +95 -0
- data/ext/wiringpi/WiringPi/examples/spiSpeed.c +118 -0
- data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
- data/ext/wiringpi/WiringPi/gpio/gpio.c +1351 -0
- data/ext/wiringpi/WiringPi/gpio/pins.c +33 -0
- data/ext/wiringpi/WiringPi/gpio/readall.c +334 -0
- data/ext/wiringpi/WiringPi/gpio/version.h +1 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +201 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/max31855.c +81 -0
- data/ext/wiringpi/WiringPi/wiringPi/max31855.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/max5322.c +84 -0
- data/ext/wiringpi/WiringPi/wiringPi/max5322.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +149 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +164 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016reg.h +48 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +189 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +236 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3002.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3002.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3004.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +110 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +43 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +76 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp4802.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +126 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8574.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +90 -0
- data/ext/wiringpi/WiringPi/wiringPi/pcf8591.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +51 -0
- data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
- data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +75 -0
- data/ext/wiringpi/WiringPi/wiringPi/sn3218.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +166 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.c +211 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.c +150 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.h +39 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.c +109 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +2007 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +224 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +232 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +136 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +36 -0
- data/ext/wiringpi/{serial.c → WiringPi/wiringPi/wiringSerial.c} +38 -29
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
- data/ext/wiringpi/{wiringShift.c → WiringPi/wiringPi/wiringShift.c} +3 -4
- data/ext/wiringpi/{wiringShift.h → WiringPi/wiringPi/wiringShift.h} +5 -5
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +731 -0
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.h +26 -0
- data/ext/wiringpi/extconf.rb +7 -1
- data/ext/wiringpi/wiringpi_wrap.c +1741 -218
- data/lib/wiringpi.rb +24 -222
- data/lib/wiringpi/event.rb +21 -0
- data/lib/wiringpi/gpio.rb +139 -0
- data/lib/wiringpi/i2c.rb +26 -0
- data/lib/wiringpi/mcp23x17.rb +31 -0
- data/lib/wiringpi/serial.rb +49 -0
- data/lib/wiringpi/spi.rb +15 -0
- metadata +146 -22
- data/ext/wiringpi/wiringPi.c +0 -729
- data/ext/wiringpi/wiringPi.h +0 -69
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* buttons.c:
|
|
3
|
+
* Read the Gertboard buttons. Each one will act as an on/off
|
|
4
|
+
* tiggle switch for 3 different LEDs
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
|
7
|
+
***********************************************************************
|
|
8
|
+
* This file is part of wiringPi:
|
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
10
|
+
*
|
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
* (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU Lesser General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
22
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
***********************************************************************
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include <stdio.h>
|
|
27
|
+
#include <wiringPi.h>
|
|
28
|
+
|
|
29
|
+
// Array to keep track of our LEDs
|
|
30
|
+
|
|
31
|
+
int leds [] = { 0, 0, 0 } ;
|
|
32
|
+
|
|
33
|
+
// scanButton:
|
|
34
|
+
// See if a button is pushed, if so, then flip that LED and
|
|
35
|
+
// wait for the button to be let-go
|
|
36
|
+
|
|
37
|
+
void scanButton (int button)
|
|
38
|
+
{
|
|
39
|
+
if (digitalRead (button) == HIGH) // Low is pushed
|
|
40
|
+
return ;
|
|
41
|
+
|
|
42
|
+
leds [button] ^= 1 ; // Invert state
|
|
43
|
+
digitalWrite (4 + button, leds [button]) ;
|
|
44
|
+
|
|
45
|
+
while (digitalRead (button) == LOW) // Wait for release
|
|
46
|
+
delay (10) ;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
int main (void)
|
|
50
|
+
{
|
|
51
|
+
int i ;
|
|
52
|
+
|
|
53
|
+
printf ("Raspberry Pi Gertboard Button Test\n") ;
|
|
54
|
+
|
|
55
|
+
wiringPiSetup () ;
|
|
56
|
+
|
|
57
|
+
// Setup the outputs:
|
|
58
|
+
// Pins 3, 4, 5, 6 and 7 output:
|
|
59
|
+
// We're not using 3 or 4, but make sure they're off anyway
|
|
60
|
+
// (Using same hardware config as blink12.c)
|
|
61
|
+
|
|
62
|
+
for (i = 3 ; i < 8 ; ++i)
|
|
63
|
+
{
|
|
64
|
+
pinMode (i, OUTPUT) ;
|
|
65
|
+
digitalWrite (i, 0) ;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Setup the inputs
|
|
69
|
+
|
|
70
|
+
for (i = 0 ; i < 3 ; ++i)
|
|
71
|
+
{
|
|
72
|
+
pinMode (i, INPUT) ;
|
|
73
|
+
pullUpDnControl (i, PUD_UP) ;
|
|
74
|
+
leds [i] = 0 ;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
for (;;)
|
|
78
|
+
{
|
|
79
|
+
for (i = 0 ; i < 3 ; ++i)
|
|
80
|
+
scanButton (i) ;
|
|
81
|
+
delay (1) ;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* gertboard.c:
|
|
3
|
+
* Simple test for the SPI bus on the Gertboard
|
|
4
|
+
*
|
|
5
|
+
* Hardware setup:
|
|
6
|
+
* D/A port 0 jumpered to A/D port 0.
|
|
7
|
+
*
|
|
8
|
+
* We output a sine wave on D/A port 0 and sample A/D port 0. We then
|
|
9
|
+
* plot the input value on the terminal as a sort of vertical scrolling
|
|
10
|
+
* oscilloscipe.
|
|
11
|
+
*
|
|
12
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
|
13
|
+
***********************************************************************
|
|
14
|
+
* This file is part of wiringPi:
|
|
15
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
16
|
+
*
|
|
17
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
18
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
19
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
20
|
+
* (at your option) any later version.
|
|
21
|
+
*
|
|
22
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
23
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
24
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
25
|
+
* GNU Lesser General Public License for more details.
|
|
26
|
+
*
|
|
27
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
28
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
29
|
+
***********************************************************************
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
#include <stdio.h>
|
|
33
|
+
#include <sys/ioctl.h>
|
|
34
|
+
#include <stdlib.h>
|
|
35
|
+
#include <math.h>
|
|
36
|
+
|
|
37
|
+
// Gertboard D to A is an 8-bit unit.
|
|
38
|
+
|
|
39
|
+
#define B_SIZE 256
|
|
40
|
+
|
|
41
|
+
#include <wiringPi.h>
|
|
42
|
+
#include <gertboard.h>
|
|
43
|
+
|
|
44
|
+
int main (void)
|
|
45
|
+
{
|
|
46
|
+
double angle ;
|
|
47
|
+
int i, inputValue ;
|
|
48
|
+
int buffer [B_SIZE] ;
|
|
49
|
+
int cols ;
|
|
50
|
+
struct winsize w ;
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
printf ("Raspberry Pi Gertboard SPI test program\n") ;
|
|
54
|
+
printf ("=======================================\n") ;
|
|
55
|
+
|
|
56
|
+
ioctl (fileno (stdin), TIOCGWINSZ, &w);
|
|
57
|
+
cols = w.ws_col - 2 ;
|
|
58
|
+
|
|
59
|
+
// Always initialise wiringPi. Use wiringPiSys() if you don't need
|
|
60
|
+
// (or want) to run as root
|
|
61
|
+
|
|
62
|
+
wiringPiSetupSys () ;
|
|
63
|
+
|
|
64
|
+
// Initialise the Gertboard analog hardware at pin 100
|
|
65
|
+
|
|
66
|
+
gertboardAnalogSetup (100) ;
|
|
67
|
+
|
|
68
|
+
// Generate a Sine Wave and store in our buffer
|
|
69
|
+
|
|
70
|
+
for (i = 0 ; i < B_SIZE ; ++i)
|
|
71
|
+
{
|
|
72
|
+
angle = ((double)i / (double)B_SIZE) * M_PI * 2.0 ;
|
|
73
|
+
buffer [i] = (int)rint ((sin (angle)) * 127.0 + 128.0) ;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Loop, output the sine wave on analog out port 0, read it into A-D port 0
|
|
77
|
+
// and display it on the screen
|
|
78
|
+
|
|
79
|
+
for (;;)
|
|
80
|
+
{
|
|
81
|
+
for (i = 0 ; i < B_SIZE ; ++i)
|
|
82
|
+
{
|
|
83
|
+
analogWrite (100, buffer [i]) ;
|
|
84
|
+
|
|
85
|
+
inputValue = analogRead (100) ;
|
|
86
|
+
|
|
87
|
+
// We don't need to wory about the scale or sign - the analog hardware is
|
|
88
|
+
// a 10-bit value, so 0-1023. Just scale this to our terminal
|
|
89
|
+
|
|
90
|
+
printf ("%*s\n", (inputValue * cols) / 1023, "*") ;
|
|
91
|
+
delay (2) ;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return 0 ;
|
|
96
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* record.c:
|
|
3
|
+
* Record some audio via the Gertboard
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2013 Gordon Henderson
|
|
6
|
+
***********************************************************************
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#include <stdio.h>
|
|
10
|
+
#include <sys/time.h>
|
|
11
|
+
|
|
12
|
+
#include <wiringPi.h>
|
|
13
|
+
#include <gertboard.h>
|
|
14
|
+
|
|
15
|
+
#define B_SIZE 40000
|
|
16
|
+
|
|
17
|
+
int main ()
|
|
18
|
+
{
|
|
19
|
+
int i ;
|
|
20
|
+
struct timeval tStart, tEnd, tTaken ;
|
|
21
|
+
unsigned char buffer [B_SIZE] ;
|
|
22
|
+
|
|
23
|
+
printf ("\n") ;
|
|
24
|
+
printf ("Gertboard demo: Recorder\n") ;
|
|
25
|
+
printf ("========================\n") ;
|
|
26
|
+
|
|
27
|
+
// Always initialise wiringPi. Use wiringPiSys() if you don't need
|
|
28
|
+
// (or want) to run as root
|
|
29
|
+
|
|
30
|
+
wiringPiSetupSys () ;
|
|
31
|
+
|
|
32
|
+
// Initialise the Gertboard analog hardware at pin 100
|
|
33
|
+
|
|
34
|
+
gertboardAnalogSetup (100) ;
|
|
35
|
+
|
|
36
|
+
gettimeofday (&tStart, NULL) ;
|
|
37
|
+
|
|
38
|
+
for (i = 0 ; i < B_SIZE ; ++i)
|
|
39
|
+
buffer [i] = analogRead (100) >> 2 ;
|
|
40
|
+
|
|
41
|
+
gettimeofday (&tEnd, NULL) ;
|
|
42
|
+
|
|
43
|
+
timersub (&tEnd, &tStart, &tTaken) ;
|
|
44
|
+
|
|
45
|
+
printf ("Time taken for %d reads: %ld.%ld\n", B_SIZE, tTaken.tv_sec, tTaken.tv_usec) ;
|
|
46
|
+
|
|
47
|
+
gettimeofday (&tStart, NULL) ;
|
|
48
|
+
|
|
49
|
+
for (i = 0 ; i < B_SIZE ; ++i)
|
|
50
|
+
analogWrite (100, buffer [i]) ;
|
|
51
|
+
|
|
52
|
+
gettimeofday (&tEnd, NULL) ;
|
|
53
|
+
|
|
54
|
+
timersub (&tEnd, &tStart, &tTaken) ;
|
|
55
|
+
|
|
56
|
+
printf ("Time taken for %d writes: %ld.%ld\n", B_SIZE, tTaken.tv_sec, tTaken.tv_usec) ;
|
|
57
|
+
|
|
58
|
+
return 0 ;
|
|
59
|
+
}
|
|
60
|
+
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* temperature.c:
|
|
3
|
+
* Demonstrate use of the Gertboard A to D converter to make
|
|
4
|
+
* a simple thermometer using the LM35.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
|
7
|
+
***********************************************************************
|
|
8
|
+
* This file is part of wiringPi:
|
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
10
|
+
*
|
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
* (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU Lesser General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
22
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
***********************************************************************
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include <stdio.h>
|
|
27
|
+
|
|
28
|
+
#include <wiringPi.h>
|
|
29
|
+
#include <gertboard.h>
|
|
30
|
+
|
|
31
|
+
int main ()
|
|
32
|
+
{
|
|
33
|
+
int x1, x2 ;
|
|
34
|
+
double v1, v2 ;
|
|
35
|
+
|
|
36
|
+
printf ("\n") ;
|
|
37
|
+
printf ("Gertboard demo: Simple Thermemeter\n") ;
|
|
38
|
+
printf ("==================================\n") ;
|
|
39
|
+
|
|
40
|
+
// Always initialise wiringPi. Use wiringPiSys() if you don't need
|
|
41
|
+
// (or want) to run as root
|
|
42
|
+
|
|
43
|
+
wiringPiSetupSys () ;
|
|
44
|
+
|
|
45
|
+
// Initialise the Gertboard analog hardware at pin 100
|
|
46
|
+
|
|
47
|
+
gertboardAnalogSetup (100) ;
|
|
48
|
+
|
|
49
|
+
printf ("\n") ;
|
|
50
|
+
printf ("| Channel 0 | Channel 1 | Temperature 1 | Temperature 2 |\n") ;
|
|
51
|
+
|
|
52
|
+
for (;;)
|
|
53
|
+
{
|
|
54
|
+
|
|
55
|
+
// Read the 2 channels:
|
|
56
|
+
|
|
57
|
+
x1 = analogRead (100) ;
|
|
58
|
+
x2 = analogRead (101) ;
|
|
59
|
+
|
|
60
|
+
// Convert to a voltage:
|
|
61
|
+
|
|
62
|
+
v1 = (double)x1 / 1023.0 * 3.3 ;
|
|
63
|
+
v2 = (double)x2 / 1023.0 * 3.3 ;
|
|
64
|
+
|
|
65
|
+
// Print
|
|
66
|
+
|
|
67
|
+
printf ("| %6.3f | %6.3f |", v1, v2) ;
|
|
68
|
+
|
|
69
|
+
// Print Temperature of both channels by converting the LM35 reading
|
|
70
|
+
// to a temperature. Fortunately these are easy: 0.01 volts per C.
|
|
71
|
+
|
|
72
|
+
printf (" %4.1f | %4.1f |\r", v1 * 100.0, v2 * 100.0) ;
|
|
73
|
+
fflush (stdout) ;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return 0 ;
|
|
77
|
+
}
|
|
78
|
+
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* voltmeter.c:
|
|
3
|
+
* Demonstrate use of the Gertboard A to D converter to make
|
|
4
|
+
* a simple voltmeter.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
|
7
|
+
***********************************************************************
|
|
8
|
+
* This file is part of wiringPi:
|
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
10
|
+
*
|
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
* (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU Lesser General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
22
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
***********************************************************************
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include <stdio.h>
|
|
27
|
+
|
|
28
|
+
#include <wiringPi.h>
|
|
29
|
+
#include <gertboard.h>
|
|
30
|
+
|
|
31
|
+
int main ()
|
|
32
|
+
{
|
|
33
|
+
int x1, x2 ;
|
|
34
|
+
double v1, v2 ;
|
|
35
|
+
|
|
36
|
+
printf ("\n") ;
|
|
37
|
+
printf ("Gertboard demo: Simple Voltmeters\n") ;
|
|
38
|
+
printf ("=================================\n") ;
|
|
39
|
+
|
|
40
|
+
// Always initialise wiringPi. Use wiringPiSys() if you don't need
|
|
41
|
+
// (or want) to run as root
|
|
42
|
+
|
|
43
|
+
wiringPiSetupSys () ;
|
|
44
|
+
|
|
45
|
+
// Initialise the Gertboard analog hardware at pin 100
|
|
46
|
+
|
|
47
|
+
gertboardAnalogSetup (100) ;
|
|
48
|
+
|
|
49
|
+
printf ("\n") ;
|
|
50
|
+
printf ("| Channel 0 | Channel 1 |\n") ;
|
|
51
|
+
|
|
52
|
+
for (;;)
|
|
53
|
+
{
|
|
54
|
+
|
|
55
|
+
// Read the 2 channels:
|
|
56
|
+
|
|
57
|
+
x1 = analogRead (100) ;
|
|
58
|
+
x2 = analogRead (101) ;
|
|
59
|
+
|
|
60
|
+
// Convert to a voltage:
|
|
61
|
+
|
|
62
|
+
v1 = (double)x1 / 1023.0 * 3.3 ;
|
|
63
|
+
v2 = (double)x2 / 1023.0 * 3.3 ;
|
|
64
|
+
|
|
65
|
+
// Print
|
|
66
|
+
|
|
67
|
+
printf ("| %6.3f | %6.3f |\r", v1, v2) ;
|
|
68
|
+
fflush (stdout) ;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return 0 ;
|
|
72
|
+
}
|
|
73
|
+
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* vumeter.c:
|
|
3
|
+
* Simple VU meter
|
|
4
|
+
*
|
|
5
|
+
* Heres the theory:
|
|
6
|
+
* We will sample at 4000 samples/sec and put the data into a
|
|
7
|
+
* low-pass filter with a depth of 1000 samples. This will give
|
|
8
|
+
* us 1/4 a second of lag on the signal, but I think it might
|
|
9
|
+
* produce a more pleasing output.
|
|
10
|
+
*
|
|
11
|
+
* The input of the microphone should be at mid-pont with no
|
|
12
|
+
* sound input, but we might have to sample that too, to get
|
|
13
|
+
* our reference zero...
|
|
14
|
+
*
|
|
15
|
+
* Copyright (c) 2013 Gordon Henderson
|
|
16
|
+
***********************************************************************
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#include <stdio.h>
|
|
20
|
+
#include <stdlib.h>
|
|
21
|
+
#include <sys/time.h>
|
|
22
|
+
|
|
23
|
+
#include <wiringPi.h>
|
|
24
|
+
#include <gertboard.h>
|
|
25
|
+
|
|
26
|
+
#ifndef TRUE
|
|
27
|
+
#define TRUE (1==1)
|
|
28
|
+
#define FALSE (!TRUE)
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
#define B_SIZE 1000
|
|
32
|
+
#define S_SIZE 128
|
|
33
|
+
|
|
34
|
+
static int buffer [B_SIZE] ;
|
|
35
|
+
static int bPtr = 0 ;
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
* ledPercent:
|
|
39
|
+
* Output the given value as a percentage on the LEDs
|
|
40
|
+
*********************************************************************************
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
static void ledPercent (int percent)
|
|
44
|
+
{
|
|
45
|
+
unsigned int output = 0 ;
|
|
46
|
+
|
|
47
|
+
if (percent > 11) output |= 0x01 ;
|
|
48
|
+
if (percent > 22) output |= 0x02 ;
|
|
49
|
+
if (percent > 33) output |= 0x04 ;
|
|
50
|
+
if (percent > 44) output |= 0x08 ;
|
|
51
|
+
if (percent > 55) output |= 0x10 ;
|
|
52
|
+
if (percent > 66) output |= 0x20 ;
|
|
53
|
+
if (percent > 77) output |= 0x40 ;
|
|
54
|
+
if (percent > 88) output |= 0x80 ;
|
|
55
|
+
|
|
56
|
+
digitalWriteByte (output) ;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static unsigned int tPeriod, tNextSampleTime ;
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
* sample:
|
|
63
|
+
* Get a sample from the Gertboard. If not enough time has elapsed
|
|
64
|
+
* since the last sample, then wait...
|
|
65
|
+
*********************************************************************************
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
static void sample (void)
|
|
69
|
+
{
|
|
70
|
+
unsigned int tFuture ;
|
|
71
|
+
|
|
72
|
+
// Calculate the future sample time
|
|
73
|
+
|
|
74
|
+
tFuture = tPeriod + tNextSampleTime ;
|
|
75
|
+
|
|
76
|
+
// Wait until the next sample time
|
|
77
|
+
|
|
78
|
+
while (micros () < tNextSampleTime)
|
|
79
|
+
;
|
|
80
|
+
|
|
81
|
+
buffer [bPtr] = gertboardAnalogRead (0) ;
|
|
82
|
+
|
|
83
|
+
tNextSampleTime = tFuture ;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
int main ()
|
|
88
|
+
{
|
|
89
|
+
int quietLevel, min, max ;
|
|
90
|
+
int i, sum ;
|
|
91
|
+
unsigned int tStart, tEnd ;
|
|
92
|
+
|
|
93
|
+
printf ("\n") ;
|
|
94
|
+
printf ("Gertboard demo: VU Meter\n") ;
|
|
95
|
+
printf ("========================\n") ;
|
|
96
|
+
|
|
97
|
+
wiringPiSetup () ;
|
|
98
|
+
gertboardSPISetup () ;
|
|
99
|
+
|
|
100
|
+
ledPercent (0) ;
|
|
101
|
+
for (i = 0 ; i < 8 ; ++i)
|
|
102
|
+
pinMode (i, OUTPUT) ;
|
|
103
|
+
|
|
104
|
+
for (bPtr = 0 ; bPtr < B_SIZE ; ++bPtr)
|
|
105
|
+
buffer [bPtr] = 99 ;
|
|
106
|
+
|
|
107
|
+
tPeriod = 1000000 / 1000 ;
|
|
108
|
+
|
|
109
|
+
printf ("Shhhh.... ") ; fflush (stdout) ;
|
|
110
|
+
delay (1000) ;
|
|
111
|
+
printf ("Sampling quiet... ") ; fflush (stdout) ;
|
|
112
|
+
|
|
113
|
+
tStart = micros () ;
|
|
114
|
+
|
|
115
|
+
tNextSampleTime = micros () ;
|
|
116
|
+
for (bPtr = 0 ; bPtr < B_SIZE ; ++bPtr)
|
|
117
|
+
sample () ;
|
|
118
|
+
|
|
119
|
+
tEnd = micros () ;
|
|
120
|
+
|
|
121
|
+
quietLevel = 0 ;
|
|
122
|
+
max = 0 ;
|
|
123
|
+
min = 1024 ;
|
|
124
|
+
for (i = 0 ; i < B_SIZE ; ++i)
|
|
125
|
+
{
|
|
126
|
+
quietLevel += buffer [i] ;
|
|
127
|
+
if (buffer [i] > max) max = buffer [i] ;
|
|
128
|
+
if (buffer [i] < min) min = buffer [i] ;
|
|
129
|
+
}
|
|
130
|
+
quietLevel /= B_SIZE ;
|
|
131
|
+
|
|
132
|
+
printf ("Done. Quiet level is: %d [%d:%d] [%d:%d]\n", quietLevel, min, max, quietLevel - min, max - quietLevel) ;
|
|
133
|
+
|
|
134
|
+
printf ("Time taken for %d reads: %duS\n", B_SIZE, tEnd - tStart) ;
|
|
135
|
+
|
|
136
|
+
for (bPtr = 0 ;;)
|
|
137
|
+
{
|
|
138
|
+
sample () ;
|
|
139
|
+
sum = 0 ;
|
|
140
|
+
for (i = 0 ; i < S_SIZE ; ++i)
|
|
141
|
+
sum += buffer [i] ;
|
|
142
|
+
sum /= S_SIZE ;
|
|
143
|
+
sum = abs (quietLevel - sum) ;
|
|
144
|
+
sum = (sum * 1000) / quietLevel ;
|
|
145
|
+
ledPercent (sum) ;
|
|
146
|
+
if (++bPtr > S_SIZE)
|
|
147
|
+
bPtr = 0 ;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
return 0 ;
|
|
152
|
+
}
|