diff options
author | SudhakarKuma | 2021-05-03 20:05:41 +0530 |
---|---|---|
committer | SudhakarKuma | 2021-05-03 20:05:41 +0530 |
commit | 73b3d5e6715aa6a5cc5472402cdf96b6558e404b (patch) | |
tree | 22c312d4113761340e5e3679218feb8b6a7cae6f | |
parent | 5f297288cde71936a6c11b98e8f7940053fa78c8 (diff) | |
download | FLOSS-Arduino-Book-73b3d5e6715aa6a5cc5472402cdf96b6558e404b.tar.gz FLOSS-Arduino-Book-73b3d5e6715aa6a5cc5472402cdf96b6558e404b.tar.bz2 FLOSS-Arduino-Book-73b3d5e6715aa6a5cc5472402cdf96b6558e404b.zip |
Maintain consistency in thermistor codes
-rw-r--r-- | tools/openmodelica/windows/Arduino.mo | 17 | ||||
-rw-r--r-- | user-code/thermistor/OpenModelica/therm-buzzer.mo | 34 | ||||
-rw-r--r-- | user-code/thermistor/OpenModelica/therm-read.mo | 20 | ||||
-rw-r--r-- | user-code/thermistor/arduino/therm-buzzer/therm-buzzer.ino | 5 | ||||
-rw-r--r-- | user-code/thermistor/arduino/therm-read/therm-read.ino | 2 | ||||
-rw-r--r-- | user-code/thermistor/julia/therm-buzzer.jl | 9 | ||||
-rw-r--r-- | user-code/thermistor/python/therm-buzzer.py | 4 | ||||
-rw-r--r-- | user-code/thermistor/scilab/therm-buzzer.sce | 3 | ||||
-rw-r--r-- | user-code/thermistor/scilab/therm-buzzer.zcos | bin | 5601 -> 5595 bytes | |||
-rw-r--r-- | user-code/thermistor/scilab/therm-read.zcos | bin | 4525 -> 4520 bytes |
10 files changed, 50 insertions, 44 deletions
diff --git a/tools/openmodelica/windows/Arduino.mo b/tools/openmodelica/windows/Arduino.mo index 6680ee6..4958cb7 100644 --- a/tools/openmodelica/windows/Arduino.mo +++ b/tools/openmodelica/windows/Arduino.mo @@ -748,26 +748,27 @@ Arduino.SerialCommunication.Functions.<b>ieeesingle2num</b>(hexa); import sComm = Arduino.SerialCommunication.Functions; import strm = Modelica.Utilities.Streams; Integer ok(fixed = false); - Integer analog_in(fixed = false); + Integer val(fixed = false); Integer digital_out(fixed = false); Integer c_ok(fixed = false); algorithm when initial() then ok := sComm.open_serial(1, 2, 115200) "At port 2 with baudrate of 115200"; - sCOmm.delay(2000); + sComm.delay(2000); end when; if ok <> 0 then strm.print("Unable to open serial port, please check"); else - analog_in := sComm.cmd_analog_in(1, 4) "read analog pin 4"; - strm.print("Thermistor Readings: " + String(analog_in)); - if analog_in > 550 then + val := sComm.cmd_analog_in(1, 4) "read analog pin 4"; + strm.print("Thermistor Readings: " + String(val)); + if val > 550 then digital_out := sComm.cmd_digital_out(1, 3, 1) "Turn ON Buzzer"; else digital_out := sComm.cmd_digital_out(1, 3, 0) "Turn OFF Buzzer"; end if; sComm.delay(500); end if; + digital_out := sComm.cmd_digital_out(1, 3, 0) "Turn OFF Buzzer"; //for i in 1:500 loop //end for; //Run for 500 iterations @@ -784,7 +785,7 @@ Arduino.SerialCommunication.Functions.<b>ieeesingle2num</b>(hexa); import sComm = Arduino.SerialCommunication.Functions; import strm = Modelica.Utilities.Streams; Integer ok(fixed = false); - Integer analog_in(fixed = false); + Integer val(fixed = false); Integer c_ok(fixed = false); algorithm when initial() then @@ -794,8 +795,8 @@ Arduino.SerialCommunication.Functions.<b>ieeesingle2num</b>(hexa); if ok <> 0 then strm.print("Unable to open serial port, please check"); else - analog_in := sComm.cmd_analog_in(1, 4) "read analog pin 5 (ldr)"; - strm.print("Thermistor Readings: " + String(analog_in)); + val := sComm.cmd_analog_in(1, 4) "read analog pin 5 (ldr)"; + strm.print("Thermistor Readings: " + String(val)); sComm.delay(500); end if; when terminal() then diff --git a/user-code/thermistor/OpenModelica/therm-buzzer.mo b/user-code/thermistor/OpenModelica/therm-buzzer.mo index 9c4e0e2..22f4a76 100644 --- a/user-code/thermistor/OpenModelica/therm-buzzer.mo +++ b/user-code/thermistor/OpenModelica/therm-buzzer.mo @@ -10,25 +10,27 @@ algorithm when initial() then
ok := sComm.open_serial(1, 2, 115200) "At port 2 with baudrate of 115200";
sComm.delay(2000);
- if ok <> 0 then
- strm.print("Unable to open serial port, please check");
+ end when;
+ if ok <> 0 then
+ strm.print("Unable to open serial port, please check");
+ else
+ val := sComm.cmd_analog_in(1, 4) "read analog pin 4";
+ strm.print("Thermistor Readings: " + String(val));
+ if val > 550 then
+ digital_out := sComm.cmd_digital_out(1, 3, 1) "Turn ON Buzzer";
else
- for i in 1:500 loop
- val := sComm.cmd_analog_in(1, 4) "read analog pin 4";
- strm.print("Thermistor Readings: " + String(val));
- if val > 550 then
- digital_out := sComm.cmd_digital_out(1, 3, 1) "Turn ON Buzzer";
- else
- digital_out := sComm.cmd_digital_out(1, 3, 0) "Turn OFF Buzzer";
- end if;
- sComm.delay(500);
- end for;
+ digital_out := sComm.cmd_digital_out(1, 3, 0) "Turn OFF Buzzer";
end if;
- end when;
- //Run for 500 iterations
- //Setting Threshold value of 500
+ sComm.delay(500);
+ end if;
+ digital_out := sComm.cmd_digital_out(1, 3, 0) "Turn OFF Buzzer";
+//for i in 1:500 loop
+//end for;
+//Run for 500 iterations
+//Setting Threshold value of 500
when terminal() then
c_ok := sComm.close_serial(1) "To close the connection safely";
end when;
- annotation(experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.02));
+ annotation(
+ experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.1));
end therm_buzzer;
diff --git a/user-code/thermistor/OpenModelica/therm-read.mo b/user-code/thermistor/OpenModelica/therm-read.mo index 4e212f8..25fe82c 100644 --- a/user-code/thermistor/OpenModelica/therm-read.mo +++ b/user-code/thermistor/OpenModelica/therm-read.mo @@ -9,19 +9,17 @@ algorithm when initial() then
ok := sComm.open_serial(1, 2, 115200) "At port 2 with baudrate of 115200";
sComm.delay(2000);
- if ok <> 0 then
- strm.print("Unable to open serial port, please check");
- else
- for i in 1:20 loop
- val := sComm.cmd_analog_in(1, 4) "read analog pin 4 (thermistor)";
- strm.print("Thermistor Readings: " + String(val));
- sComm.delay(500);
- end for;
- end if;
end when;
+ if ok <> 0 then
+ strm.print("Unable to open serial port, please check");
+ else
+ val := sComm.cmd_analog_in(1, 4) "read analog pin 5 (ldr)";
+ strm.print("Thermistor Readings: " + String(val));
+ sComm.delay(500);
+ end if;
when terminal() then
c_ok := sComm.close_serial(1) "To close the connection safely";
end when;
- //Run for 20 iterations
- annotation(experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.5));
+ annotation(
+ experiment(StartTime = 0, StopTime = 20, Tolerance = 1e-6, Interval = 1));
end therm_read;
diff --git a/user-code/thermistor/arduino/therm-buzzer/therm-buzzer.ino b/user-code/thermistor/arduino/therm-buzzer/therm-buzzer.ino index 6ff308f..0cbed53 100644 --- a/user-code/thermistor/arduino/therm-buzzer/therm-buzzer.ino +++ b/user-code/thermistor/arduino/therm-buzzer/therm-buzzer.ino @@ -6,12 +6,12 @@ void setup() pinMode(3, OUTPUT); Serial.begin(115200); - for(i = 1; i < 100; i++) + for(i = 1; i <= 20; i++) { val = analogRead(A4); //read value from thermistor Serial.println(val); //display - if(value > 550) + if(val > 550) { digitalWrite(3, HIGH); // Turn ON buzzer } @@ -21,6 +21,7 @@ void setup() } delay(500); } + digitalWrite(3, LOW); // Turn OFF buzzer } void loop() diff --git a/user-code/thermistor/arduino/therm-read/therm-read.ino b/user-code/thermistor/arduino/therm-read/therm-read.ino index e749f87..68033e9 100644 --- a/user-code/thermistor/arduino/therm-read/therm-read.ino +++ b/user-code/thermistor/arduino/therm-read/therm-read.ino @@ -4,7 +4,7 @@ int i; void setup() { Serial.begin(115200); - for(i = 1; i <= 40; i++) + for(i = 1; i <= 20; i++) { val = analogRead(A4); //read value from thermistor Serial.println(val); //display diff --git a/user-code/thermistor/julia/therm-buzzer.jl b/user-code/thermistor/julia/therm-buzzer.jl index 144e5ed..5e6948d 100644 --- a/user-code/thermistor/julia/therm-buzzer.jl +++ b/user-code/thermistor/julia/therm-buzzer.jl @@ -3,14 +3,15 @@ include("ArduinoTools.jl") ser = ArduinoTools.connectBoard(115200) ArduinoTools.pinMode(ser, 3, "OUTPUT") -for i = 1:50 +for i = 1:20 val = ArduinoTools.analogRead(ser, 4) println(val) - if (val > 550) + if (val > 550) ArduinoTools.digiWrite(ser, 3, 1) - else - ArduinoTools.digiWrite(ser, 3, 0) + else + ArduinoTools.digiWrite(ser, 3, 0) end sleep(0.5) end +ArduinoTools.digiWrite(ser, 3, 0) close(ser) diff --git a/user-code/thermistor/python/therm-buzzer.py b/user-code/thermistor/python/therm-buzzer.py index e72a7b2..5b9bbe7 100644 --- a/user-code/thermistor/python/therm-buzzer.py +++ b/user-code/thermistor/python/therm-buzzer.py @@ -31,7 +31,9 @@ class THERM_BUZZER: self.obj_arduino.cmd_digital_out(1, self.buzzer, 1)
else:
self.obj_arduino.cmd_digital_out(1, self.buzzer, 0)
- sleep(0.5)
+ sleep(0.5)
+ self.obj_arduino.cmd_digital_out(1, self.buzzer, 0)
+
def exit(self):
self.obj_arduino.close_serial()
diff --git a/user-code/thermistor/scilab/therm-buzzer.sce b/user-code/thermistor/scilab/therm-buzzer.sce index 6850202..94bf080 100644 --- a/user-code/thermistor/scilab/therm-buzzer.sce +++ b/user-code/thermistor/scilab/therm-buzzer.sce @@ -1,6 +1,6 @@ ok = open_serial(1, 2, 115200); // port 2, baudrate 115200
if ok ~= 0 then error('Unable to open serial port, please check'); end
-for i = 1:500 //Run for 500 iterations
+for i = 1:20 //Run for 20 iterations
val = cmd_analog_in(1, 4) // read analog pin 4 (thermistor)
disp(val);
if(val > 550) // Setting Threshold value of 550
@@ -10,4 +10,5 @@ for i = 1:500 //Run for 500 iterations end
sleep(500);
end
+cmd_digital_out(1, 3, 0) // Turn OFF BUZZER
close_serial(1);
diff --git a/user-code/thermistor/scilab/therm-buzzer.zcos b/user-code/thermistor/scilab/therm-buzzer.zcos Binary files differindex 2b8d5b3..ac6101e 100644 --- a/user-code/thermistor/scilab/therm-buzzer.zcos +++ b/user-code/thermistor/scilab/therm-buzzer.zcos diff --git a/user-code/thermistor/scilab/therm-read.zcos b/user-code/thermistor/scilab/therm-read.zcos Binary files differindex c853ae8..ebf8240 100644 --- a/user-code/thermistor/scilab/therm-read.zcos +++ b/user-code/thermistor/scilab/therm-read.zcos |