Application Note 49. Using the Digi TransPort Fleet Card. October 2011



Similar documents
Teltonika FM41XX. Configurator v. 1.0

Application Note 2. Using the TCPDIAL & TCPPERM Commands to Connect Two TransPort router Serial Interfaces Over TCP/IP.

Software User Guide UG-461

L16. Quectel GNSS Engine. EVB User Guide L16_EVB_UGD_V1.0

The BSN Hardware and Software Platform: Enabling Easy Development of Body Sensor Network Applications

SuperGuard VT-05 Vehicle Tracking Device

Quick Note 026. Using the firewall of a Digi TransPort to redirect HTTP Traffic to a proxy server. Digi International Technical Support December 2011

Understanding SAE J1939. by Simma Software, Inc.

BIT COMMANDER. Serial RS232 / RS485 to Ethernet Converter

RN-XV-RD2 Evaluation Board

EMG Ethernet Modbus Gateway User Manual

B&K Precision 1785B, 1786B, 1787B, 1788 Power supply Python Library

Bluetooth to serial HC-06 wireless module

Table 1 below is a complete list of MPTH commands with descriptions. Table 1 : MPTH Commands. Command Name Code Setting Value Description

2015/02/07 05:41 1/23 WIZ550WEB Users' Guide

User s Manual TCP/IP TO RS-232/422/485 CONVERTER. 1.1 Introduction. 1.2 Main features. Dynamic DNS

USER MANUAL V5.0 VT300

Card Swipe and ibutton Access Configuration

3.1 RS-232/422/485 Pinout:PORT1-4(RJ-45) RJ-45 RS-232 RS-422 RS-485 PIN1 TXD PIN2 RXD PIN3 GND PIN4 PIN5 T PIN6 T PIN7 R+ PIN8 R-

ATB50v1 GPRS / GPS Based Fleet Management Terminal. Datasheet

GPS Fleet Setup Manual. Created by the team at FollowUs. A short documentation to get you started and setup with regards to the GPS Fleet

International Journal of Research in Advent Technology Available Online at:

vyacht Wifi Router vyacht yacht automation About this manual

Bluetooth HID Profile

IP SERIAL DEVICE SERVER

Modbus and ION Technology

L10. Quectel GPS Engine. EVB User Guide L10_EVB_UGD_V1.00

Ethernet Interface Manual Thermal / Label Printer. Rev Metapace T-1. Metapace T-2 Metapace L-1 Metapace L-2

Debugging Network Communications. 1 Check the Network Cabling

Lab Configure Basic AP Security through IOS CLI

WA Manager Alarming System Management Software Windows 98, NT, XP, 2000 User Guide

Bluetooth HC-06 with serial port module Easy guide

Monitoring Software using Sun Spots. Corey Andalora February 19, 2008

Tutorial for MPLAB Starter Kit for PIC18F

Quick Note 20. Configuring a GRE tunnel over an IPSec tunnel and using BGP to propagate routing information. (GRE over IPSec with BGP)

MeshBee Open Source ZigBee RF Module CookBook

Building a Basic Communication Network using XBee DigiMesh. Keywords: XBee, Networking, Zigbee, Digimesh, Mesh, Python, Smart Home

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

June 2013 v. 0.2

ZC-24DO CANopen I/O Module: 24 Digital Outputs

Technical Article Developing Software for the CN3 Integrated GPS Receiver

Introducing the Adafruit Bluefruit LE Sniffer

Quick Note 53. Ethernet to W-WAN failover with logical Ethernet interface.

Fleets Vehicle GPS Tracker TR-11E User Manual (Version 1.0)

Firmware version: 1.10 Issue: 7 AUTODIALER GD30.2. Instruction Manual

IPPBX FAQ. For Firmware Version: V2.0/V

Fleets Vehicle GPS Tracker TS20 User Manual. (Version 1.0)

Modbus and ION Technology

NetFlow Aggregation. Feature Overview. Aggregation Cache Schemes

