Package pymata_aio :: Module pymata3 :: Class PyMata3
[hide private]
[frames] | no frames]

Class PyMata3

source code

This class exposes and implements a proxy API for the pymata_core asyncio API, If your application does not use asyncio directly, this is the API that you should use..

Instance Methods [hide private]
 
__init__(self, arduino_wait=2, com_port=None)
Constructor for the PyMata3 API
source code
 
analog_read(self, pin)
Retrieve the last data update for the specified analog pin.
source code
 
analog_write(self, pin, value)
Set the selected PWM pin to the specified value.
source code
 
digital_read(self, pin)
Retrieve the last data update for the specified digital pin.
source code
 
digital_write(self, pin, value=0)
Set the specified digital input pin to the provided value
source code
 
disable_analog_reporting(self, pin)
Disables analog reporting for a single analog pin.
source code
 
disable_digital_reporting(self, pin)
Disables digital reporting.
source code
 
encoder_config(self, pin_a, pin_b, cb=None)
This command enables the rotary encoder (2 pin + ground) and will enable encoder reporting.
source code
 
encoder_read(self, pin)
This method retrieves the latest encoder data value.
source code
 
enable_analog_reporting(self, pin)
Enables analog reporting for a single analog pin,
source code
 
enable_digital_reporting(self, pin)
Enables digital reporting.
source code
 
extended_analog(self, pin, data)
This method will send an extended-data analog write command to the selected pin..
source code
 
get_analog_latch_data(self, pin)
A list is returned containing the latch state for the pin, the latched value, and the time stamp [pin_num, latch_state, latched_value, time_stamp] If the the latch state is LATCH_LATCHED, the table is reset (data and timestamp set to zero) It is intended to be used for a polling application.
source code
 
get_analog_map(self, cb=None)
This method requests and returns an analog map.
source code
 
get_capability_report(self, raw=True, cb=None)
This method retrieves the Firmata capability report
source code
 
get_digital_latch_data(self, pin)
A list is returned containing the latch state for the pin, the latched value, and the time stamp [pin_num, latch_state, latched_value, time_stamp] If the the latch state is LATCH_LATCHED, the table is reset (data and timestamp set to zero).
source code
 
get_firmware_version(self, cb=None)
This method retrieves the Firmata firmware version
source code
 
get_protocol_version(self, cb=None)
This method retrieves the Firmata protocol version
source code
 
get_pin_state(self, pin, cb=None)
This method retrieves a pin state report for the specified pin
source code
 
get_pymata_version(self)
This method retrieves the PyMata version number
source code
 
i2c_config(self, read_delay_time=0)
This method configures Arduino i2c with an optional read delay time.
source code
 
i2c_read_data(self, address)
Retrieve result of last data read from i2c device.
source code
 
i2c_read_request(self, address, register, number_of_bytes, read_type, cb=None)
This method issues an i2c read request for a single read,continuous read or a stop, specified by the read_type.
source code
 
i2c_write_request(self, address, args)
Write data to an i2c device.
source code
 
play_tone(self, pin, tone_command, frequency, duration)
This method will call the Tone library for the selected pin.
source code
 
send_reset(self)
Send a Firmata reset command
source code
 
servo_config(self, pin, min_pulse=544, max_pulse=2400)
This method configures the Arduino for servo operation.
source code
 
set_analog_latch(self, pin, threshold_type, threshold_value, cb=None)
This method "arms" an analog pin for its data to be latched and saved in the latching table If a callback method is provided, when latching criteria is achieved, the callback function is called with latching data notification.
source code
 
set_digital_latch(self, pin, threshold_value, cb=None)
This method "arms" a digital pin for its data to be latched and saved in the latching table If a callback method is provided, when latching criteria is achieved, the callback function is called with latching data notification.
source code
 
set_pin_mode(self, pin_number, pin_state, callback=None)
This method sets the pin mode for the specified pin.
source code
 
