The digital functionality currently supported by the RPiSoC Python API
Class: | Provides functionality for use of the GPIO on the RPiSoC as a digital input or output, with a number of different drive mode configurations. |
---|---|
Example: | Define a digitalPin object in the following way: My_input = digitalPin(Port,Pin,'IN')
My_output = digitalPin(Port,Pin,'OUT')
'''or more generally'''
My_pin = digitalPin(Port,Pin,DRIVE_MODE)
|
Note: | Modification of which pins are available should be easy. Just add new pins to you RPiSoC schematic, give them an input and an output, and then name them as GPIO_PORT_PIN. After you do this, confirm that it was done correctly by using the DEBUG feature of the RPiSoC class. |
Method | __init__ |
---|---|
Description | Constructs and initializes a digitalPin object |
Parameters |
|
PORT |
|
PIN |
|
CONFIG |
|
Returns | No return |
Method | Configure |
---|---|
Description | Sets the drive mode of the pin as input (high impedence digital), resistive pullup, resistive pull down, open drain (drives low), open drain (drives high), output (strong drive), or resistive pull-up/down |
Parameters |
|
CONFIG |
|
Returns | No return |
Method | Read |
---|---|
Description | Determines the state of the digital pin on the RPiSoC |
Parameters | None |
Returns | bool state |
state | A True or False value when the output is determined to be HIGH or LOW, respectively |
Method | Toggle |
---|---|
Description | Toggles the state of the specified output and commits that value to the RPiSoC |
Parameters | None |
Returns | No return |
Method | Write |
---|---|
Description |
|
Parameters |
|
val |
|
Returns | No return |
Class: | This class provides functionality for use of the PWM components available on the RPiSoC. |
---|---|
Example: | Define PWM objects in the following way: My_PWM = PWM(0)
My_other_PWM = PWM(1)
'''etc etc... '''
My_last_PWM = PWM(7)
|
Method | __init__ |
---|---|
Description | Constructs and initializes PWM object |
Parameters | int portNumber |
portNumber |
|
Returns | No return |
Method | ClearFIFO |
---|---|
Description | Clears the capture FIFO of any previously captured data. Here PWM_ReadCapture() is called until the FIFO is empty |
Parameters | None |
Returns | No return |
Method | GetClockDivider |
---|---|
Description | Gets the most recently confirmed clock divider value, which is used to determine the clocking frequency of the PWM |
Parameters | None |
Returns | int div |
div | 16-bit clock divider value |
Method | GetClocks |
---|---|
Description | Calculates the actual clock rate of the PWM’s based on the most recently confirmed clock divider value |
Parameters | None |
Returns | float clk |
clk | The actual frequency of the PWM clock |
Method | GetDutyCycle |
---|---|
Description | Calculates the current duty cycle based on the current period and comparison values |
Optional Parameters | int PRECISION |
PRECISION |
|
Returns | float duty_cycle |
duty_cycle | A value which is representative of the percentage of time, between 0 and 100%, that the PWM signal is on, relative to the total length of its period |
Method | GetFrequency |
---|---|
Description | Calculates the current PWM wave frequency based on the current clock rate and period value |
Optional Parameters | int PRECISION |
PRECISION |
|
Returns | float freq |
freq | A frequency in Hz, which is representative of the current PWM signal frequency |
Method | GetMIDI |
---|---|
Description | Calculates what MIDI note corresponds to the current PWM frequency |
Parameters | None |
Returns | int MIDI |
MIDI | The MIDI note, as defined by the MIDI standard to correspond with a specific musical note, which most closely resembles the PWM frequency |
Method | ReadCompare |
---|---|
Description | Determines the compare value, in counts, currently used by the PWM component |
Parameters | None |
Returns | int cmp |
cmp | The compare value, in counts, currently used by the PWM component |
Method | ReadPeriod |
---|---|
Description | Determines the period value, in counts, currently used by the PWM component |
Parameters | None |
Returns | int period |
period | The period value, in counts, currently used by the PWM component |
Method | SetClockDivider |
---|---|
Description | Sets a divider to the desired PWM’s clock source |
Parameters | int divider |
div |
|
Returns | No return |
Method | SetClocks |
---|---|
Description |
|
Parameters | float frequency |
frequency |
|
Returns | No return |
Warning |
|
Method | SetDutyCycle |
---|---|
Description | Simplifies the process of setting a meaningful comparison value by calculating the correct cmp value based on a desired duty cycle |
Parameters | float duty_cycle |
duty_cycle |
|
Returns | No return |
Method | SetFrequency |
---|---|
Description |
|
Parameters |
|
Optional Parameters |
|
freq |
|
MAX_ERROR |
|
MIN_PERIOD |
|
Returns | No return |
Method | SetMIDI |
---|---|
Description | Generates a PWM wave frequency the corresponds to the specified MIDI note |
Parameters |
|
Optional Parameters |
|
MIDI | A MIDI note, as defined by the MIDI standard to correspond with a specific musical note |
MAX_ERROR |
|
MIN_PERIOD |
|
Returns | No return |
Method | Sleep |
---|---|
Description | Stops the PWM operation, puts the PWM component into it’s lowest power state, and saves the current configuration |
Parameters | None |
Returns | No return |
Method | Start |
---|---|
Description | Starts component operation. Sets the initVar variable, calls the PWM_Init function, and then calls the PWM_Enable function |
Parameters | None |
Returns | No return |
Method | Stop |
---|---|
Description | Disables the PWM operation |
Parameters | None |
Returns | No return |
Method | Wakeup |
---|---|
Description | Restores and enables the most recently saved configuration |
Parameters | None |
Returns | No return |
Method | WriteCompare |
---|---|
Description | Writes the period value used by the PWM hardware |
Parameters | int cmp |
cmp |
|
Returns | No return |
Method | WritePeriod |
---|---|
Description | Writes the period value used by the PWM hardware |
Parameters | int period |
period |
|
Returns | No return |
Method | isRunning |
---|---|
Description | Checks to see if the PWM component is currently operational |
Parameters | None |
Returns | bool __running |
__running | A private boolean variable which evaluates to True if the PWM component is operational, or False if it is not |
Class: | This class provides allows for easy manipulation of standard Servo Motors using PWM. |
---|---|
Example: | Define Servo objects in any the following ways: My_simple_servo = Servo(0)
My_calibrated_servo = Servo(1, 1.0, 2.5)
My_descriptive_servo = Servo(7, 1.0, 2.5, 0, 180)
|
Method | __init__ |
---|---|
Description | Creates a servo object with the given parameter set |
Parameters |
|
Optional Parameters |
|
servo_id |
|
min_pulse |
|
max_pulse |
|
min_angle |
|
max_angle |
|
Returns | No return |
Note | A servo with servo_id, n, will make PWM(n) unnavailable, since the servo controller is implemented using that PWM object. For fine control over that PWM, you can expose the object using My_servo.servo_PWM, and then you can use any of the PWM methods using My_servo.servo_PWM.method(). This is advised against though, because servos are very particular about the construction of their data signals. If you change the wrong parameter of the PWM signal, you might damage the servo |
Method | ReadAngle |
---|---|
Description | Calculates the current angle of the servomotor, linearized relative to the provided maximum and minimum angles |
Parameters | None |
Returns | float angle_cur |
angle_cur | A value representative of the angle that the servo motor is held, according to the provided scale |
Method | ReadPulse |
---|---|
Description | Calculates the current pulse width of the PWM which is driving the servomotor |
Parameters | None |
Returns | float pulse |
pulse | A pulse duration in milliseconds, representative of the PWM signal pulse width being applied ot the servomotor |
Method | SetAngle |
---|---|
Description | Calculates a pulse width based on the given angular position and the current min/max configuration parameters, then calls SetPulse() to set the position of the servo |
Parameters | float angle |
angle | The angle to which the servo should be set, linearized relative to the defined minimum and maximum angles |
Returns | No return |
Method | SetPulse |
---|---|
Description | Sets a servo position based on a pulse width in ms |
Parameters | float pulse_ms |
pulse_ms |
|
Returns | No return |
Method | Start |
---|---|
Description | Starts component operation. |
Parameters | None |
Returns | No return |
Method | Stop |
---|---|
Description | Stops the servo object by terminating the PWM channel that drives it |
Parameters | None |
Returns | No return |
Side Effects | This may cause the servo to move slightly out of position |
Method | changeAngles |
---|---|
Description | Changes the angle range that defines the minimum and maximum positions of the motor |
Parameters |
|
MIN |
|
MAX |
|
Returns | No return |
Method | isRunning |
---|---|
Description | Checks to see if the Servo component is currently operational |
Parameters | None |
Returns | bool __running |
__running | A private boolean variable which evaluates to True if the PWM component is operational, or False if it is not |
Class: | This class provides functionality for use of an Arduino NeoPixels shield on an RPiSoC through Python. |
---|---|
Example: | Create a NeoPixelShield object in the following way: shield = NeoPixelShield()
|
Method | __init__ |
---|---|
Description | Defines the register address for the striplight controller used by the NeoPixels, and it defines 140 colors as class attributes, named according to their standardized HTML and CSS names |
Parameters | None |
Returns | No return |
Method | Dim |
---|---|
Description | Preserves the color to be drawn to the shield, but dims the brightness. Effects take place immediately. |
Parameters |
|
DIM_LEVEL |
|
Returns | No return |
Method | DrawColumn |
---|---|
Description | Fully draws the chosen column the desired color |
Parameters |
|
column |
|
color |
|
Returns | No return |
Method | DrawRow |
---|---|
Description | Fully draws the chosen row the desired color |
Parameters |
|
row |
|
color |
|
Returns | No return |
Method | RGB_toHex |
---|---|
Description | Converts RGB content to the needed BRG Hex value taken by the NeoPixelShield device |
Parameters | list or tuple RGB |
RGB |
|
Returns | int hex_val |
hex_val | A hex value which can be given to a NeoPixelShield object as a valid color |
Method | SetPixel |
---|---|
Description | Sets the given pixel at location (x,y) = (row, column), to a color defined by a 24 bit Blue-Red-Green (BRG) value (8-bits each) |
Parameters |
|
row |
|
column |
|
color |
|
Returns | No return |
Method | Start |
---|---|
Description | Powers up and enables the needed hardware for the NeoPixels component |
Parameters | None |
Returns | No return |
Method | Stop |
---|---|
Description | Powers down and disables the needed hardware for the NeoPixels component |
Parameters | None |
Returns | No return |
Method | Stripe |
---|---|
Description | Draws a line of length pixelnum of the stated color, starting from the first pixel, and extending as far as the 40th (last) pixel. It will wrap around rows |
Parameters |
|
pixelnum |
|
color |
|
Returns | No return |
Method | isRunning |
---|---|
Description | Checks to see if the NeoPixels display is currently powered up |
Parameters | None |
Returns | bool __running |
__running | A private boolean variable which evaluates to True if the NeoPixels display is running, or False if it is not |
Class: | This class provides functionality for use of ultrasonic range finder devices that use standard GPIO pulse width measurement protocols |
---|---|
Example: | Define a rangeFinder object in the following way: my_ranger = rangerFinder([SIG_PORT,SIG_PIN], [TRIG_PORT, TRIG_PIN])
|
Method | __init__ |
---|---|
Description | Initializes an object by describing which pin the echo will be measured on. Optionally, provide a trigger pin if the ranger is a 4 or 5 pin form factor, also optionally provide a trigger pulse width and timeout value in milliseconds |
Parameters |
|
Optional Parameters |
|
SIG |
|
TRIGGER |
|
DELAYus |
|
TIMEOUTus |
|
Returns | No return |
Method | readCentimeters |
---|---|
Description | Uses readRaw to get a raw time value in microseconds, and then calculates the distance between the ranger and the pinged object in centimeters |
Optional Parameters |
|
sound |
|
PRECISION |
|
Returns | float meters |
meters | The distance, in meters, between the ultrasonic ranger and the pinged object |
Method | readInches |
---|---|
Description | Uses readRaw to get a raw time value in microseconds, and then calculates the distance between the ranger and the pinged object in inches |
Optional Parameters |
|
sound |
|
PRECISION |
|
Returns | float meters |
meters | The distance, in meters, between the ultrasonic ranger and the pinged object |
Method | readMeters |
---|---|
Description | Uses readRaw to get a raw time value in microseconds, and then calculates the distance between the ranger and the pinged object in meters |
Optional Parameters |
|
sound |
|
PRECISION |
|
Returns | float meters |
meters | The distance, in meters, between the ultrasonic ranger and the pinged object |
Method | readRaw |
---|---|
Description |
|
Parameters | None |
Returns | int reading |
reading |
|
Method | setDelay |
---|---|
Description | Sets the length of the trigger pulse, in microseconds, which will be used to tell the device to send out a ping |
Parameters |
|
delay_us |
|
Returns | No return |
Notes | This is handled in __init__(), so it should only be called under unique circumstances |
Method | setTimeout |
---|---|
Description | Sets the timeout length in microseconds. If the RPiSoC is still waiting for a completed response after this amount of time, it will stop counting and immediately return the result |
Parameters |
|
timeout_us |
|
Returns | No return |
Notes | This is handled in __init__(), so it should only be called under unique circumstances |