├── .gitignore ├── CHANGES.txt ├── MANIFEST.in ├── Makefile ├── README ├── README.md ├── README.rst ├── WiringPi ├── COPYING.LESSER ├── INSTALL ├── People ├── README.TXT ├── VERSION ├── build ├── debian │ └── wiringPi │ │ └── DEBIAN │ │ ├── control │ │ ├── postinst │ │ └── postrm ├── devLib │ ├── Makefile │ ├── ds1302.c │ ├── ds1302.h │ ├── font.h │ ├── gertboard.c │ ├── gertboard.h │ ├── lcd.c │ ├── lcd.h │ ├── lcd128x64.c │ ├── lcd128x64.h │ ├── maxdetect.c │ ├── maxdetect.h │ ├── piFace.c │ ├── piFace.h │ ├── piGlow.c │ ├── piGlow.h │ ├── piNes.c │ └── piNes.h ├── examples │ ├── COPYING.LESSER │ ├── Gertboard │ │ ├── 7segments.c │ │ ├── Makefile │ │ ├── buttons.c │ │ ├── gertboard.c │ │ ├── record.c │ │ ├── temperature.c │ │ ├── voltmeter.c │ │ └── vumeter.c │ ├── Makefile │ ├── PiFace │ │ ├── Makefile │ │ ├── blink.c │ │ ├── buttons.c │ │ ├── ladder.c │ │ ├── metro.c │ │ ├── motor.c │ │ └── reaction.c │ ├── PiGlow │ │ ├── Makefile │ │ ├── piGlow0.c │ │ ├── piGlow1.c │ │ └── piglow.c │ ├── README.TXT │ ├── blink.c │ ├── blink.rtb │ ├── blink.sh │ ├── blink12.c │ ├── blink12drcs.c │ ├── blink6drcs.c │ ├── blink8.c │ ├── clock.c │ ├── delayTest.c │ ├── ds1302.c │ ├── header.h │ ├── isr-osc.c │ ├── isr.c │ ├── lcd-adafruit.c │ ├── lcd.c │ ├── lowPower.c │ ├── nes.c │ ├── okLed.c │ ├── pwm.c │ ├── q2w │ │ ├── Makefile │ │ ├── binary.c │ │ ├── blink-io.c │ │ ├── blink.c │ │ ├── blink.sh │ │ ├── bright.c │ │ ├── button.c │ │ └── volts.c │ ├── rht03.c │ ├── serialRead.c │ ├── serialTest.c │ ├── servo.c │ ├── softPwm.c │ ├── softTone.c │ ├── speed.c │ ├── spiSpeed.c │ └── wfi.c ├── gpio │ ├── COPYING.LESSER │ ├── Makefile │ ├── gpio.1 │ ├── gpio.c │ ├── newVersion │ ├── pins.c │ ├── pintest │ ├── readall.c │ ├── test.sh │ └── version.h ├── pins │ ├── Makefile │ ├── pins.pdf │ └── pins.tex └── wiringPi │ ├── COPYING.LESSER │ ├── Makefile │ ├── drcSerial.c │ ├── drcSerial.h │ ├── max31855.c │ ├── max31855.h │ ├── max5322.c │ ├── max5322.h │ ├── mcp23008.c │ ├── mcp23008.h │ ├── mcp23016.c │ ├── mcp23016.h │ ├── mcp23016reg.h │ ├── mcp23017.c │ ├── mcp23017.h │ ├── mcp23s08.c │ ├── mcp23s08.h │ ├── mcp23s17.c │ ├── mcp23s17.h │ ├── mcp23x08.h │ ├── mcp23x0817.h │ ├── mcp3002.c │ ├── mcp3002.h │ ├── mcp3004.c │ ├── mcp3004.h │ ├── mcp3422.c │ ├── mcp3422.h │ ├── mcp4802.c │ ├── mcp4802.h │ ├── pcf8574.c │ ├── pcf8574.h │ ├── pcf8591.c │ ├── pcf8591.h │ ├── piHiPri.c │ ├── piThread.c │ ├── sn3218.c │ ├── sn3218.h │ ├── softPwm.c │ ├── softPwm.h │ ├── softServo.c │ ├── softServo.h │ ├── softTone.c │ ├── softTone.h │ ├── sr595.c │ ├── sr595.h │ ├── wiringPi.c │ ├── wiringPi.h │ ├── wiringPiI2C.c │ ├── wiringPiI2C.h │ ├── wiringPiSPI.c │ ├── wiringPiSPI.h │ ├── wiringSerial.c │ ├── wiringSerial.h │ ├── wiringShift.c │ ├── wiringShift.h │ ├── wpiExtensions.c │ └── wpiExtensions.h ├── build.sh ├── examples ├── RUN_THESE_WITH_SUDO ├── callback.py ├── delay.py ├── ladder-board.py ├── n5510-mcp23017.py ├── quick2wire-io.py ├── softpwm.py └── two-mcp23017.py ├── functions.txt ├── piglow.py ├── setup.py ├── test.py ├── wiringpi.i ├── wiringpi2-class.py ├── wiringpi2.py └── wiringpi_wrap.c /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | wiringpi2.egg-info/ 3 | dist/ 4 | __pycache__ 5 | *.pyc 6 | -------------------------------------------------------------------------------- /CHANGES.txt: -------------------------------------------------------------------------------- 1 | v1.0.0 -- Branched from original WiringPi to deliver new WiringPi 2 functionality 2 | v1.0.1 -- Fixed build problems involving missing header files 3 | v1.0.2 -- Fixed build issue with piNes.c 4 | v1.0.3 -- Fixed bug in physical pin assignment mode 5 | v1.0.4 -- Added class wrapper, plus analogRead/Write functions 6 | v1.0.5 -- Second attempt at pretty Pypi page 7 | v1.0.6 -- Fixed spelling error in softToneCreate - Thanks oevsegneev 8 | v1.0.7 -- Added LCD functionality 9 | v1.0.8 -- Updated manifest to include .rst and fix build error 10 | v1.0.9 -- Erroneous non-fix due to stupidity 11 | v1.0.10 -- Added I2CSetup and new I2C class 12 | v1.1.0 -- Synced to WiringPi as of 8th March 2015 13 | v1.1.1 -- Included devLib folder for headers 14 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | graft WiringPi/wiringPi 2 | graft WiringPi/devLib 3 | include *.txt 4 | include *.rst 5 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: bindings 2 | python setup.py build 3 | 4 | bindings: 5 | swig2.0 -python wiringpi.i 6 | 7 | install: 8 | sudo python setup.py install 9 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | WARNING: This is an in-development library, it will not be bug free and fully featured. 2 | Please tweet @gadgetoid, find Gadgetoid in IRC, email Phil at Gadgetoid dot com, 3 | or visit http://pi.gadgetoid.com/post/039-wiringpi-version-2-with-extra-python and 4 | comment if you have any problems, suggestions, questions or words of support. 5 | 6 | WiringPi: An implementation of most of the Arduino Wiring 7 | functions for the Raspberry Pi 8 | 9 | WiringPi2: WiringPi version 2 implements new functions for managing IO expanders. 10 | 11 | Testing: 12 | Build with gcc version 4.6.3 (Debian 4.6.3-14+rpi1) 13 | Built against Python 2.7.2, Python 3.2.3 14 | 15 | Prerequisites: 16 | You must have python-dev and python-setuptools installed 17 | If you manually rebuild the bindings with swig -python wiringpi.i 18 | 19 | Get/setup repo: 20 | git clone https://github.com/Gadgetoid/WiringPi2-Python.git 21 | cd WiringPi2-Python 22 | 23 | Build & install with: 24 | sudo python setup.py install 25 | 26 | Or Python 3 27 | sudo python3 setup.py install 28 | 29 | Class-based Usage: 30 | No classes have been created for this version yet. 31 | 32 | Usage: 33 | import wiringpi2 34 | wiringpi2.wiringPiSetup() // For sequential pin numbering, one of these MUST be called before using IO functions 35 | OR 36 | wiringpi2.wiringPiSetupSys() // For /sys/class/gpio with GPIO pin numbering 37 | OR 38 | wiringpi2.wiringPiSetupGpio() // For GPIO pin numbering 39 | 40 | Setting up IO expanders (This example was tested on a quick2wire board with one digital IO expansion board connected via I2C): 41 | wiringpi2.mcp23017Setup(65,0x20) 42 | wiringpi2.pinMode(65,1) 43 | wiringpi2.digitalWrite(65,1) 44 | 45 | General IO: 46 | wiringpi2.pinMode(1,1) // Set pin 1 to output 47 | wiringpi2.digitalWrite(1,1) // Write 1 HIGH to pin 1 48 | wiringpi2.digitalRead(1) // Read pin 1 49 | 50 | Bit shifting: 51 | wiringpi2.shiftOut(1,2,0,123) // Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2 52 | 53 | Serial: 54 | serial = wiringpi2.serialOpen('/dev/ttyAMA0',9600) // Requires device/baud and returns an ID 55 | wiringpi2.serialPuts(serial,"hello") 56 | wiringpi2.serialClose(serial) // Pass in ID 57 | 58 | Full details at: 59 | http://www.wiringpi.com 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ###THIS REPOSITORY IS DEPRECATED 2 | 3 | ####Please see: https://github.com/WiringPi/WiringPi-Python 4 | 5 | 6 | 7 | 8 | **WiringPi 2 for Python** 9 | 10 | WiringPi: An implementation of most of the Arduino Wiring 11 | functions for the Raspberry Pi 12 | 13 | WiringPi2: WiringPi version 2 implements new functions for managing IO expanders. 14 | 15 | **Testing:** 16 | Build with gcc version 4.6.3 (Debian 4.6.3-14+rpi1) 17 | Built against Python 2.7.2, Python 3.2.3 18 | 19 | **Prerequisites:** 20 | You **must** have python-dev and python-setuptools installed 21 | If you manually rebuild the bindings with swig -python wiringpi.i 22 | 23 | YOU MUST FIRST INSTALL WIRINGPI2!! 24 | ```bash 25 | git clone git://git.drogon.net/wiringPi 26 | cd wiringPi 27 | sudo ./build 28 | ``` 29 | 30 | **Get/setup repo:** 31 | ```bash 32 | git clone https://github.com/Gadgetoid/WiringPi2-Python.git 33 | cd WiringPi2-Python 34 | ``` 35 | 36 | **Build & install with:** 37 | `sudo python setup.py install` 38 | 39 | Or Python 3: 40 | `sudo python3 setup.py install` 41 | 42 | **Class-based Usage:** 43 | Description incoming! 44 | 45 | **Usage:** 46 | 47 | import wiringpi2 48 | 49 | wiringpi2.wiringPiSetup() # For sequential pin numbering, one of these MUST be called before using IO functions 50 | # OR 51 | wiringpi2.wiringPiSetupSys() # For /sys/class/gpio with GPIO pin numbering 52 | # OR 53 | wiringpi2.wiringPiSetupGpio() # For GPIO pin numbering 54 | 55 | 56 | Setting up IO expanders (This example was tested on a quick2wire board with one digital IO expansion board connected via I2C): 57 | 58 | wiringpi2.mcp23017Setup(65,0x20) 59 | wiringpi2.pinMode(65,1) 60 | wiringpi2.digitalWrite(65,1) 61 | 62 | **General IO:** 63 | 64 | wiringpi2.pinMode(6,1) # Set pin 6 to 1 ( OUTPUT ) 65 | wiringpi2.digitalWrite(6,1) # Write 1 ( HIGH ) to pin 6 66 | wiringpi2.digitalRead(6) # Read pin 6 67 | 68 | **Setting up a peripheral:** 69 | WiringPi2 supports expanding your range of available "pins" by setting up a port expander. The implementation details of 70 | your port expander will be handled transparently, and you can write to the additional pins ( starting from PIN_OFFSET >= 64 ) 71 | as if they were normal pins on the Pi. 72 | 73 | wiringpi2.mcp23017Setup(PIN_OFFSET,I2C_ADDR) 74 | 75 | **Soft Tone** 76 | 77 | Hook a speaker up to your Pi and generate music with softTone. Also useful for generating frequencies for other uses such as modulating A/C. 78 | 79 | wiringpi2.softToneCreate(PIN) 80 | wiringpi2.softToneWrite(PIN,FREQUENCY) 81 | 82 | **Bit shifting:** 83 | 84 | wiringpi2.shiftOut(1,2,0,123) # Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2 85 | 86 | **Serial:** 87 | 88 | serial = wiringpi2.serialOpen('/dev/ttyAMA0',9600) # Requires device/baud and returns an ID 89 | wiringpi2.serialPuts(serial,"hello") 90 | wiringpi2.serialClose(serial) # Pass in ID 91 | 92 | **Full details at:** 93 | http://www.wiringpi.com 94 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ====== 2 | WiringPi 2 for Python 3 | ====== 4 | 5 | WiringPi: An implementation of most of the Arduino Wiring 6 | functions for the Raspberry Pi 7 | 8 | WiringPi2: WiringPi version 2 implements new functions for managing IO expanders. 9 | 10 | Testing: 11 | ======== 12 | Build with gcc version 4.6.3 (Debian 4.6.3-14+rpi1) 13 | Built against Python 2.7.2, Python 3.2.3 14 | 15 | Prerequisites: 16 | ============== 17 | You must have python-dev and python-setuptools installed 18 | If you manually rebuild the bindings with swig -python wiringpi.i 19 | 20 | Get/setup repo: 21 | =============== 22 | git clone https://github.com/Gadgetoid/WiringPi2-Python.git 23 | cd WiringPi2-Python 24 | 25 | Build & install with: 26 | ===================== 27 | sudo python setup.py install 28 | 29 | Or Python 3 30 | sudo python3 setup.py install 31 | 32 | Class-based Usage: 33 | ================== 34 | Description incoming! 35 | 36 | Usage: 37 | ====== 38 | import wiringpi2 39 | wiringpi2.wiringPiSetup // For sequential pin numbering, one of these MUST be called before using IO functions 40 | OR 41 | wiringpi2.wiringPiSetupSys // For /sys/class/gpio with GPIO pin numbering 42 | OR 43 | wiringpi2.wiringPiSetupGpio // For GPIO pin numbering 44 | 45 | Setting up IO expanders (This example was tested on a quick2wire board with one digital IO expansion board connected via I2C): 46 | wiringpi2.mcp23017Setup(65,0x20) 47 | wiringpi2.pinMode(65,1) 48 | wiringpi2.digitalWrite(65,1) 49 | 50 | General IO: 51 | ----------- 52 | wiringpi2.pinMode(1,1) // Set pin 1 to output 53 | wiringpi2.digitalWrite(1,1) // Write 1 HIGH to pin 1 54 | wiringpi2.digitalRead(1) // Read pin 1 55 | 56 | Bit shifting: 57 | ------------- 58 | wiringpi2.shiftOut(1,2,0,123) // Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2 59 | 60 | Serial: 61 | ------- 62 | serial = wiringpi2.serialOpen('/dev/ttyAMA0',9600) // Requires device/baud and returns an ID 63 | wiringpi2.serialPuts(serial,"hello") 64 | wiringpi2.serialClose(serial) // Pass in ID 65 | 66 | Full details at: 67 | ---------------- 68 | http://www.wiringpi.com 69 | -------------------------------------------------------------------------------- /WiringPi/INSTALL: -------------------------------------------------------------------------------- 1 | 2 | How to install wiringPi 3 | ======================= 4 | 5 | The easiest way is to use the supplied 'build' script: 6 | 7 | ./build 8 | 9 | that should do a complete install or upgrade of wiringPi for you. 10 | 11 | That will install a dynamic library. 12 | 13 | Some distributions do not have /usr/local/lib in the default LD_LIBRARY_PATH. To 14 | fix this, you need to edit /etc/ld.so.conf and add in a single line: 15 | 16 | /usr/local/lib 17 | 18 | then run the ldconfig command. 19 | 20 | sudo ldconfig 21 | 22 | If you want to install a static library, you may need to do this manually: 23 | 24 | cd wiringPi 25 | make static 26 | sudo make install-static 27 | 28 | 29 | To un-install wiringPi: 30 | 31 | ./build uninstall 32 | 33 | Gordon Henderson 34 | 35 | projects@drogon.net 36 | https://projects.drogon.net/ 37 | -------------------------------------------------------------------------------- /WiringPi/People: -------------------------------------------------------------------------------- 1 | 2 | Just a quick note to some people who've provided help, suggestions, 3 | bug-fixes, etc. along the way... 4 | 5 | Nick Lott: (And others) 6 | Hints about making it work with C++ 7 | 8 | Philipp Stefan Neininger: 9 | Minor bug in the Makefile to do with cross compiling 10 | 11 | Chris McSweeny 12 | Hints and tips about the use of arithmetic in gettimeofday() 13 | inside the dealyMicrosecondsHard() function. 14 | And spotting a couple of schoolboy errors in the (experimental) 15 | softServo code, prompting me to completely re-write it. 16 | 17 | Armin (Via projects website) 18 | Some pointers about the i2c-dev.h files. 19 | 20 | Arno Wagner 21 | Suggestions for the mmap calls in wiringPiSetup() 22 | 23 | CHARLES Thibaut: 24 | A small issue in softTone 25 | 26 | Xian Stannard 27 | Fixing some typos in the man page! 28 | 29 | Andre Crone 30 | Suggested the __WIRING_PI.H__ round wiringPi.h 31 | 32 | Rik Teerling 33 | Pointing out some silly mistooks in the I2C code... 34 | -------------------------------------------------------------------------------- /WiringPi/README.TXT: -------------------------------------------------------------------------------- 1 | 2 | wiringPi README 3 | =============== 4 | 5 | Please note that the official way to get wiringPi is via git from 6 | git.drogon.net and not GitHub. 7 | 8 | ie. 9 | 10 | git clone git://git.drogon.net/wiringPi 11 | 12 | The version of wiringPi held on GitHub by "Gadgetoid" is used to build the 13 | wiringPython, Ruby, Perl, etc. wrappers for these other languages. This 14 | version may lag the official Drogon release. Pull requests may not be 15 | accepted to Github.... 16 | 17 | Please see 18 | 19 | http://wiringpi.com/ 20 | 21 | for the official documentation, etc. and the best way to submit bug reports, etc. 22 | is by sending an email to projects@drogon.net 23 | 24 | Thanks! 25 | 26 | -Gordon 27 | -------------------------------------------------------------------------------- /WiringPi/VERSION: -------------------------------------------------------------------------------- 1 | 2.25 2 | -------------------------------------------------------------------------------- /WiringPi/debian/wiringPi/DEBIAN/control: -------------------------------------------------------------------------------- 1 | Package: wiringpi 2 | Version: 2.24 3 | Section: libraries 4 | Priority: optional 5 | Architecture: armhf 6 | Depends: libc6 7 | Maintainer: Gordon Henderson 8 | Description: The wiringPi libraries, headers and gpio command 9 | Libraries to allow GPIO access on a Raspberry Pi from C and C++ 10 | programs as well as from the command-line 11 | -------------------------------------------------------------------------------- /WiringPi/debian/wiringPi/DEBIAN/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | /bin/chown root.root /usr/bin/gpio 4 | /bin/chmod 4755 /usr/bin/gpio 5 | /sbin/ldconfig 6 | -------------------------------------------------------------------------------- /WiringPi/debian/wiringPi/DEBIAN/postrm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | /sbin/ldconfig 3 | -------------------------------------------------------------------------------- /WiringPi/devLib/ds1302.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ds1302.h: 3 | * Real Time clock 4 | * 5 | * Copyright (c) 2013 Gordon Henderson. 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern unsigned int ds1302rtcRead (const int reg) ; 30 | extern void ds1302rtcWrite (const int reg, const unsigned int data) ; 31 | 32 | extern unsigned int ds1302ramRead (const int addr) ; 33 | extern void ds1302ramWrite (const int addr, const unsigned int data) ; 34 | 35 | extern void ds1302clockRead (int clockData [8]) ; 36 | extern void ds1302clockWrite (const int clockData [8]) ; 37 | 38 | extern void ds1302trickleCharge (const int diodes, const int resistors) ; 39 | 40 | extern void ds1302setup (const int clockPin, const int dataPin, const int csPin) ; 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | -------------------------------------------------------------------------------- /WiringPi/devLib/font.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gadgetoid/WiringPi2-Python/620be8c3264ed23a7d45d0a473ffeec3c2a4bc5e/WiringPi/devLib/font.h -------------------------------------------------------------------------------- /WiringPi/devLib/gertboard.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gertboard.h: 3 | * Access routines for the SPI devices on the Gertboard 4 | * Copyright (c) 2012 Gordon Henderson 5 | * 6 | * The Gertboard has an MCP4802 dual-channel D to A convertor 7 | * connected to the SPI bus, selected via chip-select B. 8 | * 9 | *********************************************************************** 10 | * This file is part of wiringPi: 11 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 12 | * 13 | * wiringPi is free software: you can redistribute it and/or modify 14 | * it under the terms of the GNU Lesser General Public License as 15 | * published by the Free Software Foundation, either version 3 of the 16 | * License, or (at your option) any later version. 17 | * 18 | * wiringPi is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU Lesser General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU Lesser General Public 24 | * License along with wiringPi. 25 | * If not, see . 26 | *********************************************************************** 27 | */ 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | // Old routines 34 | 35 | extern void gertboardAnalogWrite (const int chan, const int value) ; 36 | extern int gertboardAnalogRead (const int chan) ; 37 | extern int gertboardSPISetup (void) ; 38 | 39 | // New 40 | 41 | extern int gertboardAnalogSetup (const int pinBase) ; 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /WiringPi/devLib/lcd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lcd.h: 3 | * Text-based LCD driver. 4 | * This is designed to drive the parallel interface LCD drivers 5 | * based in the Hitachi HD44780U controller and compatables. 6 | * 7 | * Copyright (c) 2012 Gordon Henderson. 8 | *********************************************************************** 9 | * This file is part of wiringPi: 10 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 11 | * 12 | * wiringPi is free software: you can redistribute it and/or modify 13 | * it under the terms of the GNU Lesser General Public License as published by 14 | * the Free Software Foundation, either version 3 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * wiringPi is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public License 23 | * along with wiringPi. If not, see . 24 | *********************************************************************** 25 | */ 26 | 27 | #define MAX_LCDS 8 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | extern void lcdHome (const int fd) ; 34 | extern void lcdClear (const int fd) ; 35 | extern void lcdDisplay (const int fd, int state) ; 36 | extern void lcdCursor (const int fd, int state) ; 37 | extern void lcdCursorBlink (const int fd, int state) ; 38 | extern void lcdSendCommand (const int fd, unsigned char command) ; 39 | extern void lcdPosition (const int fd, int x, int y) ; 40 | extern void lcdCharDef (const int fd, int index, unsigned char data [8]) ; 41 | extern void lcdPutchar (const int fd, unsigned char data) ; 42 | extern void lcdPuts (const int fd, const char *string) ; 43 | extern void lcdPrintf (const int fd, const char *message, ...) ; 44 | 45 | extern int lcdInit (const int rows, const int cols, const int bits, 46 | const int rs, const int strb, 47 | const int d0, const int d1, const int d2, const int d3, const int d4, 48 | const int d5, const int d6, const int d7) ; 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | -------------------------------------------------------------------------------- /WiringPi/devLib/lcd128x64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lcd128x64.h: 3 | * 4 | * Copyright (c) 2013 Gordon Henderson. 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with wiringPi. If not, see . 21 | *********************************************************************** 22 | */ 23 | 24 | extern void lcd128x64setOrigin (int x, int y) ; 25 | extern void lcd128x64setOrientation (int orientation) ; 26 | extern void lcd128x64orientCoordinates (int *x, int *y) ; 27 | extern void lcd128x64getScreenSize (int *x, int *y) ; 28 | extern void lcd128x64point (int x, int y, int colour) ; 29 | extern void lcd128x64line (int x0, int y0, int x1, int y1, int colour) ; 30 | extern void lcd128x64lineTo (int x, int y, int colour) ; 31 | extern void lcd128x64rectangle (int x1, int y1, int x2, int y2, int colour, int filled) ; 32 | extern void lcd128x64circle (int x, int y, int r, int colour, int filled) ; 33 | extern void lcd128x64ellipse (int cx, int cy, int xRadius, int yRadius, int colour, int filled) ; 34 | extern void lcd128x64putchar (int x, int y, int c, int bgCol, int fgCol) ; 35 | extern void lcd128x64puts (int x, int y, const char *str, int bgCol, int fgCol) ; 36 | extern void lcd128x64update (void) ; 37 | extern void lcd128x64clear (int colour) ; 38 | 39 | extern int lcd128x64setup (void) ; 40 | -------------------------------------------------------------------------------- /WiringPi/devLib/maxdetect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * maxdetect.h: 3 | * Driver for the MaxDetect series sensors 4 | * 5 | * Copyright (c) 2013 Gordon Henderson. 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | // Main generic function 31 | 32 | int maxDetectRead (const int pin, unsigned char buffer [4]) ; 33 | 34 | // Individual sensors 35 | 36 | int readRHT03 (const int pin, int *temp, int *rh) ; 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | -------------------------------------------------------------------------------- /WiringPi/devLib/piFace.c: -------------------------------------------------------------------------------- 1 | /* 2 | * piFace.: 3 | * This file to interface with the PiFace peripheral device which 4 | * has an MCP23S17 GPIO device connected via the SPI bus. 5 | * 6 | * Copyright (c) 2012-2013 Gordon Henderson 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 13 | * published by the Free Software Foundation, either version 3 of the 14 | * License, or (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 22 | * License along with wiringPi. 23 | * If not, see . 24 | *********************************************************************** 25 | */ 26 | 27 | 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | #include "piFace.h" 35 | 36 | 37 | /* 38 | * myDigitalWrite: 39 | * Perform the digitalWrite function on the PiFace board 40 | ********************************************************************************* 41 | */ 42 | 43 | void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value) 44 | { 45 | digitalWrite (pin + 16, value) ; 46 | } 47 | 48 | 49 | /* 50 | * myDigitalRead: 51 | * Perform the digitalRead function on the PiFace board 52 | * With a slight twist - if we read from base + 8, then we 53 | * read from the output latch... 54 | ********************************************************************************* 55 | */ 56 | 57 | int myDigitalRead (struct wiringPiNodeStruct *node, int pin) 58 | { 59 | if ((pin - node->pinBase) >= 8) 60 | return digitalRead (pin + 8) ; 61 | else 62 | return digitalRead (pin + 16 + 8) ; 63 | } 64 | 65 | 66 | /* 67 | * myPullUpDnControl: 68 | * Perform the pullUpDnControl function on the PiFace board 69 | ********************************************************************************* 70 | */ 71 | 72 | void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int pud) 73 | { 74 | pullUpDnControl (pin + 16 + 8, pud) ; 75 | } 76 | 77 | 78 | /* 79 | * piFaceSetup 80 | * We're going to create an instance of the mcp23s17 here, then 81 | * provide our own read/write routines on-top of it... 82 | * The supplied PiFace code (in Pithon) treats it as an 8-bit device 83 | * where you write the output ports and read the input port using the 84 | * same pin numbers, however I have had a request to be able to read 85 | * the output port, so reading 8..15 will read the output latch. 86 | ********************************************************************************* 87 | */ 88 | 89 | int piFaceSetup (const int pinBase) 90 | { 91 | int i ; 92 | struct wiringPiNodeStruct *node ; 93 | 94 | // Create an mcp23s17 instance: 95 | 96 | mcp23s17Setup (pinBase + 16, 0, 0) ; 97 | 98 | // Set the direction bits 99 | 100 | for (i = 0 ; i < 8 ; ++i) 101 | { 102 | pinMode (pinBase + 16 + i, OUTPUT) ; // Port A is the outputs 103 | pinMode (pinBase + 16 + 8 + i, INPUT) ; // Port B inputs. 104 | } 105 | 106 | node = wiringPiNewNode (pinBase, 16) ; 107 | node->digitalRead = myDigitalRead ; 108 | node->digitalWrite = myDigitalWrite ; 109 | node->pullUpDnControl = myPullUpDnControl ; 110 | 111 | return 0 ; 112 | } 113 | -------------------------------------------------------------------------------- /WiringPi/devLib/piFace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * piFace.h: 3 | * Control the PiFace Interface board for the Raspberry Pi 4 | * Copyright (c) 2012-2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with wiringPi. If not, see . 21 | *********************************************************************** 22 | */ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | extern int piFaceSetup (const int pinBase) ; 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /WiringPi/devLib/piGlow.c: -------------------------------------------------------------------------------- 1 | /* 2 | * piGlow.c: 3 | * Easy access to the Pimoroni PiGlow board. 4 | * 5 | * Copyright (c) 2013 Gordon Henderson. 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | #include "piGlow.h" 29 | 30 | #define PIGLOW_BASE 577 31 | 32 | static int leg0 [6] = { 6, 7, 8, 5, 4, 9 } ; 33 | static int leg1 [6] = { 17, 16, 15, 13, 11, 10 } ; 34 | static int leg2 [6] = { 0, 1, 2, 3, 14, 12 } ; 35 | 36 | 37 | /* 38 | * piGlow1: 39 | * Light up an individual LED 40 | ********************************************************************************* 41 | */ 42 | 43 | void piGlow1 (const int leg, const int ring, const int intensity) 44 | { 45 | int *legLeds ; 46 | 47 | if ((leg < 0) || (leg > 2)) return ; 48 | if ((ring < 0) || (ring > 5)) return ; 49 | 50 | /**/ if (leg == 0) 51 | legLeds = leg0 ; 52 | else if (leg == 1) 53 | legLeds = leg1 ; 54 | else 55 | legLeds = leg2 ; 56 | 57 | analogWrite (PIGLOW_BASE + legLeds [ring], intensity) ; 58 | } 59 | 60 | /* 61 | * piGlowLeg: 62 | * Light up all 6 LEDs on a leg 63 | ********************************************************************************* 64 | */ 65 | 66 | void piGlowLeg (const int leg, const int intensity) 67 | { 68 | int i ; 69 | int *legLeds ; 70 | 71 | if ((leg < 0) || (leg > 2)) 72 | return ; 73 | 74 | /**/ if (leg == 0) 75 | legLeds = leg0 ; 76 | else if (leg == 1) 77 | legLeds = leg1 ; 78 | else 79 | legLeds = leg2 ; 80 | 81 | for (i = 0 ; i < 6 ; ++i) 82 | analogWrite (PIGLOW_BASE + legLeds [i], intensity) ; 83 | } 84 | 85 | 86 | /* 87 | * piGlowRing: 88 | * Light up 3 LEDs in a ring. Ring 0 is the outermost, 5 the innermost 89 | ********************************************************************************* 90 | */ 91 | 92 | void piGlowRing (const int ring, const int intensity) 93 | { 94 | if ((ring < 0) || (ring > 5)) 95 | return ; 96 | 97 | analogWrite (PIGLOW_BASE + leg0 [ring], intensity) ; 98 | analogWrite (PIGLOW_BASE + leg1 [ring], intensity) ; 99 | analogWrite (PIGLOW_BASE + leg2 [ring], intensity) ; 100 | } 101 | 102 | /* 103 | * piGlowSetup: 104 | * Initialise the board & remember the pins we're using 105 | ********************************************************************************* 106 | */ 107 | 108 | void piGlowSetup (int clear) 109 | { 110 | sn3218Setup (PIGLOW_BASE) ; 111 | 112 | if (clear) 113 | { 114 | piGlowLeg (0, 0) ; 115 | piGlowLeg (1, 0) ; 116 | piGlowLeg (2, 0) ; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /WiringPi/devLib/piGlow.h: -------------------------------------------------------------------------------- 1 | /* 2 | * piglow.h: 3 | * Easy access to the Pimoroni PiGlow board. 4 | * 5 | * Copyright (c) 2013 Gordon Henderson. 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | 26 | #define PIGLOW_RED 0 27 | #define PIGLOW_ORANGE 1 28 | #define PIGLOW_YELLOW 2 29 | #define PIGLOW_GREEN 3 30 | #define PIGLOW_BLUE 4 31 | #define PIGLOW_WHITE 5 32 | 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | extern void piGlow1 (const int leg, const int ring, const int intensity) ; 39 | extern void piGlowLeg (const int leg, const int intensity) ; 40 | extern void piGlowRing (const int ring, const int intensity) ; 41 | extern void piGlowSetup (int clear) ; 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /WiringPi/devLib/piNes.c: -------------------------------------------------------------------------------- 1 | /* 2 | * piNes.c: 3 | * Driver for the NES Joystick controller on the Raspberry Pi 4 | * Copyright (c) 2012 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | 27 | #include "piNes.h" 28 | 29 | #define MAX_NES_JOYSTICKS 8 30 | 31 | #define NES_RIGHT 0x01 32 | #define NES_LEFT 0x02 33 | #define NES_DOWN 0x04 34 | #define NES_UP 0x08 35 | #define NES_START 0x10 36 | #define NES_SELECT 0x20 37 | #define NES_B 0x40 38 | #define NES_A 0x80 39 | 40 | 41 | #define PULSE_TIME 25 42 | 43 | // Data to store the pins for each controller 44 | 45 | struct nesPinsStruct 46 | { 47 | unsigned int cPin, dPin, lPin ; 48 | } ; 49 | 50 | static struct nesPinsStruct nesPins [MAX_NES_JOYSTICKS] ; 51 | 52 | static int joysticks = 0 ; 53 | 54 | 55 | /* 56 | * setupNesJoystick: 57 | * Create a new NES joystick interface, program the pins, etc. 58 | ********************************************************************************* 59 | */ 60 | 61 | int setupNesJoystick (int dPin, int cPin, int lPin) 62 | { 63 | if (joysticks == MAX_NES_JOYSTICKS) 64 | return -1 ; 65 | 66 | nesPins [joysticks].dPin = dPin ; 67 | nesPins [joysticks].cPin = cPin ; 68 | nesPins [joysticks].lPin = lPin ; 69 | 70 | digitalWrite (lPin, LOW) ; 71 | digitalWrite (cPin, LOW) ; 72 | 73 | pinMode (lPin, OUTPUT) ; 74 | pinMode (cPin, OUTPUT) ; 75 | pinMode (dPin, INPUT) ; 76 | 77 | return joysticks++ ; 78 | } 79 | 80 | 81 | /* 82 | * readNesJoystick: 83 | * Do a single scan of the NES Joystick. 84 | ********************************************************************************* 85 | */ 86 | 87 | unsigned int readNesJoystick (int joystick) 88 | { 89 | unsigned int value = 0 ; 90 | int i ; 91 | 92 | struct nesPinsStruct *pins = &nesPins [joystick] ; 93 | 94 | // Toggle Latch - which presents the first bit 95 | 96 | digitalWrite (pins->lPin, HIGH) ; delayMicroseconds (PULSE_TIME) ; 97 | digitalWrite (pins->lPin, LOW) ; delayMicroseconds (PULSE_TIME) ; 98 | 99 | // Read first bit 100 | 101 | value = digitalRead (pins->dPin) ; 102 | 103 | // Now get the next 7 bits with the clock 104 | 105 | for (i = 0 ; i < 7 ; ++i) 106 | { 107 | digitalWrite (pins->cPin, HIGH) ; delayMicroseconds (PULSE_TIME) ; 108 | digitalWrite (pins->cPin, LOW) ; delayMicroseconds (PULSE_TIME) ; 109 | value = (value << 1) | digitalRead (pins->dPin) ; 110 | } 111 | 112 | return value ^ 0xFF ; 113 | } 114 | -------------------------------------------------------------------------------- /WiringPi/devLib/piNes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * piNes.h: 3 | * Driver for the NES Joystick controller on the Raspberry Pi 4 | * Copyright (c) 2012 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #define MAX_NES_JOYSTICKS 8 26 | 27 | #define NES_RIGHT 0x01 28 | #define NES_LEFT 0x02 29 | #define NES_DOWN 0x04 30 | #define NES_UP 0x08 31 | #define NES_START 0x10 32 | #define NES_SELECT 0x20 33 | #define NES_B 0x40 34 | #define NES_A 0x80 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | extern int setupNesJoystick (int dPin, int cPin, int lPin) ; 41 | extern unsigned int readNesJoystick (int joystick) ; 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /WiringPi/examples/Gertboard/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile: 3 | # Gertboard - Examples using wiringPi 4 | # 5 | # Copyright (c) 2013 Gordon Henderson 6 | ################################################################################# 7 | 8 | #DEBUG = -g -O0 9 | DEBUG = -O3 10 | CC = gcc 11 | INCLUDE = -I/usr/local/include 12 | CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe 13 | 14 | LDFLAGS = -L/usr/local/lib 15 | LDLIBS = -lwiringPi -lwiringPiDev -lpthread -lm 16 | 17 | # Should not alter anything below this line 18 | ############################################################################### 19 | 20 | SRC = gertboard.c \ 21 | buttons.c 7segments.c \ 22 | voltmeter.c temperature.c vumeter.c \ 23 | record.c 24 | 25 | OBJ = $(SRC:.c=.o) 26 | 27 | BINS = $(SRC:.c=) 28 | 29 | all: $(BINS) 30 | 31 | gertboard: gertboard.o 32 | @echo [link] 33 | @$(CC) -o $@ gertboard.o $(LDFLAGS) $(LDLIBS) 34 | 35 | buttons: buttons.o 36 | @echo [link] 37 | @$(CC) -o $@ buttons.o $(LDFLAGS) $(LDLIBS) 38 | 39 | 7segments: 7segments.o 40 | @echo [link] 41 | @$(CC) -o $@ 7segments.o $(LDFLAGS) $(LDLIBS) 42 | 43 | voltmeter: voltmeter.o 44 | @echo [link] 45 | @$(CC) -o $@ voltmeter.o $(LDFLAGS) $(LDLIBS) 46 | 47 | temperature: temperature.o 48 | @echo [link] 49 | @$(CC) -o $@ temperature.o $(LDFLAGS) $(LDLIBS) 50 | 51 | vumeter: vumeter.o 52 | @echo [link] 53 | @$(CC) -o $@ vumeter.o $(LDFLAGS) $(LDLIBS) 54 | 55 | record: record.o 56 | @echo [link] 57 | @$(CC) -o $@ record.o $(LDFLAGS) $(LDLIBS) 58 | 59 | .c.o: 60 | @echo [CC] $< 61 | @$(CC) -c $(CFLAGS) $< -o $@ 62 | 63 | clean: 64 | @echo [Clean] 65 | @rm -f $(OBJ) *~ core tags $(BINS) 66 | 67 | tags: $(SRC) 68 | @echo [ctags] 69 | @ctags $(SRC) 70 | 71 | depend: 72 | makedepend -Y $(SRC) 73 | 74 | # DO NOT DELETE 75 | -------------------------------------------------------------------------------- /WiringPi/examples/Gertboard/buttons.c: -------------------------------------------------------------------------------- 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. 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 . 23 | *********************************************************************** 24 | */ 25 | 26 | #include 27 | #include 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 | } 84 | -------------------------------------------------------------------------------- /WiringPi/examples/Gertboard/gertboard.c: -------------------------------------------------------------------------------- 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. 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 . 29 | *********************************************************************** 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | // Gertboard D to A is an 8-bit unit. 38 | 39 | #define B_SIZE 256 40 | 41 | #include 42 | #include 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 | } 97 | -------------------------------------------------------------------------------- /WiringPi/examples/Gertboard/record.c: -------------------------------------------------------------------------------- 1 | /* 2 | * record.c: 3 | * Record some audio via the Gertboard 4 | * 5 | * Copyright (c) 2013 Gordon Henderson 6 | *********************************************************************** 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 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 | 61 | -------------------------------------------------------------------------------- /WiringPi/examples/Gertboard/temperature.c: -------------------------------------------------------------------------------- 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. 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 . 23 | *********************************************************************** 24 | */ 25 | 26 | #include 27 | 28 | #include 29 | #include 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 | 79 | -------------------------------------------------------------------------------- /WiringPi/examples/Gertboard/voltmeter.c: -------------------------------------------------------------------------------- 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. 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 . 23 | *********************************************************************** 24 | */ 25 | 26 | #include 27 | 28 | #include 29 | #include 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 | 74 | -------------------------------------------------------------------------------- /WiringPi/examples/PiFace/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile: 3 | # wiringPi - Wiring Compatable library for the Raspberry Pi 4 | # https://projects.drogon.net/wiring-pi 5 | # 6 | # Copyright (c) 2012 Gordon Henderson 7 | ################################################################################# 8 | # This file is part of wiringPi: 9 | # Wiring Compatable library for the Raspberry Pi 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 . 23 | ################################################################################# 24 | 25 | 26 | #DEBUG = -g -O0 27 | DEBUG = -O3 28 | CC = gcc 29 | INCLUDE = -I/usr/local/include 30 | CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe 31 | 32 | LDFLAGS = -L/usr/local/lib 33 | LDLIBS = -lwiringPi -lwiringPiDev -lpthread -lm 34 | 35 | # Should not alter anything below this line 36 | ############################################################################### 37 | 38 | SRC = blink.c buttons.c reaction.c ladder.c metro.c motor.c 39 | 40 | OBJ = $(SRC:.c=.o) 41 | 42 | BINS = $(SRC:.c=) 43 | 44 | all: $(BINS) 45 | 46 | blink: blink.o 47 | @echo [link] 48 | @$(CC) -o $@ blink.o $(LDFLAGS) $(LDLIBS) 49 | 50 | buttons: buttons.o 51 | @echo [link] 52 | @$(CC) -o $@ buttons.o $(LDFLAGS) $(LDLIBS) 53 | 54 | reaction: reaction.o 55 | @echo [link] 56 | @$(CC) -o $@ reaction.o $(LDFLAGS) $(LDLIBS) 57 | 58 | ladder: ladder.o 59 | @echo [link] 60 | @$(CC) -o $@ ladder.o $(LDFLAGS) $(LDLIBS) 61 | 62 | metro: metro.o 63 | @echo [link] 64 | @$(CC) -o $@ metro.o $(LDFLAGS) $(LDLIBS) 65 | 66 | motor: motor.o 67 | @echo [link] 68 | @$(CC) -o $@ motor.o $(LDFLAGS) $(LDLIBS) 69 | 70 | .c.o: 71 | @echo [CC] $< 72 | @$(CC) -c $(CFLAGS) $< -o $@ 73 | 74 | clean: 75 | @echo "[Clean]" 76 | @rm -f $(OBJ) *~ core tags $(BINS) 77 | 78 | tags: $(SRC) 79 | @echo [ctags] 80 | @ctags $(SRC) 81 | 82 | depend: 83 | makedepend -Y $(SRC) 84 | 85 | # DO NOT DELETE 86 | -------------------------------------------------------------------------------- /WiringPi/examples/PiFace/blink.c: -------------------------------------------------------------------------------- 1 | /* 2 | * blink.c: 3 | * Simple "blink" test for the PiFace interface board. 4 | * 5 | * Copyright (c) 2012-2013 Gordon Henderson. 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | // Use 200 as the pin-base for the PiFace board, and pick a pin 31 | // for the LED that's not connected to a relay 32 | 33 | #define PIFACE 200 34 | #define LED (PIFACE+2) 35 | 36 | int main (int argc, char *argv []) 37 | { 38 | printf ("Raspberry Pi PiFace Blink\n") ; 39 | printf ("=========================\n") ; 40 | 41 | // Always initialise wiringPi. Use wiringPiSys() if you don't need 42 | // (or want) to run as root 43 | 44 | wiringPiSetupSys () ; 45 | 46 | // Setup the PiFace board 47 | 48 | piFaceSetup (PIFACE) ; 49 | 50 | for (;;) 51 | { 52 | digitalWrite (LED, HIGH) ; // On 53 | delay (500) ; // mS 54 | digitalWrite (LED, LOW) ; // Off 55 | delay (500) ; 56 | } 57 | 58 | return 0 ; 59 | } 60 | -------------------------------------------------------------------------------- /WiringPi/examples/PiFace/buttons.c: -------------------------------------------------------------------------------- 1 | /* 2 | * buttons.c: 3 | * Simple test for the PiFace interface board. 4 | * 5 | * Read the buttons and output the same to the LEDs 6 | * 7 | * Copyright (c) 2012-2013 Gordon Henderson. 8 | *********************************************************************** 9 | * This file is part of wiringPi: 10 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 11 | * 12 | * wiringPi is free software: you can redistribute it and/or modify 13 | * it under the terms of the GNU Lesser General Public License as published by 14 | * the Free Software Foundation, either version 3 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * wiringPi is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public License 23 | * along with wiringPi. If not, see . 24 | *********************************************************************** 25 | */ 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | int outputs [4] = { 0,0,0,0 } ; 33 | 34 | // Use 200 as the pin-base for the PiFace board 35 | 36 | #define PIFACE_BASE 200 37 | 38 | 39 | /* 40 | * scanButton: 41 | * Read the guiven button - if it's pressed, then flip the state 42 | * of the correspoinding output pin 43 | ********************************************************************************* 44 | */ 45 | 46 | void scanButton (int button) 47 | { 48 | if (digitalRead (PIFACE_BASE + button) == LOW) 49 | { 50 | outputs [button] ^= 1 ; 51 | digitalWrite (PIFACE_BASE + button, outputs [button]) ; 52 | printf ("Button %d pushed - output now: %s\n", 53 | button, (outputs [button] == 0) ? "Off" : "On") ; 54 | } 55 | 56 | while (digitalRead (PIFACE_BASE + button) == LOW) 57 | delay (1) ; 58 | } 59 | 60 | 61 | /* 62 | * start here 63 | ********************************************************************************* 64 | */ 65 | 66 | int main (void) 67 | { 68 | int pin, button ; 69 | 70 | printf ("Raspberry Pi wiringPi + PiFace test program\n") ; 71 | printf ("===========================================\n") ; 72 | printf ("\n") ; 73 | printf ( 74 | "This program reads the buttons and uses them to toggle the first 4\n" 75 | "outputs. Push a button once to turn an output on, and push it again to\n" 76 | "turn it off again.\n\n") ; 77 | 78 | // Always initialise wiringPi. Use wiringPiSys() if you don't need 79 | // (or want) to run as root 80 | 81 | wiringPiSetupSys () ; 82 | 83 | piFaceSetup (PIFACE_BASE) ; 84 | 85 | // Enable internal pull-ups & start with all off 86 | 87 | for (pin = 0 ; pin < 8 ; ++pin) 88 | { 89 | pullUpDnControl (PIFACE_BASE + pin, PUD_UP) ; 90 | digitalWrite (PIFACE_BASE + pin, 0) ; 91 | } 92 | 93 | // Loop, scanning the buttons 94 | 95 | for (;;) 96 | { 97 | for (button = 0 ; button < 4 ; ++button) 98 | scanButton (button) ; 99 | delay (5) ; 100 | } 101 | 102 | return 0 ; 103 | } 104 | -------------------------------------------------------------------------------- /WiringPi/examples/PiFace/metro.c: -------------------------------------------------------------------------------- 1 | /* 2 | * metronome.c: 3 | * Simple test for the PiFace interface board. 4 | * 5 | * Copyright (c) 2012-2013 Gordon Henderson. 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #define PIFACE 200 33 | 34 | /* 35 | * middleA: 36 | * Play middle A (on the relays - yea!) 37 | ********************************************************************************* 38 | */ 39 | 40 | static void middleA (void) 41 | { 42 | unsigned int next ; 43 | 44 | for (;;) 45 | { 46 | next = micros () + 1136 ; 47 | digitalWrite (PIFACE + 0, 0) ; 48 | digitalWrite (PIFACE + 1, 0) ; 49 | while (micros () < next) 50 | delayMicroseconds (1) ; 51 | 52 | next = micros () + 1137 ; 53 | digitalWrite (PIFACE + 0, 1) ; 54 | digitalWrite (PIFACE + 1, 1) ; 55 | while (micros () < next) 56 | delayMicroseconds (1) ; 57 | 58 | } 59 | } 60 | 61 | 62 | int main (int argc, char *argv []) 63 | { 64 | int bpm, msPerBeat, state = 0 ; 65 | unsigned int end ; 66 | 67 | printf ("Raspberry Pi PiFace Metronome\n") ; 68 | printf ("=============================\n") ; 69 | 70 | piHiPri (50) ; 71 | 72 | wiringPiSetupSys () ; // Needed for timing functions 73 | piFaceSetup (PIFACE) ; 74 | 75 | if (argc != 2) 76 | { 77 | printf ("Usage: %s \n", argv [0]) ; 78 | exit (1) ; 79 | } 80 | 81 | if (strcmp (argv [1], "a") == 0) 82 | middleA () ; 83 | 84 | bpm = atoi (argv [1]) ; 85 | 86 | if ((bpm < 40) || (bpm > 208)) 87 | { 88 | printf ("%s range is 40 through 208 beats per minute\n", argv [0]) ; 89 | exit (1) ; 90 | } 91 | 92 | msPerBeat = 60000 / bpm ; 93 | 94 | // Main loop: 95 | // Put some random LED pairs up for a few seconds, then blank ... 96 | 97 | for (;;) 98 | { 99 | end = millis () + msPerBeat ; 100 | 101 | digitalWrite (PIFACE + 0, state) ; 102 | digitalWrite (PIFACE + 1, state) ; 103 | 104 | while (millis () < end) 105 | delayMicroseconds (500) ; 106 | 107 | state ^= 1 ; 108 | } 109 | 110 | return 0 ; 111 | } 112 | -------------------------------------------------------------------------------- /WiringPi/examples/PiFace/motor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * motor.c: 3 | * Use the PiFace board to demonstrate an H bridge 4 | * circuit via the 2 relays. 5 | * Then add on an external transsitor to help with PWM. 6 | * 7 | * Copyright (c) 2012-2013 Gordon Henderson. 8 | *********************************************************************** 9 | * This file is part of wiringPi: 10 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 11 | * 12 | * wiringPi is free software: you can redistribute it and/or modify 13 | * it under the terms of the GNU Lesser General Public License as published by 14 | * the Free Software Foundation, either version 3 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * wiringPi is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public License 23 | * along with wiringPi. If not, see . 24 | *********************************************************************** 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | int outputs [2] = { 0,0 } ; 36 | 37 | #define PIFACE_BASE 200 38 | #define PWM_OUT_PIN 204 39 | #define PWM_UP 202 40 | #define PWM_DOWN 203 41 | 42 | void scanButton (int button) 43 | { 44 | if (digitalRead (PIFACE_BASE + button) == LOW) 45 | { 46 | outputs [button] ^= 1 ; 47 | digitalWrite (PIFACE_BASE + button, outputs [button]) ; 48 | printf ("Button %d pushed - output now: %s\n", 49 | button, (outputs [button] == 0) ? "Off" : "On") ; 50 | } 51 | 52 | while (digitalRead (PIFACE_BASE + button) == LOW) 53 | delay (1) ; 54 | } 55 | 56 | 57 | int main (void) 58 | { 59 | int pin, button ; 60 | int pwmValue = 0 ; 61 | 62 | printf ("Raspberry Pi PiFace - Motor control\n") ; 63 | printf ("==================================\n") ; 64 | printf ("\n") ; 65 | printf ( 66 | "This program is designed to be used with a motor connected to the relays\n" 67 | "in an H-Bridge type configuration with optional speeed control via PWM.\n" 68 | "\n" 69 | "Use the leftmost buttons to turn each relay on and off, and the rigthmost\n" 70 | "buttons to increase ot decrease the PWM output on the control pin (pin\n" 71 | "4)\n\n") ; 72 | 73 | wiringPiSetup () ; 74 | piFaceSetup (PIFACE_BASE) ; 75 | softPwmCreate (PWM_OUT_PIN, 100, 100) ; 76 | 77 | // Enable internal pull-ups & start with all off 78 | 79 | for (pin = 0 ; pin < 8 ; ++pin) 80 | { 81 | pullUpDnControl (PIFACE_BASE + pin, PUD_UP) ; 82 | digitalWrite (PIFACE_BASE + pin, 0) ; 83 | } 84 | 85 | for (;;) 86 | { 87 | for (button = 0 ; button < 2 ; ++button) 88 | scanButton (button) ; 89 | 90 | if (digitalRead (PWM_UP) == LOW) 91 | { 92 | pwmValue += 10 ; 93 | if (pwmValue > 100) 94 | pwmValue = 100 ; 95 | 96 | softPwmWrite (PWM_OUT_PIN, pwmValue) ; 97 | printf ("PWM -> %3d\n", pwmValue) ; 98 | 99 | while (digitalRead (PWM_UP) == LOW) 100 | delay (5) ; 101 | } 102 | 103 | if (digitalRead (PWM_DOWN) == LOW) 104 | { 105 | pwmValue -= 10 ; 106 | if (pwmValue < 0) 107 | pwmValue = 0 ; 108 | 109 | softPwmWrite (PWM_OUT_PIN, pwmValue) ; 110 | printf ("PWM -> %3d\n", pwmValue) ; 111 | 112 | while (digitalRead (PWM_DOWN) == LOW) 113 | delay (5) ; 114 | } 115 | 116 | delay (5) ; 117 | } 118 | 119 | return 0 ; 120 | } 121 | -------------------------------------------------------------------------------- /WiringPi/examples/PiGlow/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile: 3 | # wiringPi - Wiring Compatable library for the Raspberry Pi 4 | # https://projects.drogon.net/wiring-pi 5 | # 6 | # Copyright (c) 2012-2013 Gordon Henderson 7 | ################################################################################# 8 | # This file is part of wiringPi: 9 | # Wiring Compatable library for the Raspberry Pi 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 . 23 | ################################################################################# 24 | 25 | 26 | #DEBUG = -g -O0 27 | DEBUG = -O3 28 | CC = gcc 29 | INCLUDE = -I/usr/local/include 30 | CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe 31 | 32 | LDFLAGS = -L/usr/local/lib 33 | LDLIBS = -lwiringPi -lwiringPiDev -lpthread -lm 34 | 35 | # Should not alter anything below this line 36 | ############################################################################### 37 | 38 | SRC = piGlow0.c piGlow1.c piglow.c 39 | 40 | OBJ = $(SRC:.c=.o) 41 | 42 | BINS = $(SRC:.c=) 43 | 44 | all: $(BINS) 45 | 46 | piGlow0: piGlow0.o 47 | @echo [link] 48 | @$(CC) -o $@ piGlow0.o $(LDFLAGS) $(LDLIBS) 49 | 50 | piGlow1: piGlow1.o 51 | @echo [link] 52 | @$(CC) -o $@ piGlow1.o $(LDFLAGS) $(LDLIBS) 53 | 54 | piglow: piglow.o 55 | @echo [link] 56 | @$(CC) -o $@ piglow.o $(LDFLAGS) $(LDLIBS) 57 | 58 | .c.o: 59 | @echo [CC] $< 60 | @$(CC) -c $(CFLAGS) $< -o $@ 61 | 62 | clean: 63 | @echo "[Clean]" 64 | @rm -f $(OBJ) *~ core tags $(BINS) 65 | 66 | tags: $(SRC) 67 | @echo [ctags] 68 | @ctags $(SRC) 69 | 70 | install: piglow 71 | @echo Installing piglow into /usr/local/bin 72 | @cp -a piglow /usr/local/bin/piglow 73 | @chmod 755 /usr/local/bin/piglow 74 | @echo Done. Remember to load the I2C drivers! 75 | 76 | depend: 77 | makedepend -Y $(SRC) 78 | 79 | # DO NOT DELETE 80 | -------------------------------------------------------------------------------- /WiringPi/examples/PiGlow/piGlow0.c: -------------------------------------------------------------------------------- 1 | /* 2 | * piglow.c: 3 | * Very simple demonstration of the PiGlow board. 4 | * This uses the SN3218 directly - soon there will be a new PiGlow 5 | * devLib device which will handle the PiGlow board on a more easy 6 | * to use manner... 7 | * 8 | * Copyright (c) 2013 Gordon Henderson. 9 | *********************************************************************** 10 | * This file is part of wiringPi: 11 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 12 | * 13 | * wiringPi is free software: you can redistribute it and/or modify 14 | * it under the terms of the GNU Lesser General Public License as published by 15 | * the Free Software Foundation, either version 3 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * wiringPi is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU Lesser General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU Lesser General Public License 24 | * along with wiringPi. If not, see . 25 | *********************************************************************** 26 | */ 27 | 28 | #include 29 | #include 30 | 31 | #define LED_BASE 533 32 | 33 | int main (void) 34 | { 35 | int i, j ; 36 | 37 | wiringPiSetupSys () ; 38 | 39 | sn3218Setup (LED_BASE) ; 40 | 41 | for (;;) 42 | { 43 | for (i = 0 ; i < 256 ; ++i) 44 | for (j = 0 ; j < 18 ; ++j) 45 | analogWrite (LED_BASE + j, i) ; 46 | 47 | for (i = 255 ; i >= 0 ; --i) 48 | for (j = 0 ; j < 18 ; ++j) 49 | analogWrite (LED_BASE + j, i) ; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /WiringPi/examples/README.TXT: -------------------------------------------------------------------------------- 1 | 2 | wiringPi Examples 3 | ================= 4 | 5 | There are now too many examples to compile them all in a sensible time, 6 | and you probably don't want to compile or run them all anyway, so they 7 | have been separated out. 8 | 9 | To compile an individual example, just type 10 | 11 | make exampleName 12 | 13 | To really compile everything: 14 | 15 | make really-all 16 | 17 | The individual tests are: 18 | 19 | -------------------------------------------------------------------------------- /WiringPi/examples/blink.c: -------------------------------------------------------------------------------- 1 | /* 2 | * blink.c: 3 | * Standard "blink" program in wiringPi. Blinks an LED connected 4 | * to the first GPIO pin. 5 | * 6 | * Copyright (c) 2012-2013 Gordon Henderson. 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 . 23 | *********************************************************************** 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | // LED Pin - wiringPi pin 0 is BCM_GPIO 17. 30 | 31 | #define LED 0 32 | 33 | int main (void) 34 | { 35 | printf ("Raspberry Pi blink\n") ; 36 | 37 | wiringPiSetup () ; 38 | pinMode (LED, OUTPUT) ; 39 | 40 | for (;;) 41 | { 42 | digitalWrite (LED, HIGH) ; // On 43 | delay (500) ; // mS 44 | digitalWrite (LED, LOW) ; // Off 45 | delay (500) ; 46 | } 47 | return 0 ; 48 | } 49 | -------------------------------------------------------------------------------- /WiringPi/examples/blink.rtb: -------------------------------------------------------------------------------- 1 | // blink.rtb: 2 | // Blink program in Return to Basic 3 | // 4 | // Copyright (c) 2012-2013 Gordon Henderson. 5 | //********************************************************************** 6 | // This file is part of wiringPi: 7 | // https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | // 9 | // wiringPi is free software: you can redistribute it and/or modify 10 | // it under the terms of the GNU Lesser General Public License as published by 11 | // the Free Software Foundation, either version 3 of the License, or 12 | // (at your option) any later version. 13 | // 14 | // wiringPi is distributed in the hope that it will be useful, 15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | // GNU Lesser General Public License for more details. 18 | // 19 | // You should have received a copy of the GNU Lesser General Public License 20 | // along with wiringPi. If not, see . 21 | *********************************************************************** 22 | // 23 | PinMode (0, 1) // Output 24 | CYCLE 25 | DigitalWrite (0, 1) // Pin 0 ON 26 | WAIT (0.5) // 0.5 seconds 27 | DigitalWrite (0, 0) 28 | WAIT (0.5) 29 | REPEAT 30 | END 31 | -------------------------------------------------------------------------------- /WiringPi/examples/blink.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # blink.sh: 4 | # Standard "blink" program in wiringPi. Blinks an LED connected 5 | # to the first GPIO pin. 6 | # 7 | # Copyright (c) 2012-2013 Gordon Henderson. 8 | ####################################################################### 9 | # This file is part of wiringPi: 10 | # https://projects.drogon.net/raspberry-pi/wiringpi/ 11 | # 12 | # wiringPi is free software: you can redistribute it and/or modify 13 | # it under the terms of the GNU Lesser General Public License as published by 14 | # the Free Software Foundation, either version 3 of the License, or 15 | # (at your option) any later version. 16 | # 17 | # wiringPi is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | # GNU Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public License 23 | # along with wiringPi. If not, see . 24 | ####################################################################### 25 | 26 | # LED Pin - wiringPi pin 0 is BCM_GPIO 17. 27 | 28 | PIN=0 29 | 30 | gpio mode $PIN out 31 | 32 | while true; do 33 | gpio write $PIN 1 34 | sleep 0.5 35 | gpio write $PIN 0 36 | sleep 0.5 37 | done 38 | -------------------------------------------------------------------------------- /WiringPi/examples/blink12.c: -------------------------------------------------------------------------------- 1 | /* 2 | * blink12.c: 3 | * Simple sequence over the first 12 GPIO pins - LEDs 4 | * Aimed at the Gertboard, but it's fairly generic. 5 | * 6 | * Copyright (c) 2012-2013 Gordon Henderson. 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 . 23 | *********************************************************************** 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | // Simple sequencer data 30 | // Triplets of LED, On/Off and delay 31 | 32 | int data [] = 33 | { 34 | 0, 1, 1, 35 | 1, 1, 1, 36 | 0, 0, 0, 2, 1, 1, 37 | 1, 0, 0, 3, 1, 1, 38 | 2, 0, 0, 4, 1, 1, 39 | 3, 0, 0, 5, 1, 1, 40 | 4, 0, 0, 6, 1, 1, 41 | 5, 0, 0, 7, 1, 1, 42 | 6, 0, 0, 11, 1, 1, 43 | 7, 0, 0, 10, 1, 1, 44 | 11, 0, 0, 13, 1, 1, 45 | 10, 0, 0, 12, 1, 1, 46 | 13, 0, 1, 47 | 12, 0, 1, 48 | 49 | 0, 0, 1, // Extra delay 50 | 51 | // Back again 52 | 53 | 12, 1, 1, 54 | 13, 1, 1, 55 | 12, 0, 0, 10, 1, 1, 56 | 13, 0, 0, 11, 1, 1, 57 | 10, 0, 0, 7, 1, 1, 58 | 11, 0, 0, 6, 1, 1, 59 | 7, 0, 0, 5, 1, 1, 60 | 6, 0, 0, 4, 1, 1, 61 | 5, 0, 0, 3, 1, 1, 62 | 4, 0, 0, 2, 1, 1, 63 | 3, 0, 0, 1, 1, 1, 64 | 2, 0, 0, 0, 1, 1, 65 | 1, 0, 1, 66 | 0, 0, 1, 67 | 68 | 0, 0, 1, // Extra delay 69 | 70 | 0, 9, 0, // End marker 71 | 72 | } ; 73 | 74 | 75 | int main (void) 76 | { 77 | int pin ; 78 | int dataPtr ; 79 | int l, s, d ; 80 | 81 | printf ("Raspberry Pi - 12-LED Sequence\n") ; 82 | printf ("==============================\n") ; 83 | printf ("\n") ; 84 | printf ("Connect LEDs up to the first 8 GPIO pins, then pins 11, 10, 13, 12 in\n") ; 85 | printf (" that order, then sit back and watch the show!\n") ; 86 | 87 | wiringPiSetup () ; 88 | 89 | for (pin = 0 ; pin < 14 ; ++pin) 90 | pinMode (pin, OUTPUT) ; 91 | 92 | dataPtr = 0 ; 93 | 94 | for (;;) 95 | { 96 | l = data [dataPtr++] ; // LED 97 | s = data [dataPtr++] ; // State 98 | d = data [dataPtr++] ; // Duration (10ths) 99 | 100 | if (s == 9) // 9 -> End Marker 101 | { 102 | dataPtr = 0 ; 103 | continue ; 104 | } 105 | 106 | digitalWrite (l, s) ; 107 | delay (d * 100) ; 108 | } 109 | 110 | return 0 ; 111 | } 112 | -------------------------------------------------------------------------------- /WiringPi/examples/blink12drcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * blink12drcs.c: 3 | * Simple sequence over the first 12 GPIO pins - LEDs 4 | * Aimed at the Gertboard, but it's fairly generic. 5 | * This version uses DRC totalk to the ATmega on the Gertboard 6 | * 7 | * Copyright (c) 2012-2013 Gordon Henderson. 8 | *********************************************************************** 9 | * This file is part of wiringPi: 10 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 11 | * 12 | * wiringPi is free software: you can redistribute it and/or modify 13 | * it under the terms of the GNU Lesser General Public License as published by 14 | * the Free Software Foundation, either version 3 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * wiringPi is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public License 23 | * along with wiringPi. If not, see . 24 | *********************************************************************** 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #define GERT_BASE 100 32 | 33 | static int pinMap [] = 34 | { 35 | 0, 1, 2, 3, // Pi Native 36 | GERT_BASE + 2, GERT_BASE + 3, GERT_BASE + 4, GERT_BASE + 5, 37 | GERT_BASE + 6, GERT_BASE + 7, GERT_BASE + 8, GERT_BASE + 9, 38 | } ; 39 | 40 | // Simple sequencer data 41 | // Triplets of LED, On/Off and delay 42 | 43 | 44 | int data [] = 45 | { 46 | 0, 1, 1, 47 | 1, 1, 1, 48 | 0, 0, 0, 2, 1, 1, 49 | 1, 0, 0, 3, 1, 1, 50 | 2, 0, 0, 4, 1, 1, 51 | 3, 0, 0, 5, 1, 1, 52 | 4, 0, 0, 6, 1, 1, 53 | 5, 0, 0, 7, 1, 1, 54 | 6, 0, 0, 8, 1, 1, 55 | 7, 0, 0, 9, 1, 1, 56 | 8, 0, 0, 10, 1, 1, 57 | 9, 0, 0, 11, 1, 1, 58 | 10, 0, 1, 59 | 11, 0, 1, 60 | 61 | 0, 0, 1, // Extra delay 62 | 63 | // Back again 64 | 65 | 11, 1, 1, 66 | 10, 1, 1, 67 | 11, 0, 0, 9, 1, 1, 68 | 10, 0, 0, 8, 1, 1, 69 | 9, 0, 0, 7, 1, 1, 70 | 8, 0, 0, 6, 1, 1, 71 | 7, 0, 0, 5, 1, 1, 72 | 6, 0, 0, 4, 1, 1, 73 | 5, 0, 0, 3, 1, 1, 74 | 4, 0, 0, 2, 1, 1, 75 | 3, 0, 0, 1, 1, 1, 76 | 2, 0, 0, 0, 1, 1, 77 | 1, 0, 1, 78 | 0, 0, 1, 79 | 80 | 0, 0, 1, // Extra delay 81 | 82 | 0, 9, 0, // End marker 83 | 84 | } ; 85 | 86 | 87 | int main (void) 88 | { 89 | int pin ; 90 | int dataPtr ; 91 | int l, s, d ; 92 | 93 | printf ("Raspberry Pi - 12-LED Sequence\n") ; 94 | printf ("==============================\n") ; 95 | printf ("\n") ; 96 | printf ("Connect LEDs up to the first 4 Pi pins and 8 pins on the ATmega\n") ; 97 | printf (" from PD2 through PB1 in that order,\n") ; 98 | printf (" then sit back and watch the show!\n") ; 99 | 100 | wiringPiSetup () ; 101 | drcSetupSerial (GERT_BASE, 20, "/dev/ttyAMA0", 115200) ; 102 | 103 | for (pin = 0 ; pin < 12 ; ++pin) 104 | pinMode (pinMap [pin], OUTPUT) ; 105 | 106 | dataPtr = 0 ; 107 | 108 | for (;;) 109 | { 110 | l = data [dataPtr++] ; // LED 111 | s = data [dataPtr++] ; // State 112 | d = data [dataPtr++] ; // Duration (10ths) 113 | 114 | if (s == 9) // 9 -> End Marker 115 | { 116 | dataPtr = 0 ; 117 | continue ; 118 | } 119 | 120 | digitalWrite (pinMap [l], s) ; 121 | delay (d * analogRead (GERT_BASE) / 4) ; 122 | } 123 | 124 | return 0 ; 125 | } 126 | -------------------------------------------------------------------------------- /WiringPi/examples/blink6drcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * blink6drcs.c: 3 | * Simple sequence over 6 pins on a remote DRC board. 4 | * Aimed at the Gertduino, but it's fairly generic. 5 | * This version uses DRC to talk to the ATmega on the Gertduino 6 | * 7 | * Copyright (c) 2012-2014 Gordon Henderson. 8 | *********************************************************************** 9 | * This file is part of wiringPi: 10 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 11 | * 12 | * wiringPi is free software: you can redistribute it and/or modify 13 | * it under the terms of the GNU Lesser General Public License as published by 14 | * the Free Software Foundation, either version 3 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * wiringPi is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public License 23 | * along with wiringPi. If not, see . 24 | *********************************************************************** 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #define GERT_BASE 100 32 | 33 | static int pinMap [] = 34 | { 35 | GERT_BASE + 6, GERT_BASE + 5, GERT_BASE + 3, GERT_BASE + 10, GERT_BASE + 9, GERT_BASE + 13, 36 | } ; 37 | 38 | // Simple sequencer data 39 | // Triplets of LED, On/Off and delay 40 | 41 | 42 | int data [] = 43 | { 44 | 0, 1, 1, 45 | 1, 1, 1, 46 | 0, 0, 0, 2, 1, 1, 47 | 1, 0, 0, 3, 1, 1, 48 | 2, 0, 0, 4, 1, 1, 49 | 3, 0, 0, 5, 1, 1, 50 | 4, 0, 1, 51 | 5, 0, 1, 52 | 53 | 0, 0, 1, // Extra delay 54 | 55 | // Back again 56 | 57 | 5, 1, 1, 58 | 4, 1, 1, 59 | 5, 0, 0, 3, 1, 1, 60 | 4, 0, 0, 2, 1, 1, 61 | 3, 0, 0, 1, 1, 1, 62 | 2, 0, 0, 0, 1, 1, 63 | 1, 0, 1, 64 | 0, 0, 1, 65 | 66 | 0, 0, 1, // Extra delay 67 | 68 | 0, 9, 0, // End marker 69 | 70 | } ; 71 | 72 | 73 | int main (void) 74 | { 75 | int pin ; 76 | int dataPtr ; 77 | int l, s, d ; 78 | 79 | printf ("Raspberry Pi - 6-LED Sequence\n") ; 80 | printf ("=============================\n") ; 81 | printf ("\n") ; 82 | printf (" Use the 2 buttons to temporarily speed up the sequence\n") ; 83 | 84 | wiringPiSetupSys () ; // Not using the Pi's GPIO here 85 | drcSetupSerial (GERT_BASE, 20, "/dev/ttyAMA0", 115200) ; 86 | 87 | for (pin = 0 ; pin < 6 ; ++pin) 88 | pinMode (pinMap [pin], OUTPUT) ; 89 | 90 | pinMode (GERT_BASE + 16, INPUT) ; // Buttons 91 | pinMode (GERT_BASE + 17, INPUT) ; 92 | 93 | pullUpDnControl (GERT_BASE + 16, PUD_UP) ; 94 | pullUpDnControl (GERT_BASE + 17, PUD_UP) ; 95 | 96 | dataPtr = 0 ; 97 | 98 | for (;;) 99 | { 100 | l = data [dataPtr++] ; // LED 101 | s = data [dataPtr++] ; // State 102 | d = data [dataPtr++] ; // Duration (10ths) 103 | 104 | if (s == 9) // 9 -> End Marker 105 | { 106 | dataPtr = 0 ; 107 | continue ; 108 | } 109 | 110 | digitalWrite (pinMap [l], s) ; 111 | delay (d * digitalRead (GERT_BASE + 16) * 15 + digitalRead (GERT_BASE + 17) * 20) ; 112 | } 113 | 114 | return 0 ; 115 | } 116 | -------------------------------------------------------------------------------- /WiringPi/examples/blink8.c: -------------------------------------------------------------------------------- 1 | /* 2 | * blink8.c: 3 | * Simple sequence over the first 8 GPIO pins - LEDs 4 | * Aimed at the Gertboard, but it's fairly generic. 5 | * 6 | * Copyright (c) 2012-2013 Gordon Henderson. 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 . 23 | *********************************************************************** 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | int main (void) 30 | { 31 | int i, led ; 32 | 33 | printf ("Raspberry Pi - 8-LED Sequencer\n") ; 34 | printf ("==============================\n") ; 35 | printf ("\n") ; 36 | printf ("Connect LEDs to the first 8 GPIO pins and watch ...\n") ; 37 | 38 | wiringPiSetup () ; 39 | 40 | for (i = 0 ; i < 8 ; ++i) 41 | pinMode (i, OUTPUT) ; 42 | 43 | for (;;) 44 | { 45 | for (led = 0 ; led < 8 ; ++led) 46 | { 47 | digitalWrite (led, 1) ; 48 | delay (100) ; 49 | } 50 | 51 | for (led = 0 ; led < 8 ; ++led) 52 | { 53 | digitalWrite (led, 0) ; 54 | delay (100) ; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /WiringPi/examples/delayTest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * delayTest.c: 3 | * Just a little test program I'm using to experiment with 4 | * various timings and latency, etc. 5 | * 6 | * Copyright (c) 2012-2013 Gordon Henderson. 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 . 23 | *********************************************************************** 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | #define CYCLES 1000 33 | 34 | int main() 35 | { 36 | int x ; 37 | struct timeval t1, t2 ; 38 | int t ; 39 | int max, min ; 40 | int del ; 41 | int underRuns, overRuns, exactRuns, total ; 42 | int descheds ; 43 | 44 | if (wiringPiSetup () == -1) 45 | return 1 ; 46 | 47 | piHiPri (10) ; sleep (1) ; 48 | 49 | // Baseline test 50 | 51 | gettimeofday (&t1, NULL) ; 52 | gettimeofday (&t2, NULL) ; 53 | 54 | t = t2.tv_usec - t1.tv_usec ; 55 | printf ("Baseline test: %d\n", t); 56 | 57 | for (del = 1 ; del < 200 ; ++del) 58 | { 59 | underRuns = overRuns = exactRuns = total = 0 ; 60 | descheds = 0 ; 61 | max = del ; 62 | min = del ; 63 | 64 | for (x = 0 ; x < CYCLES ; ++x) 65 | { 66 | for (;;) // Repeat this if we get a delay over 999uS 67 | { // -> High probability Linux has deschedulled us 68 | gettimeofday (&t1, NULL) ; 69 | delayMicroseconds (del) ; 70 | gettimeofday (&t2, NULL) ; 71 | 72 | if (t2.tv_usec < t1.tv_usec) // Counter wrapped 73 | t = (1000000 + t2.tv_usec) - t1.tv_usec; 74 | else 75 | t = t2.tv_usec - t1.tv_usec ; 76 | if (t > 999) 77 | { 78 | ++descheds ; 79 | continue ; 80 | } 81 | else 82 | break ; 83 | } 84 | 85 | if (t > max) 86 | { 87 | max = t ; 88 | ++overRuns ; 89 | } 90 | else if (t < min) 91 | { 92 | min = t ; 93 | ++underRuns ; 94 | } 95 | else 96 | ++exactRuns ; 97 | 98 | total += t ; 99 | } 100 | printf ("Delay: %3d. Min: %3d, Max: %3d, Unders: %3d, Overs: %3d, Exacts: %3d, Average: %3d, Descheds: %2d\n", 101 | del, min, max, underRuns, overRuns, exactRuns, total / CYCLES, descheds) ; 102 | fflush (stdout) ; 103 | delay (1) ; 104 | } 105 | 106 | return 0 ; 107 | } 108 | -------------------------------------------------------------------------------- /WiringPi/examples/header.h: -------------------------------------------------------------------------------- 1 | /* 2 | * file.c: 3 | * 4 | * Copyright (c) 2012-2013 Gordon Henderson. 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with wiringPi. If not, see . 21 | *********************************************************************** 22 | */ 23 | 24 | -------------------------------------------------------------------------------- /WiringPi/examples/lowPower.c: -------------------------------------------------------------------------------- 1 | /* 2 | * lowPower.c: 3 | * Check the Pi's LOW-Power signal. 4 | * 5 | * This is a demonstration program that could be turned into some sort 6 | * of logger via e.g. syslog - however it's also probably something 7 | * that might be better handled by a future kernel - who knows. 8 | * 9 | * Copyright (c) 2014 Gordon Henderson. 10 | *********************************************************************** 11 | * This file is part of wiringPi: 12 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 13 | * 14 | * wiringPi is free software: you can redistribute it and/or modify 15 | * it under the terms of the GNU Lesser General Public License as published by 16 | * the Free Software Foundation, either version 3 of the License, or 17 | * (at your option) any later version. 18 | * 19 | * wiringPi is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU Lesser General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU Lesser General Public License 25 | * along with wiringPi. If not, see . 26 | *********************************************************************** 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | 34 | #define LOW_POWER 35 35 | 36 | /* 37 | * lowPower: 38 | * This is an ISR that waits for the low-power signal going low and 39 | * prints the result. 40 | ********************************************************************************* 41 | */ 42 | 43 | void lowPower (void) 44 | { 45 | time_t t ; 46 | 47 | time (&t) ; 48 | printf ("%s: LOW POWER DETECTED\n", ctime (&t)) ; 49 | } 50 | 51 | 52 | /* 53 | ********************************************************************************* 54 | * main 55 | ********************************************************************************* 56 | */ 57 | 58 | int main (void) 59 | { 60 | wiringPiSetupGpio () ; // GPIO mode as it's an internal pin 61 | 62 | wiringPiISR (LOW_POWER, INT_EDGE_FALLING, &lowPower) ; 63 | 64 | for (;;) 65 | delay (1000) ; 66 | 67 | return 0 ; 68 | } 69 | -------------------------------------------------------------------------------- /WiringPi/examples/nes.c: -------------------------------------------------------------------------------- 1 | /* 2 | * nes.c: 3 | * Test program for an old NES controller connected to the Pi. 4 | * 5 | * Copyright (c) 2012-2013 Gordon Henderson. 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #define BLANK "| " 33 | 34 | int main () 35 | { 36 | int joystick ; 37 | unsigned int buttons ; 38 | 39 | if (wiringPiSetup () == -1) 40 | { 41 | fprintf (stdout, "oops: %s\n", strerror (errno)) ; 42 | return 1 ; 43 | } 44 | 45 | if ((joystick = setupNesJoystick (2, 1, 0)) == -1) 46 | { 47 | fprintf (stdout, "Unable to setup joystick\n") ; 48 | return 1 ; 49 | } 50 | 51 | for (;;) 52 | { 53 | buttons = readNesJoystick (joystick) ; 54 | 55 | if ((buttons & NES_UP) != 0) printf ("| UP " ) ; else printf (BLANK) ; 56 | if ((buttons & NES_DOWN) != 0) printf ("| DOWN " ) ; else printf (BLANK) ; 57 | if ((buttons & NES_LEFT) != 0) printf ("| LEFT " ) ; else printf (BLANK) ; 58 | if ((buttons & NES_RIGHT) != 0) printf ("|RIGHT " ) ; else printf (BLANK) ; 59 | if ((buttons & NES_SELECT) != 0) printf ("|SELECT" ) ; else printf (BLANK) ; 60 | if ((buttons & NES_START) != 0) printf ("|START " ) ; else printf (BLANK) ; 61 | if ((buttons & NES_A) != 0) printf ("| A " ) ; else printf (BLANK) ; 62 | if ((buttons & NES_B) != 0) printf ("| B " ) ; else printf (BLANK) ; 63 | printf ("|\n") ; 64 | } 65 | 66 | return 0 ; 67 | } 68 | -------------------------------------------------------------------------------- /WiringPi/examples/okLed.c: -------------------------------------------------------------------------------- 1 | /* 2 | * okLed.c: 3 | * Make the OK LED on the Pi Pulsate... 4 | * 5 | * Originally posted to the Raspberry Pi forums: 6 | * http://www.raspberrypi.org/phpBB3/viewtopic.php?p=162581#p162581 7 | * 8 | * Compile this and store it somewhere, then kick it off at boot time 9 | * e.g. by putting it in /etc/rc.local and running it in the 10 | * background & 11 | * 12 | * Copyright (c) 2012-2013 Gordon Henderson. 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 . 29 | *********************************************************************** 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | 42 | // The OK/Act LED is connected to BCM_GPIO pin 16 43 | 44 | #define OK_LED 16 45 | 46 | int main () 47 | { 48 | int fd, i ; 49 | 50 | wiringPiSetupGpio () ; 51 | 52 | // Change the trigger on the OK/Act LED to "none" 53 | 54 | if ((fd = open ("/sys/class/leds/led0/trigger", O_RDWR)) < 0) 55 | { 56 | fprintf (stderr, "Unable to change LED trigger: %s\n", strerror (errno)) ; 57 | return 1 ; 58 | } 59 | write (fd, "none\n", 5) ; 60 | close (fd) ; 61 | 62 | softPwmCreate (OK_LED, 0, 100) ; 63 | 64 | for (;;) 65 | { 66 | for (i = 0 ; i <= 100 ; ++i) 67 | { 68 | softPwmWrite (OK_LED, i) ; 69 | delay (10) ; 70 | } 71 | delay (50) ; 72 | 73 | for (i = 100 ; i >= 0 ; --i) 74 | { 75 | softPwmWrite (OK_LED, i) ; 76 | delay (10) ; 77 | } 78 | delay (10) ; 79 | } 80 | 81 | return 0 ; 82 | } 83 | -------------------------------------------------------------------------------- /WiringPi/examples/pwm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pwm.c: 3 | * This tests the hardware PWM channel. 4 | * 5 | * Copyright (c) 2012-2013 Gordon Henderson. 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | int main (void) 32 | { 33 | int bright ; 34 | 35 | printf ("Raspberry Pi wiringPi PWM test program\n") ; 36 | 37 | if (wiringPiSetup () == -1) 38 | exit (1) ; 39 | 40 | pinMode (1, PWM_OUTPUT) ; 41 | 42 | for (;;) 43 | { 44 | for (bright = 0 ; bright < 1024 ; ++bright) 45 | { 46 | pwmWrite (1, bright) ; 47 | delay (1) ; 48 | } 49 | 50 | for (bright = 1023 ; bright >= 0 ; --bright) 51 | { 52 | pwmWrite (1, bright) ; 53 | delay (1) ; 54 | } 55 | } 56 | 57 | return 0 ; 58 | } 59 | -------------------------------------------------------------------------------- /WiringPi/examples/q2w/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile: 3 | # wiringPi - Wiring Compatable library for the Raspberry Pi 4 | # https://projects.drogon.net/wiring-pi 5 | # 6 | # Copyright (c) 2012-2013 Gordon Henderson 7 | ################################################################################# 8 | # This file is part of wiringPi: 9 | # Wiring Compatable library for the Raspberry Pi 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 . 23 | ################################################################################# 24 | 25 | 26 | #DEBUG = -g -O0 27 | DEBUG = -O3 28 | CC = gcc 29 | INCLUDE = -I/usr/local/include 30 | CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe 31 | 32 | LDFLAGS = -L/usr/local/lib 33 | LDLIBS = -lwiringPi -lwiringPiDev -lpthread -lm 34 | 35 | ############################################################################### 36 | 37 | SRC = blink.c button.c blink-io.c volts.c bright.c 38 | 39 | OBJ = $(SRC:.c=.o) 40 | 41 | BINS = $(SRC:.c=) 42 | 43 | all: $(BINS) 44 | 45 | blink: blink.o 46 | @echo [link] 47 | @$(CC) -o $@ blink.o $(LDFLAGS) $(LDLIBS) 48 | 49 | blink-io: blink-io.o 50 | @echo [link] 51 | @$(CC) -o $@ blink-io.o $(LDFLAGS) $(LDLIBS) 52 | 53 | button: button.o 54 | @echo [link] 55 | @$(CC) -o $@ button.o $(LDFLAGS) $(LDLIBS) 56 | 57 | volts: volts.o 58 | @echo [link] 59 | @$(CC) -o $@ volts.o $(LDFLAGS) $(LDLIBS) 60 | 61 | bright: bright.o 62 | @echo [link] 63 | @$(CC) -o $@ bright.o $(LDFLAGS) $(LDLIBS) 64 | 65 | 66 | .c.o: 67 | @echo [CC] $< 68 | @$(CC) -c $(CFLAGS) $< -o $@ 69 | 70 | clean: 71 | @echo "[Clean]" 72 | @rm -f $(OBJ) *~ core tags $(BINS) 73 | 74 | tags: $(SRC) 75 | @echo [ctags] 76 | @ctags $(SRC) 77 | 78 | depend: 79 | makedepend -Y $(SRC) 80 | 81 | # DO NOT DELETE 82 | -------------------------------------------------------------------------------- /WiringPi/examples/q2w/binary.c: -------------------------------------------------------------------------------- 1 | /* 2 | * binary.c: 3 | * Using the Quick 2 wire 16-bit GPIO expansion board to output 4 | * a binary counter. 5 | * 6 | * Copyright (c) 2012-2013 Gordon Henderson. 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 . 23 | *********************************************************************** 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #define Q2W_BASE 100 31 | 32 | int main (void) 33 | { 34 | int i, bit ; 35 | 36 | // Enable the on-goard GPIO 37 | 38 | wiringPiSetup () ; 39 | 40 | // Add in the mcp23017 on the q2w board 41 | 42 | mcp23017Setup (Q2W_BASE, 0x20) ; 43 | 44 | printf ("Raspberry Pi - quite2Wire MCP23017 Test\n") ; 45 | 46 | // On-board button Input: 47 | 48 | pinMode (0, INPUT) ; 49 | 50 | // First 10 pins on q2w board as outputs: 51 | 52 | for (i = 0 ; i < 10 ; ++i) 53 | pinMode (Q2W_BASE + i, OUTPUT) ; 54 | 55 | // Last pin as an input with the internal pull-up enabled 56 | 57 | pinMode (Q2W_BASE + 15, INPUT) ; 58 | pullUpDnControl (Q2W_BASE + 15, PUD_UP) ; 59 | 60 | // Loop, outputting a binary number, 61 | // Go faster with the button, or stop if the 62 | // on-board button is pushed 63 | 64 | for (;;) 65 | { 66 | for (i = 0 ; i < 1024 ; ++i) 67 | { 68 | for (bit = 0 ; bit < 10 ; ++bit) 69 | digitalWrite (Q2W_BASE + bit, i & (1 << bit)) ; 70 | 71 | while (digitalRead (0) == HIGH) // While pushed 72 | delay (1) ; 73 | 74 | if (digitalRead (Q2W_BASE + 15) == HIGH) // Not Pushed 75 | delay (100) ; 76 | } 77 | } 78 | return 0 ; 79 | } 80 | -------------------------------------------------------------------------------- /WiringPi/examples/q2w/blink-io.c: -------------------------------------------------------------------------------- 1 | /* 2 | * blink-io.c: 3 | * Simple "blink" test for the Quick2Wire 16-pin IO board. 4 | * 5 | * Copyright (c) 2012-2013 Gordon Henderson. 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #define LED 1 30 | #define Q2W_BASE 100 31 | 32 | int main (void) 33 | { 34 | 35 | // Enable the on-goard GPIO 36 | 37 | wiringPiSetup () ; 38 | 39 | // Add in the mcp23017 on the q2w board 40 | 41 | mcp23017Setup (Q2W_BASE, 0x20) ; 42 | 43 | printf ("Raspberry Pi - Quick2Wire MCP23017 Blink Test\n") ; 44 | 45 | // Blink the on-board LED as well as one on the mcp23017 46 | 47 | pinMode (LED, OUTPUT) ; 48 | pinMode (Q2W_BASE + 0, OUTPUT) ; 49 | 50 | for (;;) 51 | { 52 | digitalWrite (LED, HIGH) ; 53 | digitalWrite (Q2W_BASE + 0, HIGH) ; 54 | delay (500) ; 55 | digitalWrite (LED, LOW) ; 56 | digitalWrite (Q2W_BASE + 0, LOW) ; 57 | delay (500) ; 58 | } 59 | 60 | return 0 ; 61 | } 62 | -------------------------------------------------------------------------------- /WiringPi/examples/q2w/blink.c: -------------------------------------------------------------------------------- 1 | /* 2 | * blink.c: 3 | * Simple "blink" test for the Quick2Wire interface board. 4 | * 5 | * Copyright (c) 2012-2013 Gordon Henderson. 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | #define LED 1 29 | 30 | int main (void) 31 | { 32 | 33 | // Enable the on-goard GPIO 34 | 35 | wiringPiSetup () ; 36 | 37 | printf ("Raspberry Pi - Quick2Wire Mainboard LED Blink Test\n") ; 38 | 39 | pinMode (LED, OUTPUT) ; 40 | 41 | for (;;) 42 | { 43 | digitalWrite (LED, HIGH) ; 44 | delay (500) ; 45 | digitalWrite (LED, LOW) ; 46 | delay (500) ; 47 | } 48 | 49 | return 0 ; 50 | } 51 | -------------------------------------------------------------------------------- /WiringPi/examples/q2w/blink.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # blink.sh: 4 | # Standard "blink" program in wiringPi. Blinks an LED connected 5 | # to the LED on the Quick2Wire board 6 | # 7 | # Copyright (c) 2012-2013 Gordon Henderson. 8 | ####################################################################### 9 | # This file is part of wiringPi: 10 | # https://projects.drogon.net/raspberry-pi/wiringpi/ 11 | # 12 | # wiringPi is free software: you can redistribute it and/or modify 13 | # it under the terms of the GNU Lesser General Public License as published by 14 | # the Free Software Foundation, either version 3 of the License, or 15 | # (at your option) any later version. 16 | # 17 | # wiringPi is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | # GNU Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public License 23 | # along with wiringPi. If not, see . 24 | ####################################################################### 25 | 26 | # LED Pin - wiringPi pin 1 is BCM_GPIO 18. 27 | 28 | LED=1 29 | 30 | gpio mode $LED out 31 | 32 | while true; do 33 | gpio write $LED 1 34 | sleep 0.5 35 | gpio write $LED 0 36 | sleep 0.5 37 | done 38 | -------------------------------------------------------------------------------- /WiringPi/examples/q2w/bright.c: -------------------------------------------------------------------------------- 1 | /* 2 | * bright.c: 3 | * Vary the Q2W LED brightness with the analog card 4 | * 5 | * Copyright (c) 2012-2013 Gordon Henderson. 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #define LED 1 30 | #define Q2W_ABASE 120 31 | 32 | int main (void) 33 | { 34 | int value ; 35 | 36 | // Enable the on-goard GPIO 37 | 38 | wiringPiSetup () ; 39 | 40 | // Add in the pcf8591 on the q2w board 41 | 42 | pcf8591Setup (Q2W_ABASE, 0x48) ; 43 | 44 | printf ("Raspberry Pi - Quick2Wire Analog Test\n") ; 45 | 46 | // Setup the LED 47 | 48 | pinMode (LED, PWM_OUTPUT) ; 49 | pwmWrite (LED, 0) ; 50 | 51 | for (;;) 52 | { 53 | value = analogRead (Q2W_ABASE + 0) ; 54 | pwmWrite (LED, value * 4) ; 55 | delay (10) ; 56 | } 57 | 58 | return 0 ; 59 | } 60 | -------------------------------------------------------------------------------- /WiringPi/examples/q2w/button.c: -------------------------------------------------------------------------------- 1 | /* 2 | * button.c: 3 | * Simple button test for the Quick2Wire interface board. 4 | * 5 | * Copyright (c) 2012-2013 Gordon Henderson. 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | #define BUTTON 0 29 | #define LED1 1 30 | #define LED2 7 31 | 32 | int main (void) 33 | { 34 | 35 | // Enable the on-goard GPIO 36 | 37 | wiringPiSetup () ; 38 | 39 | printf ("Raspberry Pi - Quick2Wire Mainboard Button & LED Test\n") ; 40 | 41 | pinMode (BUTTON, INPUT) ; 42 | pinMode (LED1, OUTPUT) ; 43 | pinMode (LED2, OUTPUT) ; 44 | 45 | digitalWrite (LED1, HIGH) ; // On-board LED on 46 | digitalWrite (LED2, LOW) ; // 2nd LED off 47 | 48 | for (;;) 49 | { 50 | if (digitalRead (BUTTON) == HIGH) // Swap LED states 51 | { 52 | digitalWrite (LED1, LOW) ; 53 | digitalWrite (LED2, HIGH) ; 54 | while (digitalRead (BUTTON) == HIGH) 55 | delay (1) ; 56 | digitalWrite (LED1, HIGH) ; 57 | digitalWrite (LED2, LOW) ; 58 | } 59 | delay (1) ; 60 | } 61 | 62 | return 0 ; 63 | } 64 | -------------------------------------------------------------------------------- /WiringPi/examples/q2w/volts.c: -------------------------------------------------------------------------------- 1 | /* 2 | * volts.c: 3 | * Read in all 4 analogs on the Q2W analog board. 4 | * 5 | * Copyright (c) 2012-2013 Gordon Henderson. 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #define LED 1 30 | #define Q2W_ABASE 120 31 | 32 | int main (void) 33 | { 34 | int value, pin ; 35 | 36 | // Enable the on-goard GPIO 37 | 38 | wiringPiSetup () ; 39 | 40 | pinMode (LED, OUTPUT) ; // On-board LED 41 | 42 | // Add in the pcf8591 on the q2w board 43 | 44 | pcf8591Setup (Q2W_ABASE, 0x48) ; 45 | 46 | printf ("Raspberry Pi - Quick2Wire Voltmeter\n") ; 47 | 48 | for (;;) 49 | { 50 | for (pin = 0 ; pin < 4 ; ++pin) 51 | { 52 | value = analogRead (Q2W_ABASE + pin) ; 53 | printf (" %5.2f", (double)value * 3.3 / 255.0) ; 54 | } 55 | printf ("\r") ; fflush (stdout) ; 56 | 57 | delay (100) ; 58 | digitalWrite (LED, !digitalRead (LED)) ; // Flicker the LED 59 | } 60 | 61 | return 0 ; 62 | } 63 | -------------------------------------------------------------------------------- /WiringPi/examples/rht03.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rht03.c: 3 | * Driver for the MaxDetect series sensors 4 | * 5 | * Copyright (c) 2012-2013 Gordon Henderson. 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #define RHT03_PIN 0 31 | 32 | /* 33 | *********************************************************************** 34 | * The main program 35 | *********************************************************************** 36 | */ 37 | 38 | int main (void) 39 | { 40 | int temp, rh ; 41 | int newTemp, newRh ; 42 | 43 | temp = rh = newTemp = newRh = 0 ; 44 | 45 | wiringPiSetup () ; 46 | piHiPri (55) ; 47 | 48 | for (;;) 49 | { 50 | delay (100) ; 51 | 52 | if (!readRHT03 (RHT03_PIN, &newTemp, &newRh)) 53 | continue ; 54 | 55 | if ((temp != newTemp) || (rh != newRh)) 56 | { 57 | temp = newTemp ; 58 | rh = newRh ; 59 | if ((temp & 0x8000) != 0) // Negative 60 | { 61 | temp &= 0x7FFF ; 62 | temp = -temp ; 63 | } 64 | printf ("Temp: %5.1f, RH: %5.1f%%\n", temp / 10.0, rh / 10.0) ; 65 | } 66 | } 67 | 68 | return 0 ; 69 | } 70 | -------------------------------------------------------------------------------- /WiringPi/examples/serialRead.c: -------------------------------------------------------------------------------- 1 | /* 2 | * serial.c: 3 | * Example program to read bytes from the Serial line 4 | * 5 | * Copyright (c) 2012-2013 Gordon Henderson. 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | int main () 32 | { 33 | int fd ; 34 | 35 | if ((fd = serialOpen ("/dev/ttyAMA0", 115200)) < 0) 36 | { 37 | fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ; 38 | return 1 ; 39 | } 40 | 41 | // Loop, getting and printing characters 42 | 43 | for (;;) 44 | { 45 | putchar (serialGetchar (fd)) ; 46 | fflush (stdout) ; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /WiringPi/examples/serialTest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * serialTest.c: 3 | * Very simple program to test the serial port. Expects 4 | * the port to be looped back to itself 5 | * 6 | * Copyright (c) 2012-2013 Gordon Henderson. 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 . 23 | *********************************************************************** 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | int main () 34 | { 35 | int fd ; 36 | int count ; 37 | unsigned int nextTime ; 38 | 39 | if ((fd = serialOpen ("/dev/ttyAMA0", 115200)) < 0) 40 | { 41 | fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ; 42 | return 1 ; 43 | } 44 | 45 | if (wiringPiSetup () == -1) 46 | { 47 | fprintf (stdout, "Unable to start wiringPi: %s\n", strerror (errno)) ; 48 | return 1 ; 49 | } 50 | 51 | nextTime = millis () + 300 ; 52 | 53 | for (count = 0 ; count < 256 ; ) 54 | { 55 | if (millis () > nextTime) 56 | { 57 | printf ("\nOut: %3d: ", count) ; 58 | fflush (stdout) ; 59 | serialPutchar (fd, count) ; 60 | nextTime += 300 ; 61 | ++count ; 62 | } 63 | 64 | delay (3) ; 65 | 66 | while (serialDataAvail (fd)) 67 | { 68 | printf (" -> %3d", serialGetchar (fd)) ; 69 | fflush (stdout) ; 70 | } 71 | } 72 | 73 | printf ("\n") ; 74 | return 0 ; 75 | } 76 | -------------------------------------------------------------------------------- /WiringPi/examples/servo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * servo.c: 3 | * Test of the softServo code. 4 | * Do not use this code - use the servoBlaster kernel module instead 5 | * 6 | * Copyright (c) 2012-2013 Gordon Henderson. 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 . 23 | *********************************************************************** 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | int main () 34 | { 35 | if (wiringPiSetup () == -1) 36 | { 37 | fprintf (stdout, "oops: %s\n", strerror (errno)) ; 38 | return 1 ; 39 | } 40 | 41 | softServoSetup (0, 1, 2, 3, 4, 5, 6, 7) ; 42 | 43 | softServoWrite (0, 0) ; 44 | /* 45 | softServoWrite (1, 1000) ; 46 | softServoWrite (2, 1100) ; 47 | softServoWrite (3, 1200) ; 48 | softServoWrite (4, 1300) ; 49 | softServoWrite (5, 1400) ; 50 | softServoWrite (6, 1500) ; 51 | softServoWrite (7, 2200) ; 52 | */ 53 | 54 | for (;;) 55 | delay (10) ; 56 | 57 | } 58 | -------------------------------------------------------------------------------- /WiringPi/examples/softPwm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * softPwm.c: 3 | * Test of the software PWM driver. Needs 8 LEDs connected 4 | * to the Pi - e.g. Ladder board. 5 | * 6 | * Copyright (c) 2012-2013 Gordon Henderson. 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 . 23 | *********************************************************************** 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | #define RANGE 100 34 | #define NUM_LEDS 8 35 | 36 | int ledMap [NUM_LEDS] = { 0, 1, 2, 3, 4, 5, 6, 7 } ; 37 | 38 | int values [NUM_LEDS] = { 0, 25, 50, 75, 100, 75, 50, 25 } ; 39 | 40 | int main () 41 | { 42 | int i, j ; 43 | char buf [80] ; 44 | 45 | wiringPiSetup () ; 46 | 47 | for (i = 0 ; i < NUM_LEDS ; ++i) 48 | { 49 | softPwmCreate (ledMap [i], 0, RANGE) ; 50 | printf ("%3d, %3d, %3d\n", i, ledMap [i], values [i]) ; 51 | } 52 | 53 | fgets (buf, 80, stdin) ; 54 | 55 | // Bring all up one by one: 56 | 57 | for (i = 0 ; i < NUM_LEDS ; ++i) 58 | for (j = 0 ; j <= 100 ; ++j) 59 | { 60 | softPwmWrite (ledMap [i], j) ; 61 | delay (10) ; 62 | } 63 | 64 | fgets (buf, 80, stdin) ; 65 | 66 | // All Down 67 | 68 | for (i = 100 ; i > 0 ; --i) 69 | { 70 | for (j = 0 ; j < NUM_LEDS ; ++j) 71 | softPwmWrite (ledMap [j], i) ; 72 | delay (10) ; 73 | } 74 | 75 | fgets (buf, 80, stdin) ; 76 | 77 | for (;;) 78 | { 79 | for (i = 0 ; i < NUM_LEDS ; ++i) 80 | softPwmWrite (ledMap [i], values [i]) ; 81 | 82 | delay (50) ; 83 | 84 | i = values [0] ; 85 | for (j = 0 ; j < NUM_LEDS - 1 ; ++j) 86 | values [j] = values [j + 1] ; 87 | values [NUM_LEDS - 1] = i ; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /WiringPi/examples/softTone.c: -------------------------------------------------------------------------------- 1 | /* 2 | * softTone.c: 3 | * Test of the softTone module in wiringPi 4 | * Plays a scale out on pin 3 - connect pizeo disc to pin 3 & 0v 5 | * 6 | * Copyright (c) 2012-2013 Gordon Henderson. 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 . 23 | *********************************************************************** 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | #define PIN 3 34 | 35 | int scale [8] = { 262, 294, 330, 349, 392, 440, 494, 525 } ; 36 | 37 | int main () 38 | { 39 | int i ; 40 | 41 | wiringPiSetup () ; 42 | 43 | softToneCreate (PIN) ; 44 | 45 | for (;;) 46 | { 47 | for (i = 0 ; i < 8 ; ++i) 48 | { 49 | printf ("%3d\n", i) ; 50 | softToneWrite (PIN, scale [i]) ; 51 | delay (500) ; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /WiringPi/examples/speed.c: -------------------------------------------------------------------------------- 1 | /* 2 | * speed.c: 3 | * Simple program to measure the speed of the various GPIO 4 | * access mechanisms. 5 | * 6 | * Copyright (c) 2012-2013 Gordon Henderson. 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 . 23 | *********************************************************************** 24 | */ 25 | 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #define FAST_COUNT 10000000 33 | #define SLOW_COUNT 1000000 34 | #define PASSES 5 35 | 36 | void speedTest (int pin, int maxCount) 37 | { 38 | int count, sum, perSec, i ; 39 | unsigned int start, end ; 40 | 41 | sum = 0 ; 42 | 43 | for (i = 0 ; i < PASSES ; ++i) 44 | { 45 | start = millis () ; 46 | for (count = 0 ; count < maxCount ; ++count) 47 | digitalWrite (pin, 1) ; 48 | end = millis () ; 49 | printf (" %6d", end - start) ; 50 | fflush (stdout) ; 51 | sum += (end - start) ; 52 | } 53 | 54 | digitalWrite (pin, 0) ; 55 | printf (". Av: %6dmS", sum / PASSES) ; 56 | perSec = (int)(double)maxCount / (double)((double)sum / (double)PASSES) * 1000.0 ; 57 | printf (": %7d/sec\n", perSec) ; 58 | } 59 | 60 | 61 | int main (void) 62 | { 63 | printf ("Raspberry Pi wiringPi GPIO speed test program\n") ; 64 | printf ("=============================================\n") ; 65 | 66 | // Start the standard way 67 | 68 | printf ("\nNative wiringPi method: (%8d iterations)\n", FAST_COUNT) ; 69 | wiringPiSetup () ; 70 | pinMode (0, OUTPUT) ; 71 | speedTest (0, FAST_COUNT) ; 72 | 73 | // GPIO 74 | 75 | printf ("\nNative GPIO method: (%8d iterations)\n", FAST_COUNT) ; 76 | wiringPiSetupGpio () ; 77 | pinMode (17, OUTPUT) ; 78 | speedTest (17, FAST_COUNT) ; 79 | 80 | // Phys 81 | 82 | printf ("\nPhysical pin GPIO method: (%8d iterations)\n", FAST_COUNT) ; 83 | wiringPiSetupPhys () ; 84 | pinMode (11, OUTPUT) ; 85 | speedTest (11, FAST_COUNT) ; 86 | 87 | // Switch to SYS mode: 88 | 89 | system ("/usr/local/bin/gpio export 17 out") ; 90 | printf ("\n/sys/class/gpio method: (%8d iterations)\n", SLOW_COUNT) ; 91 | wiringPiSetupSys () ; 92 | speedTest (17, SLOW_COUNT) ; 93 | 94 | return 0 ; 95 | } 96 | -------------------------------------------------------------------------------- /WiringPi/gpio/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile: 3 | # The gpio command: 4 | # A swiss-army knige of GPIO shenanigans. 5 | # https://projects.drogon.net/wiring-pi 6 | # 7 | # Copyright (c) 2012-2015 Gordon Henderson 8 | ################################################################################# 9 | # This file is part of wiringPi: 10 | # Wiring Compatable library for the Raspberry Pi 11 | # 12 | # wiringPi is free software: you can redistribute it and/or modify 13 | # it under the terms of the GNU Lesser General Public License as published by 14 | # the Free Software Foundation, either version 3 of the License, or 15 | # (at your option) any later version. 16 | # 17 | # wiringPi is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | # GNU Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public License 23 | # along with wiringPi. If not, see . 24 | ################################################################################# 25 | 26 | DESTDIR=/usr 27 | PREFIX=/local 28 | 29 | #DEBUG = -g -O0 30 | DEBUG = -O2 31 | CC = gcc 32 | INCLUDE = -I$(DESTDIR)$(PREFIX)/include 33 | CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe 34 | 35 | LDFLAGS = -L$(DESTDIR)$(PREFIX)/lib 36 | LIBS = -lwiringPi -lwiringPiDev -lpthread -lm 37 | 38 | # May not need to alter anything below this line 39 | ############################################################################### 40 | 41 | SRC = gpio.c readall.c pins.c 42 | 43 | OBJ = $(SRC:.c=.o) 44 | 45 | all: gpio 46 | 47 | version.h: ../VERSION 48 | ./newVersion 49 | 50 | gpio: $(OBJ) 51 | @echo [Link] 52 | @$(CC) -o $@ $(OBJ) $(LDFLAGS) $(LIBS) 53 | 54 | .c.o: 55 | @echo [Compile] $< 56 | @$(CC) -c $(CFLAGS) $< -o $@ 57 | 58 | .PHONY: clean 59 | clean: 60 | @echo "[Clean]" 61 | @rm -f $(OBJ) gpio *~ core tags *.bak 62 | 63 | .PHONY: tags 64 | tags: $(SRC) 65 | @echo [ctags] 66 | @ctags $(SRC) 67 | 68 | .PHONY: install 69 | install: gpio 70 | @echo "[Install]" 71 | @cp gpio $(DESTDIR)$(PREFIX)/bin 72 | @chown root.root $(DESTDIR)$(PREFIX)/bin/gpio 73 | @chmod 4755 $(DESTDIR)$(PREFIX)/bin/gpio 74 | @mkdir -p $(DESTDIR)$(PREFIX)/man/man1 75 | @cp gpio.1 $(DESTDIR)$(PREFIX)/man/man1 76 | 77 | .PHONY: install-deb 78 | install-deb: gpio 79 | @echo "[Install: deb]" 80 | @install -m 0755 -d ~/wiringPi/debian/wiringPi/usr/bin 81 | @install -m 0755 gpio ~/wiringPi/debian/wiringPi/usr/bin 82 | 83 | .PHONY: uninstall 84 | uninstall: 85 | @echo "[UnInstall]" 86 | @rm -f $(DESTDIR)$(PREFIX)/bin/gpio 87 | @rm -f $(DESTDIR)$(PREFIX)/man/man1/gpio.1 88 | 89 | .PHONY: depend 90 | depend: 91 | makedepend -Y $(SRC) 92 | 93 | # DO NOT DELETE 94 | -------------------------------------------------------------------------------- /WiringPi/gpio/newVersion: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # newVersion: 4 | # Utility to create the version.h include file for the gpio command. 5 | # 6 | # Copyright (c) 2012-2015 Gordon Henderson 7 | ################################################################################# 8 | # This file is part of wiringPi: 9 | # Wiring Compatable library for the Raspberry Pi 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 . 23 | ################################################################################# 24 | 25 | rm -f version.h 26 | echo "#define VERSION \"`cat ../VERSION`\"" > version.h 27 | -------------------------------------------------------------------------------- /WiringPi/gpio/pins.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pins.c: 3 | * Just display a handy Pi pinnout diagram. 4 | * Copyright (c) 2012-2015 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with wiringPi. If not, see . 21 | *********************************************************************** 22 | */ 23 | 24 | 25 | #include 26 | 27 | void doPins (void) 28 | { 29 | printf ("The pins command has been deprecated - sorry. Please use the\n") ; 30 | printf (" gpio readall\n") ; 31 | printf ("command to get a list of the pinnouts for your Pi.\n") ; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /WiringPi/gpio/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # test.sh: 4 | # Simple test: Assumes LEDs on Pins 0-7 and lights them 5 | # in-turn. 6 | ################################################################################# 7 | # This file is part of wiringPi: 8 | # Wiring Compatable library for the Raspberry Pi 9 | # 10 | # wiringPi is free software: you can redistribute it and/or modify 11 | # it under the terms of the GNU Lesser General Public License as published by 12 | # the Free Software Foundation, either version 3 of the License, or 13 | # (at your option) any later version. 14 | # 15 | # wiringPi is distributed in the hope that it will be useful, 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | # GNU Lesser General Public License for more details. 19 | # 20 | # You should have received a copy of the GNU Lesser General Public License 21 | # along with wiringPi. If not, see . 22 | ################################################################################# 23 | 24 | # Simple test - assumes LEDs on Pins 0-7. 25 | 26 | for i in `seq 0 7`; 27 | do 28 | gpio mode $i out 29 | done 30 | 31 | while true; 32 | do 33 | for i in `seq 0 7`; 34 | do 35 | gpio write $i 1 36 | sleep 0.1 37 | done 38 | 39 | for i in `seq 0 7`; 40 | do 41 | gpio write $i 0 42 | sleep 0.1 43 | done 44 | done 45 | -------------------------------------------------------------------------------- /WiringPi/gpio/version.h: -------------------------------------------------------------------------------- 1 | #define VERSION "2.26" 2 | -------------------------------------------------------------------------------- /WiringPi/pins/Makefile: -------------------------------------------------------------------------------- 1 | 2 | SRC = pins.tex 3 | 4 | 5 | all: ${SRC} 6 | @echo Generating DVI 7 | @latex pins.tex 8 | 9 | pins.dvi: pins.tex 10 | @latex pins.tex 11 | 12 | pdf: pins.dvi 13 | @dvipdf pins.dvi 14 | 15 | 16 | .PHONY: clean 17 | clean: 18 | @rm -f *.dvi *.aux *.log *.ps *.toc *.bak *~ 19 | -------------------------------------------------------------------------------- /WiringPi/pins/pins.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gadgetoid/WiringPi2-Python/620be8c3264ed23a7d45d0a473ffeec3c2a4bc5e/WiringPi/pins/pins.pdf -------------------------------------------------------------------------------- /WiringPi/wiringPi/drcSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | * drcSerial.h: 3 | * Extend wiringPi with the DRC Serial protocol (e.g. to Arduino) 4 | * Copyright (c) 2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern int drcSetupSerial (const int pinBase, const int numPins, const char *device, const int baud) ; 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/max31855.c: -------------------------------------------------------------------------------- 1 | /* 2 | * max31855.c: 3 | * Extend wiringPi with the max31855 SPI Analog to Digital convertor 4 | * Copyright (c) 2012-2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | #include "max31855.h" 29 | 30 | /* 31 | * myAnalogRead: 32 | * Return the analog value of the given pin 33 | * Note: The chip really only has one read "channel", but we're faking it 34 | * here so we can read the error registers. Channel 0 will be the data 35 | * channel, and 1 is the error register code. 36 | * Note: Temperature returned is temp in C * 4, so divide result by 4 37 | ********************************************************************************* 38 | */ 39 | 40 | static int myAnalogRead (struct wiringPiNodeStruct *node, int pin) 41 | { 42 | unsigned int spiData ; 43 | int temp ; 44 | int chan = pin - node->pinBase ; 45 | 46 | wiringPiSPIDataRW (node->fd, (unsigned char *)&spiData, 4) ; 47 | 48 | if (chan == 0) // Read temp in C 49 | { 50 | spiData >>= 18 ; 51 | temp = spiData & 0x3FFF ; // Bottom 13 bits 52 | if ((spiData & 0x2000) != 0) // Negative 53 | temp = -temp ; 54 | return temp ; 55 | } 56 | else // Return error bits 57 | return spiData & 0x7 ; 58 | } 59 | 60 | 61 | /* 62 | * max31855Setup: 63 | * Create a new wiringPi device node for an max31855 on the Pi's 64 | * SPI interface. 65 | ********************************************************************************* 66 | */ 67 | 68 | int max31855Setup (const int pinBase, int spiChannel) 69 | { 70 | struct wiringPiNodeStruct *node ; 71 | 72 | if (wiringPiSPISetup (spiChannel, 5000000) < 0) // 5MHz - prob 4 on the Pi 73 | return -1 ; 74 | 75 | node = wiringPiNewNode (pinBase, 2) ; 76 | 77 | node->fd = spiChannel ; 78 | node->analogRead = myAnalogRead ; 79 | 80 | return 0 ; 81 | } 82 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/max31855.h: -------------------------------------------------------------------------------- 1 | /* 2 | * max31855.c: 3 | * Extend wiringPi with the MAX31855 SPI Thermocouple driver 4 | * Copyright (c) 2012-2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern int max31855Setup (int pinBase, int spiChannel) ; 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/max5322.c: -------------------------------------------------------------------------------- 1 | /* 2 | * max5322.c: 3 | * Extend wiringPi with the MAX5322 SPI Digital to Analog convertor 4 | * Copyright (c) 2012-2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | #include "max5322.h" 29 | 30 | /* 31 | * myAnalogWrite: 32 | * Write analog value on the given pin 33 | ********************************************************************************* 34 | */ 35 | 36 | static void myAnalogWrite (struct wiringPiNodeStruct *node, int pin, int value) 37 | { 38 | unsigned char spiData [2] ; 39 | unsigned char chanBits, dataBits ; 40 | int chan = pin - node->pinBase ; 41 | 42 | if (chan == 0) 43 | chanBits = 0b01000000 ; 44 | else 45 | chanBits = 0b01010000 ; 46 | 47 | chanBits |= ((value >> 12) & 0x0F) ; 48 | dataBits = ((value ) & 0xFF) ; 49 | 50 | spiData [0] = chanBits ; 51 | spiData [1] = dataBits ; 52 | 53 | wiringPiSPIDataRW (node->fd, spiData, 2) ; 54 | } 55 | 56 | /* 57 | * max5322Setup: 58 | * Create a new wiringPi device node for an max5322 on the Pi's 59 | * SPI interface. 60 | ********************************************************************************* 61 | */ 62 | 63 | int max5322Setup (const int pinBase, int spiChannel) 64 | { 65 | struct wiringPiNodeStruct *node ; 66 | unsigned char spiData [2] ; 67 | 68 | if (wiringPiSPISetup (spiChannel, 8000000) < 0) // 10MHz Max 69 | return -1 ; 70 | 71 | node = wiringPiNewNode (pinBase, 2) ; 72 | 73 | node->fd = spiChannel ; 74 | node->analogWrite = myAnalogWrite ; 75 | 76 | // Enable both DACs 77 | 78 | spiData [0] = 0b11100000 ; 79 | spiData [1] = 0 ; 80 | 81 | wiringPiSPIDataRW (node->fd, spiData, 2) ; 82 | 83 | return 0 ; 84 | } 85 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/max5322.h: -------------------------------------------------------------------------------- 1 | /* 2 | * max5322.h: 3 | * Extend wiringPi with the MAX5322 SPI Digital to Analog convertor 4 | * Copyright (c) 2012-2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern int max5322Setup (int pinBase, int spiChannel) ; 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/mcp23008.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 23008.h: 3 | * Extend wiringPi with the MCP 23008 I2C GPIO expander chip 4 | * Copyright (c) 2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern int mcp23008Setup (const int pinBase, const int i2cAddress) ; 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/mcp23016.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mcp23016.h: 3 | * Extend wiringPi with the MCP 23016 I2C GPIO expander chip 4 | * Copyright (c) 2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern int mcp23016Setup (const int pinBase, const int i2cAddress) ; 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/mcp23016reg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mcp23016: 3 | * Copyright (c) 2012-2013 Gordon Henderson 4 | * 5 | * Header file for code using the MCP23016 GPIO expander 6 | * chip. 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 13 | * published by the Free Software Foundation, either version 3 of the 14 | * License, or (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 22 | * License along with wiringPi. 23 | * If not, see . 24 | *********************************************************************** 25 | */ 26 | 27 | // MCP23016 Registers 28 | 29 | #define MCP23016_GP0 0x00 30 | #define MCP23016_GP1 0x01 31 | #define MCP23016_OLAT0 0x02 32 | #define MCP23016_OLAT1 0x03 33 | #define MCP23016_IPOL0 0x04 34 | #define MCP23016_IPOL1 0x05 35 | #define MCP23016_IODIR0 0x06 36 | #define MCP23016_IODIR1 0x07 37 | #define MCP23016_INTCAP0 0x08 38 | #define MCP23016_INTCAP1 0x09 39 | #define MCP23016_IOCON0 0x0A 40 | #define MCP23016_IOCON1 0x0B 41 | 42 | // Bits in the IOCON register 43 | 44 | #define IOCON_IARES 0x01 45 | 46 | // Default initialisation mode 47 | 48 | #define IOCON_INIT 0 49 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/mcp23017.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 23017.h: 3 | * Extend wiringPi with the MCP 23017 I2C GPIO expander chip 4 | * Copyright (c) 2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern int mcp23017Setup (const int pinBase, const int i2cAddress) ; 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/mcp23s08.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 23s08.h: 3 | * Extend wiringPi with the MCP 23s08 SPI GPIO expander chip 4 | * Copyright (c) 2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern int mcp23s08Setup (const int pinBase, const int spiPort, const int devId) ; 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/mcp23s17.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 23s17.h: 3 | * Extend wiringPi with the MCP 23s17 SPI GPIO expander chip 4 | * Copyright (c) 2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern int mcp23s17Setup (int pinBase, int spiPort, int devId) ; 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/mcp23x08.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mcp23x17: 3 | * Copyright (c) 2012-2013 Gordon Henderson 4 | * 5 | * Header file for code using the MCP23x17 GPIO expander chip. 6 | * This comes in 2 flavours: MCP23017 which has an I2C interface, 7 | * an the MXP23S17 which has an SPI interface. 8 | *********************************************************************** 9 | * This file is part of wiringPi: 10 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 11 | * 12 | * wiringPi is free software: you can redistribute it and/or modify 13 | * it under the terms of the GNU Lesser General Public License as 14 | * published by the Free Software Foundation, either version 3 of the 15 | * License, or (at your option) any later version. 16 | * 17 | * wiringPi is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with wiringPi. 24 | * If not, see . 25 | *********************************************************************** 26 | */ 27 | 28 | 29 | // MCP23x17 Registers 30 | 31 | #define IODIRA 0x00 32 | #define IPOLA 0x02 33 | #define GPINTENA 0x04 34 | #define DEFVALA 0x06 35 | #define INTCONA 0x08 36 | #define IOCON 0x0A 37 | #define GPPUA 0x0C 38 | #define INTFA 0x0E 39 | #define INTCAPA 0x10 40 | #define GPIOA 0x12 41 | #define OLATA 0x14 42 | 43 | #define IODIRB 0x01 44 | #define IPOLB 0x03 45 | #define GPINTENB 0x05 46 | #define DEFVALB 0x07 47 | #define INTCONB 0x09 48 | #define IOCONB 0x0B 49 | #define GPPUB 0x0D 50 | #define INTFB 0x0F 51 | #define INTCAPB 0x11 52 | #define GPIOB 0x13 53 | #define OLATB 0x15 54 | 55 | // Bits in the IOCON register 56 | 57 | #define IOCON_UNUSED 0x01 58 | #define IOCON_INTPOL 0x02 59 | #define IOCON_ODR 0x04 60 | #define IOCON_HAEN 0x08 61 | #define IOCON_DISSLW 0x10 62 | #define IOCON_SEQOP 0x20 63 | #define IOCON_MIRROR 0x40 64 | #define IOCON_BANK_MODE 0x80 65 | 66 | // Default initialisation mode 67 | 68 | #define IOCON_INIT (IOCON_SEQOP) 69 | 70 | // SPI Command codes 71 | 72 | #define CMD_WRITE 0x40 73 | #define CMD_READ 0x41 74 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/mcp23x0817.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mcp23xxx: 3 | * Copyright (c) 2012-2013 Gordon Henderson 4 | * 5 | * Header file for code using the MCP23x08 and 17 GPIO expander 6 | * chips. 7 | * This comes in 2 flavours: MCP230xx (08/17) which has an I2C 8 | * interface, and the MXP23Sxx (08/17) which has an SPI interface. 9 | *********************************************************************** 10 | * This file is part of wiringPi: 11 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 12 | * 13 | * wiringPi is free software: you can redistribute it and/or modify 14 | * it under the terms of the GNU Lesser General Public License as 15 | * published by the Free Software Foundation, either version 3 of the 16 | * License, or (at your option) any later version. 17 | * 18 | * wiringPi is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU Lesser General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU Lesser General Public 24 | * License along with wiringPi. 25 | * If not, see . 26 | *********************************************************************** 27 | */ 28 | 29 | // MCP23x08 Registers 30 | 31 | #define MCP23x08_IODIR 0x00 32 | #define MCP23x08_IPOL 0x01 33 | #define MCP23x08_GPINTEN 0x02 34 | #define MCP23x08_DEFVAL 0x03 35 | #define MCP23x08_INTCON 0x04 36 | #define MCP23x08_IOCON 0x05 37 | #define MCP23x08_GPPU 0x06 38 | #define MCP23x08_INTF 0x07 39 | #define MCP23x08_INTCAP 0x08 40 | #define MCP23x08_GPIO 0x09 41 | #define MCP23x08_OLAT 0x0A 42 | 43 | // MCP23x17 Registers 44 | 45 | #define MCP23x17_IODIRA 0x00 46 | #define MCP23x17_IPOLA 0x02 47 | #define MCP23x17_GPINTENA 0x04 48 | #define MCP23x17_DEFVALA 0x06 49 | #define MCP23x17_INTCONA 0x08 50 | #define MCP23x17_IOCON 0x0A 51 | #define MCP23x17_GPPUA 0x0C 52 | #define MCP23x17_INTFA 0x0E 53 | #define MCP23x17_INTCAPA 0x10 54 | #define MCP23x17_GPIOA 0x12 55 | #define MCP23x17_OLATA 0x14 56 | 57 | #define MCP23x17_IODIRB 0x01 58 | #define MCP23x17_IPOLB 0x03 59 | #define MCP23x17_GPINTENB 0x05 60 | #define MCP23x17_DEFVALB 0x07 61 | #define MCP23x17_INTCONB 0x09 62 | #define MCP23x17_IOCONB 0x0B 63 | #define MCP23x17_GPPUB 0x0D 64 | #define MCP23x17_INTFB 0x0F 65 | #define MCP23x17_INTCAPB 0x11 66 | #define MCP23x17_GPIOB 0x13 67 | #define MCP23x17_OLATB 0x15 68 | 69 | // Bits in the IOCON register 70 | 71 | #define IOCON_UNUSED 0x01 72 | #define IOCON_INTPOL 0x02 73 | #define IOCON_ODR 0x04 74 | #define IOCON_HAEN 0x08 75 | #define IOCON_DISSLW 0x10 76 | #define IOCON_SEQOP 0x20 77 | #define IOCON_MIRROR 0x40 78 | #define IOCON_BANK_MODE 0x80 79 | 80 | // Default initialisation mode 81 | 82 | #define IOCON_INIT (IOCON_SEQOP) 83 | 84 | // SPI Command codes 85 | 86 | #define CMD_WRITE 0x40 87 | #define CMD_READ 0x41 88 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/mcp3002.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mcp3002.c: 3 | * Extend wiringPi with the MCP3002 SPI Analog to Digital convertor 4 | * Copyright (c) 2012-2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | #include "mcp3002.h" 29 | 30 | /* 31 | * myAnalogRead: 32 | * Return the analog value of the given pin 33 | ********************************************************************************* 34 | */ 35 | 36 | static int myAnalogRead (struct wiringPiNodeStruct *node, int pin) 37 | { 38 | unsigned char spiData [2] ; 39 | unsigned char chanBits ; 40 | int chan = pin - node->pinBase ; 41 | 42 | if (chan == 0) 43 | chanBits = 0b11010000 ; 44 | else 45 | chanBits = 0b11110000 ; 46 | 47 | spiData [0] = chanBits ; 48 | spiData [1] = 0 ; 49 | 50 | wiringPiSPIDataRW (node->fd, spiData, 2) ; 51 | 52 | return ((spiData [0] << 7) | (spiData [1] >> 1)) & 0x3FF ; 53 | } 54 | 55 | 56 | /* 57 | * mcp3002Setup: 58 | * Create a new wiringPi device node for an mcp3002 on the Pi's 59 | * SPI interface. 60 | ********************************************************************************* 61 | */ 62 | 63 | int mcp3002Setup (const int pinBase, int spiChannel) 64 | { 65 | struct wiringPiNodeStruct *node ; 66 | 67 | if (wiringPiSPISetup (spiChannel, 1000000) < 0) 68 | return -1 ; 69 | 70 | node = wiringPiNewNode (pinBase, 2) ; 71 | 72 | node->fd = spiChannel ; 73 | node->analogRead = myAnalogRead ; 74 | 75 | return 0 ; 76 | } 77 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/mcp3002.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mcp3002.c: 3 | * Extend wiringPi with the MCP3002 SPI Analog to Digital convertor 4 | * Copyright (c) 2012-2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern int mcp3002Setup (int pinBase, int spiChannel) ; 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/mcp3004.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mcp3004.c: 3 | * Extend wiringPi with the MCP3004 SPI Analog to Digital convertor 4 | * Copyright (c) 2012-2013 Gordon Henderson 5 | * 6 | * Thanks also to "ShorTie" on IRC for some remote debugging help! 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 13 | * published by the Free Software Foundation, either version 3 of the 14 | * License, or (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 22 | * License along with wiringPi. 23 | * If not, see . 24 | *********************************************************************** 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | #include "mcp3004.h" 31 | 32 | /* 33 | * myAnalogRead: 34 | * Return the analog value of the given pin 35 | ********************************************************************************* 36 | */ 37 | 38 | static int myAnalogRead (struct wiringPiNodeStruct *node, int pin) 39 | { 40 | unsigned char spiData [3] ; 41 | unsigned char chanBits ; 42 | int chan = pin - node->pinBase ; 43 | 44 | chanBits = 0b10000000 | (chan << 4) ; 45 | 46 | spiData [0] = 1 ; // Start bit 47 | spiData [1] = chanBits ; 48 | spiData [2] = 0 ; 49 | 50 | wiringPiSPIDataRW (node->fd, spiData, 3) ; 51 | 52 | return ((spiData [1] << 8) | spiData [2]) & 0x3FF ; 53 | } 54 | 55 | 56 | /* 57 | * mcp3004Setup: 58 | * Create a new wiringPi device node for an mcp3004 on the Pi's 59 | * SPI interface. 60 | ********************************************************************************* 61 | */ 62 | 63 | int mcp3004Setup (const int pinBase, int spiChannel) 64 | { 65 | struct wiringPiNodeStruct *node ; 66 | 67 | if (wiringPiSPISetup (spiChannel, 1000000) < 0) 68 | return -1 ; 69 | 70 | node = wiringPiNewNode (pinBase, 8) ; 71 | 72 | node->fd = spiChannel ; 73 | node->analogRead = myAnalogRead ; 74 | 75 | return 0 ; 76 | } 77 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/mcp3004.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mcp3004.c: 3 | * Extend wiringPi with the MCP3004 SPI Analog to Digital convertor 4 | * Copyright (c) 2012-2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern int mcp3004Setup (int pinBase, int spiChannel) ; 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/mcp3422.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mcp3422.c: 3 | * Extend wiringPi with the MCP3422 I2C ADC chip 4 | * Also works for the MCP3423 and MCP3224 (4 channel) chips 5 | * Copyright (c) 2013 Gordon Henderson 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as 12 | * published by the Free Software Foundation, either version 3 of the 13 | * License, or (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with wiringPi. 22 | * If not, see . 23 | *********************************************************************** 24 | */ 25 | 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | #include "mcp3422.h" 38 | 39 | 40 | /* 41 | * myAnalogRead: 42 | * Read a channel from the device 43 | ********************************************************************************* 44 | */ 45 | 46 | int myAnalogRead (struct wiringPiNodeStruct *node, int chan) 47 | { 48 | unsigned char config ; 49 | unsigned char buffer [4] ; 50 | int value = 0 ; 51 | 52 | // One-shot mode, trigger plus the other configs. 53 | 54 | config = 0x80 | ((chan - node->pinBase) << 5) | (node->data0 << 2) | (node->data1) ; 55 | 56 | wiringPiI2CWrite (node->fd, config) ; 57 | 58 | switch (node->data0) // Sample rate 59 | { 60 | case MCP3422_SR_3_75: // 18 bits 61 | delay (270) ; 62 | read (node->fd, buffer, 4) ; 63 | value = ((buffer [0] & 3) << 16) | (buffer [1] << 8) | buffer [0] ; 64 | break ; 65 | 66 | case MCP3422_SR_15: // 16 bits 67 | delay ( 70) ; 68 | read (node->fd, buffer, 3) ; 69 | value = (buffer [0] << 8) | buffer [1] ; 70 | break ; 71 | 72 | case MCP3422_SR_60: // 14 bits 73 | delay ( 17) ; 74 | read (node->fd, buffer, 3) ; 75 | value = ((buffer [0] & 0x3F) << 8) | buffer [1] ; 76 | break ; 77 | 78 | case MCP3422_SR_240: // 12 bits 79 | delay ( 5) ; 80 | read (node->fd, buffer, 3) ; 81 | value = ((buffer [0] & 0x0F) << 8) | buffer [0] ; 82 | break ; 83 | } 84 | 85 | return value ; 86 | } 87 | 88 | 89 | /* 90 | * mcp3422Setup: 91 | * Create a new wiringPi device node for the mcp3422 92 | ********************************************************************************* 93 | */ 94 | 95 | int mcp3422Setup (int pinBase, int i2cAddress, int sampleRate, int gain) 96 | { 97 | int fd ; 98 | struct wiringPiNodeStruct *node ; 99 | 100 | if ((fd = wiringPiI2CSetup (i2cAddress)) < 0) 101 | return fd ; 102 | 103 | node = wiringPiNewNode (pinBase, 4) ; 104 | 105 | node->data0 = sampleRate ; 106 | node->data1 = gain ; 107 | node->analogRead = myAnalogRead ; 108 | 109 | return 0 ; 110 | } 111 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/mcp3422.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mcp3422.c: 3 | * Extend wiringPi with the MCP3422 I2C ADC chip 4 | *********************************************************************** 5 | * This file is part of wiringPi: 6 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 7 | * 8 | * wiringPi is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation, either version 3 of the 11 | * License, or (at your option) any later version. 12 | * 13 | * wiringPi is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with wiringPi. 20 | * If not, see . 21 | *********************************************************************** 22 | */ 23 | 24 | #define MCP3422_SR_3_75 0 25 | #define MCP3422_SR_15 1 26 | #define MCP3422_SR_60 2 27 | #define MCP3422_SR_240 3 28 | 29 | #define MCP3422_GAIN_1 0 30 | #define MCP3422_GAIN_2 1 31 | #define MCP3422_GAIN_4 2 32 | #define MCP3422_GAIN_8 3 33 | 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | extern int mcp3422Setup (int pinBase, int i2cAddress, int sampleRate, int gain) ; 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/mcp4802.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mcp4802.c: 3 | * Extend wiringPi with the MCP4802 SPI Digital to Analog convertor 4 | * Copyright (c) 2012-2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | #include "mcp4802.h" 29 | 30 | /* 31 | * myAnalogWrite: 32 | * Write analog value on the given pin 33 | ********************************************************************************* 34 | */ 35 | 36 | static void myAnalogWrite (struct wiringPiNodeStruct *node, int pin, int value) 37 | { 38 | unsigned char spiData [2] ; 39 | unsigned char chanBits, dataBits ; 40 | int chan = pin - node->pinBase ; 41 | 42 | if (chan == 0) 43 | chanBits = 0x30 ; 44 | else 45 | chanBits = 0xB0 ; 46 | 47 | chanBits |= ((value >> 4) & 0x0F) ; 48 | dataBits = ((value << 4) & 0xF0) ; 49 | 50 | spiData [0] = chanBits ; 51 | spiData [1] = dataBits ; 52 | 53 | wiringPiSPIDataRW (node->fd, spiData, 2) ; 54 | } 55 | 56 | /* 57 | * mcp4802Setup: 58 | * Create a new wiringPi device node for an mcp4802 on the Pi's 59 | * SPI interface. 60 | ********************************************************************************* 61 | */ 62 | 63 | int mcp4802Setup (const int pinBase, int spiChannel) 64 | { 65 | struct wiringPiNodeStruct *node ; 66 | 67 | if (wiringPiSPISetup (spiChannel, 1000000) < 0) 68 | return -1 ; 69 | 70 | node = wiringPiNewNode (pinBase, 2) ; 71 | 72 | node->fd = spiChannel ; 73 | node->analogWrite = myAnalogWrite ; 74 | 75 | return 0 ; 76 | } 77 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/mcp4802.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mcp4802.c: 3 | * Extend wiringPi with the MCP4802 SPI Digital to Analog convertor 4 | * Copyright (c) 2012-2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern int mcp4802Setup (int pinBase, int spiChannel) ; 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/pcf8574.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pcf8574.h: 3 | * Extend wiringPi with the PCF8574 I2C GPIO expander chip 4 | * Copyright (c) 2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern int pcf8574Setup (const int pinBase, const int i2cAddress) ; 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/pcf8591.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pcf8591.c: 3 | * Extend wiringPi with the PCF8591 I2C GPIO Analog expander chip 4 | * The chip has 1 8-bit DAC and 4 x 8-bit ADCs 5 | * Copyright (c) 2013 Gordon Henderson 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as 12 | * published by the Free Software Foundation, either version 3 of the 13 | * License, or (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with wiringPi. 22 | * If not, see . 23 | *********************************************************************** 24 | */ 25 | 26 | #include 27 | 28 | #include "wiringPi.h" 29 | #include "wiringPiI2C.h" 30 | 31 | #include "pcf8591.h" 32 | 33 | 34 | /* 35 | * myAnalogWrite: 36 | ********************************************************************************* 37 | */ 38 | 39 | static void myAnalogWrite (struct wiringPiNodeStruct *node, int pin, int value) 40 | { 41 | unsigned char b [2] ; 42 | b [0] = 0x40 ; 43 | b [1] = value & 0xFF ; 44 | write (node->fd, b, 2) ; 45 | } 46 | 47 | 48 | /* 49 | * myAnalogRead: 50 | ********************************************************************************* 51 | */ 52 | 53 | static int myAnalogRead (struct wiringPiNodeStruct *node, int pin) 54 | { 55 | int x ; 56 | 57 | wiringPiI2CWrite (node->fd, 0x40 | ((pin - node->pinBase) & 3)) ; 58 | 59 | x = wiringPiI2CRead (node->fd) ; // Throw away the first read 60 | x = wiringPiI2CRead (node->fd) ; 61 | 62 | return x ; 63 | } 64 | 65 | 66 | /* 67 | * pcf8591Setup: 68 | * Create a new instance of a PCF8591 I2C GPIO interface. We know it 69 | * has 4 pins, (4 analog inputs and 1 analog output which we'll shadow 70 | * input 0) so all we need to know here is the I2C address and the 71 | * user-defined pin base. 72 | ********************************************************************************* 73 | */ 74 | 75 | int pcf8591Setup (const int pinBase, const int i2cAddress) 76 | { 77 | int fd ; 78 | struct wiringPiNodeStruct *node ; 79 | 80 | if ((fd = wiringPiI2CSetup (i2cAddress)) < 0) 81 | return fd ; 82 | 83 | node = wiringPiNewNode (pinBase, 4) ; 84 | 85 | node->fd = fd ; 86 | node->analogRead = myAnalogRead ; 87 | node->analogWrite = myAnalogWrite ; 88 | 89 | return 0 ; 90 | } 91 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/pcf8591.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pcf8591.h: 3 | * Extend wiringPi with the PCF8591 I2C GPIO Analog expander chip 4 | * Copyright (c) 2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern int pcf8591Setup (const int pinBase, const int i2cAddress) ; 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/piHiPri.c: -------------------------------------------------------------------------------- 1 | /* 2 | * piHiPri: 3 | * Simple way to get your program running at high priority 4 | * with realtime schedulling. 5 | * 6 | * Copyright (c) 2012 Gordon Henderson 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 13 | * published by the Free Software Foundation, either version 3 of the 14 | * License, or (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 22 | * License along with wiringPi. 23 | * If not, see . 24 | *********************************************************************** 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | #include "wiringPi.h" 31 | 32 | 33 | /* 34 | * piHiPri: 35 | * Attempt to set a high priority schedulling for the running program 36 | ********************************************************************************* 37 | */ 38 | 39 | int piHiPri (const int pri) 40 | { 41 | struct sched_param sched ; 42 | 43 | memset (&sched, 0, sizeof(sched)) ; 44 | 45 | if (pri > sched_get_priority_max (SCHED_RR)) 46 | sched.sched_priority = sched_get_priority_max (SCHED_RR) ; 47 | else 48 | sched.sched_priority = pri ; 49 | 50 | return sched_setscheduler (0, SCHED_RR, &sched) ; 51 | } 52 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/piThread.c: -------------------------------------------------------------------------------- 1 | /* 2 | * piThread.c: 3 | * Provide a simplified interface to pthreads 4 | * 5 | * Copyright (c) 2012 Gordon Henderson 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as 12 | * published by the Free Software Foundation, either version 3 of the 13 | * License, or (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with wiringPi. 22 | * If not, see . 23 | *********************************************************************** 24 | */ 25 | 26 | #include 27 | #include "wiringPi.h" 28 | 29 | static pthread_mutex_t piMutexes [4] ; 30 | 31 | 32 | 33 | /* 34 | * piThreadCreate: 35 | * Create and start a thread 36 | ********************************************************************************* 37 | */ 38 | 39 | int piThreadCreate (void *(*fn)(void *)) 40 | { 41 | pthread_t myThread ; 42 | 43 | return pthread_create (&myThread, NULL, fn, NULL) ; 44 | } 45 | 46 | /* 47 | * piLock: piUnlock: 48 | * Activate/Deactivate a mutex. 49 | * We're keeping things simple here and only tracking 4 mutexes which 50 | * is more than enough for out entry-level pthread programming 51 | ********************************************************************************* 52 | */ 53 | 54 | void piLock (int key) 55 | { 56 | pthread_mutex_lock (&piMutexes [key]) ; 57 | } 58 | 59 | void piUnlock (int key) 60 | { 61 | pthread_mutex_unlock (&piMutexes [key]) ; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/sn3218.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sn3218.c: 3 | * Extend wiringPi with the SN3218 I2C LEd Driver 4 | * Copyright (c) 2012-2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | #include "sn3218.h" 29 | 30 | /* 31 | * myAnalogWrite: 32 | * Write analog value on the given pin 33 | ********************************************************************************* 34 | */ 35 | 36 | static void myAnalogWrite (struct wiringPiNodeStruct *node, int pin, int value) 37 | { 38 | int fd = node->fd ; 39 | int chan = 0x01 + (pin - node->pinBase) ; 40 | 41 | wiringPiI2CWriteReg8 (fd, chan, value & 0xFF) ; // Value 42 | wiringPiI2CWriteReg8 (fd, 0x16, 0x00) ; // Update 43 | } 44 | 45 | /* 46 | * sn3218Setup: 47 | * Create a new wiringPi device node for an sn3218 on the Pi's 48 | * SPI interface. 49 | ********************************************************************************* 50 | */ 51 | 52 | int sn3218Setup (const int pinBase) 53 | { 54 | int fd ; 55 | struct wiringPiNodeStruct *node ; 56 | 57 | if ((fd = wiringPiI2CSetup (0x54)) < 0) 58 | return fd ; 59 | 60 | // Setup the chip - initialise all 18 LEDs to off 61 | 62 | //wiringPiI2CWriteReg8 (fd, 0x17, 0) ; // Reset 63 | wiringPiI2CWriteReg8 (fd, 0x00, 1) ; // Not Shutdown 64 | wiringPiI2CWriteReg8 (fd, 0x13, 0x3F) ; // Enable LEDs 0- 5 65 | wiringPiI2CWriteReg8 (fd, 0x14, 0x3F) ; // Enable LEDs 6-11 66 | wiringPiI2CWriteReg8 (fd, 0x15, 0x3F) ; // Enable LEDs 12-17 67 | wiringPiI2CWriteReg8 (fd, 0x16, 0x00) ; // Update 68 | 69 | node = wiringPiNewNode (pinBase, 18) ; 70 | 71 | node->fd = fd ; 72 | node->analogWrite = myAnalogWrite ; 73 | 74 | return 0 ; 75 | } 76 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/sn3218.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sn3218.c: 3 | * Extend wiringPi with the SN3218 I2C LED driver board. 4 | * Copyright (c) 2012-2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern int sn3218Setup (int pinBase) ; 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/softPwm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * softPwm.h: 3 | * Provide 2 channels of software driven PWM. 4 | * Copyright (c) 2012 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern int softPwmCreate (int pin, int value, int range) ; 30 | extern void softPwmWrite (int pin, int value) ; 31 | extern void softPwmStop (int pin) ; 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/softServo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * softServo.h: 3 | * Provide N channels of software driven PWM suitable for RC 4 | * servo motors. 5 | * Copyright (c) 2012 Gordon Henderson 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as 12 | * published by the Free Software Foundation, either version 3 of the 13 | * License, or (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with wiringPi. 22 | * If not, see . 23 | *********************************************************************** 24 | */ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | extern void softServoWrite (int pin, int value) ; 31 | extern int softServoSetup (int p0, int p1, int p2, int p3, int p4, int p5, int p6, int p7) ; 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/softTone.h: -------------------------------------------------------------------------------- 1 | /* 2 | * softTone.c: 3 | * For that authentic retro sound... 4 | * Er... A little experiment to produce tones out of a Pi using 5 | * one (or 2) GPIO pins and a piezeo "speaker" element. 6 | * (Or a high impedance speaker, but don'y blame me if you blow-up 7 | * the GPIO pins!) 8 | * Copyright (c) 2012 Gordon Henderson 9 | *********************************************************************** 10 | * This file is part of wiringPi: 11 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 12 | * 13 | * wiringPi is free software: you can redistribute it and/or modify 14 | * it under the terms of the GNU Lesser General Public License as 15 | * published by the Free Software Foundation, either version 3 of the 16 | * License, or (at your option) any later version. 17 | * 18 | * wiringPi is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU Lesser General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU Lesser General Public 24 | * License along with wiringPi. 25 | * If not, see . 26 | *********************************************************************** 27 | */ 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | extern int softToneCreate (int pin) ; 34 | extern void softToneStop (int pin) ; 35 | extern void softToneWrite (int pin, int freq) ; 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/sr595.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sr595.c: 3 | * Extend wiringPi with the 74x595 shift register as a GPIO 4 | * expander chip. 5 | * Note that the code can cope with a number of 595's 6 | * daisy-chained together - up to 4 for now as we're storing 7 | * the output "register" in a single unsigned int. 8 | * 9 | * Copyright (c) 2013 Gordon Henderson 10 | *********************************************************************** 11 | * This file is part of wiringPi: 12 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 13 | * 14 | * wiringPi is free software: you can redistribute it and/or modify 15 | * it under the terms of the GNU Lesser General Public License as 16 | * published by the Free Software Foundation, either version 3 of the 17 | * License, or (at your option) any later version. 18 | * 19 | * wiringPi is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU Lesser General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU Lesser General Public 25 | * License along with wiringPi. 26 | * If not, see . 27 | *********************************************************************** 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | #include "wiringPi.h" 34 | 35 | #include "sr595.h" 36 | 37 | 38 | /* 39 | * myDigitalWrite: 40 | ********************************************************************************* 41 | */ 42 | 43 | static void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value) 44 | { 45 | unsigned int mask ; 46 | int dataPin, clockPin, latchPin ; 47 | int bit, bits, output ; 48 | 49 | pin -= node->pinBase ; // Normalise pin number 50 | bits = node->pinMax - node->pinBase + 1 ; // ie. number of clock pulses 51 | dataPin = node->data0 ; 52 | clockPin = node->data1 ; 53 | latchPin = node->data2 ; 54 | output = node->data3 ; 55 | 56 | mask = 1 << pin ; 57 | 58 | if (value == LOW) 59 | output &= (~mask) ; 60 | else 61 | output |= mask ; 62 | 63 | node->data3 = output ; 64 | 65 | // A low -> high latch transition copies the latch to the output pins 66 | 67 | digitalWrite (latchPin, LOW) ; delayMicroseconds (1) ; 68 | for (bit = bits - 1 ; bit >= 0 ; --bit) 69 | { 70 | digitalWrite (dataPin, output & (1 << bit)) ; 71 | 72 | digitalWrite (clockPin, HIGH) ; delayMicroseconds (1) ; 73 | digitalWrite (clockPin, LOW) ; delayMicroseconds (1) ; 74 | } 75 | digitalWrite (latchPin, HIGH) ; delayMicroseconds (1) ; 76 | } 77 | 78 | 79 | /* 80 | * sr595Setup: 81 | * Create a new instance of a 74x595 shift register GPIO expander. 82 | ********************************************************************************* 83 | */ 84 | 85 | int sr595Setup (const int pinBase, const int numPins, 86 | const int dataPin, const int clockPin, const int latchPin) 87 | { 88 | struct wiringPiNodeStruct *node ; 89 | 90 | node = wiringPiNewNode (pinBase, numPins) ; 91 | 92 | node->data0 = dataPin ; 93 | node->data1 = clockPin ; 94 | node->data2 = latchPin ; 95 | node->data3 = 0 ; // Output register 96 | node->digitalWrite = myDigitalWrite ; 97 | 98 | // Initialise the underlying hardware 99 | 100 | digitalWrite (dataPin, LOW) ; 101 | digitalWrite (clockPin, LOW) ; 102 | digitalWrite (latchPin, HIGH) ; 103 | 104 | pinMode (dataPin, OUTPUT) ; 105 | pinMode (clockPin, OUTPUT) ; 106 | pinMode (latchPin, OUTPUT) ; 107 | 108 | return 0 ; 109 | } 110 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/sr595.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sr595.h: 3 | * Extend wiringPi with the 74x595 shift registers. 4 | * Copyright (c) 2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern int sr595Setup (const int pinBase, const int numPins, 30 | const int dataPin, const int clockPin, const int latchPin) ; 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/wiringPiI2C.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wiringPiI2C.h: 3 | * Simplified I2C access routines 4 | * Copyright (c) 2013 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern int wiringPiI2CRead (int fd) ; 30 | extern int wiringPiI2CReadReg8 (int fd, int reg) ; 31 | extern int wiringPiI2CReadReg16 (int fd, int reg) ; 32 | 33 | extern int wiringPiI2CWrite (int fd, int data) ; 34 | extern int wiringPiI2CWriteReg8 (int fd, int reg, int data) ; 35 | extern int wiringPiI2CWriteReg16 (int fd, int reg, int data) ; 36 | 37 | extern int wiringPiI2CSetupInterface (const char *device, int devId) ; 38 | extern int wiringPiI2CSetup (const int devId) ; 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/wiringPiSPI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wiringPiSPI.h: 3 | * Simplified SPI access routines 4 | * Copyright (c) 2012-2015 Gordon Henderson 5 | *********************************************************************** 6 | * This file is part of wiringPi: 7 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 8 | * 9 | * wiringPi is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * wiringPi is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with wiringPi. 21 | * If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | int wiringPiSPIGetFd (int channel) ; 30 | int wiringPiSPIDataRW (int channel, unsigned char *data, int len) ; 31 | int wiringPiSPISetupMode (int channel, int speed, int mode) ; 32 | int wiringPiSPISetup (int channel, int speed) ; 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/wiringSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wiringSerial.h: 3 | * Handle a serial port 4 | *********************************************************************** 5 | * This file is part of wiringPi: 6 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 7 | * 8 | * wiringPi is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * wiringPi is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with wiringPi. If not, see . 20 | *********************************************************************** 21 | */ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | extern int serialOpen (const char *device, const int baud) ; 28 | extern void serialClose (const int fd) ; 29 | extern void serialFlush (const int fd) ; 30 | extern void serialPutchar (const int fd, const unsigned char c) ; 31 | extern void serialPuts (const int fd, const char *s) ; 32 | extern void serialPrintf (const int fd, const char *message, ...) ; 33 | extern int serialDataAvail (const int fd) ; 34 | extern int serialGetchar (const int fd) ; 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/wiringShift.c: -------------------------------------------------------------------------------- 1 | /* 2 | * wiringShift.c: 3 | * Emulate some of the Arduino wiring functionality. 4 | * 5 | * Copyright (c) 2009-2012 Gordon Henderson. 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #include 26 | 27 | #include "wiringPi.h" 28 | #include "wiringShift.h" 29 | 30 | /* 31 | * shiftIn: 32 | * Shift data in from a clocked source 33 | ********************************************************************************* 34 | */ 35 | 36 | uint8_t shiftIn (uint8_t dPin, uint8_t cPin, uint8_t order) 37 | { 38 | uint8_t value = 0 ; 39 | int8_t i ; 40 | 41 | if (order == MSBFIRST) 42 | for (i = 7 ; i >= 0 ; --i) 43 | { 44 | digitalWrite (cPin, HIGH) ; 45 | value |= digitalRead (dPin) << i ; 46 | digitalWrite (cPin, LOW) ; 47 | } 48 | else 49 | for (i = 0 ; i < 8 ; ++i) 50 | { 51 | digitalWrite (cPin, HIGH) ; 52 | value |= digitalRead (dPin) << i ; 53 | digitalWrite (cPin, LOW) ; 54 | } 55 | 56 | return value; 57 | } 58 | 59 | /* 60 | * shiftOut: 61 | * Shift data out to a clocked source 62 | ********************************************************************************* 63 | */ 64 | 65 | void shiftOut (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val) 66 | { 67 | int8_t i; 68 | 69 | if (order == MSBFIRST) 70 | for (i = 7 ; i >= 0 ; --i) 71 | { 72 | digitalWrite (dPin, val & (1 << i)) ; 73 | digitalWrite (cPin, HIGH) ; 74 | digitalWrite (cPin, LOW) ; 75 | } 76 | else 77 | for (i = 0 ; i < 8 ; ++i) 78 | { 79 | digitalWrite (dPin, val & (1 << i)) ; 80 | digitalWrite (cPin, HIGH) ; 81 | digitalWrite (cPin, LOW) ; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/wiringShift.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wiringShift.h: 3 | * Emulate some of the Arduino wiring functionality. 4 | * 5 | * Copyright (c) 2009-2012 Gordon Henderson. 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | #define LSBFIRST 0 26 | #define MSBFIRST 1 27 | 28 | #ifndef _STDINT_H 29 | # include 30 | #endif 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | extern uint8_t shiftIn (uint8_t dPin, uint8_t cPin, uint8_t order) ; 37 | extern void shiftOut (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val) ; 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | -------------------------------------------------------------------------------- /WiringPi/wiringPi/wpiExtensions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * extensions.h: 3 | * Part of the GPIO program to test, peek, poke and otherwise 4 | * noodle with the GPIO hardware on the Raspberry Pi. 5 | * Copyright (c) 2012-2015 Gordon Henderson 6 | *********************************************************************** 7 | * This file is part of wiringPi: 8 | * https://projects.drogon.net/raspberry-pi/wiringpi/ 9 | * 10 | * wiringPi is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * wiringPi is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with wiringPi. If not, see . 22 | *********************************************************************** 23 | */ 24 | 25 | 26 | extern int loadWPiExtension (char *progName, char *extensionData, int verbose) ; 27 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | swig2.0 -python -threads wiringpi.i 2 | sudo python setup.py build install 3 | sudo python test.py 4 | -------------------------------------------------------------------------------- /examples/RUN_THESE_WITH_SUDO: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gadgetoid/WiringPi2-Python/620be8c3264ed23a7d45d0a473ffeec3c2a4bc5e/examples/RUN_THESE_WITH_SUDO -------------------------------------------------------------------------------- /examples/callback.py: -------------------------------------------------------------------------------- 1 | import wiringpi2 2 | PIN_TO_SENSE = 23 3 | 4 | def gpio_callback(): 5 | print "GPIO_CALLBACK!" 6 | 7 | wiringpi2.wiringPiSetupGpio() 8 | wiringpi2.pinMode(PIN_TO_SENSE, wiringpi2.GPIO.INPUT) 9 | wiringpi2.pullUpDnControl(PIN_TO_SENSE, wiringpi2.GPIO.PUD_UP) 10 | 11 | wiringpi2.wiringPiISR(PIN_TO_SENSE, wiringpi2.GPIO.INT_EDGE_BOTH, gpio_callback) 12 | 13 | while True: 14 | wiringpi2.delay(2000) 15 | -------------------------------------------------------------------------------- /examples/delay.py: -------------------------------------------------------------------------------- 1 | # Demonstrates use of Arduino-like delay function 2 | import wiringpi2 3 | print 'Hello World' 4 | wiringpi2.delay(1500) # Delay for 1.5 seconds 5 | print 'Hi again!' 6 | -------------------------------------------------------------------------------- /examples/ladder-board.py: -------------------------------------------------------------------------------- 1 | import wiringpi2 as wiringpi 2 | INPUT = 0 3 | OUTPUT = 1 4 | LOW = 0 5 | HIGH = 1 6 | BUTTONS = [13,12,10,11] 7 | LEDS = [0,1,2,3,4,5,6,7,8,9] 8 | PUD_UP = 2 9 | 10 | wiringpi.wiringPiSetup() 11 | 12 | for button in BUTTONS: 13 | wiringpi.pinMode(button,INPUT) 14 | wiringpi.pullUpDnControl(button,PUD_UP) 15 | 16 | for led in LEDS: 17 | wiringpi.pinMode(led,OUTPUT) 18 | 19 | while 1: 20 | for index,button in enumerate(BUTTONS): 21 | button_state = wiringpi.digitalRead(button) 22 | first_led = LEDS[index*2] 23 | second_led = LEDS[(index*2)+1] 24 | #print str(button) + ' ' + str(button_state) 25 | wiringpi.digitalWrite(first_led,1-button_state) 26 | wiringpi.digitalWrite(second_led,1-button_state) 27 | wiringpi.delay(20) 28 | -------------------------------------------------------------------------------- /examples/n5510-mcp23017.py: -------------------------------------------------------------------------------- 1 | # Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander ) 2 | import wiringpi2 as wiringpi 3 | 4 | PIN_BACKLIGHT = 67 # LED 5 | PIN_SCLK = 68 # Clock SCLK 6 | PIN_SDIN = 69 # DN(MOSI) 7 | PIN_DC = 70 # D/C 8 | PIN_RESET = 71 # RST Reset 9 | PIN_SCE = 72 # SCE 10 | 11 | #PIN_BACKLIGHT = 5 12 | #PIN_SCLK = 4 13 | #PIN_SDIN = 3 14 | #PIN_DC = 2 15 | #PIN_RESET = 1 16 | #PIN_SCE = 0 17 | 18 | OUTPUT = 1 19 | INPUT = 0 20 | HIGH = 1 21 | LOW = 0 22 | 23 | LCD_C = 0 24 | LCD_D = 1 25 | 26 | LCD_X = 84 27 | LCD_Y = 48 28 | LCD_SEGS = 504 29 | 30 | MSBFIRST = 1 31 | LSBFIRST = 0 32 | 33 | SLOW_DOWN = 400 34 | 35 | pin_base = 65 36 | i2c_addr = 0x21 37 | 38 | wiringpi.wiringPiSetup() 39 | wiringpi.mcp23017Setup(pin_base,i2c_addr) 40 | 41 | def slow_shift_out(data_pin, clock_pin, data): 42 | for bit in bin(data).replace('0b','').rjust(8,'0'): 43 | wiringpi.digitalWrite(clock_pin,LOW) 44 | wiringpi.delay(SLOW_DOWN) 45 | wiringpi.digitalWrite(data_pin,int(bit)) 46 | wiringpi.delay(SLOW_DOWN) 47 | wiringpi.digitalWrite(clock_pin,HIGH) 48 | wiringpi.delay(SLOW_DOWN) 49 | 50 | def lcd_write(dc, data): 51 | wiringpi.digitalWrite(PIN_DC, dc) 52 | wiringpi.digitalWrite(PIN_SCE, LOW) 53 | wiringpi.delay(SLOW_DOWN) 54 | #wiringpi.shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data) 55 | slow_shift_out(PIN_SDIN, PIN_SCLK, data) 56 | wiringpi.digitalWrite(PIN_SCE, HIGH) 57 | wiringpi.delay(SLOW_DOWN) 58 | #wiringpi.delay(2) 59 | 60 | def lcd_initialise(): 61 | wiringpi.pinMode(PIN_BACKLIGHT,OUTPUT) 62 | wiringpi.digitalWrite(PIN_BACKLIGHT, HIGH) 63 | wiringpi.pinMode(PIN_SCE, OUTPUT) 64 | wiringpi.pinMode(PIN_RESET, OUTPUT) 65 | wiringpi.pinMode(PIN_DC, OUTPUT) 66 | wiringpi.pinMode(PIN_SDIN, OUTPUT) 67 | wiringpi.pinMode(PIN_SCLK, OUTPUT) 68 | wiringpi.digitalWrite(PIN_RESET, LOW) 69 | wiringpi.delay(SLOW_DOWN) 70 | wiringpi.digitalWrite(PIN_RESET, HIGH) 71 | wiringpi.delay(SLOW_DOWN) 72 | lcd_write(LCD_C, 0x21 ) # LCD Extended Commands. 73 | lcd_write(LCD_C, 0xCC ) # Set LCD Vop (Contrast). 74 | lcd_write(LCD_C, 0x04 ) # Set Temp coefficent. //0x04 75 | lcd_write(LCD_C, 0x14 ) # LCD bias mode 1:48. //0x13 76 | lcd_write(LCD_C, 0x0C ) # LCD in normal mode. 77 | lcd_write(LCD_C, 0x20 ) 78 | lcd_write(LCD_C, 0x0C ) 79 | 80 | def lcd_clear(): 81 | for time in range(0, LCD_SEGS): 82 | lcd_write(LCD_D, 0x00) 83 | 84 | def lcd_fill(): 85 | for time in range(0, LCD_SEGS): 86 | lcd_write(LCD_D, 0xFF) 87 | 88 | 89 | lcd_initialise() 90 | 91 | for time in range(0,4): 92 | lcd_clear() 93 | wiringpi.delay(1000) 94 | lcd_fill() 95 | wiringpi.delay(1000) -------------------------------------------------------------------------------- /examples/quick2wire-io.py: -------------------------------------------------------------------------------- 1 | # Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander ) 2 | import wiringpi2 3 | 4 | pin_base = 65 5 | i2c_addr = 0x20 6 | pins = [65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80] 7 | 8 | wiringpi2.wiringPiSetup() 9 | wiringpi2.mcp23017Setup(pin_base,i2c_addr) 10 | 11 | for pin in pins: 12 | wiringpi2.pinMode(pin,1) 13 | wiringpi2.digitalWrite(pin,1) 14 | # wiringpi2.delay(1000) 15 | # wiringpi2.digitalWrite(pin,0) 16 | -------------------------------------------------------------------------------- /examples/softpwm.py: -------------------------------------------------------------------------------- 1 | # Pulsates an LED connected to GPIO pin 1 with a suitable resistor 4 times using softPwm 2 | # softPwm uses a fixed frequency 3 | import wiringpi2 4 | 5 | OUTPUT = 1 6 | 7 | PIN_TO_PWM = 1 8 | 9 | wiringpi2.wiringPiSetup() 10 | wiringpi2.pinMode(PIN_TO_PWM,OUTPUT) 11 | wiringpi2.softPwmCreate(PIN_TO_PWM,0,100) # Setup PWM using Pin, Initial Value and Range parameters 12 | 13 | for time in range(0,4): 14 | for brightness in range(0,100): # Going from 0 to 100 will give us full off to full on 15 | wiringpi2.softPwmWrite(PIN_TO_PWM,brightness) # Change PWM duty cycle 16 | wiringpi2.delay(10) # Delay for 0.2 seconds 17 | for brightness in reversed(range(0,100)): 18 | wiringpi2.softPwmWrite(PIN_TO_PWM,brightness) 19 | wiringpi2.delay(10) 20 | -------------------------------------------------------------------------------- /examples/two-mcp23017.py: -------------------------------------------------------------------------------- 1 | # Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander ) 2 | import wiringpi2 3 | 4 | pin_base = 65 5 | i2c_addr = 0x20 6 | i2c_addr_2 = 0x21 7 | #pins = [65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80] 8 | 9 | wiringpi2.wiringPiSetup() 10 | wiringpi2.mcp23017Setup(pin_base,i2c_addr) 11 | wiringpi2.mcp23017Setup(pin_base+16,i2c_addr_2) 12 | 13 | #for pin in pins: 14 | for pin in range(65,96): 15 | wiringpi2.pinMode(pin,1) 16 | wiringpi2.digitalWrite(pin,1) 17 | # wiringpi2.delay(1000) 18 | # wiringpi2.digitalWrite(pin,0) 19 | -------------------------------------------------------------------------------- /piglow.py: -------------------------------------------------------------------------------- 1 | import wiringpi2 as wiringpi 2 | io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS) 3 | io.piGlowSetup() 4 | io.piGlowLeg(1,100) 5 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from setuptools import setup, find_packages, Extension 4 | from glob import glob 5 | 6 | _wiringpi2 = Extension( 7 | '_wiringpi2', 8 | include_dirs=['WiringPi/wiringPi','WiringPi/devLib'], 9 | sources=glob('WiringPi/devLib/*.c')+glob('WiringPi/wiringPi/*.c')+['wiringpi_wrap.c'] 10 | ) 11 | 12 | setup( 13 | name = 'wiringpi2', 14 | version = '1.1.1', 15 | author = "Philip Howard", 16 | author_email = "phil@gadgetoid.com", 17 | url = 'https://github.com/Gadgetoid/WiringPi2-Python/', 18 | description = """A python interface to WiringPi 2.0 library which allows for 19 | easily interfacing with the GPIO pins of the Raspberry Pi. Also supports 20 | i2c and SPI""", 21 | long_description=open('README').read(), 22 | ext_modules = [ _wiringpi2 ], 23 | py_modules = ["wiringpi2"], 24 | install_requires=[], 25 | headers=glob('WiringPi/wiringPi/*.h')+glob('WiringPi/devLib/*.h') 26 | ) 27 | -------------------------------------------------------------------------------- /test.py: -------------------------------------------------------------------------------- 1 | import wiringpi2 as wiringpi 2 | io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS) 3 | print io.digitalRead(1) 4 | print io.analogRead(1) 5 | --------------------------------------------------------------------------------