set_sampling_interval(self, interval)
This method sets the sampling interval for the Firmata loop method
source code
 
sleep(self, time)
Perform an asyncio sleep for the time specified in seconds.
source code
 
shutdown(self)
Shutdown the application and exit
source code
 
sonar_data_retrieve(self)
Retrieve Ping (HC-SR04 type) data.
source code
 
sonar_config(self, trigger_pin, echo_pin, cb=None, ping_interval=50, max_distance=200)
Configure the pins,ping interval and maximum distance for an HC-SR04 type device.
source code
 
stepper_config(self, steps_per_revolution, stepper_pins)
Configure stepper motor prior to operation.
source code
 
stepper_step(self, motor_speed, number_of_steps)
Move a stepper motor for the number of steps at the specified speed This is a FirmataPlus feature.
source code
Method Details [hide private]

__init__(self, arduino_wait=2, com_port=None)
(Constructor)

source code 

Constructor for the PyMata3 API

Parameters:
  • arduino_wait - Amount of time to allow Arduino to finish its reset (2 seconds for Uno, Leonardo can be 0)
  • com_port - If specified, auto port detection will not be performed and this com port will be used.
Returns:
None

analog_read(self, pin)

source code 

Retrieve the last data update for the specified analog pin. It is intended for a polling application.

Parameters:
  • pin - Analog pin number (ex. A2 is specified as 2)
Returns:
Last value reported for the analog pin

analog_write(self, pin, value)

source code 

Set the selected PWM pin to the specified value.

Parameters:
  • pin - PWM pin number
  • value - Set the selected pin to the specified value. 0-0x4000 (14 bits)
Returns:
No return value

digital_read(self, pin)

source code 

Retrieve the last data update for the specified digital pin. It is intended for a polling application.

Parameters:
  • pin - Digital pin number
Returns:
Last value reported for the digital pin

digital_write(self, pin, value=0)

source code 

Set the specified digital input pin to the provided value

Parameters:
  • pin - Digital pin to be set
  • value - 0 or 1
Returns:
No return value

disable_analog_reporting(self, pin)

source code 

Disables analog reporting for a single analog pin.

Parameters:
  • pin - Analog pin number. For example for A0, the number is 0.
Returns:
No return value

disable_digital_reporting(self, pin)

source code 

Disables digital reporting. By turning reporting off for this pin, reporting is disabled for all 8 bits in the "port" -

Parameters:
  • pin - Pin and all pins for this port
Returns:
No return value

encoder_config(self, pin_a, pin_b, cb=None)

source code 

This command enables the rotary encoder (2 pin + ground) and will enable encoder reporting.

This is a FirmataPlus feature.

Encoder data is retrieved by performing a digital_read from pin a (encoder pin 1)

Parameters:
  • pin_a - Encoder pin 1.
  • pin_b - Encoder pin 2.
  • cb - callback function to report encoder changes
Returns:
No return value

encoder_read(self, pin)

source code 

This method retrieves the latest encoder data value. It is a FirmataPlus feature.

Parameters:
  • pin - Encoder Pin
Returns:
encoder data value

enable_analog_reporting(self, pin)

source code 

Enables analog reporting for a single analog pin,

Parameters:
  • pin - Analog pin number. For example for A0, the number is 0.
Returns:
No return value

enable_digital_reporting(self, pin)

source code 

Enables digital reporting. By turning reporting on for all 8 bits in the "port" - This is part of Firmata's protocol specification.

Parameters:
  • pin - Pin and all pins for this port
Returns:
No return value

extended_analog(self, pin, data)

source code 

This method will send an extended-data analog write command to the selected pin..

Parameters:
  • pin - 0 - 127
  • data - 0 - 0-0x4000 (14 bits)
Returns:
No return value

get_analog_latch_data(self, pin)

source code 

