From: Jan Michel Date: Sun, 22 Apr 2018 14:23:27 +0000 (+0200) Subject: add BME280 to sensor board code X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=2fcbcbb2fad8261382225d0b72a6547e76a8fe8c;p=avr.git add BME280 to sensor board code add flag to select type of PCB TSL2591 included but not yet working --- diff --git a/sensors/MagneticFieldSensor/BME280.c b/sensors/MagneticFieldSensor/BME280.c new file mode 100644 index 0000000..75169d8 --- /dev/null +++ b/sensors/MagneticFieldSensor/BME280.c @@ -0,0 +1,183 @@ +#include "main.h" + +uint8_t InitBME(BME280* bme280){ + + uint8_t dataToWrite = 0; //Temporary variable + + //Reading all compensation data, range 0x88:A1, 0xE1:E7 + bme280->calibration.dig_T1 = ((uint16_t)((readRegister(bme280->settings.I2CAddress,BME280_DIG_T1_MSB_REG) << 8) + readRegister(bme280->settings.I2CAddress,BME280_DIG_T1_LSB_REG))); + bme280->calibration.dig_T2 = ((int16_t)((readRegister(bme280->settings.I2CAddress,BME280_DIG_T2_MSB_REG) << 8) + readRegister(bme280->settings.I2CAddress,BME280_DIG_T2_LSB_REG))); + bme280->calibration.dig_T3 = ((int16_t)((readRegister(bme280->settings.I2CAddress,BME280_DIG_T3_MSB_REG) << 8) + readRegister(bme280->settings.I2CAddress,BME280_DIG_T3_LSB_REG))); + + bme280->calibration.dig_P1 = ((uint16_t)((readRegister(bme280->settings.I2CAddress,BME280_DIG_P1_MSB_REG) << 8) + readRegister(bme280->settings.I2CAddress,BME280_DIG_P1_LSB_REG))); + bme280->calibration.dig_P2 = ((int16_t)((readRegister(bme280->settings.I2CAddress,BME280_DIG_P2_MSB_REG) << 8) + readRegister(bme280->settings.I2CAddress,BME280_DIG_P2_LSB_REG))); + bme280->calibration.dig_P3 = ((int16_t)((readRegister(bme280->settings.I2CAddress,BME280_DIG_P3_MSB_REG) << 8) + readRegister(bme280->settings.I2CAddress,BME280_DIG_P3_LSB_REG))); + bme280->calibration.dig_P4 = ((int16_t)((readRegister(bme280->settings.I2CAddress,BME280_DIG_P4_MSB_REG) << 8) + readRegister(bme280->settings.I2CAddress,BME280_DIG_P4_LSB_REG))); + bme280->calibration.dig_P5 = ((int16_t)((readRegister(bme280->settings.I2CAddress,BME280_DIG_P5_MSB_REG) << 8) + readRegister(bme280->settings.I2CAddress,BME280_DIG_P5_LSB_REG))); + bme280->calibration.dig_P6 = ((int16_t)((readRegister(bme280->settings.I2CAddress,BME280_DIG_P6_MSB_REG) << 8) + readRegister(bme280->settings.I2CAddress,BME280_DIG_P6_LSB_REG))); + bme280->calibration.dig_P7 = ((int16_t)((readRegister(bme280->settings.I2CAddress,BME280_DIG_P7_MSB_REG) << 8) + readRegister(bme280->settings.I2CAddress,BME280_DIG_P7_LSB_REG))); + bme280->calibration.dig_P8 = ((int16_t)((readRegister(bme280->settings.I2CAddress,BME280_DIG_P8_MSB_REG) << 8) + readRegister(bme280->settings.I2CAddress,BME280_DIG_P8_LSB_REG))); + bme280->calibration.dig_P9 = ((int16_t)((readRegister(bme280->settings.I2CAddress,BME280_DIG_P9_MSB_REG) << 8) + readRegister(bme280->settings.I2CAddress,BME280_DIG_P9_LSB_REG))); + + bme280->calibration.dig_H1 = ((uint8_t)(readRegister(bme280->settings.I2CAddress,BME280_DIG_H1_REG))); + bme280->calibration.dig_H2 = ((int16_t)((readRegister(bme280->settings.I2CAddress,BME280_DIG_H2_MSB_REG) << 8) + readRegister(bme280->settings.I2CAddress,BME280_DIG_H2_LSB_REG))); + bme280->calibration.dig_H3 = ((uint8_t)(readRegister(bme280->settings.I2CAddress,BME280_DIG_H3_REG))); + bme280->calibration.dig_H4 = ((int16_t)((readRegister(bme280->settings.I2CAddress,BME280_DIG_H4_MSB_REG) << 4) + (readRegister(bme280->settings.I2CAddress,BME280_DIG_H4_LSB_REG) & 0x0F))); + bme280->calibration.dig_H5 = ((int16_t)((readRegister(bme280->settings.I2CAddress,BME280_DIG_H5_MSB_REG) << 4) + ((readRegister(bme280->settings.I2CAddress,BME280_DIG_H4_LSB_REG) >> 4) & 0x0F))); + bme280->calibration.dig_H6 = ((uint8_t)readRegister(bme280->settings.I2CAddress,BME280_DIG_H6_REG)); + + //Set the oversampling control words. + //config will only be writeable in sleep mode, so first insure that. + writeRegister(bme280->settings.I2CAddress,BME280_CTRL_MEAS_REG, 0x00); + + //Set the config word + dataToWrite = (bme280->settings.tStandby << 0x5) & 0xE0; + dataToWrite |= (bme280->settings.filter << 0x02) & 0x1C; + writeRegister(bme280->settings.I2CAddress,BME280_CONFIG_REG, dataToWrite); + + //Set ctrl_hum first, then ctrl_meas to activate ctrl_hum + dataToWrite = bme280->settings.humidOverSample & 0x07; //all other bits can be ignored + writeRegister(bme280->settings.I2CAddress,BME280_CTRL_HUMIDITY_REG, dataToWrite); + + //set ctrl_meas + //First, set temp oversampling + dataToWrite = (bme280->settings.tempOverSample << 0x5) & 0xE0; + //Next, pressure oversampling + + dataToWrite |= (bme280->settings.pressOverSample << 0x02) & 0x1C; + //Last, set mode + dataToWrite |= (bme280->settings.runMode) & 0x03; + //Load the byte + writeRegister(bme280->settings.I2CAddress,BME280_CTRL_MEAS_REG, dataToWrite); + + return readRegister(bme280->settings.I2CAddress,0xD0); +} + + +//Strictly resets. Run .begin() afterwards +void reset( BME280* bme280) +{ + writeRegister(bme280->settings.I2CAddress,BME280_RST_REG, 0xB6); +} + + +float readFloatPressure( BME280 *bme280) +{ + + // Returns pressure in Pa as unsigned 32 bit integer in Q24.8 format (24 integer bits and 8 fractional bits). + // Output value of “24674867” represents 24674867/256 = 96386.2 Pa = 963.862 hPa + int32_t adc_P = ((uint32_t)readRegister(bme280->settings.I2CAddress,BME280_PRESSURE_MSB_REG) << 12) | ((uint32_t)readRegister(bme280->settings.I2CAddress,BME280_PRESSURE_LSB_REG) << 4) | ((readRegister(bme280->settings.I2CAddress,BME280_PRESSURE_XLSB_REG) >> 4) & 0x0F); + + int64_t var1, var2, p_acc; + var1 = ((int64_t)bme280->t_fine) - 128000; + var2 = var1 * var1 * (int64_t)bme280->calibration.dig_P6; + var2 = var2 + ((var1 * (int64_t)bme280->calibration.dig_P5)<<17); + var2 = var2 + (((int64_t)bme280->calibration.dig_P4)<<35); + var1 = ((var1 * var1 * (int64_t)bme280->calibration.dig_P3)>>8) + ((var1 * (int64_t)bme280->calibration.dig_P2)<<12); + var1 = (((((int64_t)1)<<47)+var1))*((int64_t)bme280->calibration.dig_P1)>>33; + if (var1 == 0) + { + return 0; // avoid exception caused by division by zero + } + p_acc = 1048576 - adc_P; + p_acc = (((p_acc<<31) - var2)*3125)/var1; + var1 = (((int64_t)bme280->calibration.dig_P9) * (p_acc>>13) * (p_acc>>13)) >> 25; + var2 = (((int64_t)bme280->calibration.dig_P8) * p_acc) >> 19; + p_acc = ((p_acc + var1 + var2) >> 8) + (((int64_t)bme280->calibration.dig_P7)<<4); + + return (float)p_acc / 256.0; + +} + + +float readFloatHumidity( BME280* bme280 ) +{ + // Returns humidity in %RH as unsigned 32 bit integer in Q22. 10 format (22 integer and 10 fractional bits). + // Output value of “47445” represents 47445/1024 = 46. 333 %RH + int32_t adc_H = ((uint32_t)readRegister(bme280->settings.I2CAddress,BME280_HUMIDITY_MSB_REG) << 8) | ((uint32_t)readRegister(bme280->settings.I2CAddress,BME280_HUMIDITY_LSB_REG)); + + int32_t var1; + var1 = (bme280->t_fine - ((int32_t)76800)); + var1 = (((((adc_H << 14) - (((int32_t)bme280->calibration.dig_H4) << 20) - (((int32_t)bme280->calibration.dig_H5) * var1)) + + ((int32_t)16384)) >> 15) * (((((((var1 * ((int32_t)bme280->calibration.dig_H6)) >> 10) * (((var1 * ((int32_t)bme280->calibration.dig_H3)) >> 11) + ((int32_t)32768))) >> 10) + ((int32_t)2097152)) * + ((int32_t)bme280->calibration.dig_H2) + 8192) >> 14)); + var1 = (var1 - (((((var1 >> 15) * (var1 >> 15)) >> 7) * ((int32_t)bme280->calibration.dig_H1)) >> 4)); + var1 = (var1 < 0 ? 0 : var1); + var1 = (var1 > 419430400 ? 419430400 : var1); + + return (float)(var1>>12) / 1024.0; +} + + +float readTempC( BME280* bme280 ) +{ + // Returns temperature in DegC, resolution is 0.01 DegC. Output value of “5123” equals 51.23 DegC. + // t_fine carries fine temperature as global value + + //get the reading (adc_T); + int32_t adc_T = ((uint32_t)readRegister(bme280->settings.I2CAddress,BME280_TEMPERATURE_MSB_REG) << 12) | ((uint32_t)readRegister(bme280->settings.I2CAddress,BME280_TEMPERATURE_LSB_REG) << 4) | ((readRegister(bme280->settings.I2CAddress,BME280_TEMPERATURE_XLSB_REG) >> 4) & 0x0F); + + //By datasheet, calibrate + int64_t var1, var2; + + var1 = ((((adc_T>>3) - ((int32_t)bme280->calibration.dig_T1<<1))) * ((int32_t)bme280->calibration.dig_T2)) >> 11; + var2 = (((((adc_T>>4) - ((int32_t)bme280->calibration.dig_T1)) * ((adc_T>>4) - ((int32_t)bme280->calibration.dig_T1))) >> 12) * + ((int32_t)bme280->calibration.dig_T3)) >> 14; + bme280->t_fine = var1 + var2; + float output = (bme280->t_fine * 5 + 128) >> 8; + + output = output / 100; + + return output; +} + + +void readRegisterRegion(uint8_t Addr, uint8_t *outputPointer , uint8_t offset, uint8_t length) +{ + //define pointer that will point to the external space + ///uint8_t i = 0; + uint8_t c = 0; + twi_writeTo(Addr,&offset,1,1,true); + + for(int i = 0 ; i +#include +#include +*/ +#include "TSL2591.h" + +void Init_TSL2591(TSL2591* tsl) +{ + tsl->_initialized = true; + tsl->_integration = TSL2591_INTEGRATIONTIME_100MS; + tsl->_gain = TSL2591_GAIN_MED; + TSL2591_setTiming(tsl, tsl->_integration); + TSL2591_setGain(tsl, tsl->_gain); + TSL2591_disable(); +} + + +void TSL2591_enable() +{ + // Enable the device by setting the control bit to 0x01 + TSL2591_write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_ENABLE, TSL2591_ENABLE_POWERON | TSL2591_ENABLE_AEN | TSL2591_ENABLE_AIEN | TSL2591_ENABLE_NPIEN); +} + +void TSL2591_disable() +{ + // Disable the device by setting the control bit to 0x00 + TSL2591_write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_ENABLE, TSL2591_ENABLE_POWEROFF); +} + +void TSL2591_setGain(TSL2591* tsl, tsl2591Gain_t gain) +{ + TSL2591_enable(); + tsl->_gain = gain; + TSL2591_write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CONTROL, tsl->_integration | tsl->_gain); + TSL2591_disable(); +} + +tsl2591Gain_t TSL2591_getGain(TSL2591* tsl) +{ + return tsl->_gain; +} + +void TSL2591_setTiming(TSL2591* tsl, tsl2591IntegrationTime_t integration) +{ + TSL2591_enable(); + tsl->_integration = integration; + TSL2591_write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CONTROL, tsl->_integration | tsl->_gain); + TSL2591_disable(); +} + +tsl2591IntegrationTime_t TSL2591_getTiming(TSL2591* tsl) +{ + return tsl->_integration; +} + +uint32_t TSL2591_calculateLux(TSL2591* tsl, uint16_t ch0, uint16_t ch1) +{ + float atime, again; + float cpl, lux1, lux2, lux; + uint32_t chan0, chan1; + + // Check for overflow conditions first + if ((ch0 == 0xFFFF) | (ch1 == 0xFFFF)) + { + // Signal an overflow + return 0; + } + + // Note: This algorithm is based on preliminary coefficients + // provided by AMS and may need to be updated in the future + + switch (tsl->_integration) + { + case TSL2591_INTEGRATIONTIME_100MS : + atime = 100.0F; + break; + case TSL2591_INTEGRATIONTIME_200MS : + atime = 200.0F; + break; + case TSL2591_INTEGRATIONTIME_300MS : + atime = 300.0F; + break; + case TSL2591_INTEGRATIONTIME_400MS : + atime = 400.0F; + break; + case TSL2591_INTEGRATIONTIME_500MS : + atime = 500.0F; + break; + case TSL2591_INTEGRATIONTIME_600MS : + atime = 600.0F; + break; + default: // 100ms + atime = 100.0F; + break; + } + + switch (tsl->_gain) + { + case TSL2591_GAIN_LOW : + again = 1.0F; + break; + case TSL2591_GAIN_MED : + again = 25.0F; + break; + case TSL2591_GAIN_HIGH : + again = 428.0F; + break; + case TSL2591_GAIN_MAX : + again = 9876.0F; + break; + default: + again = 1.0F; + break; + } + + // cpl = (ATIME * AGAIN) / DF + cpl = (atime * again) / TSL2591_LUX_DF; + + lux1 = ( (float)ch0 - (TSL2591_LUX_COEFB * (float)ch1) ) / cpl; + lux2 = ( ( TSL2591_LUX_COEFC * (float)ch0 ) - ( TSL2591_LUX_COEFD * (float)ch1 ) ) / cpl; + lux = lux1 > lux2 ? lux1 : lux2; + + // Alternate lux calculation + //lux = ( (float)ch0 - ( 1.7F * (float)ch1 ) ) / cpl; + + // Signal I2C had no errors + return (uint32_t)lux; +} + +uint32_t TSL2591_getFullLuminosity (TSL2591* tsl) +{ + // Enable the device + TSL2591_enable(); + + // Wait x ms for ADC to complete + for (uint8_t d=0; d<=tsl->_integration; d++) + { + _delay_ms(120); + } + + uint32_t x; + x = TSL2591_read16(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CHAN1_LOW); + x <<= 16; + x |= TSL2591_read16(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CHAN0_LOW); + + TSL2591_disable(); + + return x; +} + +uint16_t TSL2591_getLuminosity (TSL2591* tsl, uint8_t channel) +{ + uint32_t x = TSL2591_getFullLuminosity(tsl); + + if (channel == TSL2591_FULLSPECTRUM) + { + // Reads two byte value from channel 0 (visible + infrared) + return (x & 0xFFFF); + } + else if (channel == TSL2591_INFRARED) + { + // Reads two byte value from channel 1 (infrared) + return (x >> 16); + } + else if (channel == TSL2591_VISIBLE) + { + // Reads all and subtracts out just the visible! + return ( (x & 0xFFFF) - (x >> 16)); + } + + // unknown channel! + return 0; +} + + +uint8_t TSL2591_read8(uint8_t reg) +{ + uint8_t x; + twi_writeTo(TSL2591_ADDR, ®, 1,1, true); + twi_readFrom(TSL2591_ADDR, &x, 1, true); + + return x; +} + +uint16_t TSL2591_read16(uint8_t reg) +{ + uint16_t x[2]; + + twi_writeTo(TSL2591_ADDR, ®, 1,1, true); + twi_readFrom(TSL2591_ADDR, x, 2, true); + + x[1] <<= 8; + x[1] |= x[0]; + return x; +} + +void TSL2591_write8 (uint8_t reg, uint8_t value) +{ + uint8_t write_val[2] = {reg, value}; + twi_writeTo(TSL2591_ADDR, reg, 2,1, true); +} + + diff --git a/sensors/MagneticFieldSensor/TSL2591.h b/sensors/MagneticFieldSensor/TSL2591.h new file mode 100644 index 0000000..8da5cac --- /dev/null +++ b/sensors/MagneticFieldSensor/TSL2591.h @@ -0,0 +1,121 @@ +#include "main.h" + +#ifndef _TSL2591_H_ +#define _TSL2591_H_ + +#define TSL2591_VISIBLE (2) // channel 0 - channel 1 +#define TSL2591_INFRARED (1) // channel 1 +#define TSL2591_FULLSPECTRUM (0) // channel 0 + +#define TSL2591_ADDR (0x29) +#define TSL2591_READBIT (0x01) + +#define TSL2591_COMMAND_BIT (0xA0) // 1010 0000: bits 7 and 5 for 'command normal' +#define TSL2591_CLEAR_INT (0xE7) +#define TSL2591_TEST_INT (0xE4) +#define TSL2591_WORD_BIT (0x20) // 1 = read/write word (rather than byte) +#define TSL2591_BLOCK_BIT (0x10) // 1 = using block read/write + +#define TSL2591_ENABLE_POWEROFF (0x00) +#define TSL2591_ENABLE_POWERON (0x01) +#define TSL2591_ENABLE_AEN (0x02) // ALS Enable. This field activates ALS function. Writing a one activates the ALS. Writing a zero disables the ALS. +#define TSL2591_ENABLE_AIEN (0x10) // ALS Interrupt Enable. When asserted permits ALS interrupts to be generated, subject to the persist filter. +#define TSL2591_ENABLE_NPIEN (0x80) // No Persist Interrupt Enable. When asserted NP Threshold conditions will generate an interrupt, bypassing the persist filter + +#define TSL2591_LUX_DF (408.0F) +#define TSL2591_LUX_COEFB (1.64F) // CH0 coefficient +#define TSL2591_LUX_COEFC (0.59F) // CH1 coefficient A +#define TSL2591_LUX_COEFD (0.86F) // CH2 coefficient B + +enum +{ + TSL2591_REGISTER_ENABLE = 0x00, + TSL2591_REGISTER_CONTROL = 0x01, + TSL2591_REGISTER_THRESHOLD_AILTL = 0x04, // ALS low threshold lower byte + TSL2591_REGISTER_THRESHOLD_AILTH = 0x05, // ALS low threshold upper byte + TSL2591_REGISTER_THRESHOLD_AIHTL = 0x06, // ALS high threshold lower byte + TSL2591_REGISTER_THRESHOLD_AIHTH = 0x07, // ALS high threshold upper byte + TSL2591_REGISTER_THRESHOLD_NPAILTL = 0x08, // No Persist ALS low threshold lower byte + TSL2591_REGISTER_THRESHOLD_NPAILTH = 0x09, // etc + TSL2591_REGISTER_THRESHOLD_NPAIHTL = 0x0A, + TSL2591_REGISTER_THRESHOLD_NPAIHTH = 0x0B, + TSL2591_REGISTER_PERSIST_FILTER = 0x0C, + TSL2591_REGISTER_PACKAGE_PID = 0x11, + TSL2591_REGISTER_DEVICE_ID = 0x12, + TSL2591_REGISTER_DEVICE_STATUS = 0x13, + TSL2591_REGISTER_CHAN0_LOW = 0x14, + TSL2591_REGISTER_CHAN0_HIGH = 0x15, + TSL2591_REGISTER_CHAN1_LOW = 0x16, + TSL2591_REGISTER_CHAN1_HIGH = 0x17 +}; + +typedef enum +{ + TSL2591_INTEGRATIONTIME_100MS = 0x00, + TSL2591_INTEGRATIONTIME_200MS = 0x01, + TSL2591_INTEGRATIONTIME_300MS = 0x02, + TSL2591_INTEGRATIONTIME_400MS = 0x03, + TSL2591_INTEGRATIONTIME_500MS = 0x04, + TSL2591_INTEGRATIONTIME_600MS = 0x05, +} +tsl2591IntegrationTime_t; + +typedef enum +{ + // bit 7:4: 0 + TSL2591_PERSIST_EVERY = 0x00, // Every ALS cycle generates an interrupt + TSL2591_PERSIST_ANY = 0x01, // Any value outside of threshold range + TSL2591_PERSIST_2 = 0x02, // 2 consecutive values out of range + TSL2591_PERSIST_3 = 0x03, // 3 consecutive values out of range + TSL2591_PERSIST_5 = 0x04, // 5 consecutive values out of range + TSL2591_PERSIST_10 = 0x05, // 10 consecutive values out of range + TSL2591_PERSIST_15 = 0x06, // 15 consecutive values out of range + TSL2591_PERSIST_20 = 0x07, // 20 consecutive values out of range + TSL2591_PERSIST_25 = 0x08, // 25 consecutive values out of range + TSL2591_PERSIST_30 = 0x09, // 30 consecutive values out of range + TSL2591_PERSIST_35 = 0x0A, // 35 consecutive values out of range + TSL2591_PERSIST_40 = 0x0B, // 40 consecutive values out of range + TSL2591_PERSIST_45 = 0x0C, // 45 consecutive values out of range + TSL2591_PERSIST_50 = 0x0D, // 50 consecutive values out of range + TSL2591_PERSIST_55 = 0x0E, // 55 consecutive values out of range + TSL2591_PERSIST_60 = 0x0F, // 60 consecutive values out of range +} +tsl2591Persist_t; + +typedef enum +{ + TSL2591_GAIN_LOW = 0x00, // low gain (1x) + TSL2591_GAIN_MED = 0x10, // medium gain (25x) + TSL2591_GAIN_HIGH = 0x20, // medium gain (428x) + TSL2591_GAIN_MAX = 0x30, // max gain (9876x) +} +tsl2591Gain_t; + +typedef struct { + tsl2591Gain_t _gain; + tsl2591IntegrationTime_t _integration; + bool _initialized; +} +TSL2591; + + + void Init_TSL2591 ( TSL2591* tsl ); + + void TSL2591_enable ( void ); + void TSL2591_disable ( void ); + void TSL2591_write8 ( uint8_t r, uint8_t v ); + uint16_t TSL2591_read16 ( uint8_t reg ); + uint8_t TSL2591_read8 ( uint8_t reg ); + + uint32_t TSL2591_calculateLux (TSL2591* tsl, uint16_t ch0, uint16_t ch1 ); + void TSL2591_setGain (TSL2591* tsl, tsl2591Gain_t gain ); + void TSL2591_setTiming (TSL2591* tsl, tsl2591IntegrationTime_t integration ); + uint16_t TSL2591_getLuminosity (TSL2591* tsl, uint8_t channel ); + uint32_t TSL2591_getFullLuminosity (TSL2591* tsl ); + + tsl2591IntegrationTime_t TSL2591_getTiming(TSL2591* tsl); + tsl2591Gain_t TSL2591_getGain(TSL2591* tsl); + + +#endif + diff --git a/sensors/MagneticFieldSensor/main.c b/sensors/MagneticFieldSensor/main.c index 0ec2d45..96ea472 100644 --- a/sensors/MagneticFieldSensor/main.c +++ b/sensors/MagneticFieldSensor/main.c @@ -14,13 +14,16 @@ volatile uint8_t mode = 0; int main(void) { char s[30]; char SerNum[10]; - uint8_t Status[4]={0,0,0,0}; + uint8_t Status[5]={0,0,0,0,0}; uint8_t TC_Enabled[4]={0,0,0,0}; uint8_t Status_Mag[4]={0,0,0,0}; uint16_t TRef[4]={0,0,0,0}; float SensX[4]; float SensY[4]; float SensZ[4]; + BME280 bme280; + TSL2591 tsl; + //For CLK setting CLKPR = (1<> 16; + uint16_t full = lum & 0xFFFF; + + uputs("Bright: "); + sprintf(s,"%u",full); uputs(s); + uputs(" / "); + sprintf(s,"%u",ir); uputsnl(s); +#endif _delay_ms(500); } else {// CONFIG MODE //Setting: I2C Address, Mode, RegAddr, Data Byte Low, Data byte high. diff --git a/sensors/MagneticFieldSensor/main.h b/sensors/MagneticFieldSensor/main.h index 8d79d03..c9e87e7 100644 --- a/sensors/MagneticFieldSensor/main.h +++ b/sensors/MagneticFieldSensor/main.h @@ -21,6 +21,8 @@ #include #include "uart/uart.h" #include "MagnetSensor.h" +#include "BME280.h" +#include "TSL2591.h" #include "twi/twi.h" #include #include @@ -39,7 +41,9 @@ #define ADDR_MAG_3 0x0F +#define ADDR_ENV 0x76 +#define MULTISENSE 1 //0: 4 magnetic sensors, 1: 1x magnetic, environment #ifndef __AVR_ATmega168P__ #define __AVR_ATmega168P__ diff --git a/sensors/MagneticFieldSensor/readme b/sensors/MagneticFieldSensor/readme index 07dea39..16e8bf7 100644 --- a/sensors/MagneticFieldSensor/readme +++ b/sensors/MagneticFieldSensor/readme @@ -4,6 +4,8 @@ The microcontroller runs off an external 16MHz oscillator. The board can be powered with 3V3 or 5V. 3V3 operation is only stable with 8MHz. Thus, a prescaler of 2 for the main clock is applied in the early startup of the uC. +In main.h, set MULTISENSE to define the type of board + Each board will get a serial number that is being compiled into the firmware. It needs to be specified at compile time: