def test_load_python_03(self): cfg = config.Config() cfg.load_python(""" i2c = { "port": 5, } bus = [ { "type": "i2chub", "address": 0x72, "children": [ { "type": "i2chub", "address": 0x70, "channel": 1, "children": [ { "type": "sht25", "channel": 2, }, { "type": "mag01", "channel": 2, }, ], }, ], }, ] """)
def connect(self): cfg = config.Config( i2c={ "port": self.port, "device": 'serial', }, bus=[ { "name": "spi", "type": "i2cspi" }, ], ) cfg.initialize() self.spi = cfg.get_device("spi") self.spi.route() self.spi.SPI_config( self.spi.I2CSPI_MSB_FIRST | self.spi.I2CSPI_MODE_CLK_IDLE_HIGH_DATA_EDGE_TRAILING | self.spi.I2CSPI_CLK_461kHz) time.sleep(.25) self.AxA = axis.axis( self.spi, self.spi.I2CSPI_SS1, 1, 1 ) # set Number of Steps per axis Unit and set Direction of Rotation self.AxA.Reset() self.AxA.MaxSpeed(0x33ffff) # set maximal motor speed self.AxB = axis.axis(self.spi, self.spi.I2CSPI_SS0, 1, 1) self.AxB.Reset() self.AxB.MaxSpeed(0x33ffff) # set maximal motor speed
def init_i2c(self): cfg = config.Config( i2c = { "device": 'hid', "led": True, }, bus = [ { "name":"spi", "type":"i2cspi" }, ], ) cfg.initialize() spi = cfg.get_device("spi") spi.SPI_config(spi.I2CSPI_MSB_FIRST| spi.I2CSPI_MODE_CLK_IDLE_HIGH_DATA_EDGE_TRAILING| spi.I2CSPI_CLK_461kHz) self.motor = axis.axis_between(SPI = spi, SPI_CS = spi.I2CSPI_SS0, StepsPerUnit=1) self.motor.setConfig(F_PWM_INT = None, F_PWM_DEC = None, POW_SR = None, OC_SD = None, RESERVED = None, EN_VSCOMP = None, SW_MODE = None, EXT_CLK = None, OSC_SEL = None) self.motor.Setup(MAX_SPEED = 200, KVAL_ACC=0.3, KVAL_RUN=0.3, ACC = 100, DEC = 100, FS_SPD=3000) self.motor.setMaxSpeed(speed = 900) self.motor.setMinSpeed(speed = 200*16, LSPD_OPT = True)
def test_load_python_00(self): cfg = config.Config() cfg.load_python(""" i2c = { "port": 5, } bus = [ ] """)
def coroutine(): def sleep(time): for i in xrange(int(math.ceil(float(time) / row_duration))): yield if len(args) != 5: raise Exception("usage: pysdr-waterfall [OTHER_PYSDR_ARGS] -d 'detectors/noise_level.py I2C_CONFIG_FILENAME OUTPUT_FILENAME START_HZ STOP_HZ STEP_HZ'") cfg = config.Config() cfg.load_python(args[0]) cfg.initialize() fgen = cfg.get_device('clkgen') fgen.reset() for i in sleep(3.0): yield fgen = cfg.get_device('clkgen') fgen.recall_nvm() for i in sleep(2.0): yield freqs = xrange(int(args[2]), int(args[3]), int(args[4])) nmeas_rows = int(math.ceil(float(1.0) / row_duration)) arr = np.zeros(nmeas_rows, dtype=np.float32) with file(args[1], 'w') as outfile: for freq in freqs: fgen.recall_nvm() print "resetting" for i in sleep(0.2): yield freq_mhz = float(freq) / 1000000 fgen.set_freq(10., freq_mhz * 2) print "setting freq %f" % freq_mhz for i in sleep(1.0): yield row, _s, _n = yield emit_event("mlab.aabb_event.measurement_area", (row, row + nmeas_rows, 0, 4096, "%f MHz" % (freq_mhz,))) for i in xrange(nmeas_rows): _r, _s, noise_lvl = yield arr[i] = noise_lvl noise_lvl_sum = reduce(arr) print "for freq %f, noise level is %f" % (freq_mhz, noise_lvl_sum) outfile.write("\t%f\t%f\n" % (freq_mhz, noise_lvl_sum)) outfile.flush()
def test_load_python_01(self): cfg = config.Config() cfg.load_python(""" i2c = { "port": 5, } bus = [ { "type": "mag01", "address": 0x68 }, { "type": "sht25" } ] """)
def test_load_python_02(self): cfg = config.Config() cfg.load_python(""" i2c = { "port": 5, } bus = [ { "type": "i2chub", "address": 0x70, "children": [ {"type": "mag01", "channel": 0}, {"type": "mag01", "channel": 1}, ] }, { "type": "mag01", "address": 0x68 } ] """)
def test_load_python_04(self): cfg = config.Config() cfg.load_python(""" i2c = { "port": 1, } bus = [ { "type": "altimet01", "name": "alt", }, ] """)
def __init__(self, settings): self.settings = settings self.Devices = {} cfg = config.Config(i2c={"port": self.settings["I2C_Bus"]["port"]}, bus=self.settings["I2C_Bus"]["children"]) cfg.initialize() for device_name, device_type in list( self.__getSensors( self.settings["I2C_Bus"]["children"]).items()): if device_type in sensor_classes: self.Devices[device_name] = sensor_classes[device_type]( cfg.get_device(device_name), self.settings) sleep(0.5)
def __init__(self, configFileName): self.settings = self.__getSettings(configFileName) try: cfg = config.Config(i2c={"port": 1}, bus=self.settings["I2C_configuration"]) cfg.initialize() self.NameTypeDict = self.__getTypes( self.settings["I2C_configuration"]) self.Devices = {} for device in self.__getNames(self.settings["I2C_configuration"]): self.Devices[device] = cfg.get_device(device) except Exception as e: sys.exit("Initialization of I2c failed: " + str(e)) time.sleep(0.5)
# -*- coding: utf-8 -*- import axis from pymlab import config import time import logging logging.basicConfig(level=logging.INFO) cfg = config.Config( i2c={ "device": 'hid', "port": 1, }, bus=[{ "name": "spi", "type": "i2cspi" }, { "name": "gpio", "type": "USBI2C_gpio" }], ) cfg.initialize() spi = cfg.get_device("spi") gpio = cfg.get_device("gpio") spi.SPI_config(spi.I2CSPI_MSB_FIRST | spi.I2CSPI_MODE_CLK_IDLE_HIGH_DATA_EDGE_TRAILING | spi.I2CSPI_CLK_461kHz) motor = axis.axis(SPI=spi, SPI_CS=spi.I2CSPI_SS0, StepsPerUnit=200)
if len(sys.argv) != 2: sys.stderr.write("Invalid number of arguments.\n") sys.stderr.write("Usage: %s PORT ADDRESS\n" % (sys.argv[0], )) sys.exit(1) port = eval(sys.argv[1]) #### Sensor Configuration ########################################### cfg = config.Config( i2c={ "port": port, }, bus=[ { "name": "light", "type": "isl03", }, ], ) cfg.initialize() print "LTS2902001A light sensor example \r\n" print "Light [%%] \r\n" sensor = cfg.get_device("light") time.sleep(0.5) sensor.config(0x0000) i = 0
sys.stderr.write("Script expects 3 arguments.\n") sys.stderr.write("Usage: %s PORT HUB_ADDRESS HUB_CONFIG\n" % (sys.argv[0], )) sys.exit(1) port = int(sys.argv[1]) hub_address = eval(sys.argv[2]) hub_config = eval(sys.argv[3]) #### Sensor Configuration ########################################### cfg = config.Config( port=port, bus=[ { "type": "i2chub", "address": hub_address, "name": "hub" }, ], ) hub = cfg.get_device("hub") #### Communication ################################################## print "Get initial I2CHUB setup:" print "I2CHUB channel setup:", bin(hub.get_status()) print "Setup I2CHUB to channel configuration:", bin(hub_config) hub.setup(hub_config)
if len(sys.argv) != 2: sys.stderr.write("Invalid number of arguments.\n") sys.stderr.write("Usage: %s PORT ADDRESS\n" % (sys.argv[0], )) sys.exit(1) port = eval(sys.argv[1]) #### Sensor Configuration ########################################### cfg = config.Config( i2c={ "port": port, }, bus=[ { "name": "i2cpwm", "type": "i2cpwm", }, ], ) cfg.initialize() print "I2C PWM translator \r\n" pwm = cfg.get_device("i2cpwm") time.sleep(0.5) pwm.set_ls0(0b11111111) pwm.set_ls1(0b10101010) frequency = 100
cfg = config.Config( i2c={ "port": port, }, bus=[ { "type": "i2chub", "address": 0x72, "children": [ { "type": "i2chub", "address": 0x70, "channel": 0, "children": [ { "name": "barometer", "type": "altimet01", "channel": 0, }, { "name": "hum_temp", "type": "sht25", "channel": 1, }, # {"name": "wind_direction", "type": "mag01" , "channel": 1, }, # {"name": "thermometer", "type": "lts01" , "channel": 2, }, ], }, # {"name": "barometer2", "type": "altimet01" , "channel": 6, }, ], }, ], )
ax2.set_xlabel('time (s)') ax2.set_ylabel('temperature (C)') ax2.set_title('Temperature internal') ax2.plot(t, s, linewidth=3.0) show(block=False, layout=2, open_plot=True) # show the figure manager but don't block script execution so animation works.. while True: #### Sensor Configuration ########################################### cfg = config.Config( i2c={ "port": 0, # I2C bus number }, bus=[ { "name": "adc", "type": "i2cadc01", #"channel": 7, }, ], ) cfg.initialize() adc = cfg.get_device("adc") n = t[-1] + 1 try: while True: # Temperature readout temperature = adc.readTemp() print "Internal Temperature =", float(
spi.SPI_write_byte(self.CS, 0xA8) # End Class axis -------------------------------------------------- print "Clock motor control script started. \r\n" print "Requested speed is: %f steps/s" % SPEED pylirc.init("pylirc", "/home/odroid/conf") cfg = config.Config( i2c={ "port": 1, }, bus=[ { "name": "spi", "type": "i2cspi", "address": 0x2e, }, ], ) cfg.initialize() spi = cfg.get_device("spi") spi.route() try: print "Configuring SPI.." spi.SPI_config(spi.I2CSPI_MSB_FIRST
cfg = config.Config( i2c={ "port": port, }, bus=[ { "type": "i2chub", "address": 0x70, "children": [ { "name": "pca9635_1", "type": "PCA9635", "channel": 1, }, { "name": "pca9635_2", "type": "PCA9635", "channel": 2, }, { "name": "pca9635_3", "type": "PCA9635", "channel": 3, }, { "name": "pca9635_4", "type": "PCA9635", "channel": 4, }, ], }, ], )
port = sys.argv[1] address = 0x48 #### Sensor Configuration ########################################### cfg = config.Config( i2c={ "port": port, "device": None, # here you can explicitly set I2C driver with 'hid', 'smbus', 'serial' }, bus=[ { "type": "i2chub", "address": 0x73, "children": [{ "name": "lts01", "type": "lts01", "address": address, "channel": 0, }], }, ], ) ''' cfg = config.Config( i2c = { "port": port, },
import time import sys from pymlab import config while True: #### Sensor Configuration ########################################### cfg = config.Config( i2c={ "port": 0, # I2C bus number }, bus=[ { "type": "i2chub", "address": 0x73, "children": [ { "name": "guage", "type": "lioncell", "channel": 7, }, ], }, ], ) cfg.initialize() guage = cfg.get_device("guage") #flash = guage.ReadFlashBlock(64, 0) #print " ".join([hex(i) for i in flash])
import math import threading from pymlab import config port = '/dev/ttyUSB0' baud = 2400 serial_port = serial.Serial(port, baud, timeout=5) cfg = config.Config( i2c={ "port": 1, }, bus=[ { "name": "altimet", "type": "altimet01", }, ], ) cfg.initialize() alt = cfg.get_device("altimet") time.sleep(0.5) def handle_data(data): print data, datafname = '/home/odroid/mrakomer/station/data/' + str( time.strftime("%Y%m%d%H0000000")) + "_LS-M0_meta" + ".csv"
cfglist = [ config.Config( i2c={ "port": port, }, bus=[ { "type": "i2chub", "address": 0x73, "children": [ { "name": "altimet", "type": "altimet01", "channel": 0, }, { "name": "sht25", "type": "sht25", "channel": 5, }, { "name": "guage", "type": "lioncell", "channel": 3, }, ], }, ], ), ]
import logging from pymlab import config logging.basicConfig(level=logging.DEBUG) cfg = config.Config() cfg.load_file("../config.py")
cfg = config.Config( i2c={ "port": 1, # I2C bus number }, bus=[ { "type": "i2chub", "address": 0x73, #0x72 "children": [ { "name": "adc1", "type": "i2cadc01", "channel": 1, }, { "name": "adc2", "type": "i2cadc01", "channel": 2, }, { "name": "adc3", "type": "i2cadc01", "channel": 3, }, { "name": "adc4", "type": "i2cadc01", "channel": 4, }, { "name": "adc5", "type": "i2cadc01", "channel": 5, }, { "name": "adc6", "type": "i2cadc01", "channel": 6, }, ], }, ], )
if self.ReadStatusBit(1) == 1: return False else: return True # End Class axis -------------------------------------------------- cfg = config.Config( i2c={ "port": 1, }, bus=[ { "type": "i2chub", "address": 0x70, "children": [{ "name": "spi", "type": "i2cspi", "channel": 7 }], }, ], ) cfg.initialize() print "Irradiation unit. \r\n" spi = cfg.get_device("spi") spi.route()
import datetime import sys from pymlab import config #### Sensor Configuration ########################################### cfg = config.Config( i2c={ "port": 1, # for ODROID C1 }, bus=[ { "type": "i2chub", "address": 0x70, "children": [{ "name": "lcd", "type": "i2clcd", "address": 0x27, "channel": 5, }], }, ], ) cfg.initialize() lcd = cfg.get_device("lcd") lcd.route() lcd.reset()
""" Return True if tehre are motion """ if self.ReadStatusBit(1) == 1: return False else: return True # End Class axis -------------------------------------------------- while True: cfg = config.Config( i2c={ "port": 1, }, bus=[ { "name": "spi", "type": "i2cspi" }, ], ) cfg.initialize() print "Stepper motor control example. \r\n" spi = cfg.get_device("spi") spi.route() try: print "SPI configuration.."
#!/usr/bin/python # # Sample of motor control import time import datetime import sys from pymlab import config cfg = config.Config( port=0, #!!! KAKL port bus=[ { "name": "motor", "type": "motor01" }, ], ) cfg = config.Config( i2c={ "port": 0, }, bus=[ # { # "type": "i2chub", # "address": 0x71, # # "children": [ # {"name": "acc", "type": "imu01_acc", "sensitivity": 4.0, "channel": 0, } # ],
"address": 0x72, "children": [ {"name": "encoder", "type": "rps01", "channel": 1, } ], }, ], ) ''' cfg = config.Config( i2c = { "port": port, }, bus = [ { "name": "encoder", "type": "rps01", }, ], ) cfg.initialize() print "RPS01A magnetic position sensor RPS01 readout example \r\n" sensor = cfg.get_device("encoder") print sensor.get_address() print sensor.get_zero_position()
#logging.basicConfig(level=logging.DEBUG) from pymlab import config #### Sensor Configuration ########################################### try: cfg = config.Config( i2c={ "port": 1, # for ODROID C1 }, bus=[ { "type": "i2chub", "address": 0x70, "children": [ { "name": "altimet", "type": "altimet01", "channel": 4, }, ], }, ], ) except IndexError: sys.stdout.write("Invalid configuration number.") sys.exit(1) cfg.initialize()