Skip to content

Commit

Permalink
fix: Created microcontroller-computer monitoring program
Browse files Browse the repository at this point in the history
  • Loading branch information
TomsBicans committed Apr 1, 2023
1 parent efb00ac commit e29835b
Show file tree
Hide file tree
Showing 8 changed files with 706 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@
*.exe
*.out
*.app

*.log
2 changes: 2 additions & 0 deletions info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Start: 17:40
End: 21:50
51 changes: 51 additions & 0 deletions log/analyze.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import sys
import os
import serial
import threading
import time
import os.path as path
from pathlib import Path

LOG_DIR = path.dirname(__file__)
LOG_FILE = path.join(LOG_DIR, "measurement_data.log")


def get_data_lines(data: list[str]):
res = []
for l in data:
if any(p.lower() in l.lower() for p in ["OBS", "Total"]):
continue
res.append(l)
return res


def get_time_lines(data: list[str]):
res = []
for l in data:
if any(p.lower() in l.lower() for p in ["Total"]):
res.append(l)
return res


def write_to_file(loc: str, data: str):
with open(loc, "w") as f:
f.write(data)
return loc


def main():
file = Path(LOG_FILE)
data = str(file.read_text())
data = data.splitlines()
data = [l for l in data if l]
time_data = get_time_lines(data)
# time_data =
data = get_data_lines(data)
[print(l) for l in data]
data = "\n".join(data) + "\n"
loc = path.join(LOG_DIR, "results.csv")
write_to_file(loc, data)


if __name__ == "__main__":
main()
5 changes: 4 additions & 1 deletion log/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import serial
import threading
import time
import os.path as path

LOG_FILE = path.join(path.dirname(__file__), "running_logs.log")


def monitor(comport: str, baudrate: int):
Expand All @@ -24,7 +27,7 @@ def monitor(comport: str, baudrate: int):
# print fields
# print("device ID: ", ID)
# write to file
text_file = open("Pdata.log", "a")
text_file = open(LOG_FILE, "a")
# line = str(TIME) + ": " + str(CT) + "\n"
text_file.write(line)
text_file.close()
Expand Down
439 changes: 439 additions & 0 deletions log/results.csv

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions main/Examples/DS3231_TEST/7.semestris.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"folders": [
{
"path": "../../../../../Universitate/LU_Datorzinatnes/7.semestris"
}
]
}
199 changes: 199 additions & 0 deletions main/Examples/DS3231_TEST/DS3231_TEST.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/*
DS3231_test.pde
Eric Ayars
4/11
Test/demo of read routines for a DS3231 RTC.
Turn on the serial monitor after loading this to check if things are
working as they should.
*/

#include <DS3231.h>
#include <Wire.h>

DS3231 Clock;
bool Century=false;
bool h12;
bool PM;
byte ADay, AHour, AMinute, ASecond, ABits;
bool ADy, A12h, Apm;

byte year, month, date, DoW, hour, minute, second;