A list is returned containing the latch state for the pin, the latched value, and the time stamp [pin_num, latch_state, latched_value, time_stamp] If the the latch state is LATCH_LATCHED, the table is reset (data and timestamp set to zero) It is intended to be used for a polling application.

Parameters:
  • pin - Pin number.
Returns:
[latched_state, threshold_type, threshold_value, latched_data, time_stamp]

get_analog_map(self, cb=None)

source code 

This method requests and returns an analog map.

Returns:
An analog map response or None if a timeout occurs

get_capability_report(self, raw=True, cb=None)

source code 

This method retrieves the Firmata capability report

Parameters:
  • raw - If True, it either stores or provides the callback with a report as list. If False, prints a formatted report to the console
  • cb - Optional callback reference to receive a raw report
Returns:
capability report

get_digital_latch_data(self, pin)

source code 

A list is returned containing the latch state for the pin, the latched value, and the time stamp [pin_num, latch_state, latched_value, time_stamp] If the the latch state is LATCH_LATCHED, the table is reset (data and timestamp set to zero). It is intended for use by a polling application.

Parameters:
  • pin - Pin number.
Returns:
[latched_state, threshold_type, threshold_value, latched_data, time_stamp]

get_firmware_version(self, cb=None)

source code 

This method retrieves the Firmata firmware version

Parameters:
  • cb - Reference to a callback function
Returns:
If no callback is specified, the firmware version

get_protocol_version(self, cb=None)

source code 

This method retrieves the Firmata protocol version

Parameters:
  • cb - Optional callback reference.
Returns:
If no callback is specified, the firmware version

get_pin_state(self, pin, cb=None)

source code 

This method retrieves a pin state report for the specified pin

Parameters:
  • pin - Pin of interest
  • cb - optional callback reference
Returns:
pin state report

get_pymata_version(self)

source code 

This method retrieves the PyMata version number

Returns:
PyMata version number.

i2c_config(self, read_delay_time=0)

source code 

This method configures Arduino i2c with an optional read delay time.

Parameters:
  • read_delay_time - firmata i2c delay time
Returns:
No return value

i2c_read_data(self, address)

source code 

Retrieve result of last data read from i2c device. i2c_read_request should be called before trying to retrieve data. It is intended for use by a polling application.

Parameters:
  • address - i2c
Returns:
last data read or None if no data is present.

i2c_read_request(self, address, register, number_of_bytes, read_type, cb=None)

source code 

This method issues an i2c read request for a single read,continuous read or a stop, specified by the read_type. Because different i2c devices return data at different rates, if a callback is not specified, the user must first call this method and then call i2c_read_data after waiting for sufficient time for the i2c device to respond. Some devices require that transmission be restarted (e.g. MMA8452Q accelerometer). Use I2C_READ | I2C_RESTART_TX for those cases.

Parameters:
  • address - i2c device
  • register - i2c register number
  • number_of_bytes - number of bytes to be returned
  • read_type - Constants.I2C_READ, Constants.I2C_READ_CONTINUOUSLY or Constants.I2C_STOP_READING. Constants.I2C_RESTART_TX may be OR'ed when required
  • cb - optional callback reference
Returns:
No return value

i2c_write_request(self, address, args)

source code 

Write data to an i2c device.

Parameters:
  • address - i2c device address
  • args - A variable number of bytes to be sent to the device passed in as a list.
Returns:
No return value

play_tone(self, pin, tone_command, frequency, duration)

source code 

This method will call the Tone library for the selected pin. It requires FirmataPlus to be loaded onto the arduino If the tone command is set to TONE_TONE, then the specified tone will be played. Else, if the tone command is TONE_NO_TONE, then any currently playing tone will be disabled. It is intended for a future release of Arduino Firmata

Parameters:
  • pin - Pin number
  • tone_command - Either TONE_TONE, or TONE_NO_TONE
  • frequency - Frequency of tone
  • duration - Duration of tone in milliseconds
Returns:
No return value

send_reset(self)

source code 