Installing the IF-NMEASC & SC30 Windows XP Drivers & Software

WIFI OBD GPS Tracker T356 User Manual

CANnes PC CAN Interface Manual

Different Ways of Connecting to. 3DLevelScanner II. A.P.M Automation Solutions LTD. Version 3.0

Surveillance System Using Wireless Sensor Networks

Procedure: You can find the problem sheet on Drive D: of the lab PCs. Part 1: Router & Switch

Iridium Extreme TM Satellite Phone. Data Services Manual

Exploring the Remote Access Configuration Utility

RPDO 1 TPDO 1 TPDO 5 TPDO 6 TPDO 7 TPDO 8

Flight Controller. Mini Fun Fly

How To Configure A Network Monitor Probe On A Network Wire On A Microsoft Ipv6 (Networking) Device (Netware) On A Pc Or Ipv4 (Network) On An Ipv2 (Netnet) Or Ip

SSL (Secure Socket Layer)

Application/Connection Examples

Remote Access. Table Of Contents. Rev: 3.30, 8/03

IntesisBox KNX Modbus TCP master

In-System Programmer USER MANUAL RN-ISP-UM RN-WIFLYCR-UM

DAQlink III System 24 bit Acquisition System

Wireless Communication With Arduino

Setting Up the ZigBee Ethernet Gateway

DSX Master Communications

PANDORA FMS NETWORK DEVICE MONITORING

TOSR0X-D. USB/Wireless Timer Relay Module. User Manual. Tinysine 2013 Version 1.0

Programming and Using the Courier V.Everything Modem for Remote Operation of DDF6000

Using IPM to Measure Network Performance

New OBD Smart PC Tool User Manual

RN-WIFLY-EVAL-UM. WiFly Evaluation Kit Roving Networks. All rights reserved. RN-WIFLY-EVAL-UM Version 1.32r 10/9/2012 USER MANUAL

Arduino Wifi shield And reciever. 5V adapter. Connecting wifi module on shield: Make sure the wifi unit is connected the following way on the shield:

Quick Note 32. Using Digi RealPort with a Digi TransPort Router. UK Support September 2012

Micro800 Programmable Controllers: Getting Started with CIP Client Messaging

GPS Vehicle and personal location tracker. User manual

Bluetooth to Serial Adapter

Quick Note 040. Create an SSL Tunnel with Certificates on a Digi TransPort WR router using Protocol Switch.

Fleet Tracking Capability. FX 500 / FX 250 FleetBroadband Satellite Terminal

SX-3000EDM Integration Guide

WIZnet S2E (Serial-to-Ethernet) Device s Configuration Tool Programming Guide

Configuring IP to Serial with Auto Answer and Serial to IP

Data sheet Wireless UART firmware version 4.02

Follow these steps to prepare the module and evaluation board for testing.

EPM2000 LabVIEW Building Applications Instructions

Prestige 310. Cable/xDSL Modem Sharing Router. User's Guide Supplement

1 Data information is sent onto the network cable using which of the following? A Communication protocol B Data packet

Process Control and Automation using Modbus Protocol

MANUAL FOR RX700 LR and NR

RN-131-PICTAIL & RN-171-PICTAIL Evaluation Boards

GM862 Arduino Shield

Signal K - The Internet of Things Afloat & Next Generation Interfacing

To perform Ethernet setup and communication verification, first perform RS232 setup and communication verification:

Welcome to the Introduction to Controller Area Network web seminar My name is William Stuart, and I am a Applications Engineer for the Automotive

CMC-DN01 DeviceNet Slave Communication Card Operation Manual

Configuring the Switch with the CLI-Based Setup Program

Transcription:

Application Note 49 Using the Digi TransPort Fleet Card October 2011

