====== compas2OSC.py ====== la boussole HMC6352 est sur un bus i2c. Donne l'angle au nord en degré dans le sens horaire (heading) #!/usr/bin/python # -*- coding: utf-8 -*- import sys,time,liblo from smbus import SMBus BUS_NUMBER = 2 IP='127.0.0.1' PORT=9001 ADRS=33 # 0x21 - compass osc_path='/pos/compas' b = SMBus(BUS_NUMBER) # 0 indicates /dev/i2c-0 data = {} try: target = liblo.Address('127.0.0.1',9001) except liblo.AddressError, err: print str(err) sys.exit() while True: try: b.write_byte(0x21,0x41) # send 'A' to HMC6352 compass time.sleep(0.02) data_block = b.read_i2c_block_data(0x21,2) heading = (data_block[0] * 2**8 + data_block[1]) / 10 time.sleep(0.02) # print('Compas',heading) liblo.send(target, osc_path, heading) except KeyError: pass except KeyboardInterrupt: quit() except StopIteration: session = None print "end" except: # print('echec') continue