void setup() {
// Start the I2C interface
Wire.begin();
Clock.setSecond(50);//Set the second
Clock.setMinute(59);//Set the minute
Clock.setHour(11); //Set the hour
Clock.setDoW(5); //Set the day of the week
Clock.setDate(31); //Set the date of the month
Clock.setMonth(5); //Set the month of the year
Clock.setYear(13); //Set the year (Last two digits of the year)
// Start the serial interface
Serial.begin(115200);
}
void ReadDS3231()
{
int second,minute,hour,date,month,year,temperature;
second=Clock.getSecond();
minute=Clock.getMinute();
hour=Clock.getHour(h12, PM);
date=Clock.getDate();
month=Clock.getMonth(Century);
year=Clock.getYear();

temperature=Clock.getTemperature();

Serial.print("20");
Serial.print(year,DEC);
Serial.print('-');
Serial.print(month,DEC);
Serial.print('-');
Serial.print(date,DEC);
Serial.print(' ');
Serial.print(hour,DEC);
Serial.print(':');
Serial.print(minute,DEC);
Serial.print(':');
Serial.print(second,DEC);
Serial.print('\n');
Serial.print("Temperature=");
Serial.print(temperature);
Serial.print('\n');
}
void loop() {ReadDS3231();delay(1000);
// send what's going on to the serial monitor.
// Start with the year
/* Serial.print("2");
if (Century) { // Won't need this for 89 years.
Serial.print("1");
} else {
Serial.print("0");
}
Serial.print(Clock.getYear(), DEC);
Serial.print('-');
// then the month
Serial.print(Clock.getMonth(Century), DEC);
Serial.print('-');
// then the date
Serial.print(Clock.getDate(), DEC);
Serial.print(' ');*/
// and the day of the week
/*Serial.print(Clock.getDoW(), DEC);
Serial.print(' ');*/
// Finally the hour, minute, and second
/*Serial.print(Clock.getHour(h12, PM), DEC);
Serial.print(':');
Serial.print(Clock.getMinute(), DEC);
Serial.print(':');
Serial.print(Clock.getSecond(), DEC);
// Add AM/PM indicator
if (h12) {
if (PM) {
Serial.print(" PM ");
} else {
Serial.print(" AM ");
}
} else {
Serial.print(" 24h ");
}
// Display the temperature
Serial.print("T=");
Serial.print(Clock.getTemperature(), 2);
// Tell whether the time is (likely to be) valid
if (Clock.oscillatorCheck()) {
Serial.print(" O+");
} else {
Serial.print(" O-");
}*/
// Indicate whether an alarm went off
/*if (Clock.checkIfAlarm(1)) {
Serial.print(" A1!");
}
if (Clock.checkIfAlarm(2)) {
Serial.print(" A2!");
}*/
// New line on display
//Serial.print('\n');
// delay(1000);
// Display Alarm 1 information
/* Serial.print("Alarm 1: ");
Clock.getA1Time(ADay, AHour, AMinute, ASecond, ABits, ADy, A12h, Apm);
Serial.print(ADay, DEC);
if (ADy) {
Serial.print(" DoW");
} else {
Serial.print(" Date");
}
Serial.print(' ');
Serial.print(AHour, DEC);
Serial.print(' ');
Serial.print(AMinute, DEC);
Serial.print(' ');
Serial.print(ASecond, DEC);
Serial.print(' ');
if (A12h) {
if (Apm) {
Serial.print('pm ');
} else {
Serial.print('am ');
}
}
if (Clock.checkAlarmEnabled(1)) {
Serial.print("enabled");
}
Serial.print('\n');
// Display Alarm 2 information
Serial.print("Alarm 2: ");
Clock.getA2Time(ADay, AHour, AMinute, ABits, ADy, A12h, Apm);
Serial.print(ADay, DEC);
if (ADy) {
Serial.print(" DoW");
} else {
Serial.print(" Date");
}
Serial.print(' ');
Serial.print(AHour, DEC);
Serial.print(' ');
Serial.print(AMinute, DEC);
Serial.print(' ');
if (A12h) {
if (Apm) {
Serial.print('pm');
} else {
Serial.print('am');
}
}
if (Clock.checkAlarmEnabled(2)) {
Serial.print("enabled");
}*/
/* display alarm bits
Serial.print('\n');
Serial.print('Alarm bits: ');
Serial.print(ABits, DEC);
*/
/*
Serial.print('\n');
Serial.print('\n');
delay(1000);
// Display the time once more as a test of the getTime() function
Clock.getTime(year, month, date, DoW, hour, minute, second);
Serial.print(year, DEC);
Serial.print("/");
Serial.print(month, DEC);
Serial.print("/");
Serial.print(date, DEC);
Serial.print("day of the week :");
Serial.println(DoW, DEC);
Serial.print(hour, DEC);
Serial.print(":");
Serial.print(minute, DEC);
Serial.print(":");
Serial.println(second, DEC);*/
}

3 changes: 2 additions & 1 deletion main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,8 @@ void setup()
while (!timer.hasElapsed()){ util::display_whole_text_LCD(lcd1_conf, TEXT_BUFFER); continue;}
}
buzzer::success();
delay(1500);
delay(1000);
measurement::print_headers();
}

int LOOP_COUNT = 0;
Expand Down

0 comments on commit e29835b

Please sign in to comment.