Contents 1 INTRODUCTION... 3 1.1 Outline... 3 1.2 Assumptions... 3 1.3 Corrections... 3 1.4 Version... 3 2 Fleet card Features... 4 2.1 CAN bus / J1939... 5 2.2 J1708 bus... 7 2.3 GPS... 8 2.4 Accelerometer... 9 2.5 Power Control of WR41 / WR44... 10 2.6 Four non-isolated digital I/O ports... 11 3 Python Examples... 12 3.1 CAN bus... 12 3.2 J1939... 13 3.3 J1708... 15 3.4 GPS... 16 3.5 Accelerometer... 17 3.6 Digital I/O... 18 Figures Figure 1 User Accessible Ports... 4 Figure 2 Data Connector Pin out... 5 Figure 3 WR44R with cable 76000873... 10

1 INTRODUCTION 1.1 Outline The fleet card is designed for transportation / fleet applications requiring CAN/J1939, J1708, GPS, I/O and Ignition Sense interfaces. It is fully programmable using Python to send and receive data over the CAN/J1939 and J1708 interfaces, receive GPS data and to control the I/O ports. It can also be configured to control the power to the WR router so that it can remain powered up after the vehicle s ignition has been switched off to allow the WR router to download data. The WR router will be switched off automatically after a configurable period of time. 1.2 Assumptions This guide has been written for use by technically competent personnel with a good understanding of the communications technologies used in the product and of the requirements for their specific application. It also assumes a basic ability to access and navigate a Digi TransPort router and configure it with basic routing functions. This application note applies only to: Model: Digi TransPort WR41 and WR44 fitted with the Fleet card Firmware versions: TransPort firmware version 5140 or later Configuration: This Application Note assumes the devices are set to their factory default configurations. Most configuration commands are only shown if they differ from the factory default. 1.3 Corrections Requests for corrections or amendments to this application note are welcome and should be addressed to: support.wizards@digi.com Requests for new application notes can be sent to the same address. 1.4 Version 1.0 Published Status Page 3

2 FLEET CARD FEATURES The Fleet card for the WR routers has the following features CAN bus / J1939 J1708 bus GPS Accelerometer Power Control of WR41/WR44 Four non-isolated digital I/O ports User Accessible Ports Figure 1 depicts the user accessible ports available on the CAN-bus card. The Data port gives access to the CAN-bus / J1939 interface, J1708, the 4 x Digital IO ports and the Ignition Sense input. Figure 2 gives the pin designations for the Data port. The Pwr port is used to power the CAN-bus card. The GPS port is where a GPS antenna is attached. Figure 1 User Accessible Ports Pin Signal 1 CAN-bus High 2 CAN-bus Low 3 J1708 Positive 4 J1708 Negative 5 J1708 Ground 6 CAN-bus Ground 7 Ground 8 Ground 9 Ground Page 4

10 Ground 11 Ignition Sense 12 Digital IO 0 13 Digital IO 1 14 Digital IO 2 15 Digital IO 3 Figure 2 Data Connector Pin out 2.1 CAN bus / J1939 CAN-bus is a vehicle bus standard that is fitted to most new vehicles and uses a differential pair of signals. The CAN-bus card supports baud rates of up to 1Mbps and is configured via the CLI and the Digi Python digicanbus module. J1939 is a high level vehicle bus standard that defines how communication between nodes occurs on the CAN bus. The Fleet card can send and receive raw CAN messages to and from the vehicle s CAN-bus as well as J1939 messages. To configure the CAN bitrate, the CLI command is can 0 bitrate <bitrate> where <bitrate> is in the range of 10000 to 1000000. The default bitrate is 250000. To display the CAN statistics, the CLI command is can 0 stats [r] If the r parameter is entered, the CAN statistics are reset. The CLI command can 0 debug 7 can be used to dump out CAN messages to the debug port. To access the debug, use the CLI command: debug t to send debug output to the connected Telnet session debug 0 to send debug output to a terminal session on SERIAL 0. Page 5

Using Python The Fleet card supports the use of the Digi Canbus Python module. It can be used to configure the bitrate and to send and receive raw CAN messages. import digicanbus To create a CAN instance and configure the bitrate can_h = digicanbus.canhandle(<bus id>) can_h.configure(<bitrate>) To send a CAN message where can_h.send(width, id, remote_frame, data) width id remote_frame 11 or 29, referring to the bits in CAN identifier. 11 or 29 bit integer value. true or false, indicating if this is a remote or data frame. To receive a CAN message, the a receive method is registered for a particular message id where can_h.register_filter(width, id, mask, recv_method, context) width id mask recv_method context 11 or 29, referring to the bits in CAN identifier. 11 or 29 bit integer value. An id mask. It should be in the same format as the id parameter and indicates which bits in the identifier are significant for matching. The Python method to be called when a matching message is received. Context data passed to the receive method. The receive callback method has the following definition def recv_method(width, id, mask, payload, context) The callback method can be unregistered Page 6

can_h.unregister_filter(width, id, mask, recv_method, context) The Digi Canbus Python module can also be used to create and parse J1939 PDUs. To create a J1939 PDU PDU = J1939_PDU() PDU = J1939_PDU(width, identifier, remote_frame, payload, return_arg) To create a CAN message from a J1939 PDU can_msg = PDU.CANMsgTuple() 2.2 J1708 bus J1708 is a vehicle communications standard for heavy duty vehicles. It consists of a 2 wire (18 gauge, twisted pair) interface that operates at 9600 bits per second. The Fleet card can send and receive J1708 messages to and from the vehicle s bus. The card uses the Digi J1708 Python module to send and receive the messages. Using Python The Fleet card supports the use of the Digi J1708 Python module. It can be used to configure the bus and to send and receive J1708 messages. import digij1708 To create and configure a J1708 instance j1708_h = digij1708.j1708handle(<bus id>) j1708_h.configure(<options>) The valid options are mid=n SAE J1708 message identification character. No two devices on the bus should share a message identifier, per specification. 'n' must be between 0 and 255. If the mid option is left unconfigured, the ability to send is disabled. To send a J1708 message j1708_h.send(priority, data) Page 7

where priority 1 8, as defined in the SAE J1708 specification. data a string of 19 characters or less. To receive a J1708 message, the a receive method has to be registered j1708_h.register_filter(recv_method, context) where recv_method context The Python method to be called when a matching message is received. Context data passed to the receive method The receive callback function has the following definition def j1708_recv_function(mid, payload, context) A callback function can be unregistered j1708_h.unregister_filter(recv_method, context) 2.3 GPS The Fleet card is fitted with a GPS device. The WR router can be configured to receive GPS messages and either process them locally or to forward the data onto a remote device via TCP or UDP. When the GPS data is processed locally, the longitude, latitude, altitude, number of satellites, speed, heading, and time are displayed when available. Using Python The WR router supports the Digi hardware Python module, digihw. import digihw To get the GPS data gpsdata = digihw.gps_location() where Page 8

gpsdata A tuple containing latitude, longitude, altitude and timestamp. 2.4 Accelerometer The Fleet card is fitted with a 3 axes accelerometer. This can detect movement in all directions. To take a sample of the current forces, the CLI command is accel 0 show [num of samples] It is possible a threshold which if it is exceeded the WR router will display the previous 33 samples on the debug port. To set the threshold for the accelerometer, the CLI command is where accel 0 set <threshold> <threshold> = (0.00-15.99)*64) For example, to set a threshold of 1.5G, you would enter 96 (= 1.5 x 64). Using Python The Fleet card supports the use of the Digi Accelerometer Python module. This Python module can be used to set thresholds and read the current forces being detected. import digihw To take a sample of the current forces accel = digihw.accelerometer() accel.sample() This method returns a 3-tuple (x, y, z) representing the g-forces measured in the X, Y and Z axes. The Fleet card can be configured to call a callback method when a certain threshold is exceeded accel = digihw.accelerometer() accel.register_threshold(threshold, method, context) where threshold G-force threshold on any axis Page 9

