def test_adc_stop(self): SensorManager.mux_select(ADC) SensorManager.stop_adc_sensor(ADC) SensorManager.mux_select(ADC) SensorManager.init_adc(ADC) addr = SensorEntropy.addr(ADC) adc_reg = SensorEntropy.reg(ADC) bus = SensorManager.bus config = bus.read_byte_data(addr, adc_reg['CONFIG_REG']) self.assertEqual(config, 0x00)
def test_adc_init(self): SensorManager.mux_select(ADC) SensorManager.init_adc(ADC) addr = SensorEntropy.addr(ADC) adc_reg = SensorEntropy.reg(ADC) bus = SensorManager.bus config = bus.read_byte_data(addr, adc_reg['CONFIG_REG']) mode = bus.read_byte_data(addr, adc_reg['ADV_CONFIG_REG']) conv = bus.read_byte_data(addr, adc_reg['CONV_RATE_REG']) ch = bus.read_byte_data(addr, adc_reg['CHANNEL_DISABLE_REG']) limits = bus.read_byte_data(addr, adc_reg['LIMIT_REG_BASE']) self.assertEqual(config, 0x01) self.assertEqual(mode, 0x04) self.assertEqual(conv, 0x01) self.assertEqual(ch, 0x00) self.assertEqual(limits, 0x05)
def main(): magSensorList= [MAG_0, MAG_1, MAG_2] SensorManager.mux_select(magSensorList[0]) bus = smbus.SMBus(0) address = 0x1e write_byte(0, 0b01110000) # Set to 8 samples @ 15Hz write_byte(1, 0b00100000) # 1.3 gain LSb / Gauss 1090 (default) write_byte(2, 0b00000000) # Continuous sampling scale = 0.92 """ ***************** """ # for i in range(0,500): # x_out = read_word_2c(3) # y_out = read_word_2c(7) # z_out = read_word_2c(5) # # bearing = math.atan2(y_out, x_out) # if (bearing < 0): # bearing += 2 * math.pi # # print x_out, y_out, (x_out * scale), (y_out * scale) # time.sleep(0.1) """ ***************** """ x_out = read_word_2c(3) * scale y_out = read_word_2c(7) * scale z_out = read_word_2c(5) * scale bearing = math.atan2(y_out, x_out) if (bearing < 0): bearing += 2 * math.pi print("Bearing: {}".format(math.degrees(bearing))) """ ***************** """