first commit

This commit is contained in:
gaohz 2024-06-06 04:13:43 +00:00
commit b8768c3ff8
249 changed files with 38439 additions and 0 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
.vscode
build/
*.egg-info/
dist/
__pycache__
*.pyc
wiringpi_wrap.c
wiringpi.py
bindings.i

4
.gitmodules vendored Normal file
View File

@ -0,0 +1,4 @@
[submodule "wiringOP"]
path = wiringOP
url = https://github.com/orangepi-xunlong/wiringOP
branch = next

14
CHANGES.txt Normal file
View File

@ -0,0 +1,14 @@
v1.0.0 -- Branched from original WiringPi to deliver new WiringPi 2 functionality
v1.0.1 -- Fixed build problems involving missing header files
v1.0.2 -- Fixed build issue with piNes.c
v1.0.3 -- Fixed bug in physical pin assignment mode
v1.0.4 -- Added class wrapper, plus analogRead/Write functions
v1.0.5 -- Second attempt at pretty Pypi page
v1.0.6 -- Fixed spelling error in softToneCreate - Thanks oevsegneev
v1.0.7 -- Added LCD functionality
v1.0.8 -- Updated manifest to include .rst and fix build error
v1.0.9 -- Erroneous non-fix due to stupidity
v1.0.10 -- Added I2CSetup and new I2C class
v1.1.0 -- Synced to WiringPi as of 8th March 2015
v1.1.1 -- Included devLib folder for headers
v1.2.1 -- Synced to WIringPi as of 27th February 2016

165
LICENSE.txt Normal file
View File

@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

7
MANIFEST.in Normal file
View File

@ -0,0 +1,7 @@
graft wiringOP/wiringPi
graft wiringOP/devLib
include README.rst
include LICENSE.txt
include setup.cfg
include wiringpi.py
include wiringpi_wrap.c

15
Makefile Normal file
View File

@ -0,0 +1,15 @@
all: bindings
python3 setup.py build
bindings:
python3 generate-bindings.py > bindings.i
clean:
rm -rf build dist wiringpi.egg-info
rm -rf wiringpi.py wiringpi_wrap.c
install: bindings
sudo python3 setup.py install
test:
pytest tests

64
README.rst Normal file
View File

@ -0,0 +1,64 @@
Note
~~~~
wiringOP for Python
===================
wiringOP: An implementation of most of the Arduino Wiring functions for
the Orange Pi.
Supported boards
===================
tested on:
``Orange Pi Zero2``
``Orange Pi 3 LTS``
``Orange Pi 4 LTS``
Manual Build
============
Get/setup repo
--------------
.. code:: bash
git clone --recursive https://github.com/orangepi-xunlong/wiringOP-Python.git
cd wiringOP-Python
Don't forget the --recursive; it is required to also pull in the WiringPi C code from its own repository.
Prerequisites
-------------
To rebuild the bindings you **must** first have installed ``swig``,
``python3-dev``, and ``python3-setuptools``. wiringOP should also be installed system-wide for access
to the ``gpio`` tool.
.. code:: bash
sudo apt-get install swig python3-dev python3-setuptools
Build & install with
--------------------
``python3 generate-bindings.py > bindings.i``
``sudo python3 setup.py install``
Usage
=====
.. code:: python
import wiringpi
# One of the following MUST be called before using IO functions:
wiringpi.wiringPiSetup() # For sequential pin numbering
**General IO:**
.. code:: python
wiringpi.pinMode(6, 1) # Set pin 6 to 1 ( OUTPUT )
wiringpi.digitalWrite(6, 1) # Write 1 ( HIGH ) to pin 6
wiringpi.digitalRead(6) # Read pin 6

47
constants.py Normal file
View File

@ -0,0 +1,47 @@
%pythoncode %{
# wiringPi modes
WPI_MODE_PINS = 0;
WPI_MODE_GPIO = 1;
WPI_MODE_GPIO_SYS = 2;
WPI_MODE_PHYS = 3;
WPI_MODE_PIFACE = 4;
WPI_MODE_UNINITIALISED = -1;
# Pin modes
INPUT = 0;
OUTPUT = 1;
PWM_OUTPUT = 2;
GPIO_CLOCK = 3;
SOFT_PWM_OUTPUT = 4;
SOFT_TONE_OUTPUT = 5;
PWM_TONE_OUTPUT = 6;
LOW = 0;
HIGH = 1;
# Pull up/down/none
PUD_OFF = 0;
PUD_DOWN = 1;
PUD_UP = 2;
# PWM
PWM_MODE_MS = 0;
PWM_MODE_BAL = 1;
# Interrupt levels
INT_EDGE_SETUP = 0;
INT_EDGE_FALLING = 1;
INT_EDGE_RISING = 2;
INT_EDGE_BOTH = 3;
# Shifting (from wiringShift.h)
LSBFIRST = 0;
MSBFIRST = 1;
%}

View File

22
examples/blink.py Normal file
View File

@ -0,0 +1,22 @@
import wiringpi
import time
import sys
from wiringpi import GPIO
wiringpi.wiringPiSetup()
NUM = wiringpi.getGpioNum()
for i in range(0, NUM):
wiringpi.pinMode(i, GPIO.OUTPUT) ;
while True:
try:
for i in range(0, NUM):
wiringpi.digitalWrite(i, GPIO.HIGH)
time.sleep(1)
for i in range(0, NUM):
wiringpi.digitalWrite(i, GPIO.LOW)
time.sleep(1)
except KeyboardInterrupt:
print("\nexit")
sys.exit(0)

14
examples/callback.py Normal file
View File

@ -0,0 +1,14 @@
import wiringpi
PIN_TO_SENSE = 23
def gpio_callback():
print "GPIO_CALLBACK!"
wiringpi.wiringPiSetupGpio()
wiringpi.pinMode(PIN_TO_SENSE, wiringpi.GPIO.INPUT)
wiringpi.pullUpDnControl(PIN_TO_SENSE, wiringpi.GPIO.PUD_UP)
wiringpi.wiringPiISR(PIN_TO_SENSE, wiringpi.GPIO.INT_EDGE_BOTH, gpio_callback)
while True:
wiringpi.delay(2000)

5
examples/delay.py Normal file
View File

@ -0,0 +1,5 @@
# Demonstrates use of Arduino-like delay function
import wiringpi
print 'Hello World'
wiringpi.delay(1500) # Delay for 1.5 seconds
print 'Hi again!'

133
examples/ds1307.py Normal file
View File

@ -0,0 +1,133 @@
import sys
import time
import wiringpi
from datetime import datetime
import operator
import argparse
parser = argparse.ArgumentParser(description='i2c')
parser.add_argument("--device", type=str, default="/dev/i2c-0", help='specify the i2c node')
args = parser.parse_args()
i2caddr = 0x68
def b2s(bcd, mask):
bcd &= mask
b1 = bcd & 0x0F
b2 = ((bcd >> 4) & 0x0F)*10
return b1 + b2
def decCompensation(units):
unitsU = units%10
if units >= 50:
units = 0x50 + unitsU
elif units >= 40:
units = 0x40 + unitsU
elif units >= 30:
units = 0x30 + unitsU
elif units >= 20:
units = 0x20 + unitsU
elif units >= 10:
units = 0x10 + unitsU
return units
def getHours():
HH = time.strftime("%H")
return decCompensation(int(HH))
def getMins():
MM = time.strftime("%M")
return decCompensation(int(MM))
def getSecs():
SS = time.strftime("%S")
return decCompensation(int(SS))
def getWeeks():
WW = time.strftime("%w")
return decCompensation(int(WW))
def getDays():
DD = time.strftime("%d")
return decCompensation(int(DD))
def getMons():
MON = time.strftime("%m")
return decCompensation(int(MON))
def getYear():
YY = time.strftime("%Y")
return decCompensation(int(YY))
def ds1307_write_byte(fd, reg, byte):
if wiringpi.wiringPiI2CWriteReg8(fd, reg, byte) < 0:
print("Error write byte to ds1307")
return -1
return 0
def ds1307_read_byte(fd, reg):
byte = wiringpi.wiringPiI2CReadReg8(fd, reg)
if byte < 0:
print("Error read byte from ds1307")
return -1
return byte
def sys2rtcSet(fd):
ds1307_write_byte(fd, 0x02, getHours())
ds1307_write_byte(fd, 0x01, getMins())
ds1307_write_byte(fd, 0x00, getSecs())
ds1307_write_byte(fd, 0x03, getWeeks())
ds1307_write_byte(fd, 0x04, getDays())
ds1307_write_byte(fd, 0x05, getMons())
ds1307_write_byte(fd, 0x06, getYear())
def read_register(fd):
byte = ds1307_read_byte(fd, 0x0)
if byte >> 7:
ds1307_write_byte(fd, 0x0, 0x0)
second = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10
byte = ds1307_read_byte(fd, 0x01)
minute = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10
byte = ds1307_read_byte(fd, 0x02)
hour = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10
week = ds1307_read_byte(fd, 0x03)
byte = ds1307_read_byte(fd, 0x04)
day = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10
byte = ds1307_read_byte(fd, 0x05)
month = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10
byte = ds1307_read_byte(fd, 0x06)
year = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10 + 1970
if year == 2000 or month > 12 or month<1 or day < 1 or day > 31:
return False
if second > 59:
return False
return datetime(year,month,day,hour,minute,second)
def main():
wiringpi.wiringPiSetup()
fd = wiringpi.wiringPiI2CSetupInterface(args.device, i2caddr)
try:
sys2rtcSet(fd)
while True:
time.sleep(1)
dt = read_register(fd)
if not dt:
continue
else:
str_time = dt.strftime("%a %Y-%m-%d %H:%M:%S")
print("%s"%(str_time))
except KeyboardInterrupt:
print("\nexit")
sys.exit(0)
if __name__ == '__main__':
main()

27
examples/ladder-board.py Normal file
View File

@ -0,0 +1,27 @@
import wiringpi
INPUT = 0
OUTPUT = 1
LOW = 0
HIGH = 1
BUTTONS = [13,12,10,11]
LEDS = [0,1,2,3,4,5,6,7,8,9]
PUD_UP = 2
wiringpi.wiringPiSetup()
for button in BUTTONS:
wiringpi.pinMode(button,INPUT)
wiringpi.pullUpDnControl(button,PUD_UP)
for led in LEDS:
wiringpi.pinMode(led,OUTPUT)
while 1:
for index,button in enumerate(BUTTONS):
button_state = wiringpi.digitalRead(button)
first_led = LEDS[index*2]
second_led = LEDS[(index*2)+1]
#print str(button) + ' ' + str(button_state)
wiringpi.digitalWrite(first_led,1-button_state)
wiringpi.digitalWrite(second_led,1-button_state)
wiringpi.delay(20)

View File

@ -0,0 +1,95 @@
# Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander )
import wiringpi
PIN_BACKLIGHT = 67 # LED
PIN_SCLK = 68 # Clock SCLK
PIN_SDIN = 69 # DN(MOSI)
PIN_DC = 70 # D/C
PIN_RESET = 71 # RST Reset
PIN_SCE = 72 # SCE
#PIN_BACKLIGHT = 5
#PIN_SCLK = 4
#PIN_SDIN = 3
#PIN_DC = 2
#PIN_RESET = 1
#PIN_SCE = 0
OUTPUT = 1
INPUT = 0
HIGH = 1
LOW = 0
LCD_C = 0
LCD_D = 1
LCD_X = 84
LCD_Y = 48
LCD_SEGS = 504
MSBFIRST = 1
LSBFIRST = 0
SLOW_DOWN = 400
pin_base = 65
i2c_addr = 0x21
wiringpi.wiringPiSetup()
wiringpi.mcp23017Setup(pin_base,i2c_addr)
def slow_shift_out(data_pin, clock_pin, data):
for bit in bin(data).replace('0b','').rjust(8,'0'):
wiringpi.digitalWrite(clock_pin,LOW)
wiringpi.delay(SLOW_DOWN)
wiringpi.digitalWrite(data_pin,int(bit))
wiringpi.delay(SLOW_DOWN)
wiringpi.digitalWrite(clock_pin,HIGH)
wiringpi.delay(SLOW_DOWN)
def lcd_write(dc, data):
wiringpi.digitalWrite(PIN_DC, dc)
wiringpi.digitalWrite(PIN_SCE, LOW)
wiringpi.delay(SLOW_DOWN)
#wiringpi.shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data)
slow_shift_out(PIN_SDIN, PIN_SCLK, data)
wiringpi.digitalWrite(PIN_SCE, HIGH)
wiringpi.delay(SLOW_DOWN)
#wiringpi.delay(2)
def lcd_initialise():
wiringpi.pinMode(PIN_BACKLIGHT,OUTPUT)
wiringpi.digitalWrite(PIN_BACKLIGHT, HIGH)
wiringpi.pinMode(PIN_SCE, OUTPUT)
wiringpi.pinMode(PIN_RESET, OUTPUT)
wiringpi.pinMode(PIN_DC, OUTPUT)
wiringpi.pinMode(PIN_SDIN, OUTPUT)
wiringpi.pinMode(PIN_SCLK, OUTPUT)
wiringpi.digitalWrite(PIN_RESET, LOW)
wiringpi.delay(SLOW_DOWN)
wiringpi.digitalWrite(PIN_RESET, HIGH)
wiringpi.delay(SLOW_DOWN)
lcd_write(LCD_C, 0x21 ) # LCD Extended Commands.
lcd_write(LCD_C, 0xCC ) # Set LCD Vop (Contrast).
lcd_write(LCD_C, 0x04 ) # Set Temp coefficent. //0x04
lcd_write(LCD_C, 0x14 ) # LCD bias mode 1:48. //0x13
lcd_write(LCD_C, 0x0C ) # LCD in normal mode.
lcd_write(LCD_C, 0x20 )
lcd_write(LCD_C, 0x0C )
def lcd_clear():
for time in range(0, LCD_SEGS):
lcd_write(LCD_D, 0x00)
def lcd_fill():
for time in range(0, LCD_SEGS):
lcd_write(LCD_D, 0xFF)
lcd_initialise()
for time in range(0,4):
lcd_clear()
wiringpi.delay(1000)
lcd_fill()
wiringpi.delay(1000)

View File

@ -0,0 +1,28 @@
import sys
import time
import wiringpi
from wiringpi import GPIO
I2C_ADDR = 0x38
BASE = 100
wiringpi.wiringPiSetup()
wiringpi.pcf8574Setup(BASE, I2C_ADDR)
i = 0
while i < 8:
wiringpi.pinMode(BASE + i, GPIO.OUTPUT)
i += 1
wiringpi.pinMode(BASE + 0, GPIO.OUTPUT)
while True:
try:
wiringpi.digitalWrite(BASE + 0, GPIO.HIGH)
time.sleep(1)
wiringpi.digitalWrite(BASE + 0, GPIO.LOW)
time.sleep(1)
except KeyboardInterrupt:
print('\nExit')
sys.exit(0)

View File

@ -0,0 +1,19 @@
import sys
import time
import wiringpi
from wiringpi import GPIO
I2C_ADDR = 0x48
BASE = 64
A0 = BASE+0
wiringpi.wiringPiSetup()
wiringpi.pcf8591Setup(BASE, I2C_ADDR)
while True:
try:
value = wiringpi.analogRead(A0)
print("value: %d"%value)
time.sleep(2)
except KeyboardInterrupt:
print('\nExit')
sys.exit(0)

View File

@ -0,0 +1,67 @@
import wiringpi
from wiringpi import GPIO
pin = 6
def getval(pin):
tl=[]
tb=[]
wiringpi.wiringPiSetup()
wiringpi.pinMode(pin, GPIO.OUTPUT)
wiringpi.digitalWrite(pin, GPIO.HIGH)
wiringpi.delay(1)
wiringpi.digitalWrite(pin, GPIO.LOW)
wiringpi.delay(25)
wiringpi.digitalWrite(pin, GPIO.HIGH)
wiringpi.delayMicroseconds(20)
wiringpi.pinMode(pin, GPIO.INPUT)
while(wiringpi.digitalRead(pin)==1): pass
for i in range(45):
tc=wiringpi.micros()
'''
'''
while(wiringpi.digitalRead(pin)==0): pass
while(wiringpi.digitalRead(pin)==1):
if wiringpi.micros()-tc>500:
break
if wiringpi.micros()-tc>500:
break
tl.append(wiringpi.micros()-tc)
tl=tl[1:]
for i in tl:
if i>100:
tb.append(1)
else:
tb.append(0)
return tb
def GetResult(pin):
for i in range(10):
SH=0;SL=0;TH=0;TL=0;C=0
result=getval(pin)
if len(result)==40:
for i in range(8):
SH*=2;SH+=result[i] # humi Integer
SL*=2;SL+=result[i+8] # humi decimal
TH*=2;TH+=result[i+16] # temp Integer
TL*=2;TL+=result[i+24] # temp decimal
C*=2;C+=result[i+32] # Checksum
if ((SH+SL+TH+TL)%256)==C and C!=0:
break
else:
print("Read Sucess,But checksum error! retrying")
else:
print("Read failer! Retrying")
break
wiringpi.delay(200)
return SH,SL,TH,TL
SH,SL,TH,TL=GetResult(pin)
print("humi:",SH,SL,"temp:",TH,TL)

View File

@ -0,0 +1,88 @@
#import sys
import wiringpi
from wiringpi import GPIO
PIN = 6
def oneWireReset(pin):
wiringpi.pinMode(pin, GPIO.OUTPUT)
wiringpi.digitalWrite(pin, GPIO.HIGH)
wiringpi.digitalWrite(pin, GPIO.LOW)
wiringpi.delayMicroseconds(500)
wiringpi.digitalWrite(pin, GPIO.HIGH)
wiringpi.delayMicroseconds(60)
wiringpi.pinMode(pin, GPIO.INPUT)
if not wiringpi.digitalRead(pin):
ack = 1
else:
ack = 0
wiringpi.delayMicroseconds(500)
return ack
def writeBit(pin, bit):
wiringpi.pinMode(pin, GPIO.OUTPUT)
wiringpi.digitalWrite(pin, GPIO.LOW)
wiringpi.delayMicroseconds(2)
wiringpi.digitalWrite(pin, bit)
wiringpi.delayMicroseconds(80)
wiringpi.digitalWrite(pin, GPIO.HIGH)
wiringpi.delayMicroseconds(1)
def oneWireSendComm(pin, byte):
i = 0
while i < 8:
sta = byte & 0x01
writeBit(pin, sta)
byte >>= 1
i += 1
def readBit(pin):
wiringpi.pinMode(pin, GPIO.OUTPUT)
wiringpi.digitalWrite(pin, GPIO.HIGH)
wiringpi.digitalWrite(pin, GPIO.LOW)
wiringpi.delayMicroseconds(2)
wiringpi.digitalWrite(pin, GPIO.HIGH)
wiringpi.pinMode(pin, GPIO.INPUT)
wiringpi.delayMicroseconds(2)
tmp = wiringpi.digitalRead(pin)
wiringpi.delayMicroseconds(40)
return tmp
def oneWireReceive(pin):
i = 0
k = 0
while i < 8:
j = readBit(pin)
k = (j << 7) | (k >> 1)
i += 1
k = k & 0x00FF
return k
def tempchange(lsb, msb):
if (msb >= 0xF0):
msb = 255 - msb
lsb = 256 - lsb
tem = -(msb*16*16 + lsb)
else:
tem = (msb*16*16 + lsb)
temp = tem*0.0625
print("Current Temp: %.2f"%(temp))
def main():
wiringpi.wiringPiSetup()
if oneWireReset(PIN):
oneWireSendComm(PIN, 0xcc)
oneWireSendComm(PIN, 0x44)
if oneWireReset(PIN):
oneWireSendComm(PIN, 0xcc)
oneWireSendComm(PIN, 0xbe)
lsb = oneWireReceive(PIN)
msb = oneWireReceive(PIN)
tempchange(lsb, msb)
if __name__ == '__main__':
main()

View File

@ -0,0 +1,27 @@
import sys
import time
import wiringpi
from wiringpi import GPIO
I2C_ADDR = 0x48
BASE = 64
A0 = BASE+0
A1 = BASE+1
wiringpi.wiringPiSetup()
wiringpi.pcf8591Setup(BASE, I2C_ADDR)
while True:
try:
i = 0
while i < 2:
if 0 == i:
x = wiringpi.analogRead(A0)
if 1 == i:
y = wiringpi.analogRead(A1)
i += 1
print("X=%d Y=%d"%(x,y))
time.sleep(1)
except KeyboardInterrupt:
print('\nExit')
sys.exit(0)

View File

@ -0,0 +1,22 @@
import sys
import time
import wiringpi
from wiringpi import GPIO
PIN = 6
wiringpi.wiringPiSetup()
wiringpi.pinMode(PIN, GPIO.OUTPUT)
while True:
try:
wiringpi.digitalWrite(PIN, GPIO.HIGH)
print(wiringpi.digitalRead(PIN))
time.sleep(1)
wiringpi.digitalWrite(PIN, GPIO.LOW)
print(wiringpi.digitalRead(PIN))
time.sleep(1)
except KeyboardInterrupt:
print("\nexit")
sys.exit(0)

View File

@ -0,0 +1,320 @@
import sys
import time
import wiringpi
from wiringpi import GPIO
I2C_ADDR = 0x3c
fd = 0
yi = [' ',' ',' ',' ']
zi = [
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//0
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//1
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//2
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//3
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//4
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//5
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//6
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//7
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//8
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//9
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//10
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//11
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//12
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//13
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//14
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//15
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//16
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//17
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//18
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//19
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//20
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//21
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//22
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//23
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//24
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//25
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//26
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//27
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//28
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//29
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//30
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//31
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//32
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x00,0x00,0x00,0x00,#//33
0x00,0x10,0x0C,0x02,0x10,0x0C,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//34
0x00,0x40,0xC0,0x78,0x40,0xC0,0x78,0x00,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x00,#//35
0x00,0x70,0x88,0x88,0xFC,0x08,0x30,0x00,0x00,0x18,0x20,0x20,0xFF,0x21,0x1E,0x00,#//36
0xF0,0x08,0xF0,0x80,0x60,0x18,0x00,0x00,0x00,0x31,0x0C,0x03,0x1E,0x21,0x1E,0x00,#//37
0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x2C,0x19,0x27,0x21,0x10,#//38
0x00,0x12,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//39
0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,#//40
0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,#//41
0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,#//42
0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x0F,0x01,0x01,0x01,#//43
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x90,0x70,0x00,0x00,0x00,0x00,0x00,#//44
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00,#//45
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,#//46
0x00,0x00,0x00,0x00,0xC0,0x38,0x04,0x00,0x00,0x60,0x18,0x07,0x00,0x00,0x00,0x00,#//47
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,#//48
0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,#//49
0x00,0x70,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,#//50
0x00,0x30,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x18,0x20,0x21,0x21,0x22,0x1C,0x00,#//51
0x00,0x00,0x80,0x40,0x30,0xF8,0x00,0x00,0x00,0x06,0x05,0x24,0x24,0x3F,0x24,0x24,#//52
0x00,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x20,0x20,0x20,0x11,0x0E,0x00,#//53
0x00,0xE0,0x10,0x88,0x88,0x90,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x20,0x1F,0x00,#//54
0x00,0x18,0x08,0x08,0x88,0x68,0x18,0x00,0x00,0x00,0x00,0x3E,0x01,0x00,0x00,0x00,#//55
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,#//56
0x00,0xF0,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x01,0x12,0x22,0x22,0x11,0x0F,0x00,#//57
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,#//58
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,#//59
0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,#//60
0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x00,#//61
0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,#//62
0x00,0x70,0x48,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x30,0x37,0x00,0x00,0x00,#//63
0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x28,0x2F,0x28,0x17,0x00,#//64
0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,#//65
0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,#//66
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,#//67
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,#//68
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,#//69
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,#//70
0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,#//71
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,#//72
0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#//73
0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,#//74
0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,#//75
0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,#//76
0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x01,0x3E,0x01,0x3F,0x20,0x00,#//77
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,#//78
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,#//79
0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,#//80
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x28,0x28,0x30,0x50,0x4F,0x00,#//81
0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,#//82
0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,#//83
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,#//84
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,#//85
0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,#//86
0x08,0xF8,0x00,0xF8,0x00,0xF8,0x08,0x00,0x00,0x03,0x3E,0x01,0x3E,0x03,0x00,0x00,#//87
0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,#//88
0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,#//89
0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,#//90
0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,#//91
0x00,0x04,0x38,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,#//92
0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,#//93
0x00,0x00,0x04,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//94
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,#//95
0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//96
0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x19,0x24,0x24,0x12,0x3F,0x20,0x00,#//97
0x10,0xF0,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,#//98
0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,#//99
0x00,0x00,0x80,0x80,0x80,0x90,0xF0,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,#//100
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x24,0x24,0x24,0x24,0x17,0x00,#//101
0x00,0x80,0x80,0xE0,0x90,0x90,0x20,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#//102
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,#//103
0x10,0xF0,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,#//104
0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#//105
0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,#//106
0x10,0xF0,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x06,0x29,0x30,0x20,0x00,#//107
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#//108
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,#//109
0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,#//110
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,#//111
0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0x91,0x20,0x20,0x11,0x0E,0x00,#//112
0x00,0x00,0x00,0x80,0x80,0x00,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0x91,0xFF,0x80,#//113
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,#//114
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,#//115
0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x10,0x00,#//116
0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,#//117
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x03,0x0C,0x30,0x0C,0x03,0x00,0x00,#//118
0x80,0x80,0x00,0x80,0x80,0x00,0x80,0x80,0x01,0x0E,0x30,0x0C,0x07,0x38,0x06,0x01,#//119
0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x20,0x31,0x0E,0x2E,0x31,0x20,0x00,#//120
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x81,0x86,0x78,0x18,0x06,0x01,0x00,#//121
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,#//122
0x00,0x00,0x00,0x00,0x00,0xFC,0x02,0x02,0x00,0x00,0x00,0x00,0x01,0x3E,0x40,0x40,#//122
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,#//124
0x02,0x02,0xFC,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x3E,0x01,0x00,0x00,0x00,0x00,#//125
0x00,0x02,0x01,0x02,0x02,0x04,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//126
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//127
]
def full_string(s):
while len(s) < 16:
s += ' '
return s
def main():
#init
wiringpi.wiringPiSetup()
fd = wiringpi.wiringPiI2CSetup(I2C_ADDR)
if not fd:
return False;
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xa1)
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xc8)
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x8d)
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x14)
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xa6)
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x21)
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x00)
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x7f)
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xaf)
#clear oled
for a in range(8):
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xb0 + a)
for b in range(128):
wiringpi.wiringPiI2CWriteReg8(fd, 0x40, 0x00)
while True:
try:
#get time
yi[0] = full_string("++++OrangePi++++")
#yi[1] = full_string(time.strftime("%m/%d %w"))
yi[1] = full_string(time.strftime("%m/%d %a"))
yi[2] = full_string(time.strftime("%H:%M"))
yi[3] = full_string("SSD1306 I2C OLED")
#write
for zt3 in range(4):
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xb0+(zt3*2))
for zt4 in range(16):
for zt in range(8):
wiringpi.wiringPiI2CWriteReg8(fd, 0x40, zi[ord(yi[zt3][zt4])*16+zt])
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xb0+(zt3*2)+1)
for zt4 in range(16):
for zt in range(8):
wiringpi.wiringPiI2CWriteReg8(fd, 0x40, zi[ord(yi[zt3][zt4])*16+zt+8])
time.sleep(1)
except KeyboardInterrupt:
print("\nexit")
sys.exit(0)
if __name__ == '__main__':
main()

View File

@ -0,0 +1,46 @@
import sys
import time
import wiringpi
from wiringpi import GPIO
SIA = 9
SIB= 10
SW = 6
wiringpi.wiringPiSetup()
wiringpi.pinMode(SW, GPIO.INPUT)
wiringpi.pinMode(SIA, GPIO.INPUT)
wiringpi.pinMode(SIB, GPIO.INPUT)
flag = 0
resetflag = 0
globalCount = 0
while True:
try:
lastSib = wiringpi.digitalRead(SIB)
while not wiringpi.digitalRead(SW):
resetflag = 1
while not wiringpi.digitalRead(SIA):
currentSib = wiringpi.digitalRead(SIB)
flag =1
if resetflag:
globalCount = 0
resetflag = 0
print ('Count reset\ncurrent = 0')
continue
if flag:
if lastSib == 0 and currentSib == 1:
print ('Anticlockwise rotation')
globalCount += 1
if lastSib == 1 and currentSib == 0:
print ('clockwise rotation')
globalCount -=1
flag =0
print ('current = %s' % globalCount)
except KeyboardInterrupt:
print('\nExit')
sys.exit(0)

View File

@ -0,0 +1,103 @@
import sys
import time
import wiringpi
#from wiringpi import GPIO
I2C_ADDR = 0x68
def b2s(bcd, mask):
bcd &= mask
b1 = bcd & 0x0F
b2 = ((bcd >> 4) & 0x0F)*10
return b1 + b2
def decCompensation(units):
unitsU = units%10
if units >= 50:
units = 0x50 + unitsU
elif units >= 40:
units = 0x40 + unitsU
elif units >= 30:
units = 0x30 + unitsU
elif units >= 20:
units = 0x20 + unitsU
elif units >= 10:
units = 0x10 + unitsU
return units
def getHours():
HH = time.strftime("%H")
return decCompensation(int(HH))
def getMins():
MM = time.strftime("%M")
return decCompensation(int(MM))
def getSecs():
SS = time.strftime("%S")
return decCompensation(int(SS))
def getWeeks():
WW = time.strftime("%w")
return decCompensation(int(WW))
def getDays():
DD = time.strftime("%d")
return decCompensation(int(DD))
def getMons():
MON = time.strftime("%m")
return decCompensation(int(MON))
def getYear():
YY = time.strftime("%Y")
return decCompensation(int(YY))
def clear_register(fd):
wiringpi.wiringPiI2CWriteReg8(fd, 0x02, 0b0) # hours
wiringpi.wiringPiI2CWriteReg8(fd, 0x01, 0b0) # mins
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0b10000000) # secs
wiringpi.wiringPiI2CWriteReg8(fd, 0x03, 0b0) # weeks
wiringpi.wiringPiI2CWriteReg8(fd, 0x04, 0b0) # days
wiringpi.wiringPiI2CWriteReg8(fd, 0x05, 0b0) # mons
def sys2rtcSet(fd):
wiringpi.wiringPiI2CWriteReg8(fd, 0x02, getHours())
wiringpi.wiringPiI2CWriteReg8(fd, 0x01, getMins())
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, getSecs()+0b10000000)
wiringpi.wiringPiI2CWriteReg8(fd, 0x03, getWeeks())
wiringpi.wiringPiI2CWriteReg8(fd, 0x04, getDays())
wiringpi.wiringPiI2CWriteReg8(fd, 0x05, getMons())
wiringpi.wiringPiI2CWriteReg8(fd, 0x06, getYear())
def read_register(fd):
secs = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x00), 0x7F)
mins = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x01), 0x7F)
hours = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x02) - 0b10000000, 0x3F)
week = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x03), 0x3F)
day = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x04), 0x1F)
mon = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x05), 0x07)
year = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x06), 0xFF) + 1970
print("week:%d mon:%d day:%d hours:%d mins:%d secs:%d year:%d"%(week,mon,day,hours,mins,secs,year))
def main():
wiringpi.wiringPiSetup()
fd = wiringpi.wiringPiI2CSetup(I2C_ADDR)
if not fd:
return False;
while True:
try:
# clear RTC Register
clear_register(fd)
# set sys time to RTC Register
sys2rtcSet(fd)
# read RTC Register
read_register(fd)
time.sleep(1)
except KeyboardInterrupt:
print("\nexit")
sys.exit(0)
if __name__ == '__main__':
main()

View File

@ -0,0 +1,21 @@
import sys
import wiringpi
from wiringpi import GPIO
LED = 6
PIN = 16
wiringpi.wiringPiSetup()
wiringpi.pinMode(LED, GPIO.OUTPUT)
wiringpi.pinMode(PIN, GPIO.INPUT)
while True:
try:
if wiringpi.digitalRead(PIN):
wiringpi.digitalWrite(LED, GPIO.LOW)
else:
wiringpi.digitalWrite(LED, GPIO.HIGH)
except KeyboardInterrupt:
print("\nexit")
sys.exit(0)

15
examples/quick2wire-io.py Normal file
View File

@ -0,0 +1,15 @@
# Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander )
import wiringpi
pin_base = 65
i2c_addr = 0x20
pins = [65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80]
wiringpi.wiringPiSetup()
wiringpi.mcp23017Setup(pin_base,i2c_addr)
for pin in pins:
wiringpi.pinMode(pin,1)
wiringpi.digitalWrite(pin,1)
# wiringpi.delay(1000)
# wiringpi.digitalWrite(pin,0)

29
examples/serialTest.py Normal file
View File

@ -0,0 +1,29 @@
import wiringpi
import sys
import argparse
parser = argparse.ArgumentParser(description='')
parser.add_argument("--device", type=str, default="/dev/ttyS4", help='specify the serial node')
args = parser.parse_args()
wiringpi.wiringPiSetup()
serial = wiringpi.serialOpen(args.device, 115200)
if serial < 0:
print("Unable to open serial device: %s"% args.device)
sys.exit(-1)
for count in range(0, 256):
try:
print("\nOut: %3d:" % count, end="")
wiringpi.serialFlush(serial)
wiringpi.serialPutchar(serial, count)
wiringpi.delayMicroseconds(300000)
while wiringpi.serialDataAvail(serial):
print(" -> %3d" % wiringpi.serialGetchar(serial), end="")
wiringpi.serialFlush(serial)
except KeyboardInterrupt:
print("\nexit")
sys.exit(0)
wiringpi.serialClose(serial) # Pass in ID

19
examples/softpwm.py Normal file
View File

@ -0,0 +1,19 @@
# Pulsates an LED connected to GPIO pin 1 with a suitable resistor 4 times using softPwm
# softPwm uses a fixed frequency
import wiringpi
OUTPUT = 1
PIN_TO_PWM = 1
wiringpi.wiringPiSetup()
wiringpi.pinMode(PIN_TO_PWM,OUTPUT)
wiringpi.softPwmCreate(PIN_TO_PWM,0,100) # Setup PWM using Pin, Initial Value and Range parameters
for time in range(0,4):
for brightness in range(0,100): # Going from 0 to 100 will give us full off to full on
wiringpi.softPwmWrite(PIN_TO_PWM,brightness) # Change PWM duty cycle
wiringpi.delay(10) # Delay for 0.2 seconds
for brightness in reversed(range(0,100)):
wiringpi.softPwmWrite(PIN_TO_PWM,brightness)
wiringpi.delay(10)

16
examples/softtone.py Normal file
View File

@ -0,0 +1,16 @@
# Test of the softTone module in wiringPi
# Plays a scale out on pin 3 - connect pizeo disc to pin 3 & 0v
import wiringpi
PIN = 3
SCALE = [262, 294, 330, 349, 392, 440, 494, 525]
wiringpi.wiringPiSetup()
wiringpi.softToneCreate(PIN)
while True:
for idx in range(8):
print(idx)
wiringpi.softToneWrite(PIN, SCALE[idx])
wiringpi.delay(500)

39
examples/spidev_test.py Normal file
View File

@ -0,0 +1,39 @@
import wiringpi
import argparse
parser = argparse.ArgumentParser(description='')
parser.add_argument("--channel", type=int, default=1, help='specify the spi channel')
parser.add_argument("--port", type=int, default=0, help='specify the spi port')
parser.add_argument("--speed", type=int, default=500000, help='specify the spi speed')
parser.add_argument("--mode", type=int, default=0, help='specify the spi mode')
args = parser.parse_args()
default_tx = [
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x40, 0x00, 0x00, 0x00, 0x00, 0x95,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xF0, 0x0D,
]
def hexdump(src, line_size, prefix):
result = []
digits = 4 if isinstance(src, str) else 2
for i in range(0, len(src), line_size):
s = src[i:i + line_size]
hexa = ' '.join([hex(x)[2:].upper().zfill(digits) for x in s])
text = ''.join([chr(x) if 0x20 <= x < 0x7F else '.' for x in s])
result.append(prefix + ' | ' + hexa.ljust(line_size * (digits + 1)) + ' |' + "{0}".format(text) + '|')
return '\n'.join(result)
print("spi mode: 0x%x" % args.mode);
print("max speed: %d Hz (%d KHz)\n" %(args.speed, args.speed / 1000), end='');
wiringpi.wiringPiSPISetupMode(args.channel, args.port, args.speed, args.mode)
revlen, recvData = wiringpi.wiringPiSPIDataRW(args.channel, bytes(default_tx))
print(hexdump(bytes(default_tx), 32, "TX"))
print(hexdump(bytes(recvData), 32, "RX"))

18
examples/two-mcp23017.py Normal file
View File

@ -0,0 +1,18 @@
# Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander )
import wiringpi
pin_base = 65
i2c_addr = 0x20
i2c_addr_2 = 0x21
#pins = [65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80]
wiringpi.wiringPiSetup()
wiringpi.mcp23017Setup(pin_base,i2c_addr)
wiringpi.mcp23017Setup(pin_base+16,i2c_addr_2)
#for pin in pins:
for pin in range(65,96):
wiringpi.pinMode(pin,1)
wiringpi.digitalWrite(pin,1)
# wiringpi.delay(1000)
# wiringpi.digitalWrite(pin,0)

3
fixUndefFunc.c Normal file
View File

@ -0,0 +1,3 @@
#include <wiringPi.h>
unsigned int digitalRead8 (int pin) { return 0;}
void digitalWrite8 (int pin, int value) {}

42
generate-bindings.py Normal file
View File

@ -0,0 +1,42 @@
HEADERS = []
src = open("wiringpi.i").read().split('\n')
print("extern unsigned char getGpioNum(void);")
for line in src:
line = line.strip()
if line.startswith('#include') and line.endswith('.h"'):
HEADERS.append(line.replace('#include','').replace('"','').strip())
def is_c_decl(line):
for fn in ['wiringPiISR','wiringPiSetupPiFace','wiringPiSetupPiFaceForGpioProg']:
if fn in line:
return False
for prefix in ['extern','void','int','uint8_t']:
if line.startswith(prefix):
return True
print("// Generated by generate-bindings.py - do not edit manually!")
for file in HEADERS:
print("\n// Header file {}".format(file))
if file == "wiringOP/devLib/font.h":
continue # continue here
h = open(file).read().split('\n')
extern = False
cont = False
if 'extern "C" {' not in h:
extern = True
for line in h:
line = line.strip()
if cont:
print("\t{}".format(line))
cont = ";" not in line
continue
if line.startswith('extern "C"'):
extern = True
continue
if is_c_decl(line) and extern:
print(line)
cont = ";" not in line

7
setup.cfg Normal file
View File

@ -0,0 +1,7 @@
[metadata]
author = Philip Howard
author_email = phil@gadgetoid.com
url = https://github.com/WiringPi/WiringPi-Python/
description = A python interface to WiringPi 2.0 library which allows for easily interfacing with the GPIO pins of the Raspberry Pi. Also supports i2c and SPI.
long_description = file:README.rst
license = LGPL

60
setup.py Executable file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env python
import os
import sys
from setuptools import setup, Extension
from setuptools.command.build_py import build_py
from setuptools.command.sdist import sdist
from distutils.spawn import find_executable
from glob import glob
from subprocess import Popen, PIPE
import re
sources = glob('wiringOP/devLib/*.c')
sources += ['wiringOP/examples/blink.c']
sources += glob('wiringOP/wiringPi/*.c')
sources += ['wiringpi.i']
sources += ['fixUndefFunc.c']
try:
sources.remove('wiringOP/devLib/piFaceOld.c')
except ValueError:
# the file is already excluded in the source distribution
pass
# Fix so that build_ext runs before build_py
# Without this, wiringpi.py is generated too late and doesn't
# end up in the distribution when running setup.py bdist or bdist_wheel.
# Based on:
# https://stackoverflow.com/a/29551581/7938656
# and
# https://blog.niteoweb.com/setuptools-run-custom-code-in-setup-py/
class build_py_ext_first(build_py):
def run(self):
self.run_command("build_ext")
return build_py.run(self)
# Make sure wiringpi_wrap.c is available for the source dist, also.
class sdist_ext_first(sdist):
def run(self):
self.run_command("build_ext")
return sdist.run(self)
_wiringpi = Extension(
'_wiringpi',
include_dirs=['wiringOP', 'wiringOP/wiringPi', 'wiringOP/devLib'],
swig_opts=['-threads'],
extra_link_args=['-lcrypt', '-lrt'],
sources=sources
)
setup(
name='wiringpi',
version='2.60.1',
ext_modules=[_wiringpi],
py_modules=["wiringpi"],
install_requires=[],
cmdclass={'build_py': build_py_ext_first, 'sdist': sdist_ext_first}
)

4
tests/piglow.py Normal file
View File

@ -0,0 +1,4 @@
import wiringpi
io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
io.piGlowSetup()
io.piGlowLeg(1,100)

4
tests/test.py Normal file
View File

@ -0,0 +1,4 @@
import wiringpi
io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
print io.digitalRead(1)
print io.analogRead(1)

View File

@ -0,0 +1,9 @@
import wiringpi
def test_wiringPiSetup():
assert wiringpi.wiringPiSetup() == 0
def test_digitalRead():
assert wiringpi.digitalRead(1) != None
def test_digitalWrite():
assert wiringpi.digitalWrite(1,0) == None

9
wiringOP/.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
*.o
*.so
lib*.so.*
*~
debian-template/wiringPi
debian-template/wiringpi-*.deb
gpio/gpio
examples/speed
examples/blink

165
wiringOP/COPYING.LESSER Normal file
View File

@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

29
wiringOP/INSTALL Normal file
View File

@ -0,0 +1,29 @@
How to install wiringPi
=======================
The easiest way is to use the supplied 'build' script:
./build
that should do a complete install or upgrade of wiringPi for you.
That will install a dynamic library.
Some distributions do not have /usr/local/lib in the default LD_LIBRARY_PATH. To
fix this, you need to edit /etc/ld.so.conf and add in a single line:
/usr/local/lib
then run the ldconfig command.
sudo ldconfig
To un-install wiringPi:
./build uninstall
Gordon Henderson
projects@drogon.net
https://projects.drogon.net/

37
wiringOP/People Normal file
View File

@ -0,0 +1,37 @@
Just a quick note to some people who've provided help, suggestions,
bug-fixes, etc. along the way...
Nick Lott: (And others)
Hints about making it work with C++
Philipp Stefan Neininger:
Minor bug in the Makefile to do with cross compiling
Chris McSweeny
Hints and tips about the use of arithmetic in gettimeofday()
inside the dealyMicrosecondsHard() function.
And spotting a couple of schoolboy errors in the (experimental)
softServo code, prompting me to completely re-write it.
Armin (Via projects website)
Some pointers about the i2c-dev.h files.
Arno Wagner
Suggestions for the mmap calls in wiringPiSetup()
CHARLES Thibaut:
A small issue in softTone
Xian Stannard
Fixing some typos in the man page!
Andre Crone
Suggested the __WIRING_PI.H__ round wiringPi.h
Rik Teerling
Pointing out some silly mistooks in the I2C code...
Dolf Andringa
Support for multiple SpiDev devices/ports
Debian build support

390
wiringOP/README.md Normal file
View File

@ -0,0 +1,390 @@
## How to download wiringOP
```
# apt-get update
# apt-get install -y git
# git clone https://github.com/orangepi-xunlong/wiringOP.git
```
## How to build wiringOP
```
# cd wiringOP
# ./build clean
# ./build
```
---
## The output of the gpio readall command
## Allwinner H2+
### Orange Pi Zero/R1
```
+------+-----+----------+------+---+ OPi H2 +---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| | | 3.3V | | | 1 || 2 | | | 5V | | |
| 12 | 0 | SDA.0 | ALT2 | 0 | 3 || 4 | | | 5V | | |
| 11 | 1 | SCL.0 | ALT2 | 0 | 5 || 6 | | | GND | | |
| 6 | 2 | PWM.1 | OFF | 0 | 7 || 8 | 0 | ALT2 | TXD.1 | 3 | 198 |
| | | GND | | | 9 || 10 | 0 | ALT2 | RXD.1 | 4 | 199 |
| 1 | 5 | RXD.2 | ALT2 | 0 | 11 || 12 | 0 | OFF | PA07 | 6 | 7 |
| 0 | 7 | TXD.2 | ALT2 | 0 | 13 || 14 | | | GND | | |
| 3 | 8 | CTS.2 | OFF | 0 | 15 || 16 | 0 | ALT3 | SDA.1 | 9 | 19 |
| | | 3.3V | | | 17 || 18 | 0 | ALT3 | SCK.1 | 10 | 18 |
| 15 | 11 | MOSI.1 | ALT2 | 1 | 19 || 20 | | | GND | | |
| 16 | 12 | MISO.1 | ALT2 | 0 | 21 || 22 | 0 | OFF | RTS.2 | 13 | 2 |
| 14 | 14 | SCLK.1 | ALT2 | 0 | 23 || 24 | 0 | ALT2 | CE.1 | 15 | 13 |
| | | GND | | | 25 || 26 | 0 | OFF | PA10 | 16 | 10 |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+ OPi H2 +---+------+----------+-----+------+
```
## Allwinner H3
### Orange Pi Zero Plus 2
```
+------+-----+----------+------+---+ZEROPLUS 2+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| | | 3.3V | | | 1 || 2 | | | 5V | | |
| 12 | 0 | SDA.0 | ALT2 | 0 | 3 || 4 | | | 5V | | |
| 11 | 1 | SCL.0 | ALT2 | 0 | 5 || 6 | | | GND | | |
| 6 | 2 | PA6 | OFF | 0 | 7 || 8 | 0 | ALT2 | TXD.2 | 3 | 0 |
| | | GND | | | 9 || 10 | 0 | ALT2 | RXD.2 | 4 | 1 |
| 352 | 5 | S-SCL | ALT2 | 0 | 11 || 12 | 0 | OFF | PD11 | 6 | 107 |
| 353 | 7 | S-SDA | ALT2 | 0 | 13 || 14 | | | GND | | |
| 3 | 8 | CTS.2 | OFF | 0 | 15 || 16 | 0 | ALT3 | SDA.1 | 9 | 19 |
| | | 3.3V | | | 17 || 18 | 0 | ALT3 | SCL.1 | 10 | 18 |
| 15 | 11 | MOSI.1 | ALT2 | 0 | 19 || 20 | | | GND | | |
| 16 | 12 | MISO.1 | ALT2 | 0 | 21 || 22 | 0 | OFF | RTS.2 | 13 | 2 |
| 14 | 14 | SCLK.1 | ALT2 | 0 | 23 || 24 | 0 | ALT2 | CE.1 | 15 | 13 |
| | | GND | | | 25 || 26 | 0 | OFF | PD14 | 16 | 110 |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+ZEROPLUS 2+---+------+----------+-----+------+
```
### OrangePi One/Lite/Pc/Plus/PcPlus/Plus2e
```
+------+-----+----------+------+---+OrangePiH3+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| | | 3.3V | | | 1 || 2 | | | 5V | | |
| 12 | 0 | SDA.0 | OUT | 0 | 3 || 4 | | | 5V | | |
| 11 | 1 | SCL.0 | OUT | 0 | 5 || 6 | | | GND | | |
| 6 | 2 | PA6 | OUT | 0 | 7 || 8 | 0 | OUT | TXD.3 | 3 | 13 |
| | | GND | | | 9 || 10 | 0 | OUT | RXD.3 | 4 | 14 |
| 1 | 5 | RXD.2 | OUT | 0 | 11 || 12 | 0 | OUT | PD14 | 6 | 110 |
| 0 | 7 | TXD.2 | OUT | 0 | 13 || 14 | | | GND | | |
| 3 | 8 | CTS.2 | OUT | 0 | 15 || 16 | 0 | OUT | PC04 | 9 | 68 |
| | | 3.3V | | | 17 || 18 | 0 | OUT | PC07 | 10 | 71 |
| 64 | 11 | MOSI.0 | OUT | 0 | 19 || 20 | | | GND | | |
| 65 | 12 | MISO.0 | OUT | 0 | 21 || 22 | 0 | OUT | RTS.2 | 13 | 2 |
| 66 | 14 | SCLK.0 | OUT | 0 | 23 || 24 | 0 | OUT | CE.0 | 15 | 67 |
| | | GND | | | 25 || 26 | 0 | OUT | PA21 | 16 | 21 |
| 19 | 17 | SDA.1 | OUT | 0 | 27 || 28 | 0 | OUT | SCL.1 | 18 | 18 |
| 7 | 19 | PA07 | OUT | 0 | 29 || 30 | | | GND | | |
| 8 | 20 | PA08 | OUT | 0 | 31 || 32 | 0 | OUT | RTS.1 | 21 | 200 |
| 9 | 22 | PA09 | OUT | 0 | 33 || 34 | | | GND | | |
| 10 | 23 | PA10 | OUT | 0 | 35 || 36 | 0 | OUT | CTS.1 | 24 | 201 |
| 20 | 25 | PA20 | OUT | 0 | 37 || 38 | 0 | OUT | TXD.1 | 26 | 198 |
| | | GND | | | 39 || 40 | 0 | OUT | RXD.1 | 27 | 199 |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+OrangePiH3+---+------+----------+-----+------+
```
## Allwinner H5
### Orange Pi Zero Plus
```
+------+-----+----------+------+---+ ZEROPLUS +---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| | | 3.3V | | | 1 || 2 | | | 5V | | |
| 12 | 0 | SDA.0 | ALT2 | 0 | 3 || 4 | | | 5V | | |
| 11 | 1 | SCL.0 | ALT2 | 0 | 5 || 6 | | | GND | | |
| 6 | 2 | PA6 | OFF | 0 | 7 || 8 | 0 | ALT2 | TXD.1 | 3 | 198 |
| | | GND | | | 9 || 10 | 0 | ALT2 | RXD.1 | 4 | 199 |
| 1 | 5 | RXD.2 | ALT2 | 0 | 11 || 12 | 0 | OFF | PA07 | 6 | 7 |
| 0 | 7 | TXD.2 | ALT2 | 0 | 13 || 14 | | | GND | | |
| 3 | 8 | CTS.2 | OFF | 0 | 15 || 16 | 0 | ALT3 | SDA.1 | 9 | 19 |
| | | 3.3V | | | 17 || 18 | 0 | ALT3 | SCL.1 | 10 | 18 |
| 15 | 11 | MOSI.1 | ALT2 | 0 | 19 || 20 | | | GND | | |
| 16 | 12 | MISO.1 | ALT2 | 0 | 21 || 22 | 0 | OFF | RTS.2 | 13 | 2 |
| 14 | 14 | SCLK.1 | ALT2 | 0 | 23 || 24 | 0 | ALT2 | CE.1 | 15 | 13 |
| | | GND | | | 25 || 26 | 0 | OFF | PA10 | 16 | 10 |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+ ZEROPLUS +---+------+----------+-----+------+
```
### Orange Pi Zero Plus 2
```
+------+-----+----------+------+---+ZEROPLUS 2+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| | | 3.3V | | | 1 || 2 | | | 5V | | |
| 12 | 0 | SDA.0 | ALT2 | 0 | 3 || 4 | | | 5V | | |
| 11 | 1 | SCL.0 | ALT2 | 0 | 5 || 6 | | | GND | | |
| 6 | 2 | PA6 | OFF | 0 | 7 || 8 | 0 | ALT2 | TXD.2 | 3 | 0 |
| | | GND | | | 9 || 10 | 0 | ALT2 | RXD.2 | 4 | 1 |
| 352 | 5 | S-SCL | ALT2 | 0 | 11 || 12 | 0 | OFF | PD11 | 6 | 107 |
| 353 | 7 | S-SDA | ALT2 | 0 | 13 || 14 | | | GND | | |
| 3 | 8 | CTS.2 | OFF | 0 | 15 || 16 | 0 | ALT3 | SDA.1 | 9 | 19 |
| | | 3.3V | | | 17 || 18 | 0 | ALT3 | SCL.1 | 10 | 18 |
| 15 | 11 | MOSI.1 | ALT2 | 0 | 19 || 20 | | | GND | | |
| 16 | 12 | MISO.1 | ALT2 | 0 | 21 || 22 | 0 | OFF | RTS.2 | 13 | 2 |
| 14 | 14 | SCLK.1 | ALT2 | 0 | 23 || 24 | 0 | ALT2 | CE.1 | 15 | 13 |
| | | GND | | | 25 || 26 | 0 | OFF | PD14 | 16 | 110 |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+ZEROPLUS 2+---+------+----------+-----+------+
```
### Orange Pi Pc 2
```
+------+-----+----------+------+---+ OPi PC2 +---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| | | 3.3V | | | 1 || 2 | | | 5V | | |
| 12 | 0 | SDA.0 | ALT2 | 0 | 3 || 4 | | | 5V | | |
| 11 | 1 | SCL.0 | ALT2 | 0 | 5 || 6 | | | GND | | |
| 6 | 2 | PWM.1 | OFF | 0 | 7 || 8 | 0 | OFF | PC05 | 3 | 69 |
| | | GND | | | 9 || 10 | 0 | OFF | PC06 | 4 | 70 |
| 1 | 5 | RXD.2 | ALT2 | 0 | 11 || 12 | 0 | OFF | PD14 | 6 | 110 |
| 0 | 7 | TXD.2 | ALT2 | 0 | 13 || 14 | | | GND | | |
| 3 | 8 | CTS.2 | ALT2 | 0 | 15 || 16 | 0 | OFF | PC04 | 9 | 68 |
| | | 3.3V | | | 17 || 18 | 0 | OFF | PC07 | 10 | 71 |
| 15 | 11 | MOSI.1 | ALT2 | 0 | 19 || 20 | | | GND | | |
| 16 | 12 | MISO.1 | ALT2 | 0 | 21 || 22 | 0 | ALT2 | RTS.2 | 13 | 2 |
| 14 | 14 | SCLK.1 | ALT2 | 0 | 23 || 24 | 0 | ALT2 | CE.1 | 15 | 13 |
| | | GND | | | 25 || 26 | 0 | OFF | PA21 | 16 | 21 |
| 19 | 17 | SDA.1 | ALT3 | 0 | 27 || 28 | 0 | ALT3 | SCL.1 | 18 | 18 |
| 7 | 19 | PA07 | OFF | 0 | 29 || 30 | | | GND | | |
| 8 | 20 | PA08 | OFF | 0 | 31 || 32 | 0 | ALT2 | RTS.1 | 21 | 200 |
| 9 | 22 | PA09 | OFF | 0 | 33 || 34 | | | GND | | |
| 10 | 23 | PA10 | OFF | 0 | 35 || 36 | 0 | ALT2 | CTS.1 | 24 | 201 |
| 107 | 25 | PD11 | OFF | 0 | 37 || 38 | 0 | ALT2 | TXD.1 | 26 | 198 |
| | | GND | | | 39 || 40 | 0 | ALT2 | RXD.1 | 27 | 199 |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+ OPi PC2 +---+------+----------+-----+------+
```
### Orange Pi Prime
```
+------+-----+----------+------+---+ PRIME +---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| | | 3.3V | | | 1 || 2 | | | 5V | | |
| 12 | 0 | SDA.0 | ALT2 | 0 | 3 || 4 | | | 5V | | |
| 11 | 1 | SCL.0 | ALT2 | 0 | 5 || 6 | | | GND | | |
| 6 | 2 | PWM.1 | OFF | 0 | 7 || 8 | 0 | OFF | PC05 | 3 | 69 |
| | | GND | | | 9 || 10 | 0 | OFF | PC06 | 4 | 70 |
| 1 | 5 | RXD.2 | ALT2 | 0 | 11 || 12 | 0 | OFF | PD14 | 6 | 110 |
| 0 | 7 | TXD.2 | ALT2 | 0 | 13 || 14 | | | GND | | |
| 3 | 8 | CTS.2 | ALT2 | 0 | 15 || 16 | 0 | OFF | PC04 | 9 | 68 |
| | | 3.3V | | | 17 || 18 | 0 | OFF | PC07 | 10 | 71 |
| 15 | 11 | MOSI.1 | ALT2 | 0 | 19 || 20 | | | GND | | |
| 16 | 12 | MISO.1 | ALT2 | 0 | 21 || 22 | 0 | ALT2 | RTS.2 | 13 | 2 |
| 14 | 14 | SCLK.1 | ALT2 | 0 | 23 || 24 | 0 | ALT2 | CE.1 | 15 | 13 |
| | | GND | | | 25 || 26 | 0 | OFF | PC08 | 16 | 72 |
| 19 | 17 | SDA.1 | ALT3 | 0 | 27 || 28 | 0 | ALT3 | SCL.1 | 18 | 18 |
| 7 | 19 | PA07 | OFF | 0 | 29 || 30 | | | GND | | |
| 8 | 20 | PA08 | OFF | 0 | 31 || 32 | 0 | OFF | PC09 | 21 | 73 |
| 9 | 22 | PA09 | OFF | 0 | 33 || 34 | | | GND | | |
| 10 | 23 | PA10 | OFF | 0 | 35 || 36 | 0 | OFF | PC10 | 24 | 74 |
| 107 | 25 | PD11 | OFF | 0 | 37 || 38 | 0 | OFF | PC11 | 26 | 75 |
| | | GND | | | 39 || 40 | 0 | OFF | PC12 | 27 | 76 |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+ PRIME +---+------+----------+-----+------+
```
## Allwinner A64
### Orange Pi Win/Winplus
```
+------+-----+----------+------+---+ OPi Win +---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| | | 3.3V | | | 1 || 2 | | | 5V | | |
| 227 | 0 | SDA.1 | ALT2 | 0 | 3 || 4 | | | 5V | | |
| 226 | 1 | SCL.1 | ALT2 | 0 | 5 || 6 | | | GND | | |
| 362 | 2 | PL10 | OFF | 0 | 7 || 8 | 0 | ALT2 | PL02 | 3 | 354 |
| | | GND | | | 9 || 10 | 0 | ALT2 | PL03 | 4 | 355 |
| 229 | 5 | RXD.3 | ALT2 | 0 | 11 || 12 | 0 | OFF | PD04 | 6 | 100 |
| 228 | 7 | TXD.3 | ALT2 | 0 | 13 || 14 | | | GND | | |
| 231 | 8 | CTS.3 | OUT | 0 | 15 || 16 | 0 | OFF | PL09 | 9 | 361 |
| | | 3.3V | | | 17 || 18 | 0 | OFF | PC04 | 10 | 68 |
| 98 | 11 | MOSI.1 | ALT4 | 0 | 19 || 20 | | | GND | | |
| 99 | 12 | MISO.1 | ALT4 | 0 | 21 || 22 | 0 | OFF | RTS.3 | 13 | 230 |
| 97 | 14 | SCLK.1 | ALT4 | 0 | 23 || 24 | 0 | ALT4 | CE.1 | 15 | 96 |
| | | GND | | | 25 || 26 | 0 | OFF | PD06 | 16 | 102 |
| 143 | 17 | SDA.2 | ALT3 | 0 | 27 || 28 | 0 | ALT3 | SCL.2 | 18 | 142 |
| 36 | 19 | PB04 | OFF | 0 | 29 || 30 | | | GND | | |
| 37 | 20 | PB05 | OFF | 0 | 31 || 32 | 0 | ALT2 | RTS.2 | 21 | 34 |
| 38 | 22 | PB06 | OFF | 0 | 33 || 34 | | | GND | | |
| 39 | 23 | PB07 | OFF | 0 | 35 || 36 | 0 | ALT2 | CTS.2 | 24 | 35 |
| 101 | 25 | PD05 | OFF | 0 | 37 || 38 | 0 | ALT2 | TXD.2 | 26 | 32 |
| | | GND | | | 39 || 40 | 0 | ALT2 | RXD.2 | 27 | 33 |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+ OPi Win +---+------+----------+-----+------+
```
## Allwinner H6
### Orange Pi 3/3 LTS
```
+------+-----+----------+------+---+ OPi 3 +---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| | | 3.3V | | | 1 || 2 | | | 5V | | |
| 122 | 0 | SDA.0 | OFF | 0 | 3 || 4 | | | 5V | | |
| 121 | 1 | SCL.0 | OFF | 0 | 5 || 6 | | | GND | | |
| 118 | 2 | PWM.0 | OFF | 0 | 7 || 8 | 0 | OFF | PL02 | 3 | 354 |
| | | GND | | | 9 || 10 | 0 | OFF | PL03 | 4 | 355 |
| 120 | 5 | RXD.3 | ALT4 | 0 | 11 || 12 | 0 | OFF | PD18 | 6 | 114 |
| 119 | 7 | TXD.3 | ALT4 | 0 | 13 || 14 | | | GND | | |
| 362 | 8 | PL10 | OFF | 0 | 15 || 16 | 0 | OFF | PD15 | 9 | 111 |
| | | 3.3V | | | 17 || 18 | 0 | OFF | PD16 | 10 | 112 |
| 229 | 11 | MOSI.1 | ALT2 | 0 | 19 || 20 | | | GND | | |
| 230 | 12 | MISO.1 | ALT2 | 0 | 21 || 22 | 0 | OFF | PD21 | 13 | 117 |
| 228 | 14 | SCLK.1 | ALT2 | 0 | 23 || 24 | 0 | ALT2 | CE.1 | 15 | 227 |
| | | GND | | | 25 || 26 | 0 | OFF | PL08 | 16 | 360 |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+ OPi 3 +---+------+----------+-----+------+
```
### Orange Pi Lite2/OnePlus
```
+------+-----+----------+------+---+ OPi H6 +---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| | | 3.3V | | | 1 || 2 | | | 5V | | |
| 230 | 0 | SDA.1 | OFF | 0 | 3 || 4 | | | 5V | | |
| 229 | 1 | SCL.1 | OFF | 0 | 5 || 6 | | | GND | | |
| 228 | 2 | PWM1 | OFF | 0 | 7 || 8 | 0 | OFF | PD21 | 3 | 117 |
| | | GND | | | 9 || 10 | 0 | OFF | PD22 | 4 | 118 |
| 120 | 5 | RXD.3 | ALT4 | 0 | 11 || 12 | 0 | OFF | PC09 | 6 | 73 |
| 119 | 7 | TXD.3 | ALT4 | 0 | 13 || 14 | | | GND | | |
| 122 | 8 | CTS.3 | OFF | 0 | 15 || 16 | 0 | OFF | PC08 | 9 | 72 |
| | | 3.3V | | | 17 || 18 | 0 | OFF | PC07 | 10 | 71 |
| 66 | 11 | MOSI.0 | ALT4 | 0 | 19 || 20 | | | GND | | |
| 67 | 12 | MISO.0 | ALT4 | 0 | 21 || 22 | 0 | OFF | RTS.3 | 13 | 121 |
| 64 | 14 | SCLK.0 | ALT4 | 0 | 23 || 24 | 0 | ALT4 | CE.0 | 15 | 69 |
| | | GND | | | 25 || 26 | 0 | OFF | PH03 | 16 | 227 |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+ OPi H6 +---+------+----------+-----+------+
```
## Allwinner H616
### Orange Pi Zero2/Zero2 LTS/Zero2 B
```
+------+-----+----------+------+---+ Zero 2 +---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| | | 3.3V | | | 1 || 2 | | | 5V | | |
| 229 | 0 | SDA.3 | OFF | 0 | 3 || 4 | | | 5V | | |
| 228 | 1 | SCL.3 | OFF | 0 | 5 || 6 | | | GND | | |
| 73 | 2 | PC9 | OFF | 0 | 7 || 8 | 0 | ALT2 | TXD.5 | 3 | 226 |
| | | GND | | | 9 || 10 | 0 | ALT2 | RXD.5 | 4 | 227 |
| 70 | 5 | PC6 | ALT5 | 0 | 11 || 12 | 0 | OFF | PC11 | 6 | 75 |
| 69 | 7 | PC5 | ALT5 | 0 | 13 || 14 | | | GND | | |
| 72 | 8 | PC8 | OFF | 0 | 15 || 16 | 0 | OFF | PC15 | 9 | 79 |
| | | 3.3V | | | 17 || 18 | 0 | OFF | PC14 | 10 | 78 |
| 231 | 11 | MOSI.1 | ALT4 | 0 | 19 || 20 | | | GND | | |
| 232 | 12 | MISO.1 | ALT4 | 0 | 21 || 22 | 0 | OFF | PC7 | 13 | 71 |
| 230 | 14 | SCLK.1 | ALT4 | 0 | 23 || 24 | 0 | ALT4 | CE.1 | 15 | 233 |
| | | GND | | | 25 || 26 | 0 | OFF | PC10 | 16 | 74 |
| 65 | 17 | PC1 | OFF | 0 | 27 || 28 | | | | | |
| 272 | 18 | PI16 | OFF | 0 | 29 || 30 | | | | | |
| 262 | 19 | PI6 | OFF | 0 | 31 || 32 | | | | | |
| 234 | 20 | PH10 | ALT3 | 0 | 33 || 34 | | | | | |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+ Zero 2 +---+------+----------+-----+------+
```
## RockChip RK3399
### Orange Pi RK3399
```
+------+-----+----------+------+---+OPi RK3399+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| | | 3.3V | | | 1 || 2 | | | 5V | | |
| 43 | 0 | SDA.0 | ALT2 | 1 | 3 || 4 | | | 5V | | |
| 44 | 1 | SCL.0 | ALT2 | 1 | 5 || 6 | | | GND | | |
| 64 | 2 | GPIO4 | ALT3 | 0 | 7 || 8 | 0 | ALT2 | Tx | 3 | 148 |
| | | GND | | | 9 || 10 | 1 | ALT2 | Rx | 4 | 147 |
| 80 | 5 | GPIO17 | ALT2 | 0 | 11 || 12 | 0 | ALT3 | GPIO18 | 6 | 65 |
| 81 | 7 | GPIO27 | ALT2 | 0 | 13 || 14 | | | GND | | |
| 82 | 8 | GPIO22 | ALT2 | 0 | 15 || 16 | 0 | IN | GPIO23 | 9 | 66 |
| | | 3.3V | | | 17 || 18 | 0 | IN | GPIO24 | 10 | 67 |
| 39 | 11 | MOSI | ALT2 | 1 | 19 || 20 | | | GND | | |
| 40 | 12 | MISO | ALT2 | 1 | 21 || 22 | 0 | ALT2 | GPIO25 | 13 | 83 |
| 41 | 14 | SCLK | ALT3 | 1 | 23 || 24 | 1 | ALT3 | CS0 | 15 | 42 |
| | | GND | | | 25 || 26 | 0 | ALT2 | CS1 | 16 | 133 |
| 154 | 17 | DNP1 | IN | 0 | 27 || 28 | 1 | IN | DNP2 | 18 | 50 |
| 68 | 19 | GPIO5 | OUT | 1 | 29 || 30 | | | GND | | |
| 69 | 20 | GPIO6 | OUT | 1 | 31 || 32 | 1 | OUT | GPIO12 | 21 | 76 |
| 70 | 22 | GPIO13 | OUT | 1 | 33 || 34 | | | GND | | |
| 71 | 23 | GPIO19 | OUT | 1 | 35 || 36 | 1 | OUT | GPIO16 | 24 | 73 |
| 72 | 25 | GPIO26 | OUT | 1 | 37 || 38 | 0 | IN | GPIO20 | 26 | 74 |
| | | GND | | | 39 || 40 | 0 | ALT4 | GPIO21 | 27 | 75 |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+OPi RK3399+---+------+----------+-----+------+
```
### Orange Pi 4/4B/4 LTS
```
+------+-----+----------+------+---+OrangePi 4+---+---+--+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| | | 3.3V | | | 1 || 2 | | | 5V | | |
| 64 | 0 | I2C2_SDA | ALT3 | 0 | 3 || 4 | | | 5V | | |
| 65 | 1 | I2C2_SCL | ALT3 | 0 | 5 || 6 | | | GND | | |
| 150 | 2 | PWM1 | IN | 0 | 7 || 8 | 1 | ALT2 | I2C3_SCL | 3 | 145 |
| | | GND | | | 9 || 10 | 1 | ALT2 | I2C3_SDA | 4 | 144 |
| 33 | 5 | GPIO1_A1 | IN | 0 | 11 || 12 | 1 | IN | GPIO1_C2 | 6 | 50 |
| 35 | 7 | GPIO1_A3 | OUT | 0 | 13 || 14 | | | GND | | |
| 92 | 8 | GPIO2_D4 | OUT | 1 | 15 || 16 | 0 | IN | GPIO1_C6 | 9 | 54 |
| | | 3.3V | | | 17 || 18 | 0 | IN | GPIO1_C7 | 10 | 55 |
| 40 | 11 | SPI1_TXD | ALT2 | 1 | 19 || 20 | | | GND | | |
| 39 | 12 | SPI1_RXD | ALT2 | 1 | 21 || 22 | 0 | IN | GPIO1_D0 | 13 | 56 |
| 41 | 14 | SPI1_CLK | ALT3 | 1 | 23 || 24 | 1 | ALT3 | SPI1_CS | 15 | 42 |
| | | GND | | | 25 || 26 | 0 | IN | GPIO4_C5 | 16 | 149 |
| 64 | 17 | I2C2_SDA | ALT3 | 0 | 27 || 28 | 0 | ALT3 | I2C2_SCL | 18 | 65 |
| | | I2S0_RX | | | 29 || 30 | | | GND | | |
| | | I2S0_TX | | | 31 || 32 | | | I2S_CLK | | |
| | | I2S0_SCK | | | 33 || 34 | | | GND | | |
| | | I2S0_SI0 | | | 35 || 36 | | | I2S0_SO0 | | |
| | | I2S0_SI1 | | | 37 || 38 | | | I2S0_SI2 | | |
| | | GND | | | 39 || 40 | | | I2S0_SI3 | | |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+OrangePi 4+---+---+--+----------+-----+------+
```

1
wiringOP/VERSION Normal file
View File

@ -0,0 +1 @@
2.51

194
wiringOP/build Executable file
View File

@ -0,0 +1,194 @@
#!/bin/bash -e
# build
# Simple wiringPi build and install script
#
# Copyright (c) 2012-2015 Gordon Henderson
#################################################################################
# This file is part of wiringPi:
# A "wiring" library for the Raspberry Pi
#
# wiringPi is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wiringPi is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
#################################################################################
#
# wiringPi is designed to run on a Raspberry Pi only.
# However if you're clever enough to actually look at this script to
# see why it's not building for you, then good luck.
#
# To everyone else: Stop using cheap alternatives. Support the
# Raspberry Pi Foundation as they're the only ones putting money
# back into education!
#################################################################################
check_make_ok() {
if [ $? != 0 ]; then
echo ""
echo "Make Failed..."
echo "Please check the messages and fix any problems. If you're still stuck,"
echo "then please email all the output and as many details as you can to"
echo " projects@drogon.net"
echo ""
exit 1
fi
}
sudo=${WIRINGPI_SUDO-sudo}
if [ x$1 = "xclean" ]; then
cd wiringPi
echo -n "wiringPi: " ; make clean
cd ../devLib
echo -n "DevLib: " ; make clean
cd ../gpio
echo -n "gpio: " ; make clean
cd ../examples
echo -n "Examples: " ; make clean
cd Gertboard
echo -n "Gertboard: " ; make clean
cd ../PiFace
echo -n "PiFace: " ; make clean
cd ../q2w
echo -n "Quick2Wire: " ; make clean
cd ../PiGlow
echo -n "PiGlow: " ; make clean
cd ../scrollPhat
echo -n "scrollPhat: " ; make clean
cd ../..
echo -n "Deb: " ; rm -f debian-template/wiringpi*.deb
echo
exit
fi
if [ x$1 = "xuninstall" ]; then
cd wiringPi
echo -n "wiringPi: " ; $sudo make uninstall
cd ../devLib
echo -n "DevLib: " ; $sudo make uninstall
cd ../gpio
echo -n "gpio: " ; $sudo make uninstall
exit
fi
# Only if you know what you're doing!
if [ x$1 = "xdebian" ]; then
here=`pwd`
echo "removing old libs"
cd debian-template/wiringPi
rm -rf usr
echo "building wiringPi"
cd $here/wiringPi
make install-deb
echo "building devLib"
cd $here/devLib
make install-deb INCLUDE='-I. -I../wiringPi'
echo "building gpio"
cd $here/gpio
make install-deb INCLUDE='-I../wiringPi -I../devLib' LDFLAGS=-L../debian-template/wiringPi/usr/lib
echo "Building deb package"
cd $here/debian-template
fakeroot dpkg-deb --build wiringPi
mv wiringPi.deb wiringpi-`cat $here/VERSION`-1.deb
exit
fi
if [ x$1 != "x" ]; then
echo "Usage: $0 [clean | uninstall]"
exit 1
fi
echo "wiringPi Build script"
echo "====================="
echo
hardware=`fgrep Hardware /proc/cpuinfo | head -1 | awk '{ print $3 }'`
# if [ x$hardware != "xBCM2708" ]; then
# echo ""
# echo " +------------------------------------------------------------+"
# echo " | wiringPi is designed to run on the Raspberry Pi only. |"
# echo " | This processor does not appear to be a Raspberry Pi. |"
# echo " +------------------------------------------------------------+"
# echo " | In the unlikely event that you think it is a Raspberry Pi, |"
# echo " | then please accept my apologies and email the contents of |"
# echo " | /proc/cpuinfo to projects@drogon.net. |"
# echo " | - Thanks, Gordon |"
# echo " +------------------------------------------------------------+"
# echo ""
# exit 1
# fi
echo
echo "WiringPi Library"
cd wiringPi
$sudo make uninstall
if [ x$1 = "xstatic" ]; then
make -j5 static
check_make_ok
$sudo make install-static
else
make -j5
check_make_ok
$sudo make install
fi
check_make_ok
echo
echo "WiringPi Devices Library"
cd ../devLib
$sudo make uninstall
if [ x$1 = "xstatic" ]; then
make -j5 static
check_make_ok
$sudo make install-static
else
make -j5
check_make_ok
$sudo make install
fi
check_make_ok
echo
echo "GPIO Utility"
cd ../gpio
make -j5
check_make_ok
$sudo make install
check_make_ok
# echo
# echo "wiringPi Daemon"
# cd ../wiringPiD
# make -j5
# check_make_ok
# $sudo make install
# check_make_ok
# echo
# echo "Examples"
# cd ../examples
# make
# cd ..
echo
echo All Done.
echo ""
echo "NOTE: To compile programs with wiringPi, you need to add:"
echo " -lwiringPi"
echo " to your compile line(s) To use the Gertboard, MaxDetect, etc."
echo " code (the devLib), you need to also add:"
echo " -lwiringPiDev"
echo " to your compile line(s)."
echo ""

9
wiringOP/debian/.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
*.debhelper.log
*.substvars
tmp
wiringpi
libwiringpi2
libwiringpi-dev
files
*.postinst.debhelper
*.postrm.debhelper

View File

@ -0,0 +1,6 @@
wiringpi (2.26~iwj) rpi-unstable; urgency=low
* Initial version with real Debian source package build.
-- Ian Jackson <ijackson@chiark.greenend.org.uk> Sat, 12 Sep 2015 18:31:35 +0100

1
wiringOP/debian/compat Normal file
View File

@ -0,0 +1 @@
8

29
wiringOP/debian/control Normal file
View File

@ -0,0 +1,29 @@
Source: wiringpi
Section: electronics
Priority: optional
Maintainer: Ian Jackson <ijackson@chiark.greenend.org.uk>
Standards-Version: 3.8.0
Homepage: http://wiringpi.com/
Build-Depends: debhelper (>= 8)
Package: libwiringpi2
Section: libs
Architecture: arm64
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: GPIO librariees for Raspberry Pi (runtime).
Runtime for the popular wiringPi library.
Package: wiringpi
Architecture: arm64
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: gpio utility for Raspberry Pi
The wiringPi gpio command line utility, for GPIO access on a
Raspberry Pi from the command line.
Package: libwiringpi-dev
Architecture: arm64
Depends: libwiringpi2 (= ${binary:Version}), libc6-dev, ${misc:Depends}
Suggests: wiringpi
Description: GPIO development library for Raspberry Pi
Development libraries to allow GPIO access on a Raspberry Pi from C
and C++ programs.

15
wiringOP/debian/copyright Normal file
View File