method context Callback method Context data passed to the callback method The callback method has the following definition def callback_method(sample, context) where sample context 3-tuple (x, y, z) representing the g-forces measured in the X, Y and Z axes Context data passed to the callback method 2.5 Power Control of WR41 / WR44 The Fleet card can control the power to the main WR router by using the Ignition Sense input. When the Fleet Card detects the Ignition Sense line going high (e.g. when the engine is switched on), it will provide power to the WR router. When the Fleet card detects the Ignition Sense signal going low (e.g. when the engine is turned off), it will keep the power to the WR router switched on for a configurable amount of time after which the WR router will be switched off. To use this feature with a WR41 router, power cable 76000874 should be used. To use this feature with a WR44(R) router, power cable 76000873 should be used. Figure 3 WR44R with cable 76000873 Page 10

To configure the delay between the Ignition Sense signal going low and the WR router being switched off, the CLI command is fleet 0 holdon <secs> If this feature is not required, the WR router should be powered by a separate power cable. The status of the ignition signal can be retrieved using the CLI command fleet ignition 2.6 Four non-isolated digital I/O ports The Fleet card has four digital I/O ports. All four ports share a common ground which is the same as the vehicle s ground. The ports are internally protected against back EMF current flow. The maximum output current is 50mA. The ports are configured for input or output mode via software. The CLI command is fleet gpio <port> <in out> To enable or disable the GPIO output port, the CLI command is fleet gpio <port> <on off> To retrieve the status of the ports, the CLI command is fleet gpio Using Python The Fleet card supports the use of the Digi hardware Python module, digihw. This Python module can be used to manipulate the digital I/O ports. import digihw digihw.gpio_set_value(<port>,<0 1>) digihw.gpio_set_input(<port>) digihw.gpio_get_value(<port>) Page 11

3 PYTHON EXAMPLES 3.1 CAN bus ## Import the CAN module from digicanbus import * import struct, time, sys speed = 125000 if len(sys.argv) >= 2: speed = int(sys.argv[1]) ## The digicanbus module has CANHandle(). A function that returns ## a handle to the current CAN bus. ## Specify the CAN bus number. print "Getting handle to CAN bus 0" handle = CANHandle(0) ## First we configure the bus to the speed specified print "Configuring for %d bps" %speed handle.configure(speed) ## We create a simple callback function to use with the CAN filters. ## The callback must have the following parameters defined: ## width: specifies either 11 or 29 bit message ## identifier: The identifier that was matched ## remote_frame: Boolean indicating a remote frame (RTR) ## payload: 0-8 bytes of payload for the message ## return_arg: Argument specified when creating the filter ## We will use the return_arg parameter to determine which filter ## triggered the callback. def callback_1(width, identifier, remote_frame, payload, return_arg): print "\ncallback_1 function was called" print '11 or 29 bit: ', width, ' bit' print 'Identifier matched: ', identifier print 'Is remote frame: ', remote_frame print 'Payload: ', struct.unpack('%db'%len(payload), payload) print 'Return arg: ', return_arg ## We create a tuple, which contains all the information needed for ## the filter ## Width: 11 or 29 bit message ## Identifier: Which CAN identifier will be selected ## Mask: Which bits of the identifier matter when matching ## callback function: The function will be called when something ## is matched ## return_arg: Argument passed to the call back when ## Note: Multiple filters can use the same callback function Page 12

## Below we are exploring different scenarios with the filters. print "Defining filters:" ## Filter 1 will only trigger on messages with the 0x700 identifier. ## This is done by saying that the bits 0x700 must be on, and all ## bits will be measured in the mask (0x7FF). filter_1 = (11, 0x700, 0x7FF, callback_1, 'filter_1') print "Filter 1: ", filter_1 ## Filter 2 will trigger on messages between 0x700 and 0x7FF. ## This is done by saying that the bits 0x700 must be on, but only ## the 0x700 bits will be measured in the mask. filter_2 = (11, 0x700, 0x700, callback_1, 'filter_2') print "Filter 2: ", filter_2 ## Filter 3 will trigger on all 29 bit messages. ## This is done by setting the width to 29, and using values 0x0 for ## identifier and mask. filter_3 = (29, 0x0, 0x0, callback_1, 'filter_3') print "Filter 3: ", filter_3 ## Register the filters on the CAN bus print "Registering filters..." handle.register_filter(*filter_1) handle.register_filter(*filter_2) handle.register_filter(*filter_3) counter = 0 print "Hit enter to send a CAN message, type 'quit' to exit" while raw_input().lower()!= 'quit': counter += 1 msg = (11, counter % 0x500, False, str(counter % 99999)) handle.send(*msg) ## Unregister the filters created using the stored tuples print "Unregistering filters" handle.unregister_filter(*filter_1) handle.unregister_filter(*filter_2) handle.unregister_filter(*filter_3) 3.2 J1939 ## Import the CAN module from digicanbus import * import struct, time, sys baud = 125000 if len(sys.argv) >= 2: baud = int(sys.argv[1]) ## The digicanbus module has CANHandle(). A function that returns a handle ## to the current CAN bus. Page 13

## Specify the CAN bus number. print "Getting handle to CAN bus 0" handle = CANHandle(0) ## Configures the CAN bus to a specific bps and starts it. This must be ## called at least once. print "Configuring the bus to %d bps" % baud handle.configure(baud) ## We create a function to be called when a J1939 message that is matched ## will be passed to. def callback_1(width, identifier, remote_frame, payload, return_arg): PDU = J1939_PDU(width, identifier, remote_frame, payload) print "====PDU received====" for opt in ['DA', 'DP', 'EDP', 'GE', 'PF', 'PGN', 'PS', 'SA', 'priority', 'payload']: print opt + " = " + str(pdu. getattribute (opt)) print "Converting to a raw can message, sending it over the CAN bus" raw_msg = PDU.CANMsgTuple() print "%s %s %s %s" %(raw_msg[0], hex(raw_msg[1]), raw_msg[2], raw_msg[3]) try: handle.send(*raw_msg) except Exception, e: print e else: print "Message succesfully sent" ## We create a filter that will trigger on 29 bit messages filter_1 = (29, 0x0, 0x0, callback_1, 'filter_1') print "Filter 1: ", filter_1 ## Register the filters on the CAN bus print "Registering filters..." handle.register_filter(*filter_1) counter = 0 print "Hit enter to send J1939_PDU, type 'quit' to exit" while raw_input().lower()!= 'quit': counter += 1 P = J1939_PDU() P.DA = 0x76 P.PGN = 0xF001 P.payload = 'msg' + str(counter) can_msg = P.CANMsgTuple() handle.send(*can_msg) ## Unregister the filters created using the stored tuples print "Unregistering filters" handle.unregister_filter(*filter_1) Page 14

3.3 J1708 ## Import the J1708 python API import digij1708 import struct ## Create a handle to the J1708 bus through the class J1708Handle() ## The class takes 1 parameter, the bus number to get a handle to. print "Getting a handle to the J1708 Bus" handle = digij1708.j1708handle(0) ## Configure the bus to a particular mid. in this case 0x48 handle.configure(0x48) ##Create a callback function. This function requires three parameters: ## mid, payload, and arg ## mid: The message ID ## payload: The payload of the message ## arg: An arbitrary parameter defined when setting the callback. def callback_1(mid, payload, arg): print "\nmid: ", mid print "Payload: ", payload print "Arg: ", arg ## Register the callback on the J1708 bus handle.register_callback(callback_1, 'foo') print "Type 'quit' to exit, or type a message in to send then hit enter:\n" while 1: input = raw_input() if input.lower() in ['q', 'qu', 'qui', 'quit']: break input = input.strip() ## If no input, create a fake message if len(input) == 0: msg = struct.pack('=2b', 45, 12) ## If input, take up to 19 characters of it else: if len(input) > 19: msg = input[:19] else: msg = input ## Send the message at priority 1 try: handle.send(1, msg) except Exception, e: print e ## Unregister the call back, must use exact same input as the register call print "Unregistering callback" handle.unregister_callback(callback_1, 'foo') Page 15

3.4 GPS ## The returned values from the gps_location call are NMEA parsed into a ## tuple: (latitude, longitude, altitude, timestamp) ## The sample returned is the latest received from the GPS device. The ## timestamp is assigned to it when it was successfully parsed. ## In cases where there are no sample available, an exception is raised. """\ GPS Location API Sample This example reads and displays all the values from the device's integrated GPS each 5 seconds, using the GPS Location API. """ Displays Latitude, Longitude, Altitude, Timestamp in GMT/GPS time # imports import sys import os import time import digihw gps_location ## From the digi embedded library, import the parsed # variables is_reading = True def get_formmated_value(value): """ Returns the given value formatted in degrees, minutes and seconds. """ working_value = value if working_value < 0: working_value = working_value * -1 deg = working_value; gpsdeg = int(deg) remainder = deg - (gpsdeg * 1.0) gpsmin = remainder * 60.0 remainder2 = gpsmin - int(gpsmin)*1.0 gpsseg = int(remainder2*60.0) final_value = "%sdeg %smin %ssec" %(gpsdeg, int(gpsmin), gpsseg) return final_value def get_latitude_hemisphere(latitude): """ Returns the hemisphere depending on the latitude (S or N) """ if latitude < 0: return "S" Page 16

return "N" def get_longitude_hemisphere(longitude): """ Returns the hemisphere depending on the longitude (W or E) """ if longitude < 0: return "W" return "E" # Read GPS information every 5 seconds while is_reading: try: print "Reading GPS data...\r\n" gps_data = digihw.gps_location() latitude, longitude, altitude, timestamp = gps_data print "Latitude : %s %s" %(get_formmated_value(latitude), get_latitude_hemisphere(latitude)) print "Longitude : %s %s" %(get_formmated_value(longitude), get_longitude_hemisphere(longitude)) print "Altitude : %d meters" %altitude print "Date : % s" %time.ctime(timestamp) # Wait 1 seconds print "Please, wait 1 seconds...\r\n" time.sleep(1) except: print "Couldn't read GPS data. You need to get a better GPS signal.\n Please, ensure the GPS antenna is correctly connected and \ has an open view of the sky.\r\n" # Wait 20 seconds print "Please, wait 20 seconds...\r\n\r\n" time.sleep(20) 3.5 Accelerometer # # Sets the callback threshold and displays on which axes the # threshold is exceeded. # import digihw import time import sys AXIS_X = 0 AXIS_Y = 1 AXIS_Z = 2 if len(sys.argv)!= 2: print "Usage: python accel.py <threshold>" sys.exit(-1) Page 17

threshold_g = float(sys.argv[1]) def accel_callback(sample, context): x_g = sample[axis_x] y_g = sample[axis_y] z_g = sample[axis_z] if x_g >= threshold_g: print("threshold exceeded on X axis (%fg)" % x_g) if y_g >= threshold_g: print("threshold exceeded on Y axis (%fg)" % y_g) if z_g >= threshold_g: print("threshold exceeded on Z axis (%fg)" % z_g) print "Digi TransPort Accelerometer Python example" # Register the callback function and wait for 10 seconds print ("Threshold set to %fg" % threshold_g) accel = digihw.accelerometer() accel.register_threshold(threshold_g, accel_callback, 0) time.sleep(10); print "Complete" 3.6 Digital I/O # # Sets port 0 level to 1. It then sets port 1 to be an input # and waits for the level to go to 0. When this has happened, # it sets port 0 back to 0. # import digihw import time PORT_0 = 0 PORT_1 = 1 print "Digi TransPort Digital I/O Python example" digihw.gpio_set_value(port_0, 1) digihw.gpio_set_input(port_1) print Waiting for Port 1 to go low while digihw.gpio_get_value(port_1)!= 0: time.sleep(1) digihw.gpio_set_value(port_0, 0) print "Complete" Page 18