See: https://github.com/EEEManchester/Food-Computer

Dependencies:   DHT DS1820 MODSERIAL ModbusSlave232 SoftSerial TSL2561_I2C mbed millis

Fork of ModbusRTU-RS232 by Afdhal Atiff Tan

Files at this revision

API Documentation at this revision

Comitter:
AfdhalAtiffTan
Date:
Thu Aug 11 13:11:14 2016 +0000
Parent:
4:796586b35695
Child:
6:e7a1bcea9dab
Commit message:
Tested: Water sensor seems to work better now.

Changed in this revision

DS18B20.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
pin_definitions.h Show annotated file Show diff for this revision Revisions of this file
--- a/DS18B20.lib	Thu Jul 28 16:00:51 2016 +0000
+++ b/DS18B20.lib	Thu Aug 11 13:11:14 2016 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/AfdhalAtiffTan/code/DS18B20/#9ff078416e17
+https://developer.mbed.org/users/AfdhalAtiffTan/code/DS18B20/#6f1dd22234a6
--- a/main.cpp	Thu Jul 28 16:00:51 2016 +0000
+++ b/main.cpp	Thu Aug 11 13:11:14 2016 +0000
@@ -20,20 +20,21 @@
 }
 
 int main()
-{
-    regs[MB_9] = 0xFFFF; //force all relay off       
-    
+{        
+    //force all relay off  
+    R0 = 1; R1 = 1; R2 = 1; R3 = 1; R4 = 1; R5 = 1; R6 = 1; R7 = 1;
+    regs[MB_9] = 0xFFFF;   
+       
     startMillis(); // milliseconds (arduino like)
     mbs.configure(SLAVE, BAUD, PARITY);
     
     CO2sensor.baud(9600);
     CO2sensor.printf("\nK 2\r\n"); //set the sensor into polling mode
-    //CO2sensor.scanf(" %[^\n]", &co2string); //dummy - blocking call enable later
+    CO2sensor.scanf(" %[^\n]", &co2string); //dummy - blocking call
             
     lux_sensor.enablePower();
     window_switch.mode(PullUp);
     shell_switch.mode(PullUp);
-    water_temp.set_configuration_bits(10); //9bit of resolution so that it is faster
         
     modbus_updater.attach(&update_modbus, 0.1); //visit modbus every 100ms
 
@@ -42,8 +43,8 @@
         led2 = !led2; //for debug        
         
         dht22.readData();
-        water_temp.convert_temperature(DS1820::all_devices);         //Start temperature conversion, wait until ready
-        water_temperature = water_temp.temperature('c');
+        water_temp.convertTemperature(true, DS1820::all_devices);       //Start temperature conversion, wait until ready
+        water_temperature = water_temp.temperature();
         
         CO2sensor.printf("Z\r\n"); //request CO2 reading
         //see: http://stackoverflow.com/questions/16447759/scanf-inside-while-loop-working-only-one-time
@@ -51,11 +52,11 @@
         sscanf(co2string, "%*c %d", &CO2_PPM);   
                         
         regs[MB_0] = CO2_PPM; //air_co2
-        regs[MB_1]=  (int)100.0*dht22.ReadHumidity(); //air_humidity
-        regs[MB_2]=  (int)100.0*dht22.ReadTemperature(CELCIUS); //air_temp
-        regs[MB_3] = (int)100.0*water_temperature;//water_temp in celcius
-        regs[MB_4] = (int)100.0*get_EC(water_temperature); //water_ec 
-        regs[MB_5] = (int)100.0*get_pH(); //water_ph
+        regs[MB_1]=  (int)(100.0f*dht22.ReadHumidity()); //air_humidity
+        regs[MB_2]=  (int)(100.0f*dht22.ReadTemperature(CELCIUS)); //air_temp
+        regs[MB_3] = (int)(100.0f*water_temperature);//water_temp in celcius
+        regs[MB_4] = (int)(100.0f*get_EC(water_temperature)); //water_ec 
+        regs[MB_5] = (int)(100.0f*get_pH()); //water_ph
         regs[MB_6] = lux_sensor.getLux(); //light_lux
         regs[MB_7]=  window_switch.read(); //window_switch
         regs[MB_8] = shell_switch.read(); //shell_switch                      
--- a/pin_definitions.h	Thu Jul 28 16:00:51 2016 +0000
+++ b/pin_definitions.h	Thu Aug 11 13:11:14 2016 +0000
@@ -7,6 +7,7 @@
 
 DHT dht22(D2,DHT22);
 
+//https://developer.mbed.org/users/Sissors/code/DS1820_HelloWorld/
 DS1820 water_temp(D3);
 
 DigitalOut R0(D4);