diff --git a/slave/slave/config.h b/slave/slave/config.h --- a/slave/slave/config.h +++ b/slave/slave/config.h @@ -30,14 +30,14 @@ //Sensors and IO #define SENSOR_LOOP 200 // Frequency of sensor reads (in ms) (should be 200) #define HEATER_THRESHOLD 0 // Temperature threshold in Fahrenheit where heater is activated -#define CAMERA_FREQ 10000 // Camera pulse frequency (Should be 30000 for 30 Secs) -#define CAMERA_PULSE 500 // Camera pulse duration +#define CAMERA_FREQ 5000 // Camera pulse frequency (Should be 30000 for 30 Secs) +#define CAMERA_PULSE 2500 // Camera pulse duration //I2C Addresses #define EEPROM_ADDR 0xA0 // Read 0xA1 - Write 0xA0 #define BOARDTEMP_ADDR 0x90 // Read 0x91 - Write 0x90 #define PRESSURE_ADDR 0xEE // Read 0xEF - Write 0xEE - #define HUMID_ADDR 0x26 // Read 0x27 - Write 0x26 + #define HUMID_ADDR 0x27 // Read 0x28 - Write 0x27 #define LIGHT_ADDR 0x94 // Read 0x95 - Write 0x94 #define ACCEL_ADDR 0x38 // Read 0x39 - Write 0x38 #define RTC_ADDR 0xB2 //DEBUG [Used for testing] // Read 0xA3 - Write 0xA2 diff --git a/slave/slave/lib/i2c.c b/slave/slave/lib/i2c.c --- a/slave/slave/lib/i2c.c +++ b/slave/slave/lib/i2c.c @@ -5,6 +5,7 @@ * Author: kripperger */ +#include #include #include #include "loopTimer.h" @@ -44,14 +45,14 @@ unsigned char i2c_start(unsigned char ad TWCR = (1< 10) - { - break; // Timeout Reached! - } - } +// { +// if ((time_millis() - startTime) > 10) +// { +// break; // Timeout Reached! +// } +// } // check value of TWI Status Register. Mask prescaler bits. twst = TW_STATUS & 0xF8; @@ -62,14 +63,14 @@ unsigned char i2c_start(unsigned char ad TWCR = (1< 10) - { - break; // Timeout Reached! - } - } +// { +// if ((time_millis() - startTime) > 10) +// { +// break; // Timeout Reached! +// } +// } // check value of TWI Status Register. Mask prescaler bits. twst = TW_STATUS & 0xF8; @@ -177,13 +178,13 @@ void i2c_stop(void) TWCR = (1< 10) - { - break; // Timeout Reached! - } +// if ((time_millis() - startTime) > 10) +// { +// break; // Timeout Reached! +// } } }/* i2c_stop */ @@ -281,8 +282,8 @@ unsigned char i2c_readNak(void) void i2c_write(unsigned char addr, unsigned char reg, unsigned char data) { i2c_start_wait(addr+I2C_WRITE); // set device address and write mode - i2c_writeX(reg); // write register address - i2c_writeX(data); // write value data to register + i2c_writeX(reg); // write register address + i2c_writeX(data); // write value data to register i2c_stop(); // set stop condition = release bus }/* i2c_write */ @@ -317,7 +318,7 @@ uint16_t i2c_read16(unsigned char addr) uint8_t dataL; i2c_start_wait(addr+I2C_WRITE); // set device address and write mode - + i2c_rep_start(addr+I2C_READ); // set device address and read mode data = i2c_readAck(); // read one byte dataL = i2c_readNak(); @@ -328,4 +329,31 @@ uint16_t i2c_read16(unsigned char addr) return data; -}/* i2c_read16 */ \ No newline at end of file +}/* i2c_read16 */ + +uint16_t i2c_humidRead() +{ + uint16_t data; + uint8_t dataL; + + //i2c_start_wait(HUMID_ADDR+I2C_WRITE); // set device address and write mode + //i2c_rep_start(HUMID_ADDR+I2C_READ); // set device address and read mode + + i2c_start(HUMID_ADDR+I2C_WRITE); // Measurement Request + i2c_stop(); // Stop + + + i2c_start(HUMID_ADDR+I2C_READ); // Measurement Request + + i2c_readAck(); // read one byte + i2c_readNak(); + data = i2c_readAck(); // read one byte + dataL = i2c_readAck(); + i2c_stop(); + + data = data << 8; + data = data | dataL; + + return data; + +} \ No newline at end of file diff --git a/slave/slave/lib/i2c.h b/slave/slave/lib/i2c.h --- a/slave/slave/lib/i2c.h +++ b/slave/slave/lib/i2c.h @@ -62,4 +62,6 @@ unsigned char i2c_read(unsigned char add /////////////////added for humidity uint16_t i2c_read16(unsigned char addr); +uint16_t i2c_humidRead(void); + #endif /* I2C_H_ */ \ No newline at end of file diff --git a/slave/slave/lib/inputOutput.c b/slave/slave/lib/inputOutput.c --- a/slave/slave/lib/inputOutput.c +++ b/slave/slave/lib/inputOutput.c @@ -98,7 +98,7 @@ int8_t moduleID; // Slave Module ID from io_heaterOn(); led_on(3); } - else if (sensors_getBoardTemp() > (HEATER_THRESHOLD + 5)) + else if (sensors_getBoardTemp() > (HEATER_THRESHOLD + 4)) { io_heaterOff(); led_off(3); diff --git a/slave/slave/lib/sensors.c b/slave/slave/lib/sensors.c --- a/slave/slave/lib/sensors.c +++ b/slave/slave/lib/sensors.c @@ -192,10 +192,13 @@ void sensors_readPressure() void sensors_readHumid() { - humid = i2c_read16(HUMID_ADDR); - + //i2c_write(HUMID_ADDR, 0x00, 0x00); //Measurement Request + //humid = i2c_read16(HUMID_ADDR); + + humid = i2c_humidRead(); + //calculations to relative humidity: humid = (humid/((2^14) - 1))*100% >> is divide by power, << is multiply by power, 2^14-1 = 16383 - humid = (humid / 16383) * 100; + //humid = (humid / 16383) * 100; } void sensors_readLux() diff --git a/slave/slave/modules.c b/slave/slave/modules.c --- a/slave/slave/modules.c +++ b/slave/slave/modules.c @@ -131,9 +131,9 @@ { // Gathers data and performs functions for sensor daughter board sensors_readBoardTemp(); //Data Read - sensors_readSpiTemp(); //Data Read + sensors_readSpiTemp(); //Data Read sensors_readPressure(); //Data Read - //sensors_readHumid(); //Data Read + sensors_readHumid(); //Data Read sensors_readLux(); //Data Read } @@ -151,21 +151,21 @@ //cameras_readAccelXYZ(); - if ((time_millis() - pulseOn) > CAMERA_PULSE) - { - PORTA &= ~(1 << PA0); // Pull pin on usb low - PORTA &= ~(1 << PA1); // Pull pin on usb low - PORTA &= ~(1 << PA2); // Pull pin on usb low - PORTA &= ~(1 << PA3); // Pull pin on usb low + //if ((time_millis() - pulseOn) > CAMERA_PULSE) + //{ + // PORTA &= ~(1 << PA0); // Pull pin on usb low + // PORTA &= ~(1 << PA1); // Pull pin on usb low + // PORTA &= ~(1 << PA2); // Pull pin on usb low + // PORTA &= ~(1 << PA3); // Pull pin on usb low - if ((time_millis() - lastPicture) > CAMERA_FREQ) // Frequency of photos - { - cameras_sendPulse(); - lastPicture = time_millis(); - } + // if ((time_millis() - lastPicture) > CAMERA_FREQ) // Frequency of photos + // { + // cameras_sendPulse(); + // lastPicture = time_millis(); + // } - pulseOn = time_millis(); - } + // pulseOn = time_millis(); + //} } \ No newline at end of file diff --git a/slave/slave/slave.c b/slave/slave/slave.c --- a/slave/slave/slave.c +++ b/slave/slave/slave.c @@ -37,6 +37,8 @@ #include "lib/watchdog.h" bool WDTreset = false; + uint32_t lastPicture; + uint8_t pulseOn; void micro_setup() { @@ -94,7 +96,7 @@ int main(void) io_regulateTemp(); // Gets board temperature and enables heater if below threshold - snprintf(buff,128,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |Lux: %lu |Pressure: %lu |Altitude: %lu |Battery: %u \r\n ",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getLux(),sensors_getPressure(),sensors_getAltitude(),sensors_getBatt()); //DEBUG + snprintf(buff,128,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |Lux: %lu |Press: %lu |Altitude: %lu |Batt: %u |Humidity: %u |spiTemp: %i \r\n ",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getLux(),sensors_getPressure(),sensors_getAltitude(),sensors_getBatt(),sensors_getHumid(),sensors_getSpiTemp()); //DEBUG serial1_sendString(buff); //DEBUG led_off(0); @@ -105,6 +107,25 @@ int main(void) //i2c_write(EEPROM_ADDR, 0x05, 0x03); } + + if (io_getModuleId() == 3); + { + if ((time_millis() - pulseOn) > CAMERA_PULSE) + { + PORTA &= ~(1 << PA0); // Pull pin on usb low + PORTA &= ~(1 << PA1); // Pull pin on usb low + PORTA &= ~(1 << PA2); // Pull pin on usb low + PORTA &= ~(1 << PA3); // Pull pin on usb low + + if ((time_millis() - lastPicture) > CAMERA_FREQ) // Frequency of photos + { + cameras_sendPulse(); + lastPicture = time_millis(); + } + + pulseOn = time_millis(); + } + } }