diff --git a/DOCUMENTATION.html b/DOCUMENTATION.html index c795b0e..ff9eccf 100644 --- a/DOCUMENTATION.html +++ b/DOCUMENTATION.html @@ -35,6 +35,7 @@
var wpi = require('wiring-pi');
wiringPiSetup()
>= 0.1.0
Initialises wiringPi and assumes that the calling program is going to be using the wiringPi pin numbering scheme. This is a simplified numbering scheme which provides a mapping from virtual pin numbers 0 through 16 to the real underlying Broadcom GPIO pin numbers. see the pins page (http://wiringpi.com/pins/) for a table which maps the wiringPi pin number to the Broadcom GPIO pin number to the physical location on the edge connector. This function needs to be called with root privileges.
-wiringPiSetupGpio()
Initialises wiringPi and assumes that the calling program is going to be using the wiringPi pin numbering scheme.
+This is a simplified numbering scheme which provides a mapping from virtual pin numbers 0 through 16 to the real underlying Broadcom GPIO pin numbers.
+see the pins page for a table which maps the wiringPi pin number to the Broadcom GPIO pin number to the physical location on the edge connector.
+This function needs to be called with root privileges.
+ >= 0.1.1
This is indential to above, however it allows the calling programs to use the Broadcom GPIO pin numbers directly with no re-mapping. As above, this function needs to be called with root privileges, and note that some pins are different from revision 1 to revision 2 boards.
-wiringPiSetupPhys()
This is indential to above, however it allows the calling programs to use the Broadcom GPIO pin numbers directly with no re-mapping.
+As above, this function needs to be called with root privileges, and note that some pins are different from revision 1 to revision 2 boards.
+ >= 1.0.0
Identical to above, however it allows the calling programs to use the physical pin numbers on the P1 connector only. As above, this function needs to be called with root priviliges.
-wiringPiSetupSys()
Identical to above, however it allows the calling programs to use the physical pin numbers on the P1 connector only.
+As above, this function needs to be called with root priviliges.
+ >= 0.1.1
This initialises wiringPi but uses the /sys/class/gpio interface rather than accessing the hardware directly. This can be called as a non-root user provided the GPIO pins have been exported before-hand using gpio program. Pin numbering in this mode is the native Broadcom GPIO numbers - the same as wiringPiSetGpio above, so be aware of the differences between Rev 1 and Rev 2 boards. Note: In this mode you can only use the pins which have been exported via the /sys/class/gpio interface before you run your program. You can do this in a seperate shell script, or by using the system() function from inside your program to call the gpio program. Also note that some functions have no effect when using this mode as they're not currently possible to action unless called with root privileges. (although you can use system() to call gpio to set/change modes if needed).
-setup(mode)
This initialises wiringPi but uses the /sys/class/gpio interface rather than accessing the hardware directly.
+This can be called as a non-root user provided the GPIO pins have been exported before-hand using gpio program.
+Pin numbering in this mode is the native Broadcom GPIO numbers - the same as wiringPiSetGpio above, so be aware of the differences between Rev 1 and Rev 2 boards.
+NOTE: In this mode you can only use the pins which have been exported via the /sys/class/gpio interface before you run your program.
+You can do this in a seperate shell script, or by using the system() function from inside your program to call the gpio program.
+Also note that some functions have no effect when using this mode as they're not currently possible to action unless called with root privileges. (although you can use system() to call gpio to set/change modes if needed).
+ >= 0.1.1
An handy function to setup wiringPi
mode
can be one of the following values:
setup(mode)
NOTE: >= 2.0.0
no longer accept calling setup without mode specified. (defaulting to wpi
in < 2.0.0
)
pinModeAlt(pin, mode)
>= 1.0.0
This is an un-documented special to let you set any pin to any mode.
mode
can be one of the following values:
pinModeAlt(pin, mode)
WPI_MODE_PHYS
>= 1.0.0
WPI_MODE_GPIO
>= 1.0.0
pinMode(pin, mode)
>= 0.1.0
This sets the mode of a pin. Note that only wiringPi pin 1 (BCM_GPIO 18) supports PWM output and only wiringPi pin 7 (BCM_GPIO 4) supports CLOCK output modes. This function has no effect when in Sys mode. If you need to change the pin mode, the you can do it with the gpio program in a script before you start your program.
+This sets the mode of a pin.
+Note that only wiringPi pin 1 (BCM_GPIO 18) supports PWM output and only wiringPi pin 7 (BCM_GPIO 4) supports CLOCK output modes.
+This function has no effect when in Sys mode.
+If you need to change the pin mode, the you can do it with the gpio program in a script before you start your program.
mode
can be one of the following values:
modes.INPUT
>= 0.1.1 < 2.0.0
removed
pinMode(pin, mode)
SOFT_PWM_OUTPUT
>= 1.1.0
SOFT_TONE_OUTPUT
>= 1.1.0
pullUpDnControl(pin, pud)
>= 0.2.0
This sets the pull-up or pull-down resistor mode on the given pin, which should be set as an input. Unlike Arduino, the BCM2835 has both pull-up and down internal resistors. The internal pull up/down resistors have a value of approximately 50KΩ on the Raspberry Pi.
+This sets the pull-up or pull-down resistor mode on the given pin, which should be set as an input.
+Unlike Arduino, the BCM2835 has both pull-up and down internal resistors.
+The internal pull up/down resistors have a value of approximately 50KΩ on the Raspberry Pi.
pud
can be one of the following values:
PUD_OFF
no pull up/down >= 0.2.0
PUD_DOWN
pull to ground >= 0.2.0
PUD_UP
pull to 3.3v >= 0.2.0
digitalRead(pin)
>= 0.1.1
This function returns the value read at the given pin. It will be HIGH
(1) or LOW
(0) depending on the logic level at the pin.
digitalWrite(pin, state)
This function returns the value read at the given pin.
+It will be HIGH
(1) or LOW
(0) depending on the logic level at the pin.
>= 0.1.0
Write the value HIGH
(1) or LOW
(0) to the given pin which must have been previously set as an output. WiringPi treats any non-zero number as HIGH
, however 0 is the only representation of LOW
.
Write the value HIGH
(1) or LOW
(0) to the given pin which must have been previously set as an output.
WiringPi treats any non-zero number as HIGH
, however 0 is the only representation of LOW
.
state
can be one of the following value:
HIGH
>= 0.1.2
LOW
>= 0.1.2
pwmWrite(pin, value)
>= 0.1.1
Writes the value to the PWM register for the given pin. The Raspberry Pi has one on-board PWM pin, pin 1 (BCM_GPIO 18, Phys 12) and the range is [0, 1024]. Other PWM devices may have other PWM ranges. This function is not able to control the Pi's on-board PWM when in Sys mode.
-value
must be in range of [0, 1024]
analogRead(pin)
Writes the value to the PWM register for the given pin.
+The Raspberry Pi has one on-board PWM pin, pin 1 (BCM_GPIO 18, Phys 12) and the range is [0, 1024].
+Other PWM devices may have other PWM ranges.
+This function is not able to control the Pi's on-board PWM when in Sys mode.
+ >= 1.0.0
This returns the value read on the supplied analog input pin. You will need to register additional analog modules to enable this function for device such as the Gertboard, quick2Wire analog board, etc.
-analogWrite(pin, value)
This returns the value read on the supplied analog input pin.
+You will need to register additional analog modules to enable this function for device such as the Gertboard, quick2Wire analog board, etc.
+ >= 1.0.0
This writes the given value to the supplied analog pin. You will need to register additional analog modules to enable this function for devices such as the Gertboard.
-pulseIn(pin, state)
This writes the given value to the supplied analog pin.
+You will need to register additional analog modules to enable this function for devices such as the Gertboard.
+ >= 1.1.0
Reads a pulse (either HIGH or LOW) on a pin.
+For example, if state
is HIGH, pulseIn waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing.
Returns the length of the pulse in microseconds.
+Gives up and returns 0 if no pulse starts within a specified time out.
state
can be one of the following values:
HIGH
>= 0.1.2
LOW
>= 0.1.2
delay(milliseconds)
>= 1.1.0
delayMicroseconds(microseconds)
Pauses the program for the amount of time (in miliseconds) specified as parameter.
+There are 1000 milliseconds in a second.
+ >= 1.1.0
millis()
Pauses the program for the amount of time (in microseconds) specified as parameter.
+There are a thousand microseconds in a millisecond, and a million microseconds in a second.
+For delays longer than a few thousand microseconds, you should use delay() instead.
+ >= 1.1.0
micros()
Returns the number of milliseconds since the beginning running of the current program
+ >= 1.1.0
Returns the number of microseconds since the beginning running of the current program
+ >= 2.0.0
This function registers a function to received interrupts on the specified pin.
+The edgeType parameter is either INT_EDGE_FALLING
, INT_EDGE_RISING
, INT_EDGE_BOTH
or INT_EDGE_SETUP
.
If it is INT_EDGE_SETUP
then no initialisation of the pin will happen – it’s assumed that you have already setup the pin elsewhere (e.g. with the gpio program), but if you specify one of the other types, then the pin will be exported and initialised as specified.
This is accomplished via a suitable call to the gpio utility program, so it need to be available.
+The pin number is supplied in the current mode – native wiringPi, BCM_GPIO, physical or Sys modes.
+This function will work in any mode, and does not need root privileges to work.
+The callback will be called when the interrupt triggers.
+When it is triggered, it’s cleared in the dispatcher before calling your function, so if a subsequent interrupt fires before you finish your handler, then it won’t be missed.
+However it can only track one more interrupt, if more than one interrupt fires while one is being handled then they will be ignored.
+wpi.setup('wpi');
+wpi.pinMode(7, wpi.INPUT);
+wpi.pullUpDnControl(7, wpi.PUD_UP);
+wpi.wiringPiISR(7, wpi.INT_EDGE_FALLING, function(delta) {
+ console.log('Pin 7 changed to LOW (', delta, ')');
+});
piBoardRev()
>= 0.1.1
This returns the board revision of the Raspberry Pi. It will be either 1 or 2. Some of the BCM_GPIO pins changed number and function when moving from board revision 1 to 2, so if you are using BCM_GPIO pin numbers, then you need to be aware of the differences.
-piBoardId()
This returns the board revision of the Raspberry Pi.
+It will be either 1 or 2.
+Some of the BCM_GPIO pins changed number and function when moving from board revision 1 to 2, so if you are using BCM_GPIO pin numbers, then you need to be aware of the differences.
+ >= 1.1.0
wpiPinToGpio(pin)
Do more digging into the board revision string as above, but return as much details as we can.
+Returns an object with the following keys:
+model
: indexes to PI_MODEL_NAMES
string tablerev
: indexes to PI_REVISION_NAMES
string tablemem
: 256 or 512maker
: indexes to PI_MAKER_NAMES
string tableovervolted
: 0 or 1 >= 2.0.0
NOTE: maker
was a string in versions >= 1.1.0 and < 2.0.0
Indexes of each string table have corresponding constants
+PI_MODEL_NAME
PI_MODEL_UNKNOWN
>= 2.0.0
PI_MODEL_A
>= 1.1.0
PI_MODEL_B
>= 1.1.0
PI_MODEL_BP
>= 2.0.0
PI_MODEL_CM
>= 1.1.1
PI_REVISION_NAMES
PI_VERSION_UNKNOWN
>= 2.0.0
PI_VERSION_1
>= 2.0.0
PI_VERSION_1_1
>= 2.0.0
PI_VERSION_1_2
>= 2.0.0
PI_VERSION_2
>= 2.0.0
PI_MAKER_NAMES
PI_MAKER_UNKNOWN
>= 2.0.0
PI_MAKER_EGOMAN
>= 2.0.0
PI_MAKER_SONY
>= 2.0.0
PI_MAKER_QISDA
>= 2.0.0
>= 1.0.0
This returns the BCM_GPIO pin number of the supplied wiringPi pin. It takes the board revision into account.
-physPinToGpio(pin)
This returns the BCM_GPIO pin number of the supplied wiringPi pin.
+It takes the board revision into account.
+ >= 1.0.0
This returns the BCM_GPIO pin number of the suppled physical pin on the P1 connector.
-setPadDrive(group, value)
>= 1.0.0
This sets the "strength" of the pad drivers for a particular group of pins. There are 3 groups of pins and the drive strength is from 0 to 7. Do not use the unless you know what you are doing.
-getAlt(pin)
This sets the "strength" of the pad drivers for a particular group of pins.
+There are 3 groups of pins and the drive strength is from 0 to 7.
+NOTE: Do not use the unless you know what you are doing.
+ >= 1.0.0
Returns the ALT bits for a given port.
-digitalWriteByte(byte)
>= 1.0.0
This writes the 8-bit byte supplied to the first 8 GPIO pins. It’s the fastest way to set all 8 bits at once to a particular value, although it still takes two write operations to the Pi’s GPIO hardware.
-pwmSetMode(mode)
This writes the 8-bit byte supplied to the first 8 GPIO pins.
+It’s the fastest way to set all 8 bits at once to a particular value, although it still takes two write operations to the Pi’s GPIO hardware.
+ >= 1.0.0
The PWM generator can run in 2 modes – “balanced” and “mark:space”. The mark:space mode is traditional, however the default mode in the Pi is “balanced”.
+The PWM generator can run in 2 modes – “balanced” and “mark:space”.
+The mark:space mode is traditional, however the default mode in the Pi is “balanced”.
mode
can be one of the following values:
PWM_MODE_BAL
balancedPWM_MODE_MS
mark:spacepwmSetRange(range)
>= 0.1.1
This sets the range register in the PWM generator. The default is 1024. Note: The PWM control functions can not be used when in Sys mode. To understand more about the PWM system, you’ll need to read the Broadcom ARM peripherals manual.
-pwmSetClock(divisor)
This sets the range register in the PWM generator.
+The default is 1024.
+NOTE: The PWM control functions can not be used when in Sys mode. To understand more about the PWM system, you’ll need to read the Broadcom ARM peripherals manual.
+ >= 0.1.1
This sets the divisor for the PWM clock. Note: The PWM control functions can not be used when in Sys mode. To understand more about the PWM system, you’ll need to read the Broadcom ARM peripherals manual.
-gpioClockSet(pin, frequency)
This sets the divisor for the PWM clock.
+NOTE: The PWM control functions can not be used when in Sys mode. To understand more about the PWM system, you’ll need to read the Broadcom ARM peripherals manual.
+ >= 1.0.0
Set the frequency on a GPIO clock pin
wiringPiI2CSetup(devId)
>= 2.0.0
wiringPiI2CSetupInterface(device, devId)
This initialises the I2C system with your given device identifier.
+The ID is the I2C number of the device and you can use the i2cdetect program to find this out.
+wiringPiI2CSetup() will work out which revision Raspberry Pi you have and open the appropriate device in /dev.
+The return value is the standard Linux filehandle, or -1 if any error – in which case, you can consult errno as usual.
+ >= 2.0.0
wiringPiI2CRead(fd)
Undocumented access to set the interface explicitly - might be used for the Pi's 2nd I2C interface...
+ >= 2.0.0
wiringPiI2CReadReg8(fd, reg)
Simple device read.
+Some devices present data when you read them without having to do any register transactions.
+ >= 2.0.0
wiringPiI2CReadReg16(fd, red)
This read an 8-bit value from the device register indicated.
+ >= 2.0.0
wiringPiI2CWrite(fd, data)
This read an 16-bit value from the device register indicated.
+ >= 2.0.0
wiringPiI2CWriteReg8(fd, reg, data)
Simple device write.
+Some devices accept data this way without needing to access any internal registers.
+ >= 2.0.0
wiringPiI2CWriteReg16(fd, reg, data)
This write an 8-bit data value into the device register indicated.
+ >= 2.0.0
This write an 16-bit data value into the device register indicated.
wiringPiSPIGetFd(channel)
>= 1.0.0
wiringPiSPIDataRW(channel, data)
Returns the file-descriptor for the given channel
+ >= 1.0.0
wiringPiSPISetup(channel, speed)
This performs a simultaneous write/read transaction over the selected SPI bus.
+Data that was in your buffer is overwritten by data returned from the SPI bus.
+It is possible to do simple read and writes over the SPI bus using the standard read() and write() system calls though – write() may be better to use for sending data to chains of shift registers, or those LED strings where you send RGB triplets of data.
+Devices such as A/D and D/A converters usually need to perform a concurrent write/read transaction to work.
+ >= 1.0.0
This is the way to initialise a channel (The Pi has 2 channels; 0 and 1).
+The speed parameter is an integer in the range 500,000 through 32,000,000 and represents the SPI clock speed in Hz.
+The returned value is the Linux file-descriptor for the device, or -1 on error.
+If an error has happened, you may use the standard errno global variable to see why.
serialOpen(device, baudrate)
>= 1.0.0
serialClose(fd)
This opens and initialises the serial device and sets the baud rate.
+It sets the port into “raw” mode (character at a time and no translations), and sets the read timeout to 10 seconds.
+The return value is the file descriptor or -1 for any error, in which case errno will be set as appropriate.
+NOTE: The file descriptor (fd) returned is a standard Linux file descriptor.
+You can use the standard read(), write(), etc. system calls on this file descriptor as required.
+E.g. you may wish to write a larger block of binary data where the serialPutchar() or serialPuts() function may not be the most appropriate function to use, in which case, you can use write() to send the data.
+ >= 1.0.0
serialFlush(fd)
Closes the device identified by the file descriptor given.
+ >= 1.0.0
serialPutchar(fd, character)
This discards all data received, or waiting to be send down the given device.
+ >= 1.0.0
serialPuts(fd, string)
Sends the single byte to the serial device identified by the given file descriptor.
+ >= 1.0.0
serialPrintf(fd, string)
Sends the nul-terminated string to the serial device identified by the given file descriptor.
+ Alias: serialPuts
>= 2.0.0
serialDataAvail(fd)
>= 1.0.0
serialGetchar(fd)
Returns the number of characters available for reading, or -1 for any error condition, in which case errno will be set appropriately.
+ >= 1.0.0
Returns the next character available on the serial device.
+This call will block for up to 10 seconds if no data is available (when it will return -1)
shiftIn(dPin, cPin, order)
>= 1.0.0
shiftOut(dPin, cPin, order, value)
This shifts an 8-bit data value in with the data appearing on the dPin and the clock being sent out on the cPin.
+Order is either LSBFIRST
or MSBFIRST
.
The data is sampled after the cPin goes high. (So cPin high, sample data, cPin low, repeat for 8 bits) The 8-bit value is returned by the function.
+ >= 1.0.0
The shifts an 8-bit data value val out with the data being sent out on dPin and the clock being sent out on the cPin.
+Order is as above.
+Data is clocked out on the rising or falling edge – ie. dPin is set, then cPin is taken high then low – repeated for the 8 bits.
softPwmCreate(pin, value, range)
>= 1.0.0
This creates a software controlled PWM pin.
+You can use any GPIO pin and the pin numbering will be that of the wiringPiSetup() function you used.
+Use 100 for the pwmRange, then the value can be anything from 0 (off) to 100 (fully on) for the given pin.
+The return value is 0 for success.
+Anything else and you should check the global errno variable to see what went wrong.
+NOTE: Each “cycle” of PWM output takes 10mS with the default range value of 100, so trying to change the PWM value more than 100 times a second will be futile.
+NOTE: Each pin activated in softPWM mode uses approximately 0.5% of the CPU.
+NOTE: You need to keep your program running to maintain the PWM output!
softPwmWrite(pin, value)
>= 1.0.0
This updates the PWM value on the given pin.
+The value is checked to be in-range and pins that haven’t previously been initialised via softPwmCreate will be silently ignored.
softPwmStop(pin)
>= 1.1.0
softServoSetup(p0, p1, p2,
Soft Tone
softToneCreate(pin);
>= 1.0.0
+This creates a software controlled tone pin.
+You can use any GPIO pin and the pin numbering will be that of the wiringPiSetup() function you used.
+The return value is 0 for success.
+Anything else and you should check the global errno variable to see what went wrong.
+NOTE: Each pin activated in softTone mode uses approximately 0.5% of the CPU.
+NOTE: You need to keep your program running to maintain the sound output!
softToneWrite(pin, frequency);
>= 1.0.0
+This updates the tone frequency value on the given pin.
+The tone will be played until you set the frequency to 0.
softToneStop(pin);
>= 1.1.0
Extensions
+drcSerial
+drcSetupSerial(pinBase, numPins, device, baudrate)
+max31855
+Cold-junction compensated thermocouple-to-digital converter (SPI)
+max5322
+12-Bit DAC (SPI)
+max31855Setup(pinBase, spiChannel)
+mcp23008
+8-Bit I/O expander (I2C)
+mcp23008Setup(pinBase, i2cAddress)
+mcp23016
+16-Bit I/O expander (I2C)
+mcp23016Setup(pinBase, i2cAddress)
+mpc23017
+16-Bit I/O expander (I2C)
+mcp23017Setup(pinBase, i2cAddress)
+mcp23s08
+8-Bit I/O expander (SPI)
+mcp23s08Setup(pinBase, spiChannel, devId)
+mcp23s17
+16-Bit I/O expander (SPI)
+mcp23s17Setup(pinBase, spiChannel, devId)
+mcp3002
+2-Channel 10-Bit ADC (SPI)
+mcp3002Setup(pinBase, spiChannel)
+mcp3004/8
+4/8-Channel 10-Bit ADC (SPI)
+mcp3004Setup(pinBase, spiChannel)
+mcp3422/3/4
+2/4-Channel 18-Bit ADC (I2C)
+mcp3422Setup(pinBase, i2cAddress, sampleRate, gain)
+mcp4802/12/22
+2-Channel 8/10/12-Bit DAC (SPI)
+mcp4802Setup(pinBase, spiChannel)
+pca9685
+16-Channel 12-Bit PWM led/servo driver (I2C)
+pca9685Setup(pinBase, i2cAddress, frequency)
+pcf8574
+8-Bit I/O expander (I2C)
+pcf8574Setup(pinBase, i2cAddress)
+pcf8591
+8-Bit ADC and DAC (I2C)
+pcf8591Setup(pinBase, i2cAddress)
+sn3218
+18-Channel PWM led driver (I2C)
+sn3218Setup(pinBase)
+sr595
+74x595 shift register
+sr595Setup(pinBase, numPins, dataPin, clockPin, latchPin)
+
+DevLib
+ds1302
+Trickle-charge timekeeping chip
+ds1302setup(clockPin, dataPin, csPin)
+ds1302rtcRead(reg)
+ds1302rtcWrite(reg, data)
+ds1302ramRead(address)
+ds1302ramWrite(address, data)
+ds1302clockRead()
+ds1302clockWrite(clockData[8])
+ds1302trickleCharge(diodes, resistors)
+GertBoard
+getboardAnalogSetup(pinBase)
+LCD
+lcdInit(rows, cols, bits, rs, strb, d0, d1, d2, d3, d4, d5, d6, d7)
+lcdHome(fd)
+lcdClear(fd)
+lcdDisplay(fd, state)
+lcdCursor(fd, state)
+lcdCursorBlink(fd, state)
+lcdSendCommand(fd, command)
+lcdPosition(fd, x, y)
+lcdCharDef(fd, index, data[8])
+lcdPutchar(fd, character)
+lcdPuts(fd, string)
+lcdPrintf(fd, string)
+LCD 128x64
+MaxDetect
+maxDetectRead(pin)
+readRHT03(pin)
+piFace
+piFaceSetup(pinBase)
+piGlow
+piGlowSetup(clear)
+piGlow1(leg, ring, intensity)
+piGlowLeg(leg, intensity)
+piGlowRing(ring, intensity)
+piNes
+setupNesJoystick(dPin, cPin, lPin)
+readNesJoystick(joystick)
+tcs34725
+tcs34725ReadRGBC(id)
+tcs34725GetCorrelatedColorTemperature(r, g, b)
+tcs34725GetIlluminance(r, g, b)
+tcs34725SetInterrupt(id, aien)
+tcs34725ClearInterrupt(id)
+tcs34725SetInterruptLimits(id, low, high)
+tcs34725Enable(id)
+tcs34725Disable(id)
+tcs34725Setup(i2cAddress, integrationTime, gain)