Module:digihw
From Digi Developer
This module is for interacting with special hardware within Digi some products. An exception will be thrown if you attempt access hardware which does not exist within your model.
Contents |
General I/O Pins
These routines allow access to GPIO pins from python. For a description of the available GPIO pins for your device refer to the Hardware Reference manual. Only pins which are not in use for other functions can be used.
The GPIO API uses names which correspond to the pins on the module connector. For example X2_3 refers to the third pin on connector X2, this is shown on the schematics provided with the kit on the system connectors sheet.
Refer to the GPIO appendix in the hardware reference manual which is supplied with the kit.
gpio_get_value(gpio_number) return value
Read the specified GPIO pin. An exception is raised if the gpio is invalid. Return Value: Value of the GPIO pin
gpio_set_value(gpio_number, value) return None
Set the specified GPIO pin. Value is zero or non zero. An exception is raised if the gpio is invalid.
gpio_set_input(gpio_number) return None
Set the specified GPIO pin as an input. An exception is raised if the gpio is invalid
LED Control
These routines allow a user to control the avaliable LED's. Refer to the Hardware Reference Manual supplied with the kit to determine which LED's are available.
user_led_set(value [, led=1]) return None
The user controlled LED is made to match the logic state of the "value" parameter. A true value turns on the LED, and a false value turns it off. The "led" parameter indicates which user LED to blink, a value of one indicates LED 1 (the default), a value of two indicates LED 2. The led parameter is optional on platforms with only one user LED
Examples
Wake up on a GPIO button press
# Routine which waits for a user to press user button 2 on the Connect Core 9P 9215 def wait_for_button (): # Wait for the user to press button 2 digihw.gpio_set_input(digihw.X2_52) print "Press Button 2 to continue" while(True): val = digihw.gpio_get_value(digihw.X2_52) if val == 0: break while(True): val = digihw.gpio_get_value(digihw.X2_52) if val == 1: break
Set GPIO pins low
import digihw digihw.gpio_set_value(digihw.X2_35, 0) digihw.gpio_set_value(digihw.X2_48, 0) digihw.gpio_set_value(digihw.X2_52, 0) digihw.gpio_set_value(digihw.X2_50, 0) digihw.gpio_set_value(digihw.X2_36, 0) digihw.gpio_set_value(digihw.X2_37, 0) digihw.gpio_set_value(digihw.X2_38, 0)
Read a range of GPIO pins
# Instead of the symbolic name, you can specify an index into the GPIO # table (zero based index) import digihw for pinNumber in range (low_test_range, high_test_range): val = digihw.gpio_get_value(pinNumber) if val < 0: print "The last pin is [%d]" % (pinNumber) break print "Value for pin [%d] is [%d]" % (pinNumber, val) # Set all the pins high for pinNumber in range (low_test_range, high_test_range): print "Setting pin [%d] to [%d]" % (pinNumber, 1) digihw.gpio_set_value(pinNumber, 1)
Blink the LED's
import digihw # turn off user LED's after the user presses the button # Turn on user LED's digihw.user_led_set(1, 1) digihw.user_led_set(1, 2) # This routine is define in the example above wait_for_button() # Turn off the LED's digihw.user_led_set(0, 1) digihw.user_led_set(0, 2)
Note: The Digi ConnectPort X4 only has 1 LED which is numbered one (1). So the digihw.user_led_set(1, 1) works, and digihw.user_led_set(1, 2) causes an error.
Availability - GPIO Pins
In general, most Digi Python-enabled products DO NOT support this module.
Digi Python-enabled products which do support this feature include:
- Digi ConnectCore 3G 9P 9215
- Digi ConnectPort X5
- Digi ConnectPort X4 has 1 LED (requires firmware 82001536_K or newer)
GPS Location
The GPS support in the ConnectPort X5 is managed by a self-contained, dedicated module, which delivers relatively standard NMEA strings to the embedded operating system. While it is possible for an application to retrieve and parse raw NMEA strings, if necessary, (a device named "/gps/0" exists on the system, and can be opened and read), this has two major disadvantages: (1) it adds unnecessary complexity to every application that wishes to do even the most common retrieval of information from the GPS, and (2) it is unnecessarily exclusive; only one thread, for all practical purposes, can have the special device open and be reading from it at one time.
To simplify the most common operation, the AccelePort X5 embedded operating system offers the "gps_location" command in its "digihw" embedded Python module. Any thread can call "gps_location" at any time and retrieve position information (deemed the most common extraction from an NMEA stream). The position information returned by "gps_location" is associated with a timestamp. This time is relative to the system's concept of time. This choice was made intentionally, as it seemed prudent to allow these samples to be compared with the results of a call to the "time" module's "time" function... the generally available time reference for Python scripts running in the system.
gps_location(): return (latitude, longitude, altitude, timestamp)
Returns a 4-tuple combining floating-point latitude, longitude, and altitude, as well as a timestamp taken when the sample was first parsed.
Note - for ConnectPort X3/X-trak3 devices additional information is available namely -- fixtype, speed and direction as shown below
gps_location(): return (latitude, longitude, altitude, timestamp, speed, direction,fixtype)
Returns a 7-tuple combining Fix type (2D and 3D) floating-point latitude, longitude, altitude,UTC time stamp (long integer) taken when the sample was first parsed ,speed and direction.
The timestamp is in a form consistent with that returned by the time() function of the time module, and is not drawn directly from the NMEA stream, and is thus not supplied by the GPS satellites.
Availability - GPS Location
In general, most Digi Python-enabled products DO NOT support this module.
Digi Python-enabled products which do support this feature include:
- Digi ConnectCore 3G 9P 9215
- Digi ConnectPort X4 and X4H (with external GPS hardware added)
- Digi ConnectPort X5
