spiagent |
Python3 library for the Raspberry Pi LPC1114 I/O Processor Expansion Board
See http://git.munts.com/rpi-mcu/expansion/LPC1114 for more information.
Classes |
|
|
- builtins.object
-
- ADC
- GPIO
- LegoRC
- PWM
-
- Motor(PWM, GPIO)
- Servo
- Timer
- Transport
class
ADC(builtins.object) |
|
The ADC class configures an LPC1114 GPIO pin for analog input.
WARNING: LPC1114 Analog inputs are NOT 5V tolerant!
Do NOT exceed 3.3V on any analog input.
EXAMPLE:
import spiagent
t = spiagent.Transport("bogus.com")
# Read the analog input voltage on LPC1114_ADC1
ADC1 = spiagent.ADC(t, spiagent.LPC1114_ADC1)
print(ADC1.voltage)
|
|
Methods:
- ADC(transport, pin)
- Constructor function.
Parameter transport must be a Transport instance with an open connection.
Parameter pin must be spiagent.LPC1114_ADC1 through spiagent.LPC1114_ADC5.
Properties:
- voltage
- Analog input voltage (read only).
Returns float 0.0 through 3.3 when read.
|
class
GPIO(builtins.object) |
|
The GPIO class configures an LPC1114 GPIO pin for General Purpose
Input/Output.
EXAMPLE:
import spiagent
t = spiagent.Transport("bogus.com")
# Turn on the LED
LED = spiagent.GPIO(t, spiagent.LPC1114_LED, spiagent.GPIO_MODE_OUTPUT)
LED.state = 1
print(LED.state)
|
|
Methods:
- GPIO(transport, pin, mode)
- Constructor function.
Parameter transport must be a Transport instance with an open connection.
Parameter pin must be spiagent.LPC1114_GPIO0 through spiagent.LPC1114_GPIO7,
spiagent.LPC1114_INT, or spiagent.LPC1114_LED.
Parameter mode must be an integer from spiagent.GPIO_MODE_INPUT (0) through
spiagent.GPIO_MODE_OUTPUT_OPENDRAIN (4).
Properties:
- state
- GPIO pin state (read/write).
Returns integer 0 or 1 when read.
Allowed write values are 0, 1, False, or True.
|
class LegoRC(builtins.object) |
|
The LegoRC class configures an LPC1114 GPIO pin for LEGO(R) Power Functions
Remote Control output.
NOTE: You will need to drive the infrared emitter diode (IRED) with a high
current driver such as the ULN2003A. The LPC1114 GPIO pins are not capable
of driving an IRED without current amplification.
EXAMPLE:
import spiagent
t = spiagent.Transport("bogus.com")
# Set Motor A speed to forward, 5
IRED = spiagent.LegoRC(t, spiagent.GPIO7)
IRED.SendCommand(1, spiagent.LEGORC_MOTORA, spiagent.LEGORC_FORWARD, 5)
|
|
Methods:
- SendCommand(channel, motor,
direction, speed)
-
Transmit a LEGO(R) Power Functions Remote Control command.
Parameter channel must be an integer from 1 through 4.
Parameter motor must be an integer from spiagent.LEGORC_ALLSTOP (0)
through spiagent.LEGORC.COMBOPWM (4).
Parameter direction must be an integer from spiagent.LEGORC_REVERSE (0)
through spiagent.LEGORC_FORWARD (1).
Parameter speed must be an integer from 0 through 255.
NOTE: Some motor settings restrict the speed to smaller ranges.
- LegoRC(transport, pin)
- Constructor function.
Parameter transport must be a Transport instance with an open connection.
Parameter pin must be spiagent.LPC1114_GPIO0 through spiagent.LPC1114_GPIO7.
|
class
Motor(PWM, GPIO) |
|
The Motor class configures a pair of LPC1114 GPIO pins as outputs to drive
an H-bridge DC motor driver chip or module.
EXAMPLE:
import spiagent
t = spiagent.Transport("bogus.com")
M1 = spiagent.Motor(t, spiagent.LPC1114_PWM1, spiagent.LPC1114_GPIO0, 1000)
M1.speed = 0.5
|
|
- Method resolution order:
- Motor
- PWM
- GPIO
- builtins.object
Methods:
- Motor(transport, PWMpin, DIRpin,
frequency=50)
- Constructor function.
Parameter transport must be a Transport instance with an open connection.
Parameter PWMpin must be spiagent.LPC1114_PWM1 through spiagent.LPC1114_PWM4.
Parameter DIRpin must be spiagent.LPC1114_GPIO0 through spiagent.LPC1114_GPIO7.
Parameter frequency must be an integer from value 50 through 50000 (Hertz).
Optional, default value is 50. Small hobby motors seem to work best at 50 Hz.
Larger industrial motors may work better at higher frequencies.
NOTE: PWM outputs PWM1, PWM2, and PWM3 share the same frequency generator.
The pulse frequency will be the same for all of these PWM outputs, the last
frequency configured for any of them.
Properties:
- speed
- Motor speed property (write only).
Allowed write values are float -1.0 through +1.0 (normalized speed).
Properties inherited from PWM:
- dutycycle
- PWM output duty cycle (write only).
Allowed write values are float 0.0 through 100.0 (percent duty cycle).
Properties inherited from GPIO:
- state
- GPIO pin state (read/write).
Returns integer 0 or 1 when read.
Allowed write values are 0, 1, False, or True.
|
class
PWM(builtins.object) |
|
The PWM class configures an LPC1114 GPIO pin for Pulse Width Modulated output.
EXAMPLE:
import spiagent
t = spiagent.Transport("bogus.com")
# Set the output duty cycle on LPC1114_PWM1 to 50%
PWM1 = spiagent.PWM(spiagent.LPC1114_PWM1, 50)
PWM1.dutycycle = 50.0
|
|
Methods:
- PWM(transport, pin,
frequency=50)
- Constructor function.
Parameter transport must be a Transport instance with an open connection.
Parameter pin must be spiagent.LPC1114_PWM1 through spiagent.LPC1114_PWM4.
Parameter frequency must be an integer from value 50 through 50000 (Hertz).
Optional, default value is 50.
NOTE: PWM outputs PWM1, PWM2, and PWM3 share the same frequency generator.
The pulse frequency will be the same for all of these PWM outputs, the last
frequency configured for any of them.
Properties:
- dutycycle
- PWM output duty cycle (write only).
Allowed write values are float 0.0 through 100.0 (percent duty cycle).
|
class
Servo(PWM) |
|
The Servo class configures an LPC1114 GPIO pin as an output to drive a
standard RC (Radio Control) servo. The pulse width is limited to the
range 1.0 to 2.0 milliseconds, with the neutral/null/zero position at 1.5
milliseconds.
EXAMPLE:
import spiagent
t = spiagent.Transport("bogus.com")
# Set the servo connected to LPC1114_PWM2 to the fully extended position
S1 = spiagent.Servo(spiagent.LPC1114_PWM2)
S1.position = 1.0
|
|
- Method resolution order:
- Servo
- PWM
- builtins.object
Methods:
- Servo(transport, pin,
frequency=50)
- Constructor function.
Parameter transport must be a Transport instance with an open connection.
Parameter pin must be spiagent.LPC1114_PWM1 through spiagent.LPC1114_PWM4.
Parameter frequency must be an integer from value 50 through 50000 (Hertz).
Optional, default value is 50. Standard servos operate at 50 Hz. Some
newer digital servos can operate as high as 400 Hz.
NOTE: PWM outputs PWM1, PWM2, and PWM3 share the same frequency generator.
The pulse frequency will be the same for all of these PWM outputs, the last
frequency configured for any of them.
Properties:
- position
- RC servo position (write only).
Allowed write values are float -1.0 through +1.0 (normalized deflection from
the neutral position).
Properties inherited from PWM:
- dutycycle
- PWM output duty cycle (write only).
Allowed write values are float 0.0 through 100.0 (percent duty cycle).
|
class
Timer(builtins.object) |
|
The Timer class configures an LPC1114 32-bit timer/counter.
EXAMPLE:
import spiagent
t = spiagent.Transport("bogus.com")
# Output 1000 Hz square wave on pin LPC1114_CT32B1_MAT0
T1 = spiagent.Timer(t, spiagent.CT32B1)
T1.ConfigurePrescaler(1)
T1.ConfigureMatch(0, spiagent.PCLK_FREQUENCY//1000//2, spiagent.TIMER_MATCH_OUTPUT_TOGGLE, spiagent.TIMER_MATCH_RESET)
T1.ConfigureMode(spiagent.TIMER_MODE_PCLK)
|
|
Methods:
- ConfigureCapture(edge,
features=0)
- Configure the CAP0 input capture edge.
Parameter edge must be an integer from spiagent.TIMER_CAPTURE_EDGE_DISABLED (0)
through spiagent.TIMER_CAPTURE_EDGE_CAP0_BOTH (3).
Parameter features must be 0 or spiagent.TIMER_CAPTURE_INTERRUPT (16).
- ConfigureMatch(match, value,
action, features)
- Configure a match register.
Parameter match must be an integer from 0 through 3.
Parameter value must be a 32-bit integer.
Parameter action must be an integer from spigent.TIMER_MATCH_OUTPUT_DISABLED (0)
through spiagent.TIMER_MATCH_OUTPUT_TOGGLE (3).
Parameter features must 0 or one or more of spiagent.TIMER_MATCH_INTERRUPT (16)
OR'ed with spiagent.TIMER_MATCH_RESET (32).
- ConfigureMode(mode)
- Configure the timer mode.
Parameter mode must be an integer from spiagent.TIMER_MODE_DISABLED (0)i
through spiagent.TIMER_MODE_CAP0_BOTH (5).
- ConfigurePrescaler(prescaler)
- Configure the timer prescaler.
Parameter prescaler must be a 32-bit integer.
- Timer(transport, timer,
mode=0, prescaler=1)
- Constructor function.
Parameter transport must be a Transport instance with an open connection.
Parameter timer must be an integer from spiagent.CT32B0 (0) through
spiagent.CT32B1 (1).
Parameter mode must be an integer spiagent.TIMER_MODE_DISABLED (0)
through spiagent.TIMER_MODE_CAP0_BOTH (5).
Parameter prescaler must be a 32-bit integer.
Properties:
- capture
- Capture register (read only).
Returns a 32-bit integer value.
- capture_delta
-
Capture delta (difference between last two capture values) (read only).
Returns a 32-bit integer value.
- counter
- Counter register (read only).
Returns a 32-bit integer value.
|
class Transport(builtins.object) |
|
The Transport class provides services for dispatching commands to a
Raspberry Pi running the LPC1114 I/O Processor Expansion Board SPI Agent
Firmware server.
EXAMPLE:
import spiagent
t = spiagent.Transport("bogus.com")
# Send a NOP command to the LPC1114 SPI Agent Firmware
resp=[]
t.command((spiagent.CMD_NOP, 0, 0), resp)
print(resp)
t.close()
|
|
Methods:
- Transport(server=None, lib=None)
- Constructor function.
Parameter server (string or None) indicates the domain name or IP address
of the server. If server is provided, call the open() method to
connect to the specified server.
Parameter lib (string: "auto", "libspiagent", "xml-rpc" or None) indicates
which underlying transport library to use. If lib is provided, use the
specified transport library for communicating with the server.
- close()
- Close the connection to the server.
- command(cmd, resp)
-
Dispatch a command to the SPI Agent Firmware running on the LPC1114
microcontroller.
Parameter cmd must be a list or tuple of three integers (command, pin, data).
Parameter resp must be an empty list. It will be filled with 4 integers
from the SPI Agent Firmware (command, pin, data, error).
- open(server)
-
Open a connection to the specified server.
Parameter server (string) indicates the domain name or IP address of the
server.
Properties:
Data and other attributes:
- __handler__ = None
|
|
Data |
|
|
ANALOG_BITS = 10
ANALOG_MAX_CHANNEL = 5
ANALOG_MIN_CHANNEL = 1
ANALOG_PINS = (12, 13, 14, 15, 16)
ANALOG_SPAN = 3.3
ANALOG_STEPS = 1024
ANALOG_STEPSIZE = 0.00322265625
CMD_CONFIGURE_ANALOG_INPUT = 2
CMD_CONFIGURE_GPIO = 11
CMD_CONFIGURE_GPIO_INPUT = 3
CMD_CONFIGURE_GPIO_INTERRUPT = 10
CMD_CONFIGURE_GPIO_OUTPUT = 4
CMD_CONFIGURE_PWM_OUTPUT = 5
CMD_CONFIGURE_TIMER_CAPTURE = 17
CMD_CONFIGURE_TIMER_MATCH0 = 18
CMD_CONFIGURE_TIMER_MATCH0_VALUE = 22
CMD_CONFIGURE_TIMER_MATCH1 = 19
CMD_CONFIGURE_TIMER_MATCH1_VALUE = 23
CMD_CONFIGURE_TIMER_MATCH2 = 20
CMD_CONFIGURE_TIMER_MATCH2_VALUE = 24
CMD_CONFIGURE_TIMER_MATCH3 = 21
CMD_CONFIGURE_TIMER_MATCH3_VALUE = 25
CMD_CONFIGURE_TIMER_MODE = 15
CMD_CONFIGURE_TIMER_PRESCALER = 16
CMD_GET_ANALOG = 6
CMD_GET_GPIO = 7
CMD_GET_SFR = 13
CMD_GET_TIMER_CAPTURE = 27
CMD_GET_TIMER_CAPTURE_DELTA = 28
CMD_GET_TIMER_VALUE = 26
CMD_INIT_TIMER = 29
CMD_LOOPBACK = 1
CMD_NOP = 0
CMD_PUT_GPIO = 8
CMD_PUT_LEGORC = 12
CMD_PUT_PWM = 9
CMD_PUT_SFR = 14
CT32B0 = 0
CT32B1 = 1
GPIO_INTERRUPT_BOTH = 3
GPIO_INTERRUPT_DISABLED = 0
GPIO_INTERRUPT_FALLING = 1
GPIO_INTERRUPT_RISING = 2
GPIO_MODE_INPUT = 0
GPIO_MODE_INPUT_PULLDOWN = 1
GPIO_MODE_INPUT_PULLUP = 2
GPIO_MODE_OUTPUT = 3
GPIO_MODE_OUTPUT_OPENDRAIN = 4
GPIO_PINS = (12, 13, 14, 15, 16, 17, 20, 21)
GPIO_PULLDOWN = 0
GPIO_PULLUP = 1
IMTER_MATCH_STOP = 64
LEGORC_ALLSTOP = 0
LEGORC_CHANNELS = 4
LEGORC_COMBODIRECT = 3
LEGORC_COMBOPWM = 4
LEGORC_FORWARD = 1
LEGORC_MAXSPEED = 255
LEGORC_MOTORA = 1
LEGORC_MOTORB = 2
LEGORC_REVERSE = 0
LPC1114_AD1 = 12
LPC1114_AD2 = 13
LPC1114_AD3 = 14
LPC1114_AD4 = 15
LPC1114_AD5 = 16
LPC1114_CT32B0_CAP0 = 17
LPC1114_CT32B1_CAP0 = 12
LPC1114_CT32B1_MAT0 = 13
LPC1114_CT32B1_MAT1 = 14
LPC1114_CT32B1_MAT2 = 15
LPC1114_CT32B1_MAT3 = 16
LPC1114_DEVICE_ID = 1074037748
LPC1114_GPIO0 = 12
LPC1114_GPIO1 = 13
LPC1114_GPIO1DATA = 1342246140
LPC1114_GPIO2 = 14
LPC1114_GPIO3 = 15
LPC1114_GPIO4 = 16
LPC1114_GPIO5 = 17
LPC1114_GPIO6 = 20
LPC1114_GPIO7 = 21
LPC1114_INT = 3
LPC1114_LED = 7
LPC1114_PWM1 = 13
LPC1114_PWM2 = 14
LPC1114_PWM3 = 15
LPC1114_PWM4 = 21
LPC1114_READY = 11
LPC1114_U0SCR = 1073774620
PCLK_FREQUENCY = 48000000
PWM_MAX_CHANNEL = 4
PWM_MAX_DUTYCYCLE = 100.0
PWM_MAX_FREQUENCY = 50000
PWM_MIN_CHANNEL = 1
PWM_MIN_DUTYCYCLE = 0.0
PWM_MIN_FREQUENCY = 50
PWM_PINS = (13, 14, 15, 21)
SERVO_MAX_POSITION = 1.0
SERVO_MIN_POSITION = -1.0
TIMER_CAPTURE_EDGE_CAP0_BOTH = 3
TIMER_CAPTURE_EDGE_CAP0_FALLING = 2
TIMER_CAPTURE_EDGE_CAP0_RISING = 1
TIMER_CAPTURE_EDGE_DISABLED = 0
TIMER_CAPTURE_INTERRUPT = 16
TIMER_MATCH_INTERRUPT = 16
TIMER_MATCH_OUTPUT_CLEAR = 1
TIMER_MATCH_OUTPUT_DISABLED = 0
TIMER_MATCH_OUTPUT_SET = 2
TIMER_MATCH_OUTPUT_TOGGLE = 3
TIMER_MATCH_RESET = 32
TIMER_MODE_CAP0_BOTH = 5
TIMER_MODE_CAP0_FALLING = 4
TIMER_MODE_CAP0_RISING = 3
TIMER_MODE_DISABLED = 0
TIMER_MODE_PCLK = 2
TIMER_MODE_RESET = 1
__loader__ = <_frozen_importlib.SourceFileLoader
object>
__spec__ = ModuleSpec(name='spiagent',
loader=<_frozen_impo...bject at 0x7f49fb057940>,
origin='./spiagent.py') |
Author |
|
|
Philip Munts <phil@munts.net> |
|