mirror of
https://gitlab.com/Luci_/arduino-photometrics.git
synced 2026-04-03 03:25:36 +02:00
average measure part for photosensors, and add limit to avoid EERPOM overflow
This commit is contained in:
parent
97dcdcf3b0
commit
f7adfbe25f
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -8,6 +8,7 @@ time
|
|||
MinMaxPhoto-r.ods
|
||||
serial
|
||||
*.drawio.bkp
|
||||
data/*
|
||||
|
||||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/platformio,c++
|
||||
|
|
|
|||
|
|
@ -76,4 +76,11 @@ Connect the arduino to your PC, set **serial_com** boolean to **True**, before u
|
|||
## Calibration phase
|
||||
- Improvement: Add an assisted phase to earn upper and lower threshold values to write in the code for the normalisation and storage.
|
||||
|
||||
[CI]: https://gitlab.com/Luci_/arduino-photometrics/badges/main/pipeline.svg
|
||||
[CI]: https://gitlab.com/Luci_/arduino-photometrics/badges/main/pipeline.svg
|
||||
|
||||
# Credit
|
||||
This projet are entirely made by Aurélien Gauthier.
|
||||
|
||||
The project use two library:
|
||||
- [Low-Power](https://registry.platformio.org/libraries/rocketscream/Low-Power) for the management of sleep system.
|
||||
- [DS3231 lib](https://registry.platformio.org/libraries/northernwidget/DS3231) for the management of the DS3231 RTC module.
|
||||
|
|
@ -338,13 +338,15 @@ void Storage_interface::add_last_package(bool timestamp, bool is_final_set, bool
|
|||
void Storage_interface::add_measure(uint8_t* array_photo_val, uint8_t* array_temp_val, uint32_t timestamp, uint8_t nb_photo, uint8_t nb_temp){
|
||||
uint16_t p_last_header, free_space, idx, next_free_space, nb_measure;
|
||||
|
||||
|
||||
get_last_header_nbpackage(&p_last_header);
|
||||
|
||||
get_next_package(p_last_header, &free_space);
|
||||
get_nb_measures(p_last_header, &nb_measure);
|
||||
nb_measure++;
|
||||
set_nb_measures(p_last_header, &nb_measure);
|
||||
|
||||
if(free_space > (MEGA_2560_EEPROM_SIZE - 11)) // avoid EEPROM overflow
|
||||
return;
|
||||
EEPROM.put(free_space, timestamp);
|
||||
idx = free_space + sizeof(uint32_t);
|
||||
for(int i = 0; i < nb_photo; i++, idx += sizeof(uint8_t)){
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class Storage_interface
|
|||
private:
|
||||
|
||||
static constexpr uint8_t OFFSET_MEASURES_SCH = 1, OFFSET_NB_PHOTO_SENSOR = 2, OFFSET_NB_TEMP_SENSOR = 3, OFFSET_PHOTO_MEASURES_SIZE = 4, OFFSET_TEMP_MEASURES_SIZE = 5, OFFSET_NB_MEASURES = 6, OFFSET_NEXT_PACKAGE = 8, OFFSET_START_DATA_MEASURES = 10; // unit in byte
|
||||
static constexpr uint16_t MEGA_2560_EEPROM_SIZE = 4096;
|
||||
static constexpr uint16_t MEGA_2560_EEPROM_SIZE = 32000;
|
||||
|
||||
void clear_eeprom_at(uint16_t idx);
|
||||
|
||||
|
|
|
|||
38
src/main.cpp
38
src/main.cpp
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
const long BAUD_RATE = 9600;
|
||||
|
||||
uint8_t ledPin = 2, alarm_pin = 19, decTemp = 4; // nb decimal temperature printing
|
||||
uint8_t ledPin = 2, alarm_pin = 19, decTemp = 4, nb_average_measure = 10; // nb decimal temperature printing
|
||||
const uint8_t nbPhotoSensor = 6, nbTempSensor = 1;
|
||||
uint8_t analogPin [nbPhotoSensor] = {A0, A1, A2 ,A3 ,A5 ,A6}, schedule = 0, photo_sensor_size = sizeof(uint8_t), temp_sensor_size = sizeof(uint8_t);
|
||||
int32_t min_res [nbPhotoSensor] = {128, 160, 193, 96, 323, 96}; // Manual measurement of personal sensors
|
||||
|
|
@ -24,7 +24,7 @@ bool serial_com = false;
|
|||
|
||||
// Deep sleep time based on northernwidget/DS3231 lib
|
||||
// Timer param
|
||||
byte sec = 0, min = 0, hour = 1, day = 0, alarmBits;
|
||||
byte sec = 0, min = 15, hour = 0, day = 0, alarmBits;
|
||||
bool alarmDayIsDay = false, alarmH12 = false, alarmPM = false, is_set_alarm_flag;
|
||||
|
||||
SensorOhm test[nbPhotoSensor];
|
||||
|
|
@ -52,10 +52,10 @@ void setup() {
|
|||
alarm_timer();
|
||||
|
||||
// NOTE : DS3231 lib advise to set the unused alarm to an inaccessible time to avoid unwanted signal (even alarm set off)
|
||||
min = 0xFF; // a value that will never match the time
|
||||
byte min_alarm2 = 0xFF; // a value that will never match the time
|
||||
alarmBits = 0b01100000; // Alarm 2 when minutes match, i.e., never
|
||||
|
||||
Clock.setA2Time(day, hour, min, alarmBits, alarmDayIsDay, alarmH12, alarmPM);
|
||||
Clock.setA2Time(day, hour, min_alarm2, alarmBits, alarmDayIsDay, alarmH12, alarmPM);
|
||||
Clock.turnOffAlarm(2);
|
||||
// clear Alarm 2 flag
|
||||
is_set_alarm_flag = Clock.checkIfAlarm(2);
|
||||
|
|
@ -143,31 +143,41 @@ void loop() {
|
|||
s_manager.print_min_max_res();
|
||||
#endif
|
||||
|
||||
int32_t res_array[nbPhotoSensor];
|
||||
int32_t res_array[nb_average_measure][nbPhotoSensor];
|
||||
uint32_t unixTime;
|
||||
int16_t mapped_val_array[nbPhotoSensor];
|
||||
uint8_t converted_val_array[nbPhotoSensor], temp[nbTempSensor];
|
||||
int16_t mapped_val_array[nb_average_measure][nbPhotoSensor];
|
||||
uint8_t converted_val_array[nb_average_measure][nbPhotoSensor], temp[nbTempSensor];
|
||||
|
||||
unixTime = myRTC.now().unixtime();
|
||||
|
||||
temp[0] = (uint8_t) Clock.getTemperature();
|
||||
s_manager.get_resistances(res_array, nbPhotoSensor);
|
||||
for(int i = 0; i < nb_average_measure; i++){
|
||||
s_manager.get_resistances(res_array[i], nbPhotoSensor);
|
||||
|
||||
tr.map_r(min_res, max_res, res_array, mapped_val_array, nbPhotoSensor);
|
||||
tr.res_value_int32_to_uint8(mapped_val_array, converted_val_array, nbPhotoSensor);
|
||||
tr.map_r(min_res, max_res, res_array[i], mapped_val_array[i], nbPhotoSensor);
|
||||
tr.res_value_int32_to_uint8(mapped_val_array[i], converted_val_array[i], nbPhotoSensor);
|
||||
}
|
||||
|
||||
for(int i = 1; i < nb_average_measure; i++){
|
||||
for(int y = 0; y < nbPhotoSensor; y++){
|
||||
converted_val_array[0][y] += converted_val_array[i][y];
|
||||
}
|
||||
}
|
||||
for(int y = 0; y < nbPhotoSensor; y++){
|
||||
converted_val_array[0][y] = converted_val_array[0][y] / nb_average_measure;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
Serial.println("Readed values from sensors:");
|
||||
print_named_tab(mapped_val_array, nbPhotoSensor, "int8_t normalised");
|
||||
print_named_tab(converted_val_array[0], nbPhotoSensor, "int8_t normalised");
|
||||
#endif
|
||||
|
||||
sto_intrf.add_measure(converted_val_array, temp, unixTime, nbPhotoSensor, nbTempSensor);
|
||||
sto_intrf.add_measure(converted_val_array[0], temp, unixTime, nbPhotoSensor, nbTempSensor);
|
||||
|
||||
#ifdef DEBUG
|
||||
uint8_t nbPhotoSensor_mem, nbTempSensor_mem;
|
||||
sto_intrf.get_measure(converted_val_array, temp, &unixTime, &nbPhotoSensor_mem, &nbTempSensor_mem);
|
||||
sto_intrf.get_measure(converted_val_array[0], temp, &unixTime, &nbPhotoSensor_mem, &nbTempSensor_mem);
|
||||
Serial.println("Readed values from EEPROM:");
|
||||
print_named_tab(mapped_val_array, nbPhotoSensor, "int8_t normalised");
|
||||
print_named_tab(converted_val_array[0], nbPhotoSensor, "int8_t normalised");
|
||||
#endif
|
||||
Clock.checkIfAlarm(1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue