Пример #1
0
#!/usr/bin/python
import sys
from tiberius.utils import detection
from tiberius.control.exceptions import CompassReadError
# If not running on a raspberry pi, use the dummy smbus library to allow
# simulation of I2C transactions.
if not detection.detect_pi():
    from tiberius.smbus_dummy import smbus
else:
    import smbus


class TiltCompensatedCompass:

    def __init__(self, address):
        self.bus = smbus.SMBus(1)
        self.address = address

    # Used for future work on 'smart' readings
    # TODO:Will return previous reading rather
    # than reading a new reading that is probably the same.
    __heading = -1
    __heading_degrees = -1

    __pitch_filtered = -1
    __roll_filterd = -1

    __magnet_x = -1
    __magnet_y = -1
    __magnet_z = -1
Пример #2
0
import time
import sys
from tiberius.utils import detection

# If not running on a raspberry pi, use the dummy smbus library to allow
# simulation of I2C transactions.
if detection.detect_pi():
    import serial


#####Global Variables######################################
# be sure to declare the variable as 'global var' in the fxn
ser = 0

#####FUNCTIONS#############################################
# initialize serial connection


def init_serial():
    COMNUM = 1  # set you COM port # here
    global ser  # must be declared in each fxn used
    ser = serial.Serial("/dev/ttyACM0", 9600, timeout=1)

    ser.open()  # open the serial port

    # print port open or closed
    if ser.isOpen():
        print "Open: " + ser.portstr


#####SETUP################################################