├── .gitignore ├── COPYING.LESSER ├── INSTALL ├── Makefile ├── People ├── README.md ├── build ├── debian ├── changelog ├── compat ├── control ├── copyright ├── docs ├── gpio.install ├── libwiringop-dev.dirs ├── libwiringop-dev.install ├── libwiringop2.dirs ├── libwiringop2.install ├── libwiringop2.symbols ├── libwiringopdev2.install ├── rules └── source │ └── format ├── 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 ├── piFaceOld.c ├── piGlow.c ├── piGlow.h ├── piNes.c └── piNes.h ├── examples ├── BProTest │ ├── lnIOBoard │ ├── lnIOBoard.c │ └── testLedCon6.c ├── COPYING.LESSER ├── Gertboard │ ├── 7segments.c │ ├── Makefile │ ├── buttons.c │ ├── gertboard.c │ ├── record.c │ ├── temperature.c │ ├── voltmeter.c │ └── vumeter.c ├── Makefile ├── OrangePi │ ├── Makefile │ ├── OrangePi_Common.c │ └── README.md ├── 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 ├── echo.c ├── header.h ├── isr-osc.c ├── isr.c ├── lcd-adafruit.c ├── lcd.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 ├── te.c ├── tser.c ├── wfi.c └── xserv.c ├── gpio ├── COPYING.LESSER ├── Makefile ├── OrangePi.c ├── OrangePi.h ├── extensions.c ├── extensions.h ├── gpio.1 ├── gpio.c ├── pins.c ├── pintest ├── readall.c └── test.sh ├── pins ├── Makefile ├── pins.pdf └── pins.tex └── wiringPi ├── COPYING.LESSER ├── Makefile ├── OrangePi.c ├── OrangePi.h ├── RaspberryPi.c ├── RaspberryPi.h ├── 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 /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | libwiringPiDev.so.2.0 3 | libwiringPi.so.2.0 4 | /test/ 5 | *.*~ 6 | *.swp 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | $(MAKE) -C wiringPi $@ 3 | $(MAKE) -C devLib $@ 4 | -ln -fs libwiringPiDev.so.2.0 devLib/libwiringPiDev.so 5 | -ln -fs libwiringPi.so.2.0 wiringPi/libwiringPi.so 6 | $(MAKE) -C gpio 'INCLUDE=-I../devLib -I../wiringPi' 'LDFLAGS=-L../devLib -L../wiringPi' $@ 7 | 8 | %: 9 | $(MAKE) -C wiringPi $@ 10 | $(MAKE) -C devLib $@ 11 | $(MAKE) -C gpio $@ 12 | -------------------------------------------------------------------------------- /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 | 35 | Xiao Zhengfeng 36 | Porting wiringPi for Banana Pi. 37 | 38 | Will Xiao 39 | Testing on Banana Pro/Pi. 40 | 41 | Peter Chen 42 | Porting wiringPi for Banana Pro. 43 | -------------------------------------------------------------------------------- /build: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # check if sudo is required and save the result as ${PFX}: 4 | if [ `id -u` -eq 0 ];then 5 | echo "Build WiringPi on OrangePi" 6 | else 7 | echo "Please use root: sudo ./build OrangePi_2G-IOT" 8 | exit 0 9 | fi 10 | 11 | if [ -z $1 -o ! $1 == "clean" ]; then 12 | echo "Please specify platfrom: sudo ./build OrangePi_2G-IOT" 13 | echo "More information please refer README.md" 14 | exit 0 15 | fi 16 | 17 | check_make_ok() { 18 | if [ $? != 0 ]; then 19 | echo "" 20 | echo "Make Failed..." 21 | echo "Please check the messages and fix any problems. If you're still stuck," 22 | echo "then please email all the output and as many details as you can to" 23 | echo " projects@drogon.net" 24 | echo "" 25 | exit 1 26 | fi 27 | } 28 | 29 | if [ x$1 = "xclean" ]; then 30 | cd wiringPi 31 | echo -n "wiringPi: " ; make clean 32 | cd ../devLib 33 | echo -n "DevLib: " ; make clean 34 | cd ../gpio 35 | echo -n "gpio: " ; make clean 36 | cd ../examples 37 | echo -n "Examples: " ; make clean 38 | cd Gertboard 39 | echo -n "Gertboard: " ; make clean 40 | cd ../PiFace 41 | echo -n "PiFace: " ; make clean 42 | cd ../q2w 43 | echo -n "Quick2Wire: " ; make clean 44 | cd ../PiGlow 45 | echo -n "PiGlow: " ; make clean 46 | exit 47 | fi 48 | 49 | if [ x$1 = "xuninstall" ]; then 50 | cd wiringPi 51 | echo -n "wiringPi: " ; ${PFX}make uninstall 52 | cd ../devLib 53 | echo -n "DevLib: " ; ${PFX}make uninstall 54 | cd ../gpio 55 | echo -n "gpio: " ; ${PFX}make uninstall 56 | exit 57 | fi 58 | 59 | 60 | echo "wiringPi Build script" 61 | echo "=====================" 62 | echo 63 | 64 | echo 65 | echo "WiringPi Library" 66 | cd wiringPi 67 | ${PFX}make uninstall 68 | if [ x$1 = "xstatic" ]; then 69 | make static 70 | check_make_ok 71 | ${PFX}make install-static 72 | else 73 | make PLATFORM=$1 74 | check_make_ok 75 | ${PFX}make install 76 | fi 77 | check_make_ok 78 | 79 | echo 80 | echo "WiringPi Devices Library" 81 | cd ../devLib 82 | ${PFX}make uninstall 83 | if [ x$1 = "xstatic" ]; then 84 | make static 85 | check_make_ok 86 | ${PFX}make install-static 87 | else 88 | make PLATFORM=$1 89 | check_make_ok 90 | ${PFX}make install 91 | fi 92 | check_make_ok 93 | 94 | echo 95 | echo "GPIO Utility" 96 | cd ../gpio 97 | make PLATFORM=$1 98 | check_make_ok 99 | ${PFX}make install 100 | check_make_ok 101 | 102 | # echo 103 | # echo "Examples" 104 | # cd ../examples 105 | # make 106 | # cd .. 107 | 108 | echo 109 | echo All Done. 110 | echo "" 111 | echo "NOTE: To compile programs with wiringBP v2, you need to add:" 112 | echo " -lwiringPi" 113 | echo " to your compile line(s) To use the Gertboard, MaxDetect, etc." 114 | echo " code (the devLib), you need to also add:" 115 | echo " -lwiringPiDev" 116 | echo " to your compile line(s)." 117 | echo "" 118 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | wiringop (2.0~ppa1~vivid1) vivid; urgency=high 2 | 3 | * Initial release 4 | 5 | -- Сергей Хлутчин Fri, 23 Sep 2016 18:10:04 +0400 6 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: wiringop 2 | Priority: optional 3 | Maintainer: Сергей Хлутчин 4 | Build-Depends: debhelper (>= 9) 5 | Standards-Version: 3.9.5 6 | Section: libs 7 | Homepage: https://github.com/zhaolei/WiringOP 8 | Vcs-Git: https://github.com/zhaolei/WiringOP.git 9 | Vcs-Browser: https://github.com/zhaolei/WiringOP 10 | 11 | Package: libwiringop-dev 12 | Section: libdevel 13 | Architecture: any 14 | Depends: libwiringop2 (= ${binary:Version}), libwiringopdev2 (= ${binary:Version}), ${misc:Depends} 15 | Description: GPIO access library for OrangePi. Development files. 16 | This is a modified WiringPi for OrangePi. 17 | It is based on the original WiringPi for Raspberry Pi. 18 | WiringPi is a GPIO access library written in C originally for the BCM2835 used in the Raspberry Pi. 19 | It’s released under the GNU LGPLv3 license and is usable from C and C++ 20 | and many other languages with suitable wrappers. 21 | It’s designed to be familiar to people who have used the Arduino “wiring” system. 22 | 23 | Package: libwiringop2 24 | Architecture: any 25 | Multi-Arch: same 26 | Pre-Depends: ${misc:Pre-Depends} 27 | Depends: ${shlibs:Depends}, ${misc:Depends} 28 | Description: GPIO access library for OrangePi. Dynamic library. 29 | This is a modified WiringPi for OrangePi. 30 | It is based on the original WiringPi for Raspberry Pi. 31 | WiringPi is a GPIO access library written in C originally for the BCM2835 used in the Raspberry Pi. 32 | It’s released under the GNU LGPLv3 license and is usable from C and C++ 33 | and many other languages with suitable wrappers. 34 | It’s designed to be familiar to people who have used the Arduino “wiring” system. 35 | 36 | Package: libwiringopdev2 37 | Architecture: any 38 | Multi-Arch: same 39 | Pre-Depends: ${misc:Pre-Depends} 40 | Depends: ${shlibs:Depends}, ${misc:Depends} 41 | Description: WiringPi device library for OrangePi. Dynamic library. 42 | This is a part of a modified WiringPi for OrangePi. 43 | It is based on the original WiringPi for Raspberry Pi. 44 | Dev Lib is a library of device drivers for some popular hardware devices. 45 | These device drivers are not true device drivers in the Linux kernel terms, 46 | but are C libraries to use the existing wiringPi library to access the hardware devices via simple to use APIs. 47 | 48 | Package: gpio 49 | Section: libdevel 50 | Architecture: any 51 | Depends: ${misc:Depends} 52 | Description: GPIO access Utility from the WiringPi library. 53 | This is a part of a modified WiringPi for OrangePi. 54 | gpio is an utility to acess GPIO using the WiringPi library. 55 | It also is necessary for use interrupts with this library. 56 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: wiringop 3 | Source: 4 | 5 | Files: * 6 | Copyright: Copyright (C) 2007 Free Software Foundation, Inc. 7 | License: LGPL-3.0+ 8 | 9 | Files: debian/* 10 | Copyright: 2016 Сергей Хлутчин 11 | License: LGPL-3.0+ 12 | 13 | License: LGPL-3.0+ 14 | This package is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU Lesser General Public 16 | License as published by the Free Software Foundation; either 17 | version 3 of the License, or (at your option) any later version. 18 | . 19 | This package 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 GNU 22 | Lesser General Public License for more details. 23 | . 24 | You should have received a copy of the GNU General Public License 25 | along with this program. If not, see . 26 | . 27 | On Debian systems, the complete text of the GNU Lesser General 28 | Public License can be found in "/usr/share/common-licenses/LGPL-3". 29 | 30 | # Please also look if there are files or directories which have a 31 | # different copyright/license attached and list them here. 32 | # Please avoid to pick license terms that are more restrictive than the 33 | # packaged work, as it may make Debian's contributions unacceptable upstream. 34 | -------------------------------------------------------------------------------- /debian/docs: -------------------------------------------------------------------------------- 1 | README.md 2 | -------------------------------------------------------------------------------- /debian/gpio.install: -------------------------------------------------------------------------------- 1 | usr/bin/* 2 | usr/man/* 3 | -------------------------------------------------------------------------------- /debian/libwiringop-dev.dirs: -------------------------------------------------------------------------------- 1 | usr/include 2 | -------------------------------------------------------------------------------- /debian/libwiringop-dev.install: -------------------------------------------------------------------------------- 1 | usr/include/* 2 | -------------------------------------------------------------------------------- /debian/libwiringop2.dirs: -------------------------------------------------------------------------------- 1 | usr/lib 2 | -------------------------------------------------------------------------------- /debian/libwiringop2.install: -------------------------------------------------------------------------------- 1 | usr/lib/*/libwiringPi.so.* 2 | usr/lib/*/libwiringPi.so 3 | -------------------------------------------------------------------------------- /debian/libwiringopdev2.install: -------------------------------------------------------------------------------- 1 | usr/lib/*/libwiringPiDev.so.* 2 | usr/lib/*/libwiringPiDev.so 3 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | export CC=$(DEB_TARGET_GNU_TYPE)-gcc 3 | export CXX=$(DEB_TARGET_GNU_TYPE)-g++ 4 | DEB_HOST_MULTIARCH?=$(shell dpkg-architecture -qDEB_HOST_MULTIARCH) 5 | export LIBARCH=/$(DEB_HOST_MULTIARCH) 6 | PREFIX=/usr 7 | export PREFIX 8 | # See debhelper(7) (uncomment to enable) 9 | # output every command that modifies files on the build system. 10 | DH_VERBOSE = 1 11 | 12 | # see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/* 13 | DPKG_EXPORT_BUILDFLAGS = 1 14 | include /usr/share/dpkg/default.mk 15 | 16 | # see FEATURE AREAS in dpkg-buildflags(1) 17 | #export DEB_BUILD_MAINT_OPTIONS = hardening=+all 18 | 19 | # see ENVIRONMENT in dpkg-buildflags(1) 20 | # package maintainers to append CFLAGS 21 | #export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic 22 | # package maintainers to append LDFLAGS 23 | #export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed 24 | 25 | 26 | # main packaging script based on dh7 syntax 27 | %: 28 | dh $@ 29 | 30 | # debmake generated override targets 31 | # This is example for Cmake (See http://bugs.debian.org/641051 ) 32 | #override_dh_auto_configure: 33 | # dh_auto_configure -- \ 34 | # -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) 35 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (native) 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /devLib/font.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OrangePiLibra/WiringPi/f42b63eb419862e9c6ce6a7ab43299891628bd1d/devLib/font.h -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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_YELLOW 1 28 | #define PIGLOW_ORANGE 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /examples/BProTest/lnIOBoard: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OrangePiLibra/WiringPi/f42b63eb419862e9c6ce6a7ab43299891628bd1d/examples/BProTest/lnIOBoard -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /examples/OrangePi/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile: 3 | # wiringPi - Wiring Compatable library for the OrangePi 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 = OrangePi_Common.c 39 | 40 | OBJ = $(SRC:.c=.o) 41 | 42 | BINS = $(SRC:.c=) 43 | 44 | all: 45 | @cat README.TXT 46 | @echo " $(BINS)" | fmt 47 | @echo "" 48 | 49 | really-all: $(BINS) 50 | 51 | OrangePi: OrangePi_Common.o 52 | @echo [link] 53 | @$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS) 54 | 55 | .c.o: 56 | @echo [CC] $< 57 | @$(CC) -c $(CFLAGS) $< -o $@ 58 | 59 | clean: 60 | @echo "[Clean]" 61 | @rm -f $(OBJ) *~ core tags $(BINS) 62 | 63 | tags: $(SRC) 64 | @echo [ctags] 65 | @ctags $(SRC) 66 | 67 | depend: 68 | makedepend -Y $(SRC) 69 | 70 | # DO NOT DELETE 71 | -------------------------------------------------------------------------------- /examples/OrangePi/OrangePi_Common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * OrangePi GPIO Demo 3 | * General gpio input or output 4 | * 5 | * Copyright (c) 2017 Buddy.Zhang 6 | * You should have received a copy of the GNU Lesser General Public License 7 | * along with wiringPi. If not, see . 8 | */ 9 | #include 10 | 11 | #include 12 | 13 | #define PA1 1 14 | #define GPIO_DEMO_INPUT_MODE 1 15 | #define GPIO_DEMO_OUTPUT_MODE 0 16 | #define GPIO_2G_IOT_GROUP_C 0 17 | #define GPIO_2G_IOT_GENERAL_GROUP 1 18 | 19 | static void OrangePi_2G_IOT_Demo(void); 20 | static void OrangePi_2G_IOT_GPIOC_Demo(void); 21 | 22 | /* 23 | * Main entry 24 | */ 25 | int main(int argc, char *argv[]) 26 | { 27 | #if GPIO_2G_IOT_GROUP_C 28 | /* OrangePi 2G-IOT GPIO C group */ 29 | OrangePi_2G_IOT_GPIOC_Demo(); 30 | #endif 31 | 32 | #if GPIO_2G_IOT_GENERAL_GROUP 33 | /* OrangePi 2G-IOT General GPIO */ 34 | OrangePi_2G_IOT_Demo(); 35 | #endif 36 | 37 | return 0; 38 | } 39 | 40 | /* 41 | * General gpio input or output on OrangePi 2G-IOT 42 | */ 43 | static void OrangePi_2G_IOT_Demo(void) 44 | { 45 | /* 46 | * More information about pin definition 47 | * see README.md, section OrangePi 2G-IOT 48 | */ 49 | wiringPiSetup(); 50 | 51 | #if GPIO_DEMO_OUTPUT_MODE 52 | /* Set Output mode */ 53 | pinMode(PA1, OUTPUT); 54 | 55 | for (;;) { 56 | digitalWrite(PA1, HIGH); 57 | delay(500); 58 | digitalWrite(PA1, LOW); 59 | delay(500); 60 | } 61 | #elif GPIO_DEMO_INPUT_MODE 62 | unsigned int vol; 63 | 64 | /* Set Input mode */ 65 | pinMode(PA1, INPUT); 66 | 67 | for (;;) { 68 | vol = digitalRead(PA1); 69 | delay(500); 70 | printf("Current voltage: %#x\n", vol); 71 | } 72 | #endif 73 | } 74 | 75 | /* 76 | * GPIO C group usemanual. 77 | * On hardware, the location of modem between CPU and reigster of GPIOC. 78 | * So, CPU must send message to modem before controling GPIOC. and we don't 79 | * use GPIOC as general GPIO. Now, GPIOC only support OUTPUT. 80 | * 81 | * The first number of GPIOC (GPIO_C_0) is 64, and bank is of GPIOC group is 32. 82 | * So, the last number of GPIOC (GPIO_C_31) is 95. 83 | */ 84 | static void OrangePi_2G_IOT_GPIOC_Demo(void) 85 | { 86 | /* 87 | * The range of GPIOC is 64 to 93. 88 | * So, we can get index of GPIOC: 89 | * GPIO_C_x: index = 64 + x 90 | * Demo: GPIO_C_27 91 | * index = 64 + 27 = 91 92 | */ 93 | #define GPIO_C_27 91 94 | 95 | wiringPiSetup(); 96 | 97 | /* Set gpio as output */ 98 | pinMode(GPIO_C_27, OUTPUT); 99 | 100 | for (;;) { 101 | digitalWrite(GPIO_C_27, HIGH); 102 | delay(500); 103 | digitalWrite(GPIO_C_27, LOW); 104 | delay(500); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /examples/OrangePi/README.md: -------------------------------------------------------------------------------- 1 | OrangePi WiringPi UserManual 2 | ------------------------------------------------------------------ 3 | 4 | ### Contents 5 | 6 | * OrangePi 2G-IOT 7 | 8 | * OrangePi PC2 9 | 10 | 11 | ------------------------------------------------------------------- 12 | 13 | #### OrangePi 2G-IOT 14 | 15 | OrangePi 2G-IOT contains GPIOA, GPIOB, GPIOC and GPIOD. Each of group has 32 gpio, 16 | The type of GPIO is "Input", "Output" and "specify function" such as "I2C", "I2S" and 17 | so on. 18 | 19 | On board, OrangePi 2G-IOT exports 40 pins as different function. User can uitlize these 20 | GPIO on different application scenarios. For example, User can configure the type of GPIO 21 | as "Input", and get current voltage from program. Another hand, User can configure GPIO 22 | as specify function, such as "Uart", "I2C" and "SPI". 23 | 24 | Note! On OrangePi 2G-IOT, GPIOA, GPIOB and GPIOD tract as general GPIO, but GPIOC as non-general 25 | GPIO. Because of some hardware design, The host of GPIOC is modem not CPU. So, If CPU wanna control 26 | GPIOC, it must send message to Modem, and Moden get message and control GPIOC, it's not good news. 27 | So. on version 0.1, GPIOC only support "OUTPUT" mode. but we will do more try to let GPIOC work well. 28 | The size of GPIOx group is 32, so we can get gpio map: 29 | ``` 30 | GPIOA: 0 - 31 31 | GPIOB: 32 - 63 32 | GPIOC: 64 - 95 33 | GPIOD: 96 - 127 34 | ``` 35 | Each gpio have a unique ID, and the way of caculate as follow: 36 | ``` 37 | GPIO_A_x: ID = 0 + x 38 | GPIO_B_x: ID = 32 + x 39 | GPIO_C_x: ID = 64 + x 40 | GPIO_D_x: ID = 96 + x 41 | ``` 42 | Final, this section will introduce how to configure GPIO on OrangePi 2G-IOt. 43 | 44 | * Input Mode 45 | As General GPIO, we only offer the number of GPIOx. then, use library of wiringPi, User can 46 | easily to control GPIO. Note! GPIOC not support "Input" mode. 47 | 48 | the demo code as follow: 49 | ``` 50 | #include 51 | 52 | /* Defind unique ID */ 53 | #define PA1 1 54 | #define PB5 37 55 | #define PD2 98 56 | 57 | int main(void) 58 | { 59 | unsigned int vol; 60 | 61 | /* Setup wiringPi */ 62 | wiringPiSetup(); 63 | 64 | /* Set Input Mode */ 65 | pinMode(PA1, INPUT); 66 | pinMode(PB5, INPUT); 67 | pinMode(PD2, INPUT); 68 | 69 | /* Get value from GPIO */ 70 | vol = digitalRead(PA1); 71 | vol = digitalRead(PB5); 72 | vol = digitalRead(PD2); 73 | 74 | return 0; 75 | } 76 | ``` 77 | 78 | * Output Mode 79 | 80 | All GPIO support "OUTPUT" mode. The demo code as follow: 81 | ``` 82 | #include 83 | 84 | /* Defind unique ID */ 85 | #define PA1 1 86 | #define PB5 37 87 | #define PC27 91 88 | #defien PD2 98 89 | 90 | int main(void) 91 | { 92 | /* Setup wiringPi */ 93 | wiringPiSetup(); 94 | 95 | /* Set GPIO Mode */ 96 | pinMode(PA1, OUTPUT); 97 | pinMode(PB5, OUTPUT); 98 | pinMode(PC27, OUTPUT); 99 | pinMode(PD2, OUTPUT); 100 | 101 | digitalWrite(PA1, HIGH); 102 | digitalWrite(PB5, LOW); 103 | digitalWrite(PC27, HIGH); 104 | digitalWrite(PD2, LOW); 105 | 106 | return 0; 107 | } 108 | ``` 109 | 110 | -------------------------------------------------------------------------- 111 | 112 | #### OrangePi PC2 113 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | 30 | #define LED 25 31 | 32 | int main (void) 33 | { 34 | printf ("OrangePi Pi ddblink\n"); 35 | 36 | /* Initialize and setting WiringPi */ 37 | wiringPiSetup(); 38 | 39 | /* Configure GPIO mode */ 40 | pinMode (LED, OUTPUT); 41 | 42 | for (;;) { 43 | digitalWrite(LED, HIGH); // On 44 | delay(500); // mS 45 | digitalWrite(PB24, LOW); // Off 46 | delay(500); 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /examples/echo.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 | #include 29 | 30 | #define TRIG 15 31 | #define ECHO 16 32 | 33 | float disT(void) 34 | { 35 | struct timeval tv1; 36 | struct timeval tv2; 37 | 38 | long start, stop; 39 | float dis; 40 | 41 | digitalWrite(TRIG, LOW); 42 | delayMicroseconds(2); 43 | 44 | digitalWrite(TRIG, HIGH); 45 | delayMicroseconds(10); 46 | digitalWrite(TRIG, LOW); 47 | 48 | while(!(digitalRead(ECHO) == 1)) { 49 | gettimeofday(&tv1, NULL); 50 | } 51 | 52 | while(!(digitalRead(ECHO) == 0)) { 53 | if(tv2.tv_sec - tv1.tv_sec > 10) break; 54 | gettimeofday(&tv2, NULL); 55 | } 56 | 57 | 58 | start = tv1.tv_sec * 1000000 + tv1.tv_usec; 59 | stop = tv2.tv_sec * 1000000 + tv2.tv_usec; 60 | 61 | dis = (float) (stop - start) / 1000000 * 34000 / 2; 62 | 63 | return dis; 64 | } 65 | 66 | int main (void) 67 | { 68 | float dis; 69 | 70 | wiringPiSetup () ; 71 | 72 | pinMode(TRIG, OUTPUT); 73 | pinMode(ECHO, INPUT); 74 | 75 | while(1) 76 | { 77 | dis = disT(); 78 | printf("dis: %f \n", dis); 79 | delay(1200); 80 | } 81 | 82 | return 0 ; 83 | } 84 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/ttyS2", 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /examples/te.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 leds[] = {16, 15,13, 9}; 34 | 35 | //16 15 13 9 36 | int main (void) 37 | { 38 | 39 | int i; 40 | printf ("Raspberry Pi blink\n") ; 41 | 42 | wiringPiSetup () ; 43 | pinMode (16, OUTPUT) ; 44 | pinMode (15, OUTPUT) ; 45 | pinMode (13, OUTPUT) ; 46 | pinMode (9, OUTPUT) ; 47 | 48 | for (;;) 49 | { 50 | for(i=0; i<4; i++) { 51 | digitalWrite (leds[i], HIGH) ; // On 52 | delay (20) ; // mS 53 | digitalWrite (leds[i], LOW) ; // Off 54 | delay (20) ; 55 | } 56 | delay(800); 57 | } 58 | return 0 ; 59 | } 60 | -------------------------------------------------------------------------------- /examples/tser.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 | -------------------------------------------------------------------------------- /examples/xserv.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 (int argc, char *argv[]) 34 | { 35 | if (wiringPiSetup () == -1) 36 | { 37 | fprintf (stdout, "oops: %s\n", strerror (errno)) ; 38 | return 1 ; 39 | } 40 | 41 | int du = atoi(argv[2]) ; 42 | int de = atoi(argv[1]) ; 43 | 44 | du = (du == 0) ? 1000 : du; 45 | de = (de == 0) ? 1000 : de; 46 | 47 | softServoSetup (0, 1, 2, 3, 4, 5, 6, 16) ; 48 | 49 | softServoWrite (0, 0) ; 50 | /* 51 | softServoWrite (1, 1000) ; 52 | softServoWrite (2, 1100) ; 53 | softServoWrite (3, 1200) ; 54 | softServoWrite (4, 1300) ; 55 | softServoWrite (5, 1400) ; 56 | softServoWrite (6, 1500) ; 57 | softServoWrite (7, 2200) ; 58 | */ 59 | 60 | //softServoWrite (16, du) ; 61 | // delay (1500) ; 62 | for (;;) { 63 | softServoWrite (16, de) ; 64 | delay (du) ; 65 | softServoWrite (16, 0) ; 66 | delay (du) ; 67 | printf("%d \n", de); 68 | softServoWrite (16, 0-de) ; 69 | delay (du) ; 70 | softServoWrite (16, 0) ; 71 | delay (du) ; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /gpio/OrangePi.h: -------------------------------------------------------------------------------- 1 | #ifndef _ORANGEPI_H_ 2 | #define _ORANGEPI_H_ 3 | 4 | extern char *physNames[64]; 5 | extern int physToWpi[64]; 6 | 7 | extern void OrangePiReadAll(void); 8 | extern void readallPhys(int physPin); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /gpio/extensions.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-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 | extern int doExtension (char *progName, char *extensionData) ; 27 | -------------------------------------------------------------------------------- /gpio/pins.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pins.c: 3 | * Just display a handy Pi pinnout diagram. 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 | 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | .PHONEY: clean 17 | clean: 18 | @rm -f *.dvi *.aux *.log *.ps *.toc *.bak *~ 19 | -------------------------------------------------------------------------------- /pins/pins.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OrangePiLibra/WiringPi/f42b63eb419862e9c6ce6a7ab43299891628bd1d/pins/pins.pdf -------------------------------------------------------------------------------- /wiringPi/RaspberryPi.h: -------------------------------------------------------------------------------- 1 | #ifndef _RASPBERRYPI_H 2 | #define _RASPBERRYPI_H 3 | 4 | #define BCM2708_PERI_BASE 0x20000000 5 | #define GPIO_PADS (BCM2708_PERI_BASE + 0x00100000) 6 | #define CLOCK_BASE (BCM2708_PERI_BASE + 0x00101000) 7 | #define GPIO_TIMER (BCM2708_PERI_BASE + 0x0000B000) 8 | #define GPIO_PWM (BCM2708_PERI_BASE + 0x0020C000) 9 | 10 | extern int pinToGpioR1[64]; 11 | extern int pinToGpioR2[64]; 12 | extern int physToGpioR1[64]; 13 | extern int physToGpioR2[64]; 14 | extern int pinToGpioR3[64]; 15 | extern int physToGpioR3[64]; 16 | extern int physToPinR3[64]; 17 | #endif 18 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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 | if (read (node->fd, buffer, 4) < 0) 63 | return -1; 64 | value = ((buffer [0] & 3) << 16) | (buffer [1] << 8) | buffer [0] ; 65 | break ; 66 | 67 | case MCP3422_SR_15: // 16 bits 68 | delay ( 70) ; 69 | if (read (node->fd, buffer, 3) < 0) 70 | return -1; 71 | value = (buffer [0] << 8) | buffer [1] ; 72 | break ; 73 | 74 | case MCP3422_SR_60: // 14 bits 75 | delay ( 17) ; 76 | if (read (node->fd, buffer, 3) < 0) 77 | return -1 ; 78 | value = ((buffer [0] & 0x3F) << 8) | buffer [1] ; 79 | break ; 80 | 81 | case MCP3422_SR_240: // 12 bits 82 | delay ( 5) ; 83 | if (read (node->fd, buffer, 3) < 0) 84 | return -1; 85 | value = ((buffer [0] & 0x0F) << 8) | buffer [0] ; 86 | break ; 87 | } 88 | 89 | return value ; 90 | } 91 | 92 | 93 | /* 94 | * mcp3422Setup: 95 | * Create a new wiringPi device node for the mcp3422 96 | ********************************************************************************* 97 | */ 98 | 99 | int mcp3422Setup (int pinBase, int i2cAddress, int sampleRate, int gain) 100 | { 101 | int fd ; 102 | struct wiringPiNodeStruct *node ; 103 | 104 | if ((fd = wiringPiI2CSetup (i2cAddress)) < 0) 105 | return fd ; 106 | 107 | node = wiringPiNewNode (pinBase, 4) ; 108 | 109 | node->data0 = sampleRate ; 110 | node->data1 = gain ; 111 | node->analogRead = myAnalogRead ; 112 | 113 | return 0 ; 114 | } 115 | -------------------------------------------------------------------------------- /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/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/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/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/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 | if (write (node->fd, b, 2) <0) 45 | return; 46 | } 47 | 48 | 49 | /* 50 | * myAnalogRead: 51 | ********************************************************************************* 52 | */ 53 | 54 | static int myAnalogRead (struct wiringPiNodeStruct *node, int pin) 55 | { 56 | int x ; 57 | 58 | wiringPiI2CWrite (node->fd, 0x40 | ((pin - node->pinBase) & 3)) ; 59 | 60 | x = wiringPiI2CRead (node->fd) ; // Throw away the first read 61 | x = wiringPiI2CRead (node->fd) ; 62 | 63 | return x ; 64 | } 65 | 66 | 67 | /* 68 | * pcf8591Setup: 69 | * Create a new instance of a PCF8591 I2C GPIO interface. We know it 70 | * has 4 pins, (4 analog inputs and 1 analog output which we'll shadow 71 | * input 0) so all we need to know here is the I2C address and the 72 | * user-defined pin base. 73 | ********************************************************************************* 74 | */ 75 | 76 | int pcf8591Setup (const int pinBase, const int i2cAddress) 77 | { 78 | int fd ; 79 | struct wiringPiNodeStruct *node ; 80 | 81 | if ((fd = wiringPiI2CSetup (i2cAddress)) < 0) 82 | return fd ; 83 | 84 | node = wiringPiNewNode (pinBase, 4) ; 85 | 86 | node->fd = fd ; 87 | node->analogRead = myAnalogRead ; 88 | node->analogWrite = myAnalogWrite ; 89 | 90 | return 0 ; 91 | } 92 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/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/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/wiringPiSPI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wiringPiSPI.h: 3 | * Simplified SPI access routines 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 | int wiringPiSPIGetFd (int channel) ; 30 | int wiringPiSPIDataRW (int channel, unsigned char *data, int len) ; 31 | int wiringPiSPISetup (int channel, int speed) ; 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | -------------------------------------------------------------------------------- /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/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/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 | --------------------------------------------------------------------------------