@ -0,0 +1,15 @@
wiringPi is Copyright (C) 2012-2015 Gordon Henderson.
wiringPi is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License, as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
wiringPi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
On all Debian and Raspbian systems, a copy of the GNU Lesser General
Public License version 3 can be found in
`/usr/share/common-licenses/LGPL-3'.

View File

@ -0,0 +1,2 @@
usr/lib
usr/include

View File

@ -0,0 +1,3 @@
debian/tmp/usr/include
debian/tmp/usr/lib/*.so
examples usr/share/doc/libwiringpi-dev

View File

@ -0,0 +1 @@
debian/tmp/usr/lib/lib*.so.*

View File

@ -0,0 +1,2 @@
libwiringPi 2 libwiringpi2
libwiringPiDev 2 libwiringpi2

49
wiringOP/debian/rules Executable file
View File

@ -0,0 +1,49 @@
#!/usr/bin/make -f
.PHONY: build
VERSION:=$(shell cat VERSION)
export VERSION
soname:=$(shell echo $${VERSION%%.*})
WIRINGPI_SONAME_SUFFIX:=.$(soname)
export soname
export WIRINGPI_SONAME_SUFFIX
build:
dh $@
override_dh_auto_configure:
override_dh_prep:
dh_prep -Xdebian/tmp
dirs:
dh_installdirs -A
mkdir debian/tmp
set -e; for p in `dh_listpackages`; do \
(cd debian/$$p; find -type d) | \
(cd debian/tmp; xargs mkdir -p) \
done
override_dh_clean:
dh_clean
WIRINGPI_SUDO= bash -xe ./build clean
override_dh_auto_build: dirs
V=1 LDCONFIG=: WIRINGPI_SUDO= WIRINGPI_SUID=0 \
DESTDIR=`pwd`/debian/tmp/usr \
PREFIX= WIRINGPI_SUDO= \
bash -xe ./build
override_dh_auto_install:
dh_install
set -ex; for l in libwiringPi libwiringPiDev; do \
ln -sf $$l.so.$${VERSION} \
debian/libwiringpi$$soname/usr/lib/$$l.so.$$soname; \
ln -sf $$l.so.$${VERSION} \
debian/libwiringpi-dev/usr/lib/$$l.so; \
done
%:
dh $@

View File

@ -0,0 +1 @@
usr/bin

View File

@ -0,0 +1,4 @@
debian/tmp/usr/bin
debian/tmp/usr/man usr/share
README.TXT usr/share/doc/wiringpi
People usr/share/doc/wiringpi

140
wiringOP/devLib/Makefile Normal file
View File

@ -0,0 +1,140 @@
#
# Makefile:
# wiringPi device - A "wiring" library for the Raspberry Pi
#
# Copyright (c) 2012-2016 Gordon Henderson
#################################################################################
# This file is part of wiringPi:
# https://projects.drogon.net/raspberry-pi/wiringpi/
#
# wiringPi is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wiringPi is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
#################################################################################
VERSION=$(shell cat ../VERSION)
DESTDIR?=/usr
PREFIX?=/local
LDCONFIG?=ldconfig
ifneq ($V,1)
Q ?= @
endif
STATIC=libwiringPiDev.a
DYNAMIC=libwiringPiDev.so.$(VERSION)
#DEBUG = -g -O0
DEBUG = -O2
CC = gcc
INCLUDE = -I.
DEFS = -D_GNU_SOURCE
CFLAGS = $(DEBUG) $(DEFS) -Wformat=2 -Wall -Winline $(INCLUDE) -pipe -fPIC
LIBS =
###############################################################################
SRC = ds1302.c maxdetect.c piNes.c \
gertboard.c piFace.c \
lcd128x64.c lcd.c \
scrollPhat.c \
piGlow.c
OBJ = $(SRC:.c=.o)
HEADERS = ds1302.h gertboard.h lcd128x64.h lcd.h maxdetect.h piFace.h piGlow.h piNes.h\
scrollPhat.h
all: $(DYNAMIC)
static: $(STATIC)
$(STATIC): $(OBJ)
$Q echo "[Link (Static)]"
$Q ar rcs $(STATIC) $(OBJ)
$Q ranlib $(STATIC)
# @size $(STATIC)
$(DYNAMIC): $(OBJ)
$Q echo "[Link (Dynamic)]"
$Q $(CC) -shared -Wl,-soname,libwiringPiDev.so$(WIRINGPI_SONAME_SUFFIX) -o libwiringPiDev.so.$(VERSION) -lpthread $(OBJ)
.c.o:
$Q echo [Compile] $<
$Q $(CC) -c $(CFLAGS) $< -o $@
.PHONY: clean
clean:
$Q echo "[Clean]"
$Q rm -f $(OBJ) $(OBJ_I2C) *~ core tags Makefile.bak libwiringPiDev.*
.PHONY: tags
tags: $(SRC)
$Q echo [ctags]
$Q ctags $(SRC)
.PHONY: install
install: $(DYNAMIC)
$Q echo "[Install Headers]"
$Q install -m 0755 -d $(DESTDIR)$(PREFIX)/include
$Q install -m 0644 $(HEADERS) $(DESTDIR)$(PREFIX)/include
$Q echo "[Install Dynamic Lib]"
$Q install -m 0755 -d $(DESTDIR)$(PREFIX)/lib
$Q install -m 0755 libwiringPiDev.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/libwiringPiDev.so.$(VERSION)
$Q ln -sf $(DESTDIR)$(PREFIX)/lib/libwiringPiDev.so.$(VERSION) $(DESTDIR)/lib/libwiringPiDev.so
$Q $(LDCONFIG)
.PHONY: install-static
install-static: $(STATIC)
$Q echo "[Install Headers]"
$Q install -m 0755 -d $(DESTDIR)$(PREFIX)/include
$Q install -m 0644 $(HEADERS) $(DESTDIR)$(PREFIX)/include
$Q echo "[Install Static Lib]"
$Q install -m 0755 -d $(DESTDIR)$(PREFIX)/lib
$Q install -m 0755 libwiringPiDev.a $(DESTDIR)$(PREFIX)/lib
.PHONY: install-deb
install-deb: $(DYNAMIC)
$Q echo "[Install Headers: deb]"
$Q install -m 0755 -d $(CURDIR)/../debian-template/wiringPi/usr/include
$Q install -m 0644 $(HEADERS) $(CURDIR)/../debian-template/wiringPi/usr/include
$Q echo "[Install Dynamic Lib: deb]"
install -m 0755 -d $(CURDIR)/../debian-template/wiringPi/usr/lib
install -m 0755 libwiringPiDev.so.$(VERSION) $(CURDIR)/../debian-template/wiringPi/usr/lib/libwiringPiDev.so.$(VERSION)
ln -sf $(CURDIR)/../debian-template/wiringPi/usr/lib/libwiringPiDev.so.$(VERSION) $(CURDIR)/../debian-template/wiringPi/usr/lib/libwiringPiDev.so
.PHONY: uninstall
uninstall:
$Q echo "[UnInstall]"
$Q cd $(DESTDIR)$(PREFIX)/include/ && rm -f $(HEADERS)
$Q cd $(DESTDIR)$(PREFIX)/lib/ && rm -f libwiringPiDev.*
$Q $(LDCONFIG)
.PHONY: depend
depend:
makedepend -Y $(SRC)
# DO NOT DELETE
ds1302.o: ds1302.h
maxdetect.o: maxdetect.h
piNes.o: piNes.h
gertboard.o: gertboard.h
piFace.o: piFace.h
lcd128x64.o: font.h lcd128x64.h
lcd.o: lcd.h
scrollPhat.o: scrollPhatFont.h scrollPhat.h
piGlow.o: piGlow.h

240
wiringOP/devLib/ds1302.c Normal file
View File

@ -0,0 +1,240 @@
/*
* ds1302.c:
* Real Time clock
*
* Copyright (c) 2013 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <wiringPi.h>
#include "ds1302.h"
// Register defines
#define RTC_SECS 0
#define RTC_MINS 1
#define RTC_HOURS 2
#define RTC_DATE 3
#define RTC_MONTH 4
#define RTC_DAY 5
#define RTC_YEAR 6
#define RTC_WP 7
#define RTC_TC 8
#define RTC_BM 31
// Locals
static int dPin, cPin, sPin ;
/*
* dsShiftIn:
* Shift a number in from the chip, LSB first. Note that the data is
* sampled on the trailing edge of the last clock, so it's valid immediately.
*********************************************************************************
*/
static unsigned int dsShiftIn (void)
{
uint8_t value = 0 ;
int i ;
pinMode (dPin, INPUT) ; delayMicroseconds (1) ;
for (i = 0 ; i < 8 ; ++i)
{
value |= (digitalRead (dPin) << i) ;
digitalWrite (cPin, HIGH) ; delayMicroseconds (1) ;
digitalWrite (cPin, LOW) ; delayMicroseconds (1) ;
}
return value;
}
/*
* dsShiftOut:
* A normal LSB-first shift-out, just slowed down a bit - the Pi is
* a bit faster than the chip can handle.
*********************************************************************************
*/
static void dsShiftOut (unsigned int data)
{
int i ;
pinMode (dPin, OUTPUT) ;
for (i = 0 ; i < 8 ; ++i)
{
digitalWrite (dPin, data & (1 << i)) ; delayMicroseconds (1) ;
digitalWrite (cPin, HIGH) ; delayMicroseconds (1) ;
digitalWrite (cPin, LOW) ; delayMicroseconds (1) ;
}
}
/*
* ds1302regRead: ds1302regWrite:
* Read/Write a value to an RTC Register or RAM location on the chip
*********************************************************************************
*/
static unsigned int ds1302regRead (const int reg)
{
unsigned int data ;
digitalWrite (sPin, HIGH) ; delayMicroseconds (1) ;
dsShiftOut (reg) ;
data = dsShiftIn () ;
digitalWrite (sPin, LOW) ; delayMicroseconds (1) ;
return data ;
}
static void ds1302regWrite (const int reg, const unsigned int data)
{
digitalWrite (sPin, HIGH) ; delayMicroseconds (1) ;
dsShiftOut (reg) ;
dsShiftOut (data) ;
digitalWrite (sPin, LOW) ; delayMicroseconds (1) ;
}
/*
* ds1302rtcWrite: ds1302rtcRead:
* Writes/Reads the data to/from the RTC register
*********************************************************************************
*/
unsigned int ds1302rtcRead (const int reg)
{
return ds1302regRead (0x81 | ((reg & 0x1F) << 1)) ;
}
void ds1302rtcWrite (int reg, unsigned int data)
{
ds1302regWrite (0x80 | ((reg & 0x1F) << 1), data) ;
}
/*
* ds1302ramWrite: ds1302ramRead:
* Writes/Reads the data to/from the RTC register
*********************************************************************************
*/
unsigned int ds1302ramRead (const int addr)
{
return ds1302regRead (0xC1 | ((addr & 0x1F) << 1)) ;
}
void ds1302ramWrite (const int addr, const unsigned int data)
{
ds1302regWrite ( 0xC0 | ((addr & 0x1F) << 1), data) ;
}
/*
* ds1302clockRead:
* Read all 8 bytes of the clock in a single operation
*********************************************************************************
*/
void ds1302clockRead (int clockData [8])
{
int i ;
unsigned int regVal = 0x81 | ((RTC_BM & 0x1F) << 1) ;
digitalWrite (sPin, HIGH) ; delayMicroseconds (1) ;
dsShiftOut (regVal) ;
for (i = 0 ; i < 8 ; ++i)
clockData [i] = dsShiftIn () ;
digitalWrite (sPin, LOW) ; delayMicroseconds (1) ;
}
/*
* ds1302clockWrite:
* Write all 8 bytes of the clock in a single operation
*********************************************************************************
*/
void ds1302clockWrite (const int clockData [8])
{
int i ;
unsigned int regVal = 0x80 | ((RTC_BM & 0x1F) << 1) ;
digitalWrite (sPin, HIGH) ; delayMicroseconds (1) ;
dsShiftOut (regVal) ;
for (i = 0 ; i < 8 ; ++i)
dsShiftOut (clockData [i]) ;
digitalWrite (sPin, LOW) ; delayMicroseconds (1) ;
}
/*
* ds1302trickleCharge:
* Set the bits on the trickle charger.
* Probably best left alone...
*********************************************************************************
*/
void ds1302trickleCharge (const int diodes, const int resistors)
{
if (diodes + resistors == 0)
ds1302rtcWrite (RTC_TC, 0x5C) ; // Disabled
else
ds1302rtcWrite (RTC_TC, 0xA0 | ((diodes & 3) << 2) | (resistors & 3)) ;
}
/*
* ds1302setup:
* Initialise the chip & remember the pins we're using
*********************************************************************************
*/
void ds1302setup (const int clockPin, const int dataPin, const int csPin)
{
dPin = dataPin ;
cPin = clockPin ;
sPin = csPin ;
digitalWrite (dPin, LOW) ;
digitalWrite (cPin, LOW) ;
digitalWrite (sPin, LOW) ;
pinMode (dPin, OUTPUT) ;
pinMode (cPin, OUTPUT) ;
pinMode (sPin, OUTPUT) ;
ds1302rtcWrite (RTC_WP, 0) ; // Remove write-protect
}

44
wiringOP/devLib/ds1302.h Normal file
View File

@ -0,0 +1,44 @@
/*
* ds1302.h:
* Real Time clock
*
* Copyright (c) 2013 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#ifdef __cplusplus
extern "C" {
#endif
extern unsigned int ds1302rtcRead (const int reg) ;
extern void ds1302rtcWrite (const int reg, const unsigned int data) ;
extern unsigned int ds1302ramRead (const int addr) ;
extern void ds1302ramWrite (const int addr, const unsigned int data) ;
extern void ds1302clockRead (int clockData [8]) ;
extern void ds1302clockWrite (const int clockData [8]) ;
extern void ds1302trickleCharge (const int diodes, const int resistors) ;
extern void ds1302setup (const int clockPin, const int dataPin, const int csPin) ;
#ifdef __cplusplus
}
#endif

2577
wiringOP/devLib/font.h Normal file

File diff suppressed because it is too large Load Diff

164
wiringOP/devLib/gertboard.c Normal file
View File

@ -0,0 +1,164 @@
/*
* gertboard.c:
* Access routines for the SPI devices on the Gertboard
* Copyright (c) 2012 Gordon Henderson
*
* The Gertboard has:
*
* An MCP3002 dual-channel A to D convertor connected
* to the SPI bus, selected by chip-select A, and:
*
* An MCP4802 dual-channel D to A convertor connected
* to the SPI bus, selected via chip-select B.
*
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>
#include "gertboard.h"
// The A-D convertor won't run at more than 1MHz @ 3.3v
#define SPI_ADC_SPEED 1000000
#define SPI_DAC_SPEED 1000000
#define SPI_A2D 0
#define SPI_D2A 1
/*
* gertboardAnalogWrite:
* Write an 8-bit data value to the MCP4802 Analog to digital
* convertor on the Gertboard.
*********************************************************************************
*/
void gertboardAnalogWrite (const int chan, const int value)
{
uint8_t spiData [2] ;
uint8_t chanBits, dataBits ;
if (chan == 0)
chanBits = 0x30 ;
else
chanBits = 0xB0 ;
chanBits |= ((value >> 4) & 0x0F) ;
dataBits = ((value << 4) & 0xF0) ;
spiData [0] = chanBits ;
spiData [1] = dataBits ;
wiringPiSPIDataRW (SPI_D2A, spiData, 2) ;
}
/*
* gertboardAnalogRead:
* Return the analog value of the given channel (0/1).
* The A/D is a 10-bit device
*********************************************************************************
*/
int gertboardAnalogRead (const int chan)
{
uint8_t spiData [2] ;
uint8_t chanBits ;
if (chan == 0)
chanBits = 0b11010000 ;
else
chanBits = 0b11110000 ;
spiData [0] = chanBits ;
spiData [1] = 0 ;
wiringPiSPIDataRW (SPI_A2D, spiData, 2) ;
return ((spiData [0] << 8) | (spiData [1] >> 1)) & 0x3FF ;
}
/*
* gertboardSPISetup:
* Initialise the SPI bus, etc.
*********************************************************************************
*/
int gertboardSPISetup (void)
{
if (wiringPiSPISetup (SPI_A2D, SPI_ADC_SPEED) < 0)
return -1 ;
if (wiringPiSPISetup (SPI_D2A, SPI_DAC_SPEED) < 0)
return -1 ;
return 0 ;
}
/*
* New wiringPi node extension methods.
*********************************************************************************
*/
static int myAnalogRead (struct wiringPiNodeStruct *node, const int chan)
{
return gertboardAnalogRead (chan - node->pinBase) ;
}
static void myAnalogWrite (struct wiringPiNodeStruct *node, const int chan, const int value)
{
gertboardAnalogWrite (chan - node->pinBase, value) ;
}
/*
* gertboardAnalogSetup:
* Create a new wiringPi device node for the analog devices on the
* Gertboard. We create one node with 2 pins - each pin being read
* and write - although the operations actually go to different
* hardware devices.
*********************************************************************************
*/
int gertboardAnalogSetup (const int pinBase)
{
struct wiringPiNodeStruct *node ;
int x ;
if (( x = gertboardSPISetup ()) != 0)
return x;
node = wiringPiNewNode (pinBase, 2) ;
node->analogRead = myAnalogRead ;
node->analogWrite = myAnalogWrite ;
return 0 ;
}

View File

@ -0,0 +1,45 @@
/*
* gertboard.h:
* Access routines for the SPI devices on the Gertboard
* Copyright (c) 2012 Gordon Henderson
*
* The Gertboard has an MCP4802 dual-channel D to A convertor
* connected to the SPI bus, selected via chip-select B.
*
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#ifdef __cplusplus
extern "C" {
#endif
// Old routines
extern void gertboardAnalogWrite (const int chan, const int value) ;
extern int gertboardAnalogRead (const int chan) ;
extern int gertboardSPISetup (void) ;
// New
extern int gertboardAnalogSetup (const int pinBase) ;
#ifdef __cplusplus
}
#endif

495
wiringOP/devLib/lcd.c Normal file
View File

@ -0,0 +1,495 @@
/*
* lcd.c:
* Text-based LCD driver.
* This is designed to drive the parallel interface LCD drivers
* based in the Hitachi HD44780U controller and compatables.
*
* Copyright (c) 2012 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <wiringPi.h>
#include "lcd.h"
#ifndef TRUE
# define TRUE (1==1)
# define FALSE (1==2)
#endif
// HD44780U Commands
#define LCD_CLEAR 0x01
#define LCD_HOME 0x02
#define LCD_ENTRY 0x04
#define LCD_CTRL 0x08
#define LCD_CDSHIFT 0x10
#define LCD_FUNC 0x20
#define LCD_CGRAM 0x40
#define LCD_DGRAM 0x80
// Bits in the entry register
#define LCD_ENTRY_SH 0x01
#define LCD_ENTRY_ID 0x02
// Bits in the control register
#define LCD_BLINK_CTRL 0x01
#define LCD_CURSOR_CTRL 0x02
#define LCD_DISPLAY_CTRL 0x04
// Bits in the function register
#define LCD_FUNC_F 0x04
#define LCD_FUNC_N 0x08
#define LCD_FUNC_DL 0x10
#define LCD_CDSHIFT_RL 0x04
struct lcdDataStruct
{
int bits, rows, cols ;
int rsPin, strbPin ;
int dataPins [8] ;
int cx, cy ;
} ;
struct lcdDataStruct *lcds [MAX_LCDS] ;
static int lcdControl ;
// Row offsets
static const int rowOff [4] = { 0x00, 0x40, 0x14, 0x54 } ;
/*
* strobe:
* Toggle the strobe (Really the "E") pin to the device.
* According to the docs, data is latched on the falling edge.
*********************************************************************************
*/
static void strobe (const struct lcdDataStruct *lcd)
{
// Note timing changes for new version of delayMicroseconds ()
digitalWrite (lcd->strbPin, 1) ; delayMicroseconds (50) ;
digitalWrite (lcd->strbPin, 0) ; delayMicroseconds (50) ;
}
/*
* sentDataCmd:
* Send an data or command byte to the display.
*********************************************************************************
*/
static void sendDataCmd (const struct lcdDataStruct *lcd, unsigned char data)
{
register unsigned char myData = data ;
unsigned char i, d4 ;
if (lcd->bits == 4)
{
d4 = (myData >> 4) & 0x0F;
for (i = 0 ; i < 4 ; ++i)
{
digitalWrite (lcd->dataPins [i], (d4 & 1)) ;
d4 >>= 1 ;
}
strobe (lcd) ;
d4 = myData & 0x0F ;
for (i = 0 ; i < 4 ; ++i)
{
digitalWrite (lcd->dataPins [i], (d4 & 1)) ;
d4 >>= 1 ;
}
}
else
{
for (i = 0 ; i < 8 ; ++i)
{
digitalWrite (lcd->dataPins [i], (myData & 1)) ;
myData >>= 1 ;
}
}
strobe (lcd) ;
}
/*
* putCommand:
* Send a command byte to the display
*********************************************************************************
*/
static void putCommand (const struct lcdDataStruct *lcd, unsigned char command)
{
digitalWrite (lcd->rsPin, 0) ;
sendDataCmd (lcd, command) ;
delay (2) ;
}
static void put4Command (const struct lcdDataStruct *lcd, unsigned char command)
{
register unsigned char myCommand = command ;
register unsigned char i ;
digitalWrite (lcd->rsPin, 0) ;
for (i = 0 ; i < 4 ; ++i)
{
digitalWrite (lcd->dataPins [i], (myCommand & 1)) ;
myCommand >>= 1 ;
}
strobe (lcd) ;
}
/*
*********************************************************************************
* User Callable code below here
*********************************************************************************
*/
/*
* lcdHome: lcdClear:
* Home the cursor or clear the screen.
*********************************************************************************
*/
void lcdHome (const int fd)
{
struct lcdDataStruct *lcd = lcds [fd] ;
putCommand (lcd, LCD_HOME) ;
lcd->cx = lcd->cy = 0 ;
delay (5) ;
}
void lcdClear (const int fd)
{
struct lcdDataStruct *lcd = lcds [fd] ;
putCommand (lcd, LCD_CLEAR) ;
putCommand (lcd, LCD_HOME) ;
lcd->cx = lcd->cy = 0 ;
delay (5) ;
}
/*
* lcdDisplay: lcdCursor: lcdCursorBlink:
* Turn the display, cursor, cursor blinking on/off
*********************************************************************************
*/
void lcdDisplay (const int fd, int state)
{
struct lcdDataStruct *lcd = lcds [fd] ;
if (state)
lcdControl |= LCD_DISPLAY_CTRL ;
else
lcdControl &= ~LCD_DISPLAY_CTRL ;
putCommand (lcd, LCD_CTRL | lcdControl) ;
}
void lcdCursor (const int fd, int state)
{
struct lcdDataStruct *lcd = lcds [fd] ;
if (state)
lcdControl |= LCD_CURSOR_CTRL ;
else
lcdControl &= ~LCD_CURSOR_CTRL ;
putCommand (lcd, LCD_CTRL | lcdControl) ;
}
void lcdCursorBlink (const int fd, int state)
{
struct lcdDataStruct *lcd = lcds [fd] ;
if (state)
lcdControl |= LCD_BLINK_CTRL ;
else
lcdControl &= ~LCD_BLINK_CTRL ;
putCommand (lcd, LCD_CTRL | lcdControl) ;
}
/*
* lcdSendCommand:
* Send any arbitary command to the display
*********************************************************************************
*/
void lcdSendCommand (const int fd, unsigned char command)
{
struct lcdDataStruct *lcd = lcds [fd] ;
putCommand (lcd, command) ;
}
/*
* lcdPosition:
* Update the position of the cursor on the display.
* Ignore invalid locations.
*********************************************************************************
*/
void lcdPosition (const int fd, int x, int y)
{
struct lcdDataStruct *lcd = lcds [fd] ;
if ((x > lcd->cols) || (x < 0))
return ;
if ((y > lcd->rows) || (y < 0))
return ;
putCommand (lcd, x + (LCD_DGRAM | rowOff [y])) ;
lcd->cx = x ;
lcd->cy = y ;
}
/*
* lcdCharDef:
* Defines a new character in the CGRAM
*********************************************************************************
*/
void lcdCharDef (const int fd, int index, unsigned char data [8])
{
struct lcdDataStruct *lcd = lcds [fd] ;
int i ;
putCommand (lcd, LCD_CGRAM | ((index & 7) << 3)) ;
digitalWrite (lcd->rsPin, 1) ;
for (i = 0 ; i < 8 ; ++i)
sendDataCmd (lcd, data [i]) ;
}
/*
* lcdPutchar:
* Send a data byte to be displayed on the display. We implement a very
* simple terminal here - with line wrapping, but no scrolling. Yet.
*********************************************************************************
*/
void lcdPutchar (const int fd, unsigned char data)
{
struct lcdDataStruct *lcd = lcds [fd] ;
digitalWrite (lcd->rsPin, 1) ;
sendDataCmd (lcd, data) ;
if (++lcd->cx == lcd->cols)
{
lcd->cx = 0 ;
if (++lcd->cy == lcd->rows)
lcd->cy = 0 ;
putCommand (lcd, lcd->cx + (LCD_DGRAM | rowOff [lcd->cy])) ;
}
}
/*
* lcdPuts:
* Send a string to be displayed on the display
*********************************************************************************
*/
void lcdPuts (const int fd, const char *string)
{
while (*string)
lcdPutchar (fd, *string++) ;
}
/*
* lcdPrintf:
* Printf to an LCD display
*********************************************************************************
*/
void lcdPrintf (const int fd, const char *message, ...)
{
va_list argp ;
char buffer [1024] ;
va_start (argp, message) ;
vsnprintf (buffer, 1023, message, argp) ;
va_end (argp) ;
lcdPuts (fd, buffer) ;
}
/*
* lcdInit:
* Take a lot of parameters and initialise the LCD, and return a handle to
* that LCD, or -1 if any error.
*********************************************************************************
*/
int lcdInit (const int rows, const int cols, const int bits,
const int rs, const int strb,
const int d0, const int d1, const int d2, const int d3, const int d4,
const int d5, const int d6, const int d7)
{
static int initialised = 0 ;
unsigned char func ;
int i ;
int lcdFd = -1 ;
struct lcdDataStruct *lcd ;
if (initialised == 0)
{
initialised = 1 ;
for (i = 0 ; i < MAX_LCDS ; ++i)
lcds [i] = NULL ;
}
// Simple sanity checks
if (! ((bits == 4) || (bits == 8)))
return -1 ;
if ((rows < 0) || (rows > 20))
return -1 ;
if ((cols < 0) || (cols > 20))
return -1 ;
// Create a new LCD:
for (i = 0 ; i < MAX_LCDS ; ++i)
{
if (lcds [i] == NULL)
{
lcdFd = i ;
break ;
}
}
if (lcdFd == -1)
return -1 ;
lcd = (struct lcdDataStruct *)malloc (sizeof (struct lcdDataStruct)) ;
if (lcd == NULL)
return -1 ;
lcd->rsPin = rs ;
lcd->strbPin = strb ;
lcd->bits = 8 ; // For now - we'll set it properly later.
lcd->rows = rows ;
lcd->cols = cols ;
lcd->cx = 0 ;
lcd->cy = 0 ;
lcd->dataPins [0] = d0 ;
lcd->dataPins [1] = d1 ;
lcd->dataPins [2] = d2 ;
lcd->dataPins [3] = d3 ;
lcd->dataPins [4] = d4 ;
lcd->dataPins [5] = d5 ;
lcd->dataPins [6] = d6 ;
lcd->dataPins [7] = d7 ;
lcds [lcdFd] = lcd ;
digitalWrite (lcd->rsPin, 0) ; pinMode (lcd->rsPin, OUTPUT) ;
digitalWrite (lcd->strbPin, 0) ; pinMode (lcd->strbPin, OUTPUT) ;
for (i = 0 ; i < bits ; ++i)
{
digitalWrite (lcd->dataPins [i], 0) ;
pinMode (lcd->dataPins [i], OUTPUT) ;
}
delay (35) ; // mS
// 4-bit mode?
// OK. This is a PIG and it's not at all obvious from the documentation I had,
// so I guess some others have worked through either with better documentation
// or more trial and error... Anyway here goes:
//
// It seems that the controller needs to see the FUNC command at least 3 times
// consecutively - in 8-bit mode. If you're only using 8-bit mode, then it appears
// that you can get away with one func-set, however I'd not rely on it...
//
// So to set 4-bit mode, you need to send the commands one nibble at a time,
// the same three times, but send the command to set it into 8-bit mode those
// three times, then send a final 4th command to set it into 4-bit mode, and only
// then can you flip the switch for the rest of the library to work in 4-bit
// mode which sends the commands as 2 x 4-bit values.
if (bits == 4)
{
func = LCD_FUNC | LCD_FUNC_DL ; // Set 8-bit mode 3 times
put4Command (lcd, func >> 4) ; delay (35) ;
put4Command (lcd, func >> 4) ; delay (35) ;
put4Command (lcd, func >> 4) ; delay (35) ;
func = LCD_FUNC ; // 4th set: 4-bit mode
put4Command (lcd, func >> 4) ; delay (35) ;
lcd->bits = 4 ;
}
else
{
func = LCD_FUNC | LCD_FUNC_DL ;
putCommand (lcd, func ) ; delay (35) ;
putCommand (lcd, func ) ; delay (35) ;
putCommand (lcd, func ) ; delay (35) ;
}
if (lcd->rows > 1)
{
func |= LCD_FUNC_N ;
putCommand (lcd, func) ; delay (35) ;
}
// Rest of the initialisation sequence
lcdDisplay (lcdFd, TRUE) ;
lcdCursor (lcdFd, FALSE) ;
lcdCursorBlink (lcdFd, FALSE) ;
lcdClear (lcdFd) ;
putCommand (lcd, LCD_ENTRY | LCD_ENTRY_ID) ;
putCommand (lcd, LCD_CDSHIFT | LCD_CDSHIFT_RL) ;
return lcdFd ;
}

52
wiringOP/devLib/lcd.h Normal file
View File

@ -0,0 +1,52 @@
/*
* lcd.h:
* Text-based LCD driver.
* This is designed to drive the parallel interface LCD drivers
* based in the Hitachi HD44780U controller and compatables.
*
* Copyright (c) 2012 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#define MAX_LCDS 8
#ifdef __cplusplus
extern "C" {
#endif
extern void lcdHome (const int fd) ;
extern void lcdClear (const int fd) ;
extern void lcdDisplay (const int fd, int state) ;
extern void lcdCursor (const int fd, int state) ;
extern void lcdCursorBlink (const int fd, int state) ;
extern void lcdSendCommand (const int fd, unsigned char command) ;
extern void lcdPosition (const int fd, int x, int y) ;
extern void lcdCharDef (const int fd, int index, unsigned char data [8]) ;
extern void lcdPutchar (const int fd, unsigned char data) ;
extern void lcdPuts (const int fd, const char *string) ;
extern void lcdPrintf (const int fd, const char *message, ...) ;
extern int lcdInit (const int rows, const int cols, const int bits,
const int rs, const int strb,
const int d0, const int d1, const int d2, const int d3, const int d4,
const int d5, const int d6, const int d7) ;
#ifdef __cplusplus
}
#endif

673
wiringOP/devLib/lcd128x64.c Normal file
View File

@ -0,0 +1,673 @@
/*
* lcd128x64.c:
* Graphics-based LCD driver.
* This is designed to drive the parallel interface LCD drivers
* based on the generic 12864H chips
*
* There are many variations on these chips, however they all mostly
* seem to be similar.
* This implementation has the Pins from the Pi hard-wired into it,
* in particular wiringPi pins 0-7 so that we can use
* digitalWriteByete() to speed things up somewhat.
*
* Copyright (c) 2013 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
#include "font.h"
#include "lcd128x64.h"
// Size
#define LCD_WIDTH 128
#define LCD_HEIGHT 64
// Hardware Pins
// Note pins 0-7 are the 8-bit data port
#define CS1 10
#define CS2 11
#define STROBE 12
#define RS 13
// Software copy of the framebuffer
// it's 8-bit deep although the display itself is only 1-bit deep.
static unsigned char frameBuffer [LCD_WIDTH * LCD_HEIGHT] ;
static int maxX, maxY ;
static int lastX, lastY ;
static int xOrigin, yOrigin ;
static int lcdOrientation = 0 ;
/*
* strobe:
* Toggle the strobe (Really the "E") pin to the device.
* According to the docs, data is latched on the falling edge.
*********************************************************************************
*/
static void strobe (void)
{
digitalWrite (STROBE, 1) ; delayMicroseconds (1) ;
digitalWrite (STROBE, 0) ; delayMicroseconds (5) ;
}
/*
* sentData:
* Send an data or command byte to the display.
*********************************************************************************
*/
static void sendData (const int data, const int chip)
{
digitalWrite (chip, 0) ;
digitalWriteByte (data) ;
strobe () ;
digitalWrite (chip, 1) ;
}
/*
* sendCommand:
* Send a command byte to the display
*********************************************************************************
*/
static void sendCommand (const int command, const int chip)
{
digitalWrite (RS, 0) ;
sendData (command, chip) ;
digitalWrite (RS, 1) ;
}
/*
* setCol: SetLine:
* Set the column and line addresses
*********************************************************************************
*/
static void setCol (int col, const int chip)
{ sendCommand (0x40 | (col & 0x3F), chip) ; }
static void setLine (int line, const int chip)
{ sendCommand (0xB8 | (line & 0x07), chip) ; }
/*
* lcd128x64update:
* Copy our software version to the real display
*********************************************************************************
*/
void lcd128x64update (void)
{
int line, x, y, fbLoc ;
unsigned char byte ;
// Left side
for (line = 0 ; line < 8 ; ++line)
{
setCol (0, CS1) ;
setLine (line, CS1) ;
for (x = 63 ; x >= 0 ; --x)
{
byte = 0 ;
for (y = 0 ; y < 8 ; ++y)
{
fbLoc = x + (((7 - line) * 8) + (7 - y)) * LCD_WIDTH ;
if (frameBuffer [fbLoc] != 0)
byte |= (1 << y) ;
}
sendData (byte, CS1) ;
}
}
// Right side
for (line = 0 ; line < 8 ; ++line)
{
setCol (0, CS2) ;
setLine (line, CS2) ;
for (x = 127 ; x >= 64 ; --x)
{
byte = 0 ;
for (y = 0 ; y < 8 ; ++y)
{
fbLoc = x + (((7 - line) * 8) + (7 - y)) * LCD_WIDTH ;
if (frameBuffer [fbLoc] != 0)
byte |= (1 << y) ;
}
sendData (byte, CS2) ;
}
}
}
/*
* lcd128x64setOrigin:
* Set the display offset origin
*********************************************************************************
*/
void lcd128x64setOrigin (int x, int y)
{
xOrigin = x ;
yOrigin = y ;
}
/*
* lcd128x64setOrientation:
* Set the display orientation:
* 0: Normal, the display is portrait mode, 0,0 is top left
* 1: Landscape
* 2: Portrait, flipped
* 3: Landscape, flipped
*********************************************************************************
*/
void lcd128x64setOrientation (int orientation)
{
lcdOrientation = orientation & 3 ;
lcd128x64setOrigin (0,0) ;
switch (lcdOrientation)
{
case 0:
maxX = LCD_WIDTH ;
maxY = LCD_HEIGHT ;
break ;
case 1:
maxX = LCD_HEIGHT ;
maxY = LCD_WIDTH ;
break ;
case 2:
maxX = LCD_WIDTH ;
maxY = LCD_HEIGHT ;
break ;
case 3:
maxX = LCD_HEIGHT ;
maxY = LCD_WIDTH ;
break ;
}
}
/*
* lcd128x64orientCoordinates:
* Adjust the coordinates given to the display orientation
*********************************************************************************
*/
void lcd128x64orientCoordinates (int *x, int *y)
{
register int tmp ;
*x += xOrigin ;
*y += yOrigin ;
*y = maxY - *y - 1 ;
switch (lcdOrientation)
{
case 0:
break;
case 1:
tmp = maxY - *y - 1 ;
*y = *x ;
*x = tmp ;
break;
case 2:
*x = maxX - *x - 1 ;
*y = maxY - *y - 1 ;
break;
case 3:
*x = maxX - *x - 1 ;
tmp = *y ;
*y = *x ;
*x = tmp ;
break ;
}
}
/*
* lcd128x64getScreenSize:
* Return the max X & Y screen sizes. Needs to be called again, if you
* change screen orientation.
*********************************************************************************
*/
void lcd128x64getScreenSize (int *x, int *y)
{
*x = maxX ;
*y = maxY ;
}
/*
*********************************************************************************
* Standard Graphical Functions
*********************************************************************************
*/
/*
* lcd128x64point:
* Plot a pixel.
*********************************************************************************
*/
void lcd128x64point (int x, int y, int colour)
{
lastX = x ;
lastY = y ;
lcd128x64orientCoordinates (&x, &y) ;
if ((x < 0) || (x >= LCD_WIDTH) || (y < 0) || (y >= LCD_HEIGHT))
return ;
frameBuffer [x + y * LCD_WIDTH] = colour ;
}
/*
* lcd128x64line: lcd128x64lineTo:
* Classic Bressenham Line code
*********************************************************************************
*/
void lcd128x64line (int x0, int y0, int x1, int y1, int colour)
{
int dx, dy ;
int sx, sy ;
int err, e2 ;
lastX = x1 ;
lastY = y1 ;
dx = abs (x1 - x0) ;
dy = abs (y1 - y0) ;
sx = (x0 < x1) ? 1 : -1 ;
sy = (y0 < y1) ? 1 : -1 ;
err = dx - dy ;
for (;;)
{
lcd128x64point (x0, y0, colour) ;
if ((x0 == x1) && (y0 == y1))
break ;
e2 = 2 * err ;
if (e2 > -dy)
{
err -= dy ;
x0 += sx ;
}
if (e2 < dx)
{
err += dx ;
y0 += sy ;
}
}
}
void lcd128x64lineTo (int x, int y, int colour)
{
lcd128x64line (lastX, lastY, x, y, colour) ;
}
/*
* lcd128x64rectangle:
* A rectangle is a spoilt days fishing
*********************************************************************************
*/
void lcd128x64rectangle (int x1, int y1, int x2, int y2, int colour, int filled)
{
register int x ;
if (filled)
{
/**/ if (x1 == x2)
lcd128x64line (x1, y1, x2, y2, colour) ;
else if (x1 < x2)
for (x = x1 ; x <= x2 ; ++x)
lcd128x64line (x, y1, x, y2, colour) ;
else
for (x = x2 ; x <= x1 ; ++x)
lcd128x64line (x, y1, x, y2, colour) ;
}
else
{
lcd128x64line (x1, y1, x2, y1, colour) ;
lcd128x64lineTo (x2, y2, colour) ;
lcd128x64lineTo (x1, y2, colour) ;
lcd128x64lineTo (x1, y1, colour) ;
}
}
/*
* lcd128x64circle:
* This is the midpoint circle algorithm.
*********************************************************************************
*/
void lcd128x64circle (int x, int y, int r, int colour, int filled)
{
int ddF_x = 1 ;
int ddF_y = -2 * r ;
int f = 1 - r ;
int x1 = 0 ;
int y1 = r ;
if (filled)
{
lcd128x64line (x, y + r, x, y - r, colour) ;
lcd128x64line (x + r, y, x - r, y, colour) ;
}
else
{
lcd128x64point (x, y + r, colour) ;
lcd128x64point (x, y - r, colour) ;
lcd128x64point (x + r, y, colour) ;
lcd128x64point (x - r, y, colour) ;
}
while (x1 < y1)
{
if (f >= 0)
{
y1-- ;
ddF_y += 2 ;
f += ddF_y ;
}
x1++ ;
ddF_x += 2 ;
f += ddF_x ;
if (filled)
{
lcd128x64line (x + x1, y + y1, x - x1, y + y1, colour) ;
lcd128x64line (x + x1, y - y1, x - x1, y - y1, colour) ;
lcd128x64line (x + y1, y + x1, x - y1, y + x1, colour) ;
lcd128x64line (x + y1, y - x1, x - y1, y - x1, colour) ;
}
else
{
lcd128x64point (x + x1, y + y1, colour) ; lcd128x64point (x - x1, y + y1, colour) ;
lcd128x64point (x + x1, y - y1, colour) ; lcd128x64point (x - x1, y - y1, colour) ;
lcd128x64point (x + y1, y + x1, colour) ; lcd128x64point (x - y1, y + x1, colour) ;
lcd128x64point (x + y1, y - x1, colour) ; lcd128x64point (x - y1, y - x1, colour) ;
}
}
}
/*
* lcd128x64ellipse:
* Fast ellipse drawing algorithm by
* John Kennedy
* Mathematics Department
* Santa Monica College
* 1900 Pico Blvd.
* Santa Monica, CA 90405
* jrkennedy6@gmail.com
* -Confirned in email this algorithm is in the public domain -GH-
*********************************************************************************
*/
static void plot4ellipsePoints (int cx, int cy, int x, int y, int colour, int filled)
{
if (filled)
{
lcd128x64line (cx + x, cy + y, cx - x, cy + y, colour) ;
lcd128x64line (cx - x, cy - y, cx + x, cy - y, colour) ;
}
else
{
lcd128x64point (cx + x, cy + y, colour) ;
lcd128x64point (cx - x, cy + y, colour) ;
lcd128x64point (cx - x, cy - y, colour) ;
lcd128x64point (cx + x, cy - y, colour) ;
}
}
void lcd128x64ellipse (int cx, int cy, int xRadius, int yRadius, int colour, int filled)
{
int x, y ;
int xChange, yChange, ellipseError ;
int twoAsquare, twoBsquare ;
int stoppingX, stoppingY ;
twoAsquare = 2 * xRadius * xRadius ;
twoBsquare = 2 * yRadius * yRadius ;
x = xRadius ;
y = 0 ;
xChange = yRadius * yRadius * (1 - 2 * xRadius) ;
yChange = xRadius * xRadius ;
ellipseError = 0 ;
stoppingX = twoBsquare * xRadius ;
stoppingY = 0 ;
while (stoppingX >= stoppingY) // 1st set of points
{
plot4ellipsePoints (cx, cy, x, y, colour, filled) ;
++y ;
stoppingY += twoAsquare ;
ellipseError += yChange ;
yChange += twoAsquare ;
if ((2 * ellipseError + xChange) > 0 )
{
--x ;
stoppingX -= twoBsquare ;
ellipseError += xChange ;
xChange += twoBsquare ;
}
}
x = 0 ;
y = yRadius ;
xChange = yRadius * yRadius ;
yChange = xRadius * xRadius * (1 - 2 * yRadius) ;
ellipseError = 0 ;
stoppingX = 0 ;
stoppingY = twoAsquare * yRadius ;
while (stoppingX <= stoppingY) //2nd set of points
{
plot4ellipsePoints (cx, cy, x, y, colour, filled) ;
++x ;
stoppingX += twoBsquare ;
ellipseError += xChange ;
xChange += twoBsquare ;
if ((2 * ellipseError + yChange) > 0 )
{
--y ;
stoppingY -= twoAsquare ;
ellipseError += yChange ;
yChange += twoAsquare ;
}
}
}
/*
* lcd128x64putchar:
* Print a single character to the screen
*********************************************************************************
*/
void lcd128x64putchar (int x, int y, int c, int bgCol, int fgCol)
{
int y1, y2 ;
unsigned char line ;
unsigned char *fontPtr ;
// Can't print if we're offscreen
//if ((x < 0) || (x >= (maxX - fontWidth)) || (y < 0) || (y >= (maxY - fontHeight)))
// return ;
fontPtr = font + c * fontHeight ;
for (y1 = fontHeight - 1 ; y1 >= 0 ; --y1)
{
y2 = y + y1 ;
line = *fontPtr++ ;
lcd128x64point (x + 0, y2, (line & 0x80) == 0 ? bgCol : fgCol) ;
lcd128x64point (x + 1, y2, (line & 0x40) == 0 ? bgCol : fgCol) ;
lcd128x64point (x + 2, y2, (line & 0x20) == 0 ? bgCol : fgCol) ;
lcd128x64point (x + 3, y2, (line & 0x10) == 0 ? bgCol : fgCol) ;
lcd128x64point (x + 4, y2, (line & 0x08) == 0 ? bgCol : fgCol) ;
lcd128x64point (x + 5, y2, (line & 0x04) == 0 ? bgCol : fgCol) ;
lcd128x64point (x + 6, y2, (line & 0x02) == 0 ? bgCol : fgCol) ;
lcd128x64point (x + 7, y2, (line & 0x01) == 0 ? bgCol : fgCol) ;
}
}
/*
* lcd128x64puts:
* Send a string to the display. Obeys \n and \r formatting
*********************************************************************************
*/
void lcd128x64puts (int x, int y, const char *str, int bgCol, int fgCol)
{
int c, mx, my ;
mx = x ; my = y ;
while (*str)
{
c = *str++ ;
if (c == '\r')
{
mx = x ;
continue ;
}
if (c == '\n')
{
mx = x ;
my -= fontHeight ;
continue ;
}
lcd128x64putchar (mx, my, c, bgCol, fgCol) ;
mx += fontWidth ;
if (mx >= (maxX - fontWidth))
{
mx = 0 ;
my -= fontHeight ;
}
}
}
/*
* lcd128x64clear:
* Clear the display to the given colour.
*********************************************************************************
*/
void lcd128x64clear (int colour)
{
register int i ;
register unsigned char *ptr = frameBuffer ;
for (i = 0 ; i < (maxX * maxY) ; ++i)
*ptr++ = colour ;
}
/*
* lcd128x64setup:
* Initialise the display and GPIO.
*********************************************************************************
*/
int lcd128x64setup (void)
{
int i ;
for (i = 0 ; i < 8 ; ++i)
pinMode (i, OUTPUT) ;
digitalWrite (CS1, 1) ;
digitalWrite (CS2, 1) ;
digitalWrite (STROBE, 0) ;
digitalWrite (RS, 1) ;
pinMode (CS1, OUTPUT) ;
pinMode (CS2, OUTPUT) ;
pinMode (STROBE, OUTPUT) ;
pinMode (RS, OUTPUT) ;
sendCommand (0x3F, CS1) ; // Display ON
sendCommand (0xC0, CS1) ; // Set display start line to 0
sendCommand (0x3F, CS2) ; // Display ON
sendCommand (0xC0, CS2) ; // Set display start line to 0
lcd128x64clear (0) ;
lcd128x64setOrientation (0) ;
lcd128x64update () ;
return 0 ;
}

View File

@ -0,0 +1,39 @@
/*
* lcd128x64.h:
*
* Copyright (c) 2013 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
extern void lcd128x64setOrigin (int x, int y) ;
extern void lcd128x64setOrientation (int orientation) ;
extern void lcd128x64orientCoordinates (int *x, int *y) ;
extern void lcd128x64getScreenSize (int *x, int *y) ;
extern void lcd128x64point (int x, int y, int colour) ;
extern void lcd128x64line (int x0, int y0, int x1, int y1, int colour) ;
extern void lcd128x64lineTo (int x, int y, int colour) ;
extern void lcd128x64rectangle (int x1, int y1, int x2, int y2, int colour, int filled) ;
extern void lcd128x64circle (int x, int y, int r, int colour, int filled) ;
extern void lcd128x64ellipse (int cx, int cy, int xRadius, int yRadius, int colour, int filled) ;
extern void lcd128x64putchar (int x, int y, int c, int bgCol, int fgCol) ;
extern void lcd128x64puts (int x, int y, const char *str, int bgCol, int fgCol) ;
extern void lcd128x64update (void) ;
extern void lcd128x64clear (int colour) ;
extern int lcd128x64setup (void) ;

238
wiringOP/devLib/maxdetect.c Executable file
View File

@ -0,0 +1,238 @@
/*
* maxdetect.c:
* Driver for the MaxDetect series sensors
*
* Copyright (c) 2013 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <sys/time.h>
#include <stdio.h>
//#include <stdlib.h>
//#include <unistd.h>
#include <wiringPi.h>
#include "maxdetect.h"
#ifndef TRUE
# define TRUE (1==1)
# define FALSE (1==2)
#endif
/*
* maxDetectLowHighWait:
* Wait for a transition from low to high on the bus
*********************************************************************************
*/
static int maxDetectLowHighWait (const int pin)
{
struct timeval now, timeOut, timeUp ;
// If already high then wait for pin to go low
gettimeofday (&now, NULL) ;
timerclear (&timeOut) ;
timeOut.tv_usec = 1000 ;
timeradd (&now, &timeOut, &timeUp) ;
while (digitalRead (pin) == HIGH)
{
gettimeofday (&now, NULL) ;
if (timercmp (&now, &timeUp, >))
return FALSE ;
}
// Wait for it to go HIGH
gettimeofday (&now, NULL) ;
timerclear (&timeOut) ;
timeOut.tv_usec = 1000 ;
timeradd (&now, &timeOut, &timeUp) ;
while (digitalRead (pin) == LOW)
{
gettimeofday (&now, NULL) ;
if (timercmp (&now, &timeUp, >))
return FALSE ;
}
return TRUE ;
}
/*
* maxDetectClockByte:
* Read in a single byte from the MaxDetect bus
*********************************************************************************
*/
static unsigned int maxDetectClockByte (const int pin)
{
unsigned int byte = 0 ;
int bit ;
for (bit = 0 ; bit < 8 ; ++bit)
{
if (!maxDetectLowHighWait (pin))
return 0 ;
// bit starting now - we need to time it.
delayMicroseconds (30) ;
byte <<= 1 ;
if (digitalRead (pin) == HIGH) // It's a 1
byte |= 1 ;
}
return byte ;
}
/*
* maxDetectRead:
* Read in and return the 4 data bytes from the MaxDetect sensor.
* Return TRUE/FALSE depending on the checksum validity
*********************************************************************************
*/
int maxDetectRead (const int pin, unsigned char buffer [4])
{
int i ;
unsigned int checksum ;
unsigned char localBuf [5] ;
struct timeval now, then, took ;
// See how long we took
gettimeofday (&then, NULL) ;
// Wake up the RHT03 by pulling the data line low, then high
// Low for 10mS, high for 40uS.
pinMode (pin, OUTPUT) ;
digitalWrite (pin, 0) ; delay (10) ;
digitalWrite (pin, 1) ; delayMicroseconds (40) ;
pinMode (pin, INPUT) ;
// Now wait for sensor to pull pin low
if (!maxDetectLowHighWait (pin))
return FALSE ;
// and read in 5 bytes (40 bits)
for (i = 0 ; i < 5 ; ++i)
localBuf [i] = maxDetectClockByte (pin) ;
checksum = 0 ;
for (i = 0 ; i < 4 ; ++i)
{
buffer [i] = localBuf [i] ;
checksum += localBuf [i] ;
}
checksum &= 0xFF ;
// See how long we took
gettimeofday (&now, NULL) ;
timersub (&now, &then, &took) ;
// Total time to do this should be:
// 10mS + 40µS - reset
// + 80µS + 80µS - sensor doing its low -> high thing
// + 40 * (50µS + 27µS (0) or 70µS (1) )
// = 15010µS
// so if we take more than that, we've had a scheduling interruption and the
// reading is probably bogus.
if ((took.tv_sec != 0) || (took.tv_usec > 16000))
return FALSE ;
return checksum == localBuf [4] ;
}
/*
* readRHT03:
* Read the Temperature & Humidity from an RHT03 sensor
* Values returned are *10, so 123 is 12.3.
*********************************************************************************
*/
int readRHT03 (const int pin, int *temp, int *rh)
{
static struct timeval then ; // will initialise to zero
static int lastTemp = 0 ;
static int lastRh = 0 ;
int result ;
struct timeval now, timeOut ;
unsigned char buffer [4] ;
// The data sheets say to not read more than once every 2 seconds, so you
// get the last good reading
gettimeofday (&now, NULL) ;
if (timercmp (&now, &then, <))
{
*rh = lastRh ;
*temp = lastTemp ;
return TRUE ;
}
// Set timeout for next read
gettimeofday (&now, NULL) ;
timerclear (&timeOut) ;
timeOut.tv_sec = 2 ;
timeradd (&now, &timeOut, &then) ;
// Read ...
result = maxDetectRead (pin, buffer) ;
if (!result) // Try again, but just once
result = maxDetectRead (pin, buffer) ;
if (!result)
return FALSE ;
*rh = (buffer [0] * 256 + buffer [1]) ;
*temp = (buffer [2] * 256 + buffer [3]) ;
if ((*temp & 0x8000) != 0) // Negative
{
*temp &= 0x7FFF ;
*temp = -*temp ;
}
// Discard obviously bogus readings - the checksum can't detect a 2-bit error
// (which does seem to happen - no realtime here)
if ((*rh > 999) || (*temp > 800) || (*temp < -400))
return FALSE ;
lastRh = *rh ;
lastTemp = *temp ;
return TRUE ;
}

40
wiringOP/devLib/maxdetect.h Executable file
View File

@ -0,0 +1,40 @@
/*
* maxdetect.h:
* Driver for the MaxDetect series sensors
*
* Copyright (c) 2013 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#ifdef __cplusplus
extern "C" {
#endif
// Main generic function
int maxDetectRead (const int pin, unsigned char buffer [4]) ;
// Individual sensors
int readRHT03 (const int pin, int *temp, int *rh) ;
#ifdef __cplusplus
}
#endif

112
wiringOP/devLib/piFace.c Normal file
View File

@ -0,0 +1,112 @@
/*
* piFace.:
* This file to interface with the PiFace peripheral device which
* has an MCP23S17 GPIO device connected via the SPI bus.
*
* Copyright (c) 2012-2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdint.h>
#include <wiringPi.h>
#include <mcp23s17.h>
#include "piFace.h"
/*
* myDigitalWrite:
* Perform the digitalWrite function on the PiFace board
*********************************************************************************
*/
void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
{
digitalWrite (pin + 16, value) ;
}
/*
* myDigitalRead:
* Perform the digitalRead function on the PiFace board
* With a slight twist - if we read from base + 8, then we
* read from the output latch...
*********************************************************************************
*/
int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
{
if ((pin - node->pinBase) >= 8)
return digitalRead (pin + 8) ;
else
return digitalRead (pin + 16 + 8) ;
}
/*
* myPullUpDnControl:
* Perform the pullUpDnControl function on the PiFace board
*********************************************************************************
*/
void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int pud)
{
pullUpDnControl (pin + 16 + 8, pud) ;
}
/*
* piFaceSetup
* We're going to create an instance of the mcp23s17 here, then
* provide our own read/write routines on-top of it...
* The supplied PiFace code (in Pithon) treats it as an 8-bit device
* where you write the output ports and read the input port using the
* same pin numbers, however I have had a request to be able to read
* the output port, so reading 8..15 will read the output latch.
*********************************************************************************
*/
int piFaceSetup (const int pinBase)
{
int i ;
struct wiringPiNodeStruct *node ;
// Create an mcp23s17 instance:
mcp23s17Setup (pinBase + 16, 0, 0) ;
// Set the direction bits
for (i = 0 ; i < 8 ; ++i)
{
pinMode (pinBase + 16 + i, OUTPUT) ; // Port A is the outputs
pinMode (pinBase + 16 + 8 + i, INPUT) ; // Port B inputs.
}
node = wiringPiNewNode (pinBase, 16) ;
node->digitalRead = myDigitalRead ;
node->digitalWrite = myDigitalWrite ;
node->pullUpDnControl = myPullUpDnControl ;
return 0 ;
}

32
wiringOP/devLib/piFace.h Normal file
View File

@ -0,0 +1,32 @@
/*
* piFace.h:
* Control the PiFace Interface board for the Raspberry Pi
* Copyright (c) 2012-2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#ifdef __cplusplus
extern "C" {
#endif
extern int piFaceSetup (const int pinBase) ;
#ifdef __cplusplus
}
#endif

177
wiringOP/devLib/piFaceOld.c Normal file
View File

@ -0,0 +1,177 @@
/*
* piFace.:
* Copyright (c) 2012-2016 Gordon Henderson
*
* This file to interface with the PiFace peripheral device which
* has an MCP23S17 GPIO device connected via the SPI bus.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdint.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>
#include "../wiringPi/mcp23x0817.h"
#include "piFace.h"
#define PIFACE_SPEED 4000000
#define PIFACE_DEVNO 0
/*
* writeByte:
* Write a byte to a register on the MCP23S17 on the SPI bus.
*********************************************************************************
*/
static void writeByte (uint8_t reg, uint8_t data)
{
uint8_t spiData [4] ;
spiData [0] = CMD_WRITE ;
spiData [1] = reg ;
spiData [2] = data ;
wiringPiSPIDataRW (PIFACE_DEVNO, spiData, 3) ;
}
/*
* readByte:
* Read a byte from a register on the MCP23S17 on the SPI bus.
*********************************************************************************
*/
static uint8_t readByte (uint8_t reg)
{
uint8_t spiData [4] ;
spiData [0] = CMD_READ ;
spiData [1] = reg ;
wiringPiSPIDataRW (PIFACE_DEVNO, spiData, 3) ;
return spiData [2] ;
}
/*
* myDigitalWrite:
* Perform the digitalWrite function on the PiFace board
*********************************************************************************
*/
void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
{
uint8_t mask, old ;
pin -= node->pinBase ;
mask = 1 << pin ;
old = readByte (MCP23x17_GPIOA) ;
if (value == 0)
old &= (~mask) ;
else
old |= mask ;
writeByte (MCP23x17_GPIOA, old) ;
}
/*
* myDigitalRead:
* Perform the digitalRead function on the PiFace board
*********************************************************************************
*/
int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
{
uint8_t mask, reg ;
mask = 1 << ((pin - node->pinBase) & 7) ;
if (pin < 8)
reg = MCP23x17_GPIOB ; // Input regsiter
else
reg = MCP23x17_OLATA ; // Output latch regsiter
if ((readByte (reg) & mask) != 0)
return HIGH ;
else
return LOW ;
}
/*
* myPullUpDnControl:
* Perform the pullUpDnControl function on the PiFace board
*********************************************************************************
*/
void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int pud)
{
uint8_t mask, old ;
mask = 1 << (pin - node->pinBase) ;
old = readByte (MCP23x17_GPPUB) ;
if (pud == 0)
old &= (~mask) ;
else
old |= mask ;
writeByte (MCP23x17_GPPUB, old) ;
}
/*
* piFaceSetup
* Setup the SPI interface and initialise the MCP23S17 chip
* We create one node with 16 pins - each if the first 8 pins being read
* and write - although the operations actually go to different
* hardware ports. The top 8 let you read the state of the output register.
*********************************************************************************
*/
int piFaceSetup (const int pinBase)
{
int x ;
struct wiringPiNodeStruct *node ;
if ((x = wiringPiSPISetup (PIFACE_DEVNO, PIFACE_SPEED)) < 0)
return x ;
// Setup the MCP23S17
writeByte (MCP23x17_IOCON, IOCON_INIT) ;
writeByte (MCP23x17_IODIRA, 0x00) ; // Port A -> Outputs
writeByte (MCP23x17_IODIRB, 0xFF) ; // Port B -> Inputs
node = wiringPiNewNode (pinBase, 16) ;
node->digitalRead = myDigitalRead ;
node->digitalWrite = myDigitalWrite ;
node->pullUpDnControl = myPullUpDnControl ;
return 0 ;
}

118
wiringOP/devLib/piGlow.c Normal file
View File

@ -0,0 +1,118 @@
/*
* piGlow.c:
* Easy access to the Pimoroni PiGlow board.
*
* Copyright (c) 2013 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <wiringPi.h>
#include <sn3218.h>
#include "piGlow.h"
#define PIGLOW_BASE 577
static int leg0 [6] = { 6, 7, 8, 5, 4, 9 } ;
static int leg1 [6] = { 17, 16, 15, 13, 11, 10 } ;
static int leg2 [6] = { 0, 1, 2, 3, 14, 12 } ;
/*
* piGlow1:
* Light up an individual LED
*********************************************************************************
*/
void piGlow1 (const int leg, const int ring, const int intensity)
{
int *legLeds ;
if ((leg < 0) || (leg > 2)) return ;
if ((ring < 0) || (ring > 5)) return ;
/**/ if (leg == 0)
legLeds = leg0 ;
else if (leg == 1)
legLeds = leg1 ;
else
legLeds = leg2 ;
analogWrite (PIGLOW_BASE + legLeds [ring], intensity) ;
}
/*
* piGlowLeg:
* Light up all 6 LEDs on a leg
*********************************************************************************
*/
void piGlowLeg (const int leg, const int intensity)
{
int i ;
int *legLeds ;
if ((leg < 0) || (leg > 2))
return ;
/**/ if (leg == 0)
legLeds = leg0 ;
else if (leg == 1)
legLeds = leg1 ;
else
legLeds = leg2 ;
for (i = 0 ; i < 6 ; ++i)
analogWrite (PIGLOW_BASE + legLeds [i], intensity) ;
}
/*
* piGlowRing:
* Light up 3 LEDs in a ring. Ring 0 is the outermost, 5 the innermost
*********************************************************************************
*/
void piGlowRing (const int ring, const int intensity)
{
if ((ring < 0) || (ring > 5))
return ;
analogWrite (PIGLOW_BASE + leg0 [ring], intensity) ;
analogWrite (PIGLOW_BASE + leg1 [ring], intensity) ;
analogWrite (PIGLOW_BASE + leg2 [ring], intensity) ;
}
/*
* piGlowSetup:
* Initialise the board & remember the pins we're using
*********************************************************************************
*/
void piGlowSetup (int clear)
{
sn3218Setup (PIGLOW_BASE) ;
if (clear)
{
piGlowLeg (0, 0) ;
piGlowLeg (1, 0) ;
piGlowLeg (2, 0) ;
}
}

45
wiringOP/devLib/piGlow.h Normal file
View File

@ -0,0 +1,45 @@
/*
* piglow.h:
* Easy access to the Pimoroni PiGlow board.
*
* Copyright (c) 2013 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#define PIGLOW_RED 0
#define PIGLOW_ORANGE 1
#define PIGLOW_YELLOW 2
#define PIGLOW_GREEN 3
#define PIGLOW_BLUE 4
#define PIGLOW_WHITE 5
#ifdef __cplusplus
extern "C" {
#endif
extern void piGlow1 (const int leg, const int ring, const int intensity) ;
extern void piGlowLeg (const int leg, const int intensity) ;
extern void piGlowRing (const int ring, const int intensity) ;
extern void piGlowSetup (int clear) ;
#ifdef __cplusplus
}
#endif

113
wiringOP/devLib/piNes.c Normal file
View File

@ -0,0 +1,113 @@
/*
* piNes.c:
* Driver for the NES Joystick controller on the Raspberry Pi
* Copyright (c) 2012 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <wiringPi.h>
#include "piNes.h"
#define MAX_NES_JOYSTICKS 8
#define NES_RIGHT 0x01
#define NES_LEFT 0x02
#define NES_DOWN 0x04
#define NES_UP 0x08
#define NES_START 0x10
#define NES_SELECT 0x20
#define NES_B 0x40
#define NES_A 0x80
#define PULSE_TIME 25
// Data to store the pins for each controller
struct nesPinsStruct
{
unsigned int cPin, dPin, lPin ;
} ;
static struct nesPinsStruct nesPins [MAX_NES_JOYSTICKS] ;
static int joysticks = 0 ;
/*
* setupNesJoystick:
* Create a new NES joystick interface, program the pins, etc.
*********************************************************************************
*/
int setupNesJoystick (int dPin, int cPin, int lPin)
{
if (joysticks == MAX_NES_JOYSTICKS)
return -1 ;
nesPins [joysticks].dPin = dPin ;
nesPins [joysticks].cPin = cPin ;
nesPins [joysticks].lPin = lPin ;
digitalWrite (lPin, LOW) ;
digitalWrite (cPin, LOW) ;
pinMode (lPin, OUTPUT) ;
pinMode (cPin, OUTPUT) ;
pinMode (dPin, INPUT) ;
return joysticks++ ;
}
/*
* readNesJoystick:
* Do a single scan of the NES Joystick.
*********************************************************************************
*/
unsigned int readNesJoystick (int joystick)
{
unsigned int value = 0 ;
int i ;
struct nesPinsStruct *pins = &nesPins [joystick] ;
// Toggle Latch - which presents the first bit
digitalWrite (pins->lPin, HIGH) ; delayMicroseconds (PULSE_TIME) ;
digitalWrite (pins->lPin, LOW) ; delayMicroseconds (PULSE_TIME) ;
// Read first bit
value = digitalRead (pins->dPin) ;
// Now get the next 7 bits with the clock
for (i = 0 ; i < 7 ; ++i)
{
digitalWrite (pins->cPin, HIGH) ; delayMicroseconds (PULSE_TIME) ;
digitalWrite (pins->cPin, LOW) ; delayMicroseconds (PULSE_TIME) ;
value = (value << 1) | digitalRead (pins->dPin) ;
}
return value ^ 0xFF ;
}

45
wiringOP/devLib/piNes.h Normal file
View File

@ -0,0 +1,45 @@
/*
* piNes.h:
* Driver for the NES Joystick controller on the Raspberry Pi
* Copyright (c) 2012 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#define MAX_NES_JOYSTICKS 8
#define NES_RIGHT 0x01
#define NES_LEFT 0x02
#define NES_DOWN 0x04
#define NES_UP 0x08
#define NES_START 0x10
#define NES_SELECT 0x20
#define NES_B 0x40
#define NES_A 0x80
#ifdef __cplusplus
extern "C" {
#endif
extern int setupNesJoystick (int dPin, int cPin, int lPin) ;
extern unsigned int readNesJoystick (int joystick) ;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,430 @@
/*
* scrollPhat.c:
* Simple driver for the Pimoroni Scroll Phat device
*
* Copyright (c) 2015 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include <wiringPiI2C.h>
#include "scrollPhatFont.h"
#include "scrollPhat.h"
// Size
#define SP_WIDTH 11
#define SP_HEIGHT 5
// I2C
#define PHAT_I2C_ADDR 0x60
// Software copy of the framebuffer
// it's 8-bit deep although the display itself is only 1-bit deep.
static unsigned char frameBuffer [SP_WIDTH * SP_HEIGHT] ;
static int lastX, lastY ;
static int printDelayFactor ;
static int scrollPhatFd ;
static int putcharX ;
#undef DEBUG
/*
* delay:
* Wait for some number of milliseconds.
* This taken from wiringPi as there is no-need to include the whole of
* wiringPi just for the delay function.
*********************************************************************************
*/
static void delay (unsigned int howLong)
{
struct timespec sleeper, dummy ;
sleeper.tv_sec = (time_t)(howLong / 1000) ;
sleeper.tv_nsec = (long)(howLong % 1000) * 1000000 ;
nanosleep (&sleeper, &dummy) ;
}
/*
* scrollPhatUpdate:
* Copy our software version to the real display
*********************************************************************************
*/
void scrollPhatUpdate (void)
{
register int x, y ;
register unsigned char data, pixel ;
unsigned char pixels [SP_WIDTH] ;
#ifdef DEBUG
printf ("+-----------+\n") ;
for (y = 0 ; y < SP_HEIGHT ; ++y)
{
putchar ('|') ;
for (x = 0 ; x < SP_WIDTH ; ++x)
{
pixel = frameBuffer [x + y * SP_WIDTH] ;
putchar (pixel == 0 ? ' ' : '*') ;
}
printf ("|\n") ;
}
printf ("+-----------+\n") ;
#endif
for (x = 0 ; x < SP_WIDTH ; ++x)
{
data = 0 ;
for (y = 0 ; y < SP_HEIGHT ; ++y)
{
pixel = frameBuffer [x + y * SP_WIDTH] ;
data = (data << 1) | ((pixel == 0) ? 0 : 1) ;
}
pixels [x] = data ;
}
for (x = 0 ; x < SP_WIDTH ; ++x)
wiringPiI2CWriteReg8 (scrollPhatFd, 1 + x, pixels [x]) ;
wiringPiI2CWriteReg8 (scrollPhatFd, 0x0C, 0) ;
}
/*
*********************************************************************************
* Standard Graphical Functions
*********************************************************************************
*/
/*
* scrollPhatPoint:
* Plot a pixel. Crude clipping - speed is not the essence here.
*********************************************************************************
*/
void scrollPhatPoint (int x, int y, int colour)
{
lastX = x ;
lastY = y ;
if ((x < 0) || (x >= SP_WIDTH) || (y < 0) || (y >= SP_HEIGHT))
return ;
frameBuffer [x + y * SP_WIDTH] = colour ;
}
/*
* scrollPhatLine: scrollPhatLineTo:
* Classic Bressenham Line code - rely on the point function to do the
* clipping for us here.
*********************************************************************************
*/
void scrollPhatLine (int x0, int y0, int x1, int y1, int colour)
{
int dx, dy ;
int sx, sy ;
int err, e2 ;
lastX = x1 ;
lastY = y1 ;
dx = abs (x1 - x0) ;
dy = abs (y1 - y0) ;
sx = (x0 < x1) ? 1 : -1 ;
sy = (y0 < y1) ? 1 : -1 ;
err = dx - dy ;
for (;;)
{
scrollPhatPoint (x0, y0, colour) ;
if ((x0 == x1) && (y0 == y1))
break ;
e2 = 2 * err ;
if (e2 > -dy)
{
err -= dy ;
x0 += sx ;
}
if (e2 < dx)
{
err += dx ;
y0 += sy ;
}
}
}
void scrollPhatLineTo (int x, int y, int colour)
{
scrollPhatLine (lastX, lastY, x, y, colour) ;
}
/*
* scrollPhatRectangle:
* A rectangle is a spoilt days fishing
*********************************************************************************
*/
void scrollPhatRectangle (int x1, int y1, int x2, int y2, int colour, int filled)
{
register int x ;
if (filled)
{
/**/ if (x1 == x2)
scrollPhatLine (x1, y1, x2, y2, colour) ;
else if (x1 < x2)
for (x = x1 ; x <= x2 ; ++x)
scrollPhatLine (x, y1, x, y2, colour) ;
else
for (x = x2 ; x <= x1 ; ++x)
scrollPhatLine (x, y1, x, y2, colour) ;
}
else
{
scrollPhatLine (x1, y1, x2, y1, colour) ;
scrollPhatLineTo (x2, y2, colour) ;
scrollPhatLineTo (x1, y2, colour) ;
scrollPhatLineTo (x1, y1, colour) ;
}
}
/*
* scrollPhatPutchar:
* Print a single character to the screen then advance the pointer by an
* appropriate ammount (variable width font).
* We rely on the clipping done by the pixel plot function to keep us
* out of trouble.
* Return the width + space
*********************************************************************************
*/
int scrollPhatPutchar (int c)
{
register int x, y ;
unsigned char line ;
unsigned char *fontPtr ;
unsigned char *p2 ;
int lineWidth, width, mask ;
// The font is printable characters, uppercase only...
// and somewhat varaible width...
c &= 0x7F ;
if (c > 0x60)
c -= 64 ;
else
c -= 32 ;
fontPtr = scrollPhatFont + c * fontHeight ;
// Work out width of this character
// There probably is a more efficient way to do this, but...
p2 = fontPtr ;
width = 0 ;
for (y = 0 ; y < fontHeight ; ++y)
{
mask = 0x80 ;
for (lineWidth = 8 ; lineWidth > 0 ; --lineWidth)
{
if ((*p2 & mask) != 0)
break ;
mask >>= 1 ;
}
if (lineWidth > width)
width = lineWidth ;
++p2 ;
}
if (width == 0) // Likely to be a blank or space character
width = 3 ;
for (y = fontHeight - 1 ; y >= 0 ; --y)
{
x = 0 ;
line = *fontPtr++ ;
for (mask = 1 << (width - 1) ; mask != 0 ; mask >>= 1)
{
scrollPhatPoint (putcharX + x, y, (line & mask)) ;
++x ;
}
}
// make a line of space
for (y = fontHeight - 1 ; y >= 0 ; --y)
scrollPhatPoint (putcharX + width, y, 0) ;
putcharX = putcharX + width + 1 ;
return width + 1 ;
}
/*
* scrollPhatPuts:
* Send a string to the display - and scroll it across.
* This is somewhat of a hack in that we print the entire string to the
* display and let the point clipping take care of what's off-screen...
*********************************************************************************
*/
void scrollPhatPuts (const char *str)
{
int i ;
int movingX = 0 ;
const char *s ;
int pixelLen ;
// Print it once, then we know the width in pixels...
putcharX = 0 ;
s = str ;
while (*s)
scrollPhatPutchar (*s++) ;
pixelLen = putcharX ;
// Now scroll it by printing it and moving left one pixel
movingX = 0 ;
for (i = 0 ; i < pixelLen ; ++i)
{
putcharX = movingX ;
s = str ;
while (*s)
scrollPhatPutchar (*s++) ;
--movingX ;
scrollPhatUpdate () ;
delay (printDelayFactor) ;
}
}
/*
* scrollPhatPrintf:
* Does what it says
*********************************************************************************
*/
void scrollPhatPrintf (const char *message, ...)
{
va_list argp ;
char buffer [1024] ;
va_start (argp, message) ;
vsnprintf (buffer, 1023, message, argp) ;
va_end (argp) ;
scrollPhatPuts (buffer) ;
}
/*
* scrollPhatPrintSpeed:
* Change the print speed - mS per shift by 1 pixel
*********************************************************************************
*/
void scrollPhatPrintSpeed (const int pps)
{
if (pps < 0)
printDelayFactor = 0 ;
else
printDelayFactor = pps ;
}
/*
* scrollPhatClear:
* Clear the display
*********************************************************************************
*/
void scrollPhatClear (void)
{
register int i ;
register unsigned char *ptr = frameBuffer ;
for (i = 0 ; i < (SP_WIDTH * SP_HEIGHT) ; ++i)
*ptr++ = 0 ;
scrollPhatUpdate () ;
}
/*
* scrollPhatIntensity:
* Set the display brightness - percentage
*********************************************************************************
*/
void scrollPhatIntensity (const int percent)
{
wiringPiI2CWriteReg8 (scrollPhatFd, 0x19, (127 * percent) / 100) ;
}
/*
* scrollPhatSetup:
* Initialise the Scroll Phat display
*********************************************************************************
*/
int scrollPhatSetup (void)
{
if ((scrollPhatFd = wiringPiI2CSetup (PHAT_I2C_ADDR)) < 0)
return scrollPhatFd ;
wiringPiI2CWriteReg8 (scrollPhatFd, 0x00, 0x03) ; // Enable display, set to 5x11 mode
scrollPhatIntensity (10) ;
scrollPhatClear () ;
scrollPhatPrintSpeed (100) ;
return 0 ;
}

View File

@ -0,0 +1,39 @@
/*
* scrollPhat.h:
* Simple driver for the Pimoroni Scroll Phat device
*
* Copyright (c) 2015 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
extern void scrollPhatPoint (int x, int y, int colour) ;
extern void scrollPhatLine (int x0, int y0, int x1, int y1, int colour) ;
extern void scrollPhatLineTo (int x, int y, int colour) ;
extern void scrollPhatRectangle (int x1, int y1, int x2, int y2, int colour, int filled) ;
extern void scrollPhatUpdate (void) ;
extern void scrollPhatClear (void) ;
extern int scrollPhatPutchar (int c) ;
//extern void scrollPhatPutchar (int c) ;
extern void scrollPhatPuts (const char *str) ;
extern void scrollPhatPrintf (const char *message, ...) ;
extern void scrollPhatPrintSpeed (const int cps10) ;
extern void scrollPhatIntensity (const int percent) ;
extern int scrollPhatSetup (void) ;

View File

@ -0,0 +1,544 @@
/*
* scrollPhatFont.h:
* Simple font for the Pimoroni Scroll Phat.
* Note: this is a very much reduced font - 5 pixels high and
* mostly 4 pixels wide - sometimes 5. Also only
* printable characters from space to _ uppercase only.
*
* Copyright (c) 2015-2016 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
static const int fontHeight = 5 ;
static unsigned char scrollPhatFont [] =
{
// 0x20, Space. Handeled as a special case in the code.
0x0, // ....
0x0, // ....
0x0, // ....
0x0, // ....
0x0, // ....
// 0x21, !
0x1, // *
0x1, // *
0x1, // *
0x0, // .
0x1, // *
// 0x22, "
0x5, // *..*
0x5, // *..*
0x0, // ....
0x0, // ....
0x0, // ....
// 0x23, #
0x9, // *..*
0xF, // ****
0x9, // *..*
0xF, // ****
0x9, // *..*
// 0x24, $
0x1, // ..*.
0x7, // .***
0x2, // ..*.
0xE, // ***.
0x8, // ..*.
// 0x25, %
0x9, // *..*
0x1, // ...*
0x6, // .**.
0x8, // *...
0x9, // *..*
// 0x26, &
0x6, // .**.
0x8, // *...
0x4, // .*..
0xA, // *.*.
0x5, // .*.*
// 0x27, '
0x1, // .*
0x2, // *.
0x0, // ..
0x0, // ..
0x0, // ..
// 0x28, (
0x3, // ..**
0x4, // .*..
0x8, // *...
0x4, // .*..
0x3, // ..**
// 0x29, )
0xC, // **..
0x2, // ..*.
0x1, // ...*
0x2, // ..*.
0xC, // **..
// 0x2A, *
0x9, // *..*
0x6, // .**.
0xF, // ****
0x6, // .**.
0x9, // *..*
// 0x2B, +
0x6, // .**.
0x6, // .**.
0xF, // ****
0x6, // .**.
0x6, // .**.
// 0x2C, ,
0x0, // ..
0x0, // ..
0x0, // ..
0x1, // .*
0x2, // *.
// 0x2D, -
0x0, // ....
0x0, // ....
0xF, // ****
0x0, // ....
0x0, // ....
// 0x2E, .
0x0, // .
0x0, // .
0x0, // .
0x0, // .
0x1, // *
// 0x2F, /
0x1, // ...*
0x3, // ..**
0x4, // ..*.
0xC, // **..
0x8, // *...
// 0x30, 0
0x6, // .**.
0x9, // *..*
0x9, // *..*
0x9, // *..*
0x6, // .**.
// 0x31, 1
0x2, // ..*.
0x6, // .**.
0x2, // ..*.
0x2, // ..*.
0x7, // .***
// 0x32, 2
0x6, // .**.
0x1, // ...*
0x6, // .**.
0x8, // *...
0xF, // ****
// 0x33, 3
0xE, // ***.
0x1, // ...*
0xE, // ***.
0x1, // ...*
0xE, // ***.
// 0x34, 4
0x6, // .**.
0xA, // *.*.
0xF, // ****
0x2, // ..*.
0x2, // ..*.
// 0x35, 5
0xF, // ****
0x8, // *...
0xF, // ****
0x1, // ...*
0xE, // ***.
// 0x36, 6
0x2, // ..*.
0x4, // .*..
0xA, // *.*.
0x9, // *..*
0x6, // .**.
// 0x37, 7
0xF, // ****
0x1, // ...*
0x2, // ..*.
0x4, // .*..
0x8, // *...
// 0x38, 8
0x6, // .**.
0x9, // *..*
0x6, // .**.
0x9, // *..*
0x6, // .**.
// 0x39, 9
0x6, // .**.
0x9, // *..*
0x7, // .*.*
0x1, // ..*.
0x2, // .*..
// 0x3A, :
0x0, // .
0x1, // *
0x0, // .
0x1, // *
0x0, // .
// 0x3B, ;
0x0, // ..
0x1, // .*
0x0, // ..
0x1, // .*
0x2, // *.
// 0x3C, <
0x2, // ..*.
0x4, // .*..
0x8, // *...
0x4, // .*..
0x2, // ..*.
// 0x3D, =
0x0, // ....
0xF, // ****
0x0, // ....
0xF, // ****
0x0, // ....
// 0x3E, >
0x0, // .*..
0x0, // ..*.
0x0, // ...*
0x0, // ..*.
0x0, // .*..
// 0x3F, ?
0x6, // .**.
0x1, // ...*
0x2, // ..*.
0x0, // ....
0x2, // ..*.
// 0x40, @
0x6, // .**.
0xD, // **.*
0x8, // *...
0x4, // .*..
0x3, // ..**
// 0x41, A
0x6, // .**.
0x9, // *..*
0xF, // ****
0x9, // *..*
0x9, // *..*
// 0x42, B
0xE, // ***.
0x9, // *..*
0xE, // ***.
0x9, // *..*
0xE, // ***.
// 0x43, C
0x6, // .**.
0x9, // *..*
0x8, // *...
0x9, // *..*
0x6, // .**.
// 0x44, D
0xE, // ***.
0x9, // *..*
0x9, // *..*
0x9, // *..*
0xE, // ***.
// 0x45, E
0xF, // ****
0x8, // *...
0xE, // ***.
0x8, // *...
0xF, // ****
// 0x46, F
0xF, // ****
0x8, // *...
0xE, // ***.
0x8, // *...
0x8, // *...
// 0x47, G
0x6, // .**.
0x9, // *..*
0x8, // *...
0xB, // *.**
0x6, // .**.
// 0x48, H
0x9, // *..*
0x9, // *..*
0xF, // ****
0x9, // *..*
0x9, // *..*
// 0x49, I
0x7, // ***
0x2, // .*.
0x2, // .*.
0x2, // .*.
0x7, // ***
// 0x4A, J
0x7, // .***
0x2, // ..*.
0x2, // ..*.
0xA, // *.*.
0x4, // .*..
// 0x4B, K
0x9, // *..*
0xA, // *.*.
0xC, // **..
0xA, // *.*.
0x9, // *..*
// 0x4C, L
0x4, // *..
0x4, // *..
0x4, // *..
0x4, // *..
0x7, // ***
// 0x4D, M
0x11, // *...*
0x1B, // **.**
0x15, // *.*.*
0x11, // *...*
0x11, // *...*
// 0x4E, N
0x9, // *..*
0xD, // **.*
0xB, // *.**
0x9, // *..*
0x9, // *..*
// 0x4F, O
0x6, // .**.
0x9, // *..*
0x9, // *..*
0x9, // *..*
0x6, // .**.
// 0x50, P
0xE, // ***.
0x9, // *..*
0xE, // ***.
0x8, // *...
0x8, // *...
// 0x51, Q
0x6, // .**.
0x9, // *..*
0x9, // *..*
0xA, // *.*.
0x5, // .*.*
// 0x52, R
0xE, // ***.
0x9, // *..*
0xF, // ***.
0xA, // *.*.
0x9, // *..*
// 0x53, S
0x6, // .**.
0x8, // *...
0x6, // .**.
0x1, // ...*
0x6, // .**.
// 0x54, T
0x7, // .***
0x2, // ..*.
0x2, // ..*.
0x2, // ..*.
0x2, // ..*.
// 0x55, U
0x9, // *..*
0x9, // *..*
0x9, // *..*
0x9, // *..*
0x6, // .**.
// 0x56, V
0x11, // *...*
0x11, // *...*
0x11, // *...*
0x0A, // .*.*.
0x04, // ..*..
// 0x57, W
0x11, // *...*
0x11, // *...*
0x11, // *...*
0x15, // *.*.*
0x1B, // **.**
// 0x58, X
0x9, // *..*
0x9, // *..*
0x6, // .**.
0x9, // *..*
0x9, // *..*
// 0x59, Y
0x11, // *...*
0x0A, // .*.*.
0x04, // ..*..
0x04, // ..*..
0x04, // ..*..
// 0x5A, Z
0xF, // ****
0x1, // ...*
0x6, // .**.
0x8, // *...
0xF, // ****
// 0x5B, [
0xE, // ***.
0x8, // *...
0x8, // *...
0x8, // *...
0xE, // ***.
// 0x5C, Backslash
0x8, // *...
0xC, // **..
0x6, // .**.
0x3, // ..**
0x1, // ...*
// 0x5D, ]
0x7, // .***
0x1, // ...*
0x1, // ...*
0x1, // ...*
0x7, // .***
// 0x5E, ^
0x6, // .**.
0x9, // *..*
0x0, // ....
0x0, // ....
0x0, // ....
// 0x5F, _
0x0, // ....
0x0, // ....
0x0, // ....
0x0, // ....
0xF, // ****
} ;

View File

@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

View File

@ -0,0 +1,221 @@
/*
* 7segments.c:
* Simple test program to see if we can drive a 7-segment LED
* display using the GPIO and little else on the Raspberry Pi
*
* Copyright (c) 2013 Gordon Henderson
***********************************************************************
*/
#undef PHOTO_HACK
#include <wiringPi.h>
#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
/*
* Segment mapping
*
* --a--
* | |
* f b
* | |
* --g--
* | |
* e c
* | |
* --d-- p
*/
// GPIO Pin Mapping
static int digits [6] = { 7, 11, 10, 13, 12, 14 } ;
static int segments [7] = { 6, 5, 4, 3, 2, 1, 0 } ;
static const int segmentDigits [] =
{
// a b c d e f g Segments
// 6 5 4 3 2 1 0, // wiringPi pin No.
1, 1, 1, 1, 1, 1, 0, // 0
0, 1, 1, 0, 0, 0, 0, // 1
1, 1, 0, 1, 1, 0, 1, // 2
1, 1, 1, 1, 0, 0, 1, // 3
0, 1, 1, 0, 0, 1, 1, // 4
1, 0, 1, 1, 0, 1, 1, // 5
1, 0, 1, 1, 1, 1, 1, // 6
1, 1, 1, 0, 0, 0, 0, // 7
1, 1, 1, 1, 1, 1, 1, // 8
1, 1, 1, 1, 0, 1, 1, // 9
1, 1, 1, 0, 1, 1, 1, // A
0, 0, 1, 1, 1, 1, 1, // b
1, 0, 0, 1, 1, 1, 0, // C
0, 1, 1, 1, 1, 0, 1, // d
1, 0, 0, 1, 1, 1, 1, // E
1, 0, 0, 0, 1, 1, 1, // F
0, 0, 0, 0, 0, 0, 0, // blank
} ;
// display:
// A global variable which is written to by the main program and
// read from by the thread that updates the display. Only the first
// 6 characters are used.
char display [8] ;
/*
* displayDigits:
* This is our thread that's run concurrently with the main program.
* Essentially sit in a loop, parsing and displaying the data held in
* the "display" global.
*********************************************************************************
*/
PI_THREAD (displayDigits)
{
int digit, segment ;
int index, d, segVal ;
piHiPri (50) ;
for (;;)
{
for (digit = 0 ; digit < 6 ; ++digit)
{
for (segment = 0 ; segment < 7 ; ++segment)
{
d = toupper (display [digit]) ;
/**/ if ((d >= '0') && (d <= '9')) // Digit
index = d - '0' ;
else if ((d >= 'A') && (d <= 'F')) // Hex
index = d - 'A' + 10 ;
else
index = 16 ; // Blank
segVal = segmentDigits [index * 7 + segment] ;
digitalWrite (segments [segment], segVal) ;
}
digitalWrite (digits [digit], 1) ;
delay (2) ;
digitalWrite (digits [digit], 0) ;
}
}
}
/*
* setup:
* Initialise the hardware and start the thread
*********************************************************************************
*/
void setup (void)
{
int i, c ;
wiringPiSetup () ;
// 7 segments
for (i = 0 ; i < 7 ; ++i)
{ digitalWrite (segments [i], 0) ; pinMode (segments [i], OUTPUT) ; }
// 6 digits
for (i = 0 ; i < 6 ; ++i)
{ digitalWrite (digits [i], 0) ; pinMode (digits [i], OUTPUT) ; }
strcpy (display, " ") ;
piThreadCreate (displayDigits) ;
delay (10) ; // Just to make sure it's started
// Quick countdown LED test sort of thing
c = 999999 ;
for (i = 0 ; i < 10 ; ++i)
{
sprintf (display, "%06d", c) ;
delay (400) ;
c -= 111111 ;
}
strcpy (display, " ") ;
delay (400) ;
#ifdef PHOTO_HACK
sprintf (display, "%s", "123456") ;
for (;;)
delay (1000) ;
#endif
}
/*
* teenager:
* No explanation needed. (Nor one given!)
*********************************************************************************
*/
void teenager (void)
{
char *message = " feedbeef babe cafe b00b " ;
int i ;
for (i = 0 ; i < strlen (message) - 4 ; ++i)
{
strncpy (display, &message [i], 6) ;
delay (200) ;
}
delay (1000) ;
for (i = 0 ; i < 3 ; ++i)
{
strcpy (display, " ") ;
delay (150) ;
strcpy (display, " b00b ") ;
delay (250) ;
}
delay (1000) ;
strcpy (display, " ") ;
delay (1000) ;
}
/*
*********************************************************************************
* main:
* Let the fun begin
*********************************************************************************
*/
int main (void)
{
struct tm *t ;
time_t tim ;
setup () ;
teenager () ;
tim = time (NULL) ;
for (;;)
{
while (time (NULL) == tim)
delay (5) ;
tim = time (NULL) ;
t = localtime (&tim) ;
sprintf (display, "%02d%02d%02d", t->tm_hour, t->tm_min, t->tm_sec) ;
delay (500) ;
}
return 0 ;
}

View File

@ -0,0 +1,78 @@
#
# Makefile:
# Gertboard - Examples using wiringPi
#
# Copyright (c) 2013 Gordon Henderson
#################################################################################
ifneq ($V,1)
Q ?= @
endif
#DEBUG = -g -O0
DEBUG = -O3
CC = gcc
INCLUDE = -I/usr/local/include
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
LDFLAGS = -L/usr/local/lib
LDLIBS = -lwiringPi -lwiringPiDev -lpthread -lm
# Should not alter anything below this line
###############################################################################
SRC = gertboard.c \
buttons.c 7segments.c \
voltmeter.c temperature.c vumeter.c \
record.c
OBJ = $(SRC:.c=.o)
BINS = $(SRC:.c=)
all: $(BINS)
gertboard: gertboard.o
$Q echo [link]
$Q $(CC) -o $@ gertboard.o $(LDFLAGS) $(LDLIBS)
buttons: buttons.o
$Q echo [link]
$Q $(CC) -o $@ buttons.o $(LDFLAGS) $(LDLIBS)
7segments: 7segments.o
$Q echo [link]
$Q $(CC) -o $@ 7segments.o $(LDFLAGS) $(LDLIBS)
voltmeter: voltmeter.o
$Q echo [link]
$Q $(CC) -o $@ voltmeter.o $(LDFLAGS) $(LDLIBS)
temperature: temperature.o
$Q echo [link]
$Q $(CC) -o $@ temperature.o $(LDFLAGS) $(LDLIBS)
vumeter: vumeter.o
$Q echo [link]
$Q $(CC) -o $@ vumeter.o $(LDFLAGS) $(LDLIBS)
record: record.o
$Q echo [link]
$Q $(CC) -o $@ record.o $(LDFLAGS) $(LDLIBS)
.c.o:
$Q echo [CC] $<
$Q $(CC) -c $(CFLAGS) $< -o $@
clean:
$Q echo [Clean]
$Q rm -f $(OBJ) *~ core tags $(BINS)
tags: $(SRC)
$Q echo [ctags]
$Q ctags $(SRC)
depend:
makedepend -Y $(SRC)
# DO NOT DELETE

View File

@ -0,0 +1,83 @@
/*
* buttons.c:
* Read the Gertboard buttons. Each one will act as an on/off
* tiggle switch for 3 different LEDs
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <wiringPi.h>
// Array to keep track of our LEDs
int leds [] = { 0, 0, 0 } ;
// scanButton:
// See if a button is pushed, if so, then flip that LED and
// wait for the button to be let-go
void scanButton (int button)
{
if (digitalRead (button) == HIGH) // Low is pushed
return ;
leds [button] ^= 1 ; // Invert state
digitalWrite (4 + button, leds [button]) ;
while (digitalRead (button) == LOW) // Wait for release
delay (10) ;
}
int main (void)
{
int i ;
printf ("Raspberry Pi Gertboard Button Test\n") ;
wiringPiSetup () ;
// Setup the outputs:
// Pins 3, 4, 5, 6 and 7 output:
// We're not using 3 or 4, but make sure they're off anyway
// (Using same hardware config as blink12.c)
for (i = 3 ; i < 8 ; ++i)
{
pinMode (i, OUTPUT) ;
digitalWrite (i, 0) ;
}
// Setup the inputs
for (i = 0 ; i < 3 ; ++i)
{
pinMode (i, INPUT) ;
pullUpDnControl (i, PUD_UP) ;
leds [i] = 0 ;
}
for (;;)
{
for (i = 0 ; i < 3 ; ++i)
scanButton (i) ;
delay (1) ;
}
}

View File

@ -0,0 +1,96 @@
/*
* gertboard.c:
* Simple test for the SPI bus on the Gertboard
*
* Hardware setup:
* D/A port 0 jumpered to A/D port 0.
*
* We output a sine wave on D/A port 0 and sample A/D port 0. We then
* plot the input value on the terminal as a sort of vertical scrolling
* oscilloscipe.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <math.h>
// Gertboard D to A is an 8-bit unit.
#define B_SIZE 256
#include <wiringPi.h>
#include <gertboard.h>
int main (void)
{
double angle ;
int i, inputValue ;
int buffer [B_SIZE] ;
int cols ;
struct winsize w ;
printf ("Raspberry Pi Gertboard SPI test program\n") ;
printf ("=======================================\n") ;
ioctl (fileno (stdin), TIOCGWINSZ, &w);
cols = w.ws_col - 2 ;
// Always initialise wiringPi. Use wiringPiSys() if you don't need
// (or want) to run as root
wiringPiSetupSys () ;
// Initialise the Gertboard analog hardware at pin 100
gertboardAnalogSetup (100) ;
// Generate a Sine Wave and store in our buffer
for (i = 0 ; i < B_SIZE ; ++i)
{
angle = ((double)i / (double)B_SIZE) * M_PI * 2.0 ;
buffer [i] = (int)rint ((sin (angle)) * 127.0 + 128.0) ;
}
// Loop, output the sine wave on analog out port 0, read it into A-D port 0
// and display it on the screen
for (;;)
{
for (i = 0 ; i < B_SIZE ; ++i)
{
analogWrite (100, buffer [i]) ;
inputValue = analogRead (100) ;
// We don't need to wory about the scale or sign - the analog hardware is
// a 10-bit value, so 0-1023. Just scale this to our terminal
printf ("%*s\n", (inputValue * cols) / 1023, "*") ;
delay (2) ;
}
}
return 0 ;
}

View File

@ -0,0 +1,60 @@
/*
* record.c:
* Record some audio via the Gertboard
*
* Copyright (c) 2013 Gordon Henderson
***********************************************************************
*/
#include <stdio.h>
#include <sys/time.h>
#include <wiringPi.h>
#include <gertboard.h>
#define B_SIZE 40000
int main ()
{
int i ;
struct timeval tStart, tEnd, tTaken ;
unsigned char buffer [B_SIZE] ;
printf ("\n") ;
printf ("Gertboard demo: Recorder\n") ;
printf ("========================\n") ;
// Always initialise wiringPi. Use wiringPiSys() if you don't need
// (or want) to run as root
wiringPiSetupSys () ;
// Initialise the Gertboard analog hardware at pin 100
gertboardAnalogSetup (100) ;
gettimeofday (&tStart, NULL) ;
for (i = 0 ; i < B_SIZE ; ++i)
buffer [i] = analogRead (100) >> 2 ;
gettimeofday (&tEnd, NULL) ;
timersub (&tEnd, &tStart, &tTaken) ;
printf ("Time taken for %d reads: %ld.%ld\n", B_SIZE, tTaken.tv_sec, tTaken.tv_usec) ;
gettimeofday (&tStart, NULL) ;
for (i = 0 ; i < B_SIZE ; ++i)
analogWrite (100, buffer [i]) ;
gettimeofday (&tEnd, NULL) ;
timersub (&tEnd, &tStart, &tTaken) ;
printf ("Time taken for %d writes: %ld.%ld\n", B_SIZE, tTaken.tv_sec, tTaken.tv_usec) ;
return 0 ;
}

View File

@ -0,0 +1,78 @@
/*
* temperature.c:
* Demonstrate use of the Gertboard A to D converter to make
* a simple thermometer using the LM35.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <wiringPi.h>
#include <gertboard.h>
int main ()
{
int x1, x2 ;
double v1, v2 ;
printf ("\n") ;
printf ("Gertboard demo: Simple Thermemeter\n") ;
printf ("==================================\n") ;
// Always initialise wiringPi. Use wiringPiSys() if you don't need
// (or want) to run as root
wiringPiSetupSys () ;
// Initialise the Gertboard analog hardware at pin 100
gertboardAnalogSetup (100) ;
printf ("\n") ;
printf ("| Channel 0 | Channel 1 | Temperature 1 | Temperature 2 |\n") ;
for (;;)
{
// Read the 2 channels:
x1 = analogRead (100) ;
x2 = analogRead (101) ;
// Convert to a voltage:
v1 = (double)x1 / 1023.0 * 3.3 ;
v2 = (double)x2 / 1023.0 * 3.3 ;
// Print
printf ("| %6.3f | %6.3f |", v1, v2) ;
// Print Temperature of both channels by converting the LM35 reading
// to a temperature. Fortunately these are easy: 0.01 volts per C.
printf (" %4.1f | %4.1f |\r", v1 * 100.0, v2 * 100.0) ;
fflush (stdout) ;
}
return 0 ;
}

View File

@ -0,0 +1,73 @@
/*
* voltmeter.c:
* Demonstrate use of the Gertboard A to D converter to make
* a simple voltmeter.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <wiringPi.h>
#include <gertboard.h>
int main ()
{
int x1, x2 ;
double v1, v2 ;
printf ("\n") ;
printf ("Gertboard demo: Simple Voltmeters\n") ;
printf ("=================================\n") ;
// Always initialise wiringPi. Use wiringPiSys() if you don't need
// (or want) to run as root
wiringPiSetupSys () ;
// Initialise the Gertboard analog hardware at pin 100
gertboardAnalogSetup (100) ;
printf ("\n") ;
printf ("| Channel 0 | Channel 1 |\n") ;
for (;;)
{
// Read the 2 channels:
x1 = analogRead (100) ;
x2 = analogRead (101) ;
// Convert to a voltage:
v1 = (double)x1 / 1023.0 * 3.3 ;
v2 = (double)x2 / 1023.0 * 3.3 ;
// Print
printf ("| %6.3f | %6.3f |\r", v1, v2) ;
fflush (stdout) ;
}
return 0 ;
}

View File

@ -0,0 +1,152 @@
/*
* vumeter.c:
* Simple VU meter
*
* Heres the theory:
* We will sample at 4000 samples/sec and put the data into a
* low-pass filter with a depth of 1000 samples. This will give
* us 1/4 a second of lag on the signal, but I think it might
* produce a more pleasing output.
*
* The input of the microphone should be at mid-pont with no
* sound input, but we might have to sample that too, to get
* our reference zero...
*
* Copyright (c) 2013 Gordon Henderson
***********************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <wiringPi.h>
#include <gertboard.h>
#ifndef TRUE
#define TRUE (1==1)
#define FALSE (!TRUE)
#endif
#define B_SIZE 1000
#define S_SIZE 128
static int buffer [B_SIZE] ;
static int bPtr = 0 ;
/*
* ledPercent:
* Output the given value as a percentage on the LEDs
*********************************************************************************
*/
static void ledPercent (int percent)
{
unsigned int output = 0 ;
if (percent > 11) output |= 0x01 ;
if (percent > 22) output |= 0x02 ;
if (percent > 33) output |= 0x04 ;
if (percent > 44) output |= 0x08 ;
if (percent > 55) output |= 0x10 ;
if (percent > 66) output |= 0x20 ;
if (percent > 77) output |= 0x40 ;
if (percent > 88) output |= 0x80 ;
digitalWriteByte (output) ;
}
static unsigned int tPeriod, tNextSampleTime ;
/*
* sample:
* Get a sample from the Gertboard. If not enough time has elapsed
* since the last sample, then wait...
*********************************************************************************
*/
static void sample (void)
{
unsigned int tFuture ;
// Calculate the future sample time
tFuture = tPeriod + tNextSampleTime ;
// Wait until the next sample time
while (micros () < tNextSampleTime)
;
buffer [bPtr] = gertboardAnalogRead (0) ;
tNextSampleTime = tFuture ;
}
int main ()
{
int quietLevel, min, max ;
int i, sum ;
unsigned int tStart, tEnd ;
printf ("\n") ;
printf ("Gertboard demo: VU Meter\n") ;
printf ("========================\n") ;
wiringPiSetup () ;
gertboardSPISetup () ;
ledPercent (0) ;
for (i = 0 ; i < 8 ; ++i)
pinMode (i, OUTPUT) ;
for (bPtr = 0 ; bPtr < B_SIZE ; ++bPtr)
buffer [bPtr] = 99 ;
tPeriod = 1000000 / 1000 ;
printf ("Shhhh.... ") ; fflush (stdout) ;
delay (1000) ;
printf ("Sampling quiet... ") ; fflush (stdout) ;
tStart = micros () ;
tNextSampleTime = micros () ;
for (bPtr = 0 ; bPtr < B_SIZE ; ++bPtr)
sample () ;
tEnd = micros () ;
quietLevel = 0 ;
max = 0 ;
min = 1024 ;
for (i = 0 ; i < B_SIZE ; ++i)
{
quietLevel += buffer [i] ;
if (buffer [i] > max) max = buffer [i] ;
if (buffer [i] < min) min = buffer [i] ;
}
quietLevel /= B_SIZE ;
printf ("Done. Quiet level is: %d [%d:%d] [%d:%d]\n", quietLevel, min, max, quietLevel - min, max - quietLevel) ;
printf ("Time taken for %d reads: %duS\n", B_SIZE, tEnd - tStart) ;
for (bPtr = 0 ;;)
{
sample () ;
sum = 0 ;
for (i = 0 ; i < S_SIZE ; ++i)
sum += buffer [i] ;
sum /= S_SIZE ;
sum = abs (quietLevel - sum) ;
sum = (sum * 1000) / quietLevel ;
ledPercent (sum) ;
if (++bPtr > S_SIZE)
bPtr = 0 ;
}
return 0 ;
}

197
wiringOP/examples/Makefile Normal file
View File

@ -0,0 +1,197 @@
#
# Makefile:
# wiringPi - A "wiring" library for the Raspberry Pi
# https://projects.drogon.net/wiring-pi
#
# Copyright (c) 2012-2015 Gordon Henderson
#################################################################################
# This file is part of wiringPi:
# Wiring Compatable library for the Raspberry Pi
#
# wiringPi is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wiringPi is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
#################################################################################
ifneq ($V,1)
Q ?= @
endif
#DEBUG = -g -O0
DEBUG = -O3
CC = gcc
INCLUDE = -I/usr/local/include
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
LDFLAGS = -L/usr/local/lib
LDLIBS = -lwiringPi -lwiringPiDev -lpthread -lm -lcrypt -lrt
# Should not alter anything below this line
###############################################################################
SRC = blink.c blink8.c blink12.c \
blink12drcs.c \
pwm.c \
speed.c wfi.c isr.c isr-osc.c \
lcd.c lcd-adafruit.c clock.c \
nes.c \
softPwm.c softTone.c \
delayTest.c serialRead.c serialTest.c okLed.c ds1302.c \
lowPower.c \
max31855.c \
rht03.c \
w25q64_test.c oled_demo.c spiSpeed.c \
watchdog.c spidev_test.c spidev_test_linux3_4.c
OBJ = $(SRC:.c=.o)
BINS = $(SRC:.c=)
all:
$Q cat README.TXT
$Q echo " $(BINS)" | fmt
$Q echo ""
really-all: $(BINS)
blink: blink.o
$Q echo [link]
$Q $(CC) -o $@ blink.o $(LDFLAGS) $(LDLIBS)
blink8: blink8.o
$Q echo [link]
$Q $(CC) -o $@ blink8.o $(LDFLAGS) $(LDLIBS)
blink12drcs: blink12drcs.o
$Q echo [link]
$Q $(CC) -o $@ blink12drcs.o $(LDFLAGS) $(LDLIBS)
blink12: blink12.o
$Q echo [link]
$Q $(CC) -o $@ blink12.o $(LDFLAGS) $(LDLIBS)
speed: speed.o
$Q echo [link]
$Q $(CC) -o $@ speed.o $(LDFLAGS) $(LDLIBS)
lcd: lcd.o
$Q echo [link]
$Q $(CC) -o $@ lcd.o $(LDFLAGS) $(LDLIBS)
lcd-adafruit: lcd-adafruit.o
$Q echo [link]
$Q $(CC) -o $@ lcd-adafruit.o $(LDFLAGS) $(LDLIBS)
clock: clock.o
$Q echo [link]
$Q $(CC) -o $@ clock.o $(LDFLAGS) $(LDLIBS)
wfi: wfi.o
$Q echo [link]
$Q $(CC) -o $@ wfi.o $(LDFLAGS) $(LDLIBS)
isr: isr.o
$Q echo [link]
$Q $(CC) -o $@ isr.o $(LDFLAGS) $(LDLIBS)
isr-osc: isr-osc.o
$Q echo [link]
$Q $(CC) -o $@ isr-osc.o $(LDFLAGS) $(LDLIBS)
nes: nes.o
$Q echo [link]
$Q $(CC) -o $@ nes.o $(LDFLAGS) $(LDLIBS)
rht03: rht03.o
$Q echo [link]
$Q $(CC) -o $@ rht03.o $(LDFLAGS) $(LDLIBS)
pwm: pwm.o
$Q echo [link]
$Q $(CC) -o $@ pwm.o $(LDFLAGS) $(LDLIBS)
softPwm: softPwm.o
$Q echo [link]
$Q $(CC) -o $@ softPwm.o $(LDFLAGS) $(LDLIBS)
softTone: softTone.o
$Q echo [link]
$Q $(CC) -o $@ softTone.o $(LDFLAGS) $(LDLIBS)
delayTest: delayTest.o
$Q echo [link]
$Q $(CC) -o $@ delayTest.o $(LDFLAGS) $(LDLIBS)
serialRead: serialRead.o
$Q echo [link]
$Q $(CC) -o $@ serialRead.o $(LDFLAGS) $(LDLIBS)
serialTest: serialTest.o
$Q echo [link]
$Q $(CC) -o $@ serialTest.o $(LDFLAGS) $(LDLIBS)
okLed: okLed.o
$Q echo [link]
$Q $(CC) -o $@ okLed.o $(LDFLAGS) $(LDLIBS)
tone: tone.o
$Q echo [link]
$Q $(CC) -o $@ tone.o $(LDFLAGS) $(LDLIBS)
ds1302: ds1302.o
$Q echo [link]
$Q $(CC) -o $@ ds1302.o $(LDFLAGS) $(LDLIBS)
max31855: max31855.o
$Q echo [link]
$Q $(CC) -o $@ max31855.o $(LDFLAGS) $(LDLIBS)
w25q64_test: w25q64_test.o
$Q echo [link]
$Q $(CC) -o $@ w25q64_test.o $(LDFLAGS) $(LDLIBS)
watchdog: watchdog.o
$Q echo [link]
$Q $(CC) -o $@ watchdog.o $(LDFLAGS) $(LDLIBS)
spidev_test: spidev_test.o
$Q echo [link]
$Q $(CC) -o $@ spidev_test.o $(LDFLAGS) $(LDLIBS)
spidev_test_linux3_4: spidev_test_linux3_4.o
$Q echo [link]
$Q $(CC) -o $@ spidev_test_linux3_4.o $(LDFLAGS) $(LDLIBS)
oled_demo: oled_demo.o
$Q echo [link]
$Q $(CC) -o $@ oled_demo.o $(LDFLAGS) $(LDLIBS)
spiSpeed: spiSpeed.o
$Q echo [link]
$Q $(CC) -o $@ spiSpeed.o $(LDFLAGS) $(LDLIBS)
.c.o:
$Q echo [CC] $<
$Q $(CC) -c $(CFLAGS) $< -o $@
clean:
$Q echo "[Clean]"
$Q rm -f $(OBJ) *~ core tags $(BINS)
tags: $(SRC)
$Q echo [ctags]
$Q ctags $(SRC)
depend:
makedepend -Y $(SRC)
# DO NOT DELETE

View File

@ -0,0 +1,88 @@
#
# Makefile:
# wiringPi - A "wiring" library for the Raspberry Pi
# https://projects.drogon.net/wiring-pi
#
# Copyright (c) 2012 Gordon Henderson
#################################################################################
# This file is part of wiringPi:
# A "wiring" library for the Raspberry Pi
#
# wiringPi is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wiringPi is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
#################################################################################
ifneq ($V,1)
Q ?= @
endif
#DEBUG = -g -O0
DEBUG = -O3
CC = gcc
INCLUDE = -I/usr/local/include
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
LDFLAGS = -L/usr/local/lib
LDLIBS = -lwiringPi -lwiringPiDev -lpthread -lm
# Should not alter anything below this line
###############################################################################
SRC = blink.c buttons.c reaction.c ladder.c metro.c motor.c
OBJ = $(SRC:.c=.o)
BINS = $(SRC:.c=)
all: $(BINS)
blink: blink.o
$Q echo [link]
$Q $(CC) -o $@ blink.o $(LDFLAGS) $(LDLIBS)
buttons: buttons.o
$Q echo [link]
$Q $(CC) -o $@ buttons.o $(LDFLAGS) $(LDLIBS)
reaction: reaction.o
$Q echo [link]
$Q $(CC) -o $@ reaction.o $(LDFLAGS) $(LDLIBS)
ladder: ladder.o
$Q echo [link]
$Q $(CC) -o $@ ladder.o $(LDFLAGS) $(LDLIBS)
metro: metro.o
$Q echo [link]
$Q $(CC) -o $@ metro.o $(LDFLAGS) $(LDLIBS)
motor: motor.o
$Q echo [link]
$Q $(CC) -o $@ motor.o $(LDFLAGS) $(LDLIBS)
.c.o:
$Q echo [CC] $<
$Q $(CC) -c $(CFLAGS) $< -o $@
clean:
$Q echo "[Clean]"
$Q rm -f $(OBJ) *~ core tags $(BINS)
tags: $(SRC)
$Q echo [ctags]
$Q ctags $(SRC)
depend:
makedepend -Y $(SRC)
# DO NOT DELETE

View File

@ -0,0 +1,59 @@
/*
* blink.c:
* Simple "blink" test for the PiFace interface board.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <wiringPi.h>
#include <piFace.h>
// Use 200 as the pin-base for the PiFace board, and pick a pin
// for the LED that's not connected to a relay
#define PIFACE 200
#define LED (PIFACE+2)
int main (int argc, char *argv [])
{
printf ("Raspberry Pi PiFace Blink\n") ;
printf ("=========================\n") ;
// Always initialise wiringPi. Use wiringPiSys() if you don't need
// (or want) to run as root
wiringPiSetupSys () ;
// Setup the PiFace board
piFaceSetup (PIFACE) ;
for (;;)
{
digitalWrite (LED, HIGH) ; // On
delay (500) ; // mS
digitalWrite (LED, LOW) ; // Off
delay (500) ;
}
return 0 ;
}

View File

@ -0,0 +1,103 @@
/*
* buttons.c:
* Simple test for the PiFace interface board.
*
* Read the buttons and output the same to the LEDs
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <wiringPi.h>
#include <piFace.h>
int outputs [4] = { 0,0,0,0 } ;
// Use 200 as the pin-base for the PiFace board
#define PIFACE_BASE 200
/*
* scanButton:
* Read the guiven button - if it's pressed, then flip the state
* of the correspoinding output pin
*********************************************************************************
*/
void scanButton (int button)
{
if (digitalRead (PIFACE_BASE + button) == LOW)
{
outputs [button] ^= 1 ;
digitalWrite (PIFACE_BASE + button, outputs [button]) ;
printf ("Button %d pushed - output now: %s\n",
button, (outputs [button] == 0) ? "Off" : "On") ;
}
while (digitalRead (PIFACE_BASE + button) == LOW)
delay (1) ;
}
/*
* start here
*********************************************************************************
*/
int main (void)
{
int pin, button ;
printf ("Raspberry Pi wiringPi + PiFace test program\n") ;
printf ("===========================================\n") ;
printf ("\n") ;
printf (
"This program reads the buttons and uses them to toggle the first 4\n"
"outputs. Push a button once to turn an output on, and push it again to\n"
"turn it off again.\n\n") ;
// Always initialise wiringPi. Use wiringPiSys() if you don't need
// (or want) to run as root
wiringPiSetupSys () ;
piFaceSetup (PIFACE_BASE) ;
// Enable internal pull-ups & start with all off
for (pin = 0 ; pin < 8 ; ++pin)
{
pullUpDnControl (PIFACE_BASE + pin, PUD_UP) ;
digitalWrite (PIFACE_BASE + pin, 0) ;
}
// Loop, scanning the buttons
for (;;)
{
for (button = 0 ; button < 4 ; ++button)
scanButton (button) ;
delay (5) ;
}
return 0 ;
}

337
wiringOP/examples/PiFace/ladder.c Executable file
View File

@ -0,0 +1,337 @@
/*
* ladder.c:
*
* Gordon Henderson, June 2012
***********************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <wiringPi.h>
#include <piFace.h>
#ifndef TRUE
# define TRUE (1==1)
# define FALSE (1==2)
#endif
#undef DEBUG
#define NUM_LEDS 8
// Map the LEDs to the hardware pins
// using PiFace pin numbers here
#define PIFACE 200
const int ledMap [NUM_LEDS] =
{
// 0, 1, 2, 3, 4, 5, 6, 7, 8
200, 201, 202, 203, 204, 205, 206, 207
} ;
// Some constants for our circuit simulation
const double vBatt = 9.0 ; // Volts (ie. a PP3)
const double capacitor = 0.001 ; // 1000uF
const double rCharge = 2200.0 ; // ohms
const double rDischarge = 68000.0 ; // ohms
const double timeInc = 0.01 ; // Seconds
double vCharge, vCap, vCapLast ;
/*
* setup:
* Program the GPIO correctly and initialise the lamps
***********************************************************************
*/
void setup (void)
{
int i ;
wiringPiSetupSys () ;
if (piFaceSetup (200) == -1)
exit (1) ;
// Enable internal pull-ups
for (i = 0 ; i < 8 ; ++i)
pullUpDnControl (PIFACE + i, PUD_UP) ;
// Calculate the actual charging voltage - standard calculation of
// vCharge = r2 / (r1 + r2) * vBatt
//
//
// -----+--- vBatt
// |
// R1
// |
// +---+---- vCharge
// | |
// R2 C
// | |
// -----+---+-----
vCharge = rDischarge / (rCharge + rDischarge) * vBatt ;
// Start with no charge
vCap = vCapLast = 0.0 ;
}
/*
* introLeds
* Put a little pattern on the LEDs to start with
*********************************************************************************
*/
void introLeds (void)
{
int i, j ;
printf ("Pi Ladder\n") ;
printf ("=========\n\n") ;
printf (" vBatt: %6.2f volts\n", vBatt) ;
printf (" rCharge: %6.0f ohms\n", rCharge) ;
printf (" rDischarge: %6.0f ohms\n", rDischarge) ;
printf (" vCharge: %6.2f volts\n", vCharge) ;
printf (" capacitor: %6.0f uF\n", capacitor * 1000.0) ;
// Flash 3 times:
for (j = 0 ; j < 3 ; ++j)
{
for (i = 0 ; i < NUM_LEDS ; ++i)
digitalWrite (ledMap [i], 1) ;
delay (500) ;
for (i = 0 ; i < NUM_LEDS ; ++i)
digitalWrite (ledMap [i], 0) ;
delay (100) ;
}
// All On
for (i = 0 ; i < NUM_LEDS ; ++i)
digitalWrite (ledMap [i], 1) ;
delay (500) ;
// Countdown...
for (i = NUM_LEDS - 1 ; i >= 0 ; --i)
{
digitalWrite (ledMap [i], 0) ;
delay (100) ;
}
delay (500) ;
}
/*
* winningLeds
* Put a little pattern on the LEDs to start with
*********************************************************************************
*/
void winningLeds (void)
{
int i, j ;
// Flash 3 times:
for (j = 0 ; j < 3 ; ++j)
{
for (i = 0 ; i < NUM_LEDS ; ++i)
digitalWrite (ledMap [i], 1) ;
delay (500) ;
for (i = 0 ; i < NUM_LEDS ; ++i)
digitalWrite (ledMap [i], 0) ;
delay (100) ;
}
// All On
for (i = 0 ; i < NUM_LEDS ; ++i)
digitalWrite (ledMap [i], 1) ;
delay (500) ;
// Countup...
for (i = 0 ; i < NUM_LEDS ; ++i)
{
digitalWrite (ledMap [i], 0) ;
delay (100) ;
}
delay (500) ;
}
/*
* chargeCapacitor: dischargeCapacitor:
* Add or remove charge to the capacitor.
* Standard capacitor formulae.
*********************************************************************************
*/
void chargeCapacitor (void)
{
vCap = (vCapLast - vCharge) *
exp (- timeInc / (rCharge * capacitor)) + vCharge ;
#ifdef DEBUG
printf ("+vCap: %7.4f\n", vCap) ;
#endif
vCapLast = vCap ;
}
void dischargeCapacitor (void)
{
vCap = vCapLast *
exp (- timeInc / (rDischarge * capacitor)) ;
#ifdef DEBUG
printf ("-vCap: %7.4f\n", vCap) ;
#endif
vCapLast = vCap ;
}
/*
* ledBargraph:
* Output the supplied number as a bargraph on the LEDs
*********************************************************************************
*/
void ledBargraph (double value, int topLedOn)
{
int topLed = (int)floor (value / vCharge * (double)NUM_LEDS) + 1 ;
int i ;
if (topLed > NUM_LEDS)
topLed = NUM_LEDS ;
if (!topLedOn)
--topLed ;
for (i = 0 ; i < topLed ; ++i)
digitalWrite (ledMap [i], 1) ;
for (i = topLed ; i < NUM_LEDS ; ++i)
digitalWrite (ledMap [i], 0) ;
}
/*
* ledOnAction:
* Make sure the leading LED is on and check the button
*********************************************************************************
*/
void ledOnAction (void)
{
if (digitalRead (PIFACE) == LOW)
{
chargeCapacitor () ;
ledBargraph (vCap, TRUE) ;
}
}
/*
* ledOffAction:
* Make sure the leading LED is off and check the button
*********************************************************************************
*/
void ledOffAction (void)
{
dischargeCapacitor () ;
// Are we still pushing the button?
if (digitalRead (PIFACE) == LOW)
{
vCap = vCapLast = 0.0 ;
ledBargraph (vCap, FALSE) ;
// Wait until we release the button
while (digitalRead (PIFACE) == LOW)
delay (10) ;
}
}
/*
***********************************************************************
* The main program
***********************************************************************
*/
int main (void)
{
unsigned int then, ledOnTime, ledOffTime ;
unsigned int ourDelay = (int)(1000.0 * timeInc) ;
setup () ;
introLeds () ;
// Setup the LED times - TODO reduce the ON time as the game progresses
ledOnTime = 1000 ;
ledOffTime = 1000 ;
// This is our Gate/Squarewave loop
for (;;)
{
// LED ON:
(void)ledBargraph (vCap, TRUE) ;
then = millis () + ledOnTime ;
while (millis () < then)
{
ledOnAction () ;
delay (ourDelay) ;
}
// Have we won yet?
// We need vCap to be in the top NUM_LEDS of the vCharge
if (vCap > ((double)(NUM_LEDS - 1) / (double)NUM_LEDS * vCharge)) // Woo hoo!
{
winningLeds () ;
while (digitalRead (PIFACE) == HIGH)
delay (10) ;
while (digitalRead (PIFACE) == LOW)
delay (10) ;
vCap = vCapLast = 0.0 ;
}
// LED OFF:
(void)ledBargraph (vCap, FALSE) ;
then = millis () + ledOffTime ;
while (millis () < then)
{
ledOffAction () ;
delay (ourDelay) ;
}
}
return 0 ;
}

View File

@ -0,0 +1,111 @@
/*
* metronome.c:
* Simple test for the PiFace interface board.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wiringPi.h>
#include <piFace.h>
#define PIFACE 200
/*
* middleA:
* Play middle A (on the relays - yea!)
*********************************************************************************
*/
static void middleA (void)
{
unsigned int next ;
for (;;)
{
next = micros () + 1136 ;
digitalWrite (PIFACE + 0, 0) ;
digitalWrite (PIFACE + 1, 0) ;
while (micros () < next)
delayMicroseconds (1) ;
next = micros () + 1137 ;
digitalWrite (PIFACE + 0, 1) ;
digitalWrite (PIFACE + 1, 1) ;
while (micros () < next)
delayMicroseconds (1) ;
}
}
int main (int argc, char *argv [])
{
int bpm, msPerBeat, state = 0 ;
unsigned int end ;
printf ("Raspberry Pi PiFace Metronome\n") ;
printf ("=============================\n") ;
piHiPri (50) ;
wiringPiSetupSys () ; // Needed for timing functions
piFaceSetup (PIFACE) ;
if (argc != 2)
{
printf ("Usage: %s <beates per minute>\n", argv [0]) ;
exit (1) ;
}
if (strcmp (argv [1], "a") == 0)
middleA () ;
bpm = atoi (argv [1]) ;
if ((bpm < 40) || (bpm > 208))
{
printf ("%s range is 40 through 208 beats per minute\n", argv [0]) ;
exit (1) ;
}
msPerBeat = 60000 / bpm ;
// Main loop:
// Put some random LED pairs up for a few seconds, then blank ...
for (;;)
{
end = millis () + msPerBeat ;
digitalWrite (PIFACE + 0, state) ;
digitalWrite (PIFACE + 1, state) ;
while (millis () < end)
delayMicroseconds (500) ;
state ^= 1 ;
}
return 0 ;
}

View File

@ -0,0 +1,120 @@
/*
* motor.c:
* Use the PiFace board to demonstrate an H bridge
* circuit via the 2 relays.
* Then add on an external transsitor to help with PWM.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <wiringPi.h>
#include <piFace.h>
#include <softPwm.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int outputs [2] = { 0,0 } ;
#define PIFACE_BASE 200
#define PWM_OUT_PIN 204
#define PWM_UP 202
#define PWM_DOWN 203
void scanButton (int button)
{
if (digitalRead (PIFACE_BASE + button) == LOW)
{
outputs [button] ^= 1 ;
digitalWrite (PIFACE_BASE + button, outputs [button]) ;
printf ("Button %d pushed - output now: %s\n",
button, (outputs [button] == 0) ? "Off" : "On") ;
}
while (digitalRead (PIFACE_BASE + button) == LOW)
delay (1) ;
}
int main (void)
{
int pin, button ;
int pwmValue = 0 ;
printf ("Raspberry Pi PiFace - Motor control\n") ;
printf ("==================================\n") ;
printf ("\n") ;
printf (
"This program is designed to be used with a motor connected to the relays\n"
"in an H-Bridge type configuration with optional speeed control via PWM.\n"
"\n"
"Use the leftmost buttons to turn each relay on and off, and the rigthmost\n"
"buttons to increase ot decrease the PWM output on the control pin (pin\n"
"4)\n\n") ;
wiringPiSetup () ;
piFaceSetup (PIFACE_BASE) ;
softPwmCreate (PWM_OUT_PIN, 100, 100) ;
// Enable internal pull-ups & start with all off
for (pin = 0 ; pin < 8 ; ++pin)
{
pullUpDnControl (PIFACE_BASE + pin, PUD_UP) ;
digitalWrite (PIFACE_BASE + pin, 0) ;
}
for (;;)
{
for (button = 0 ; button < 2 ; ++button)
scanButton (button) ;
if (digitalRead (PWM_UP) == LOW)
{
pwmValue += 10 ;
if (pwmValue > 100)
pwmValue = 100 ;
softPwmWrite (PWM_OUT_PIN, pwmValue) ;
printf ("PWM -> %3d\n", pwmValue) ;
while (digitalRead (PWM_UP) == LOW)
delay (5) ;
}
if (digitalRead (PWM_DOWN) == LOW)
{
pwmValue -= 10 ;
if (pwmValue < 0)
pwmValue = 0 ;
softPwmWrite (PWM_OUT_PIN, pwmValue) ;
printf ("PWM -> %3d\n", pwmValue) ;
while (digitalRead (PWM_DOWN) == LOW)
delay (5) ;
}
delay (5) ;
}
return 0 ;
}

View File

@ -0,0 +1,194 @@
/*
* reaction.c:
* Simple test for the PiFace interface board.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <wiringPi.h>
#include <piFace.h>
int outputs [4] = { 0,0,0,0 } ;
#define PIFACE 200
/*
* light:
* Light up the given LED - actually lights up a pair
*********************************************************************************
*/
void light (int led, int value)
{
led *= 2 ;
digitalWrite (PIFACE + led + 0, value) ;
digitalWrite (PIFACE + led + 1, value) ;
}
/*
* lightAll:
* All On or Off
*********************************************************************************
*/
void lightAll (int onoff)
{
light (0, onoff) ;
light (1, onoff) ;
light (2, onoff) ;
light (3, onoff) ;
}
/*
* waitForNoButtons:
* Wait for all buttons to be released
*********************************************************************************
*/
void waitForNoButtons (void)
{
int i, button ;
for (;;)
{
button = 0 ;
for (i = 0 ; i < 4 ; ++i)
button += digitalRead (PIFACE + i) ;
if (button == 4)
break ;
}
}
void scanButton (int button)
{
if (digitalRead (PIFACE + button) == LOW)
{
outputs [button] ^= 1 ;
digitalWrite (PIFACE + button, outputs [button]) ;
}
while (digitalRead (PIFACE + button) == LOW)
delay (1) ;
}
int main (void)
{
int i, j ;
int led, button ;
unsigned int start, stop ;
printf ("Raspberry Pi PiFace Reaction Timer\n") ;
printf ("==================================\n") ;
if (piFaceSetup (PIFACE) == -1)
exit (1) ;
// Enable internal pull-ups
for (i = 0 ; i < 8 ; ++i)
pullUpDnControl (PIFACE + i, PUD_UP) ;
// Main game loop:
// Put some random LED pairs up for a few seconds, then blank ...
for (;;)
{
printf ("Press any button to start ... \n") ; fflush (stdout) ;
for (;;)
{
led = rand () % 4 ;
light (led, 1) ;
delay (10) ;
light (led, 0) ;
button = 0 ;
for (j = 0 ; j < 4 ; ++j)
button += digitalRead (PIFACE + j) ;
if (button != 4)
break ;
}
waitForNoButtons () ;
printf ("Wait for it ... ") ; fflush (stdout) ;
led = rand () % 4 ;
delay (rand () % 500 + 1000) ;
light (led, 1) ;
start = millis () ;
for (button = -1 ; button == -1 ; )
{
for (j = 0 ; j < 4 ; ++j)
if (digitalRead (PIFACE + j) == 0) // Pushed
{
button = j ;
break ;
}
}
stop = millis () ;
button = 3 - button ; // Correct for the buttons/LEDs reversed
light (led, 0) ;
waitForNoButtons () ;
light (led, 1) ;
if (button == led)
{
printf ("You got it in %3d mS\n", stop - start) ;
}
else
{
printf ("Missed: You pushed %d - LED was %d\n", button, led) ;
for (;;)
{
light (button, 1) ;
delay (100) ;
light (button, 0) ;
delay (100) ;
i = 0 ;
for (j = 0 ; j < 4 ; ++j)
i += digitalRead (PIFACE + j) ;
if (i != 4)
break ;
}
waitForNoButtons () ;
}
light (led, 0) ;
delay (4000) ;
}
return 0 ;
}

View File

@ -0,0 +1,82 @@
#
# Makefile:
# wiringPi - A "wiring" library for the Raspberry Pi
# https://projects.drogon.net/wiring-pi
#
# Copyright (c) 2012-2015 Gordon Henderson
#################################################################################
# This file is part of wiringPi:
# A "wiring" library for the Raspberry Pi
#
# wiringPi is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wiringPi is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
#################################################################################
ifneq ($V,1)
Q ?= @
endif
#DEBUG = -g -O0
DEBUG = -O3
CC = gcc
INCLUDE = -I/usr/local/include
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
LDFLAGS = -L/usr/local/lib
LDLIBS = -lwiringPi -lwiringPiDev -lpthread -lm
# Should not alter anything below this line
###############################################################################
SRC = piGlow0.c piGlow1.c piglow.c
OBJ = $(SRC:.c=.o)
BINS = $(SRC:.c=)
all: $(BINS)
piGlow0: piGlow0.o
$Q echo [link]
$Q $(CC) -o $@ piGlow0.o $(LDFLAGS) $(LDLIBS)
piGlow1: piGlow1.o
$Q echo [link]
$Q $(CC) -o $@ piGlow1.o $(LDFLAGS) $(LDLIBS)
piglow: piglow.o
$Q echo [link]
$Q $(CC) -o $@ piglow.o $(LDFLAGS) $(LDLIBS)
.c.o:
$Q echo [CC] $<
$Q $(CC) -c $(CFLAGS) $< -o $@
clean:
$Q echo "[Clean]"
$Q rm -f $(OBJ) *~ core tags $(BINS)
tags: $(SRC)
$Q echo [ctags]
$Q ctags $(SRC)
install: piglow
$Q echo Installing piglow into /usr/local/bin
$Q cp -a piglow /usr/local/bin/piglow
$Q chmod 755 /usr/local/bin/piglow
$Q echo Done. Remember to load the I2C drivers!
depend:
makedepend -Y $(SRC)
# DO NOT DELETE

View File

@ -0,0 +1,51 @@
/*
* piglow.c:
* Very simple demonstration of the PiGlow board.
* This uses the SN3218 directly - soon there will be a new PiGlow
* devLib device which will handle the PiGlow board on a more easy
* to use manner...
*
* Copyright (c) 2013 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <wiringPi.h>
#include <sn3218.h>
#define LED_BASE 533
int main (void)
{
int i, j ;
wiringPiSetupSys () ;
sn3218Setup (LED_BASE) ;
for (;;)
{
for (i = 0 ; i < 256 ; ++i)
for (j = 0 ; j < 18 ; ++j)
analogWrite (LED_BASE + j, i) ;
for (i = 255 ; i >= 0 ; --i)
for (j = 0 ; j < 18 ; ++j)
analogWrite (LED_BASE + j, i) ;
}
}

View File

@ -0,0 +1,258 @@
/*
* piGlow1.c:
* Very simple demonstration of the PiGlow board.
* This uses the piGlow devLib.
*
* Copyright (c) 2013 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <poll.h>
#include <wiringPi.h>
#include <piGlow.h>
#define PIGLOW_BASE 533
#ifndef TRUE
# define TRUE (1==1)
# define FALSE (!TRUE)
#endif
/*
* keypressed: clearKeypressed:
* Simple but effective ways to tell if the enter key has been pressed
*********************************************************************************
*/
static int keypressed (void)
{
struct pollfd polls ;
polls.fd = fileno (stdin) ;
polls.events = POLLIN ;
return poll (&polls, 1, 0) != 0 ;
}
static void clearKeypressed (void)
{
while (keypressed ())
(void)getchar () ;
}
/*
* pulseLed:
* Pulses the LED at position leg, ring from off to a max. value,
* then off again
*********************************************************************************
*/
static void pulseLed (int leg, int ring)
{
int i ;
for (i = 0 ; i < 140 ; ++i)
{
piGlow1 (leg, ring, i) ;
delay (1) ;
}
delay (10) ;
for (i = 140 ; i >= 0 ; --i)
{
piGlow1 (leg, ring, i) ;
delay (1) ;
}
}
/*
* pulseLeg:
* Same as above, but a whole leg at a time
*********************************************************************************
*/
static void pulseLeg (int leg)
{
int i ;
for (i = 0 ; i < 140 ; ++i)
{
piGlowLeg (leg, i) ; delay (1) ;
}
delay (10) ;
for (i = 140 ; i >= 0 ; --i)
{
piGlowLeg (leg, i) ; delay (1) ;
}
}
/*
* pulse Ring:
* Same as above, but a whole ring at a time
*********************************************************************************
*/
static void pulseRing (int ring)
{
int i ;
for (i = 0 ; i < 140 ; ++i)
{
piGlowRing (ring, i) ; delay (1) ;
}
delay (10) ;
for (i = 140 ; i >= 0 ; --i)
{
piGlowRing (ring, i) ; delay (1) ;
}
}
#define LEG_STEPS 3
static int legSequence [] =
{
4, 12, 99,
99, 4, 12,
12, 99, 4,
} ;
#define RING_STEPS 16
static int ringSequence [] =
{
0, 0, 0, 0, 0, 64,
0, 0, 0, 0, 64, 64,
0, 0, 0, 64, 64, 0,
0, 0, 64, 64, 0, 0,
0, 64, 64, 0, 0, 0,
64, 64, 0, 0, 0, 0,
64, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
64, 0, 0, 0, 0, 0,
64, 64, 0, 0, 0, 0,
0, 64, 64, 0, 0, 0,
0, 0, 64, 64, 0, 0,
0, 0, 0, 64, 64, 0,
0, 0, 0, 0, 64, 64,
0, 0, 0, 0, 0, 64,
0, 0, 0, 0, 0, 0,
} ;
/*
* main:
* Our little demo prgoram
*********************************************************************************
*/
int main (void)
{
int i ;
int step, ring, leg ;
// Always initialise wiringPi:
// Use the Sys method if you don't need to run as root
wiringPiSetupSys () ;
// Initialise the piGlow devLib with our chosen pin base
piGlowSetup (1) ;
// LEDs, one at a time
printf ("LEDs, one at a time\n") ;
for (; !keypressed () ;)
for (leg = 0 ; leg < 3 ; ++leg)
{
for (ring = 0 ; ring < 6 ; ++ring)
{
pulseLed (leg, ring) ;
if (keypressed ())
break ;
}
if (keypressed ())
break ;
}
clearKeypressed () ;
// Rings, one at a time
printf ("Rings, one at a time\n") ;
for (; !keypressed () ;)
for (ring = 0 ; ring < 6 ; ++ring)
{
pulseRing (ring) ;
if (keypressed ())
break ;
}
clearKeypressed () ;
// Legs, one at a time
printf ("Legs, one at a time\n") ;
for (; !keypressed () ;)
for (leg = 0 ; leg < 3 ; ++leg)
{
pulseLeg (leg) ;
if (keypressed ())
break ;
}
clearKeypressed () ;
delay (1000) ;
// Sequence - alternating rings, legs and random
printf ("Sequence now\n") ;
for (; !keypressed () ;)
{
for (i = 0 ; i < 20 ; ++i)
for (step = 0 ; step < LEG_STEPS ; ++step)
{
for (leg = 0 ; leg < 3 ; ++leg)
piGlowLeg (leg, legSequence [step * 3 + leg]) ;
delay (80) ;
}
for (i = 0 ; i < 10 ; ++i)
for (step = 0 ; step < RING_STEPS ; ++step)
{
for (ring = 0 ; ring < 6 ; ++ring)
piGlowRing (ring, ringSequence [step * 6 + ring]) ;
delay (80) ;
}
for (i = 0 ; i < 1000 ; ++i)
{
leg = random () % 3 ;
ring = random () % 6 ;
piGlow1 (leg, ring, random () % 256) ;
delay (5) ;
piGlow1 (leg, ring, 0) ;
}
}
return 0 ;
}

View File

@ -0,0 +1,176 @@
/*
* piglow.c:
* Very simple demonstration of the PiGlow board.
* This uses the piGlow devLib.
*
* Copyright (c) 2013 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifndef TRUE
# define TRUE (1==1)
# define FALSE (!TRUE)
#endif
#include <wiringPi.h>
#include <piGlow.h>
static void failUsage (void)
{
fprintf (stderr, "Usage examples:\n") ;
fprintf (stderr, " piglow off # All off\n") ;
fprintf (stderr, " piglow red 50 # Light the 3 red LEDs to 50%%\n") ;
fprintf (stderr, " colours are: red, yellow, orange, green, blue and white\n") ;
fprintf (stderr, " piglow all 75 # Light all to 75%%\n") ;
fprintf (stderr, " piglow leg 0 25 # Light leg 0 to 25%%\n") ;
fprintf (stderr, " piglow ring 3 100 # Light ring 3 to 100%%\n") ;
fprintf (stderr, " piglow led 2 5 100 # Light the single LED on Leg 2, ring 5 to 100%%\n") ;
exit (EXIT_FAILURE) ;
}
static int getPercent (char *typed)
{
int percent ;
percent = atoi (typed) ;
if ((percent < 0) || (percent > 100))
{
fprintf (stderr, "piglow: percent value out of range\n") ;
exit (EXIT_FAILURE) ;
}
return (percent * 255) / 100 ;
}
/*
* main:
* Our little demo prgoram
*********************************************************************************
*/
int main (int argc, char *argv [])
{
int percent ;
int ring, leg ;
// Always initialise wiringPi:
// Use the Sys method if you don't need to run as root
wiringPiSetupSys () ;
// Initialise the piGlow devLib
piGlowSetup (FALSE) ;
if (argc == 1)
failUsage () ;
if ((argc == 2) && (strcasecmp (argv [1], "off") == 0))
{
for (leg = 0 ; leg < 3 ; ++leg)
piGlowLeg (leg, 0) ;
return 0 ;
}
if (argc == 3)
{
percent = getPercent (argv [2]) ;
/**/ if (strcasecmp (argv [1], "red") == 0)
piGlowRing (PIGLOW_RED, percent) ;
else if (strcasecmp (argv [1], "yellow") == 0)
piGlowRing (PIGLOW_YELLOW, percent) ;
else if (strcasecmp (argv [1], "orange") == 0)
piGlowRing (PIGLOW_ORANGE, percent) ;
else if (strcasecmp (argv [1], "green") == 0)
piGlowRing (PIGLOW_GREEN, percent) ;
else if (strcasecmp (argv [1], "blue") == 0)
piGlowRing (PIGLOW_BLUE, percent) ;
else if (strcasecmp (argv [1], "white") == 0)
piGlowRing (PIGLOW_WHITE, percent) ;
else if (strcasecmp (argv [1], "all") == 0)
for (ring = 0 ; ring < 6 ; ++ring)
piGlowRing (ring, percent) ;
else
{
fprintf (stderr, "piglow: invalid colour\n") ;
exit (EXIT_FAILURE) ;
}
return 0 ;
}
if (argc == 4)
{
/**/ if (strcasecmp (argv [1], "leg") == 0)
{
leg = atoi (argv [2]) ;
if ((leg < 0) || (leg > 2))
{
fprintf (stderr, "piglow: leg value out of range\n") ;
exit (EXIT_FAILURE) ;
}
percent = getPercent (argv [3]) ;
piGlowLeg (leg, percent) ;
}
else if (strcasecmp (argv [1], "ring") == 0)
{
ring = atoi (argv [2]) ;
if ((ring < 0) || (ring > 5))
{
fprintf (stderr, "piglow: ring value out of range\n") ;
exit (EXIT_FAILURE) ;
}
percent = getPercent (argv [3]) ;
piGlowRing (ring, percent) ;
}
return 0 ;
}
if (argc == 5)
{
if (strcasecmp (argv [1], "led") != 0)
failUsage () ;
leg = atoi (argv [2]) ;
if ((leg < 0) || (leg > 2))
{
fprintf (stderr, "piglow: leg value out of range\n") ;
exit (EXIT_FAILURE) ;
}
ring = atoi (argv [3]) ;
if ((ring < 0) || (ring > 5))
{
fprintf (stderr, "piglow: ring value out of range\n") ;
exit (EXIT_FAILURE) ;
}
percent = getPercent (argv [4]) ;
piGlow1 (leg, ring, percent) ;
return 0 ;
}
failUsage () ;
return 0 ;
}

Some files were not shown because too many files have changed in this diff Show More