Send a Firmata reset command

Returns:
No return value

servo_config(self, pin, min_pulse=544, max_pulse=2400)

source code 

This method configures the Arduino for servo operation.

Parameters:
  • pin - Servo control pin
  • min_pulse - Minimum pulse width
  • max_pulse - Maximum pulse width
Returns:
No return value

set_analog_latch(self, pin, threshold_type, threshold_value, cb=None)

source code 

This method "arms" an analog pin for its data to be latched and saved in the latching table If a callback method is provided, when latching criteria is achieved, the callback function is called with latching data notification.

Parameters:
  • pin - Analog pin number (value following an 'A' designator, i.e. A5 = 5
  • threshold_type - Constants.LATCH_GT | Constants.LATCH_LT | Constants.LATCH_GTE | Constants.LATCH_LTE
  • threshold_value - numerical value - between 0 and 1023
  • cb - callback method
Returns:
True if successful, False if parameter data is invalid

set_digital_latch(self, pin, threshold_value, cb=None)

source code 

This method "arms" a digital pin for its data to be latched and saved in the latching table If a callback method is provided, when latching criteria is achieved, the callback function is called with latching data notification.

Parameters:
  • pin - Digital pin number
  • threshold_value - 0 or 1
  • cb - callback function
Returns:
True if successful, False if parameter data is invalid

set_pin_mode(self, pin_number, pin_state, callback=None)

source code 

This method sets the pin mode for the specified pin.

Parameters:
  • pin_number - Arduino Pin Number
  • pin_state - INPUT/OUTPUT/ANALOG/PWM - for SERVO use servo_config()
  • callback - Optional: A reference to a call back function to be called when pin data value changes
Returns:
No return value

set_sampling_interval(self, interval)

source code 

This method sets the sampling interval for the Firmata loop method

Parameters:
  • interval - time in milliseconds
Returns:
No return value

sleep(self, time)

source code 

Perform an asyncio sleep for the time specified in seconds. This method should be used in place of time.sleep()

Parameters:
  • time - time in seconds
Returns:
No return value

shutdown(self)

source code 

Shutdown the application and exit

Returns:
No return value

sonar_data_retrieve(self)

source code 

Retrieve Ping (HC-SR04 type) data. The data is presented as a dictionary. The 'key' is the trigger pin specified in sonar_config() and the 'data' is the current measured distance (in centimeters) for that pin. If there is no data, the value is set to None. This is a FirmataPlus feature.

Returns:
active_sonar_map

sonar_config(self, trigger_pin, echo_pin, cb=None, ping_interval=50, max_distance=200)

source code 

Configure the pins,ping interval and maximum distance for an HC-SR04 type device. Single pin configuration may be used. To do so, set both the trigger and echo pins to the same value. Up to a maximum of 6 SONAR devices is supported If the maximum is exceeded a message is sent to the console and the request is ignored. NOTE: data is measured in centimeters This is FirmataPlus feature.

Parameters:
  • trigger_pin - The pin number of for the trigger (transmitter).
  • echo_pin - The pin number for the received echo.
  • cb - optional callback function to report sonar data changes
  • ping_interval - Minimum interval between pings. Lowest number to use is 33 ms.Max is 127
  • max_distance - Maximum distance in cm. Max is 200.
Returns:
No return value

stepper_config(self, steps_per_revolution, stepper_pins)

source code 

Configure stepper motor prior to operation. This is a FirmataPlus feature.

Parameters:
  • steps_per_revolution - number of steps per motor revolution
  • stepper_pins - a list of control pin numbers - either 4 or 2
Returns:
No return value

stepper_step(self, motor_speed, number_of_steps)

source code 

Move a stepper motor for the number of steps at the specified speed This is a FirmataPlus feature.

Parameters:
  • motor_speed - 21 bits of data to set motor speed
  • number_of_steps - 14 bits for number of steps & direction positive is forward, negative is reverse