Skip to content
Browse files

add a serial command to the Arduino sketch 'H' gets reading

  • Loading branch information...
1 parent 47dec67 commit e47ada40c9de74a5aba9ac23735294610fb14eea @sirleech committed May 9, 2012
View
23 arduino/AquacultureSerialThermistor/AquacultureSerialThermistor.pde
@@ -1,23 +0,0 @@
-// 10K Thermistor circuit hooked up to Analog 0
-//
-
-int a;
-int del=1000; // duration between temperature readings
-float temperature;
-int B=3975;
-float resistance;
-
-void setup()
-{
- Serial.begin(38400);
-}
-
-void loop()
-{
- a=analogRead(0);
- resistance=(float)(1023-a)*10000/a;
- temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;
- delay(del);
- Serial.println(temperature);
-}
-
View
32 arduino/SerialThermometer/SerialThermometer.pde
@@ -0,0 +1,32 @@
+// Project Seven - temperature
+//
+
+int a;
+int del=1000; // duration between temperature readings
+float temperature;
+int B=3975;
+float resistance;
+int incomingByte;
+
+void setup()
+{
+ Serial.begin(38400);
+}
+
+void loop()
+{
+
+
+ if (Serial.available() > 0) {
+ // read the oldest byte in the serial buffer:
+ incomingByte = Serial.read();
+ // if it's a capital H (ASCII 72), turn on the LED:
+ if (incomingByte == 'H') {
+ a=analogRead(0);
+ resistance=(float)(1023-a)*10000/a;
+ temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;
+ Serial.println(temperature);
+ }
+ }
+}
+
View
5 temperature.py
@@ -5,7 +5,10 @@
def getSerialSensorValue():
import serial
- ser = serial.Serial('/dev/ttyUSB0', 38400)
+ import time
+ ser = serial.Serial('/dev/ttyUSB1', 38400)
+ ser.write('H')
+ time.sleep(.5)
valueString = ser.readline()
ser.close()
return float(valueString)

0 comments on commit e47ada4

Please sign in to comment.
Something went wrong with that request. Please try again.