-

Dependencies:   DHT DS18B20 Decagon10HS DecagonEC-5 FastIO LightSensorALS-PT19 WaterMark200ss WeatherMeters mbed-src floathex1

Fork of testgeneral by Javier Sing

Committer:
agrosmart
Date:
Thu Dec 15 11:58:10 2016 +0000
Revision:
2:a13c531579dd
Parent:
1:7f1e6470cc93
test general sensores;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
javiersing 0:232c507002f4 1 #include "mbed.h"
javiersing 0:232c507002f4 2 #include "LightSensor.h"
javiersing 0:232c507002f4 3 #include "Decagon10HS.h"
javiersing 0:232c507002f4 4 #include "DecagonEC-5.h"
javiersing 0:232c507002f4 5 #include "DHT.h"
javiersing 0:232c507002f4 6 #include "FastIO.h"
javiersing 0:232c507002f4 7 #include "DS18B20.h"
javiersing 0:232c507002f4 8 #include "WaterMark200ss.h"
javiersing 0:232c507002f4 9 #include "WeatherMeters.h"
javiersing 0:232c507002f4 10 #include "Anemometer.h"
agrosmart 2:a13c531579dd 11 #include "floathex.h"
javiersing 0:232c507002f4 12
javiersing 0:232c507002f4 13
javiersing 0:232c507002f4 14 //Declaración de Puertos para cada sensor
javiersing 0:232c507002f4 15 AnalogIn moisture10HS(A0); //Decagon 10HS en el A0
javiersing 0:232c507002f4 16 AnalogIn light(A1); //ALS-PT19LIGHT en el A1
javiersing 0:232c507002f4 17 AnalogIn moistureEC5(A2); //Decagon EC-5 en el A2
javiersing 0:232c507002f4 18 AnalogIn lightref(A3); //Referencia 3.3V en el A3
javiersing 0:232c507002f4 19 AnalogIn moisture200ss(A4); //WaterMark200ss en el A4
javiersing 0:232c507002f4 20
javiersing 0:232c507002f4 21 /*El sensor DS18B20 se
javiersing 0:232c507002f4 22 define el pin en la
javiersing 0:232c507002f4 23 librería DHT*/ //Ds18B20 en el D2
javiersing 0:232c507002f4 24 DHT dht22(PB_3,DHT22); //DHT22 en el D3
javiersing 0:232c507002f4 25 CWeatherMeters WeatherMeters(D4, D5, A5); //Weather Station Anemómetro D4, Veleta D5, Pluviómetro A5
javiersing 0:232c507002f4 26
agrosmart 1:7f1e6470cc93 27 //Declaración variables para sensores:
agrosmart 2:a13c531579dd 28 float lightLvl = 0; // Sensor LUZ //Rango: 0.0 a 3.3 //3
agrosmart 2:a13c531579dd 29 float VWC10HS = 0; // Sensor 10HS //Rango: 0.0 a 3.4 //3
agrosmart 2:a13c531579dd 30 float VWCEC5 = 0; // Sensor EC-5 //Rango: 0.0 a 4 //3
agrosmart 1:7f1e6470cc93 31 float tempdht22 = 0; // Sensor DHT22 //Rango: -40.0 a 80 //4
agrosmart 1:7f1e6470cc93 32 float humdht22 = 0; // Sensor DHT22 //Rango: 0 a 100% //2
agrosmart 2:a13c531579dd 33 float tempDS18B20 = 0; // Sensor DS18B20 //Rango: -55.0 a 125.0 //4
agrosmart 2:a13c531579dd 34 float centibar = 0; // Sensor WaterMark 200ss //Rango: 0.0 a 240.0 //2
agrosmart 2:a13c531579dd 35 float rainfall = 0; // Weather Station //Rango: 0 a 100 //3
agrosmart 2:a13c531579dd 36 float windSpeed = 0; // Weather Station //Rango: 0 a 2000 //3
agrosmart 1:7f1e6470cc93 37 float maxWindSpeed = 0; // Weather Station //Rango: 0 a 2000 //3
agrosmart 1:7f1e6470cc93 38 float windDir = 0; // Weather Station //Rango: 0 a 337.5 //3
agrosmart 1:7f1e6470cc93 39 float value;
agrosmart 2:a13c531579dd 40 string lightLvlh;
agrosmart 2:a13c531579dd 41 string VWC10HSh;
agrosmart 2:a13c531579dd 42 string VWCEC5h;
agrosmart 2:a13c531579dd 43 string tempdht22h;
agrosmart 2:a13c531579dd 44 string humdht22h;
agrosmart 2:a13c531579dd 45 string tempDS18B20h;
agrosmart 2:a13c531579dd 46 string centibarh;
agrosmart 2:a13c531579dd 47 string rainfallh;
agrosmart 2:a13c531579dd 48 string windSpeedh;
agrosmart 2:a13c531579dd 49 string maxWindSpeedh;
agrosmart 2:a13c531579dd 50 string windDirh;
agrosmart 2:a13c531579dd 51 char buffer1[11]= " ";
agrosmart 2:a13c531579dd 52 char buffer2[11]= " ";
agrosmart 2:a13c531579dd 53 char buffer3[11]= " ";
javiersing 0:232c507002f4 54
agrosmart 1:7f1e6470cc93 55 void ReadSensors();
javiersing 0:232c507002f4 56
javiersing 0:232c507002f4 57 int main()
javiersing 0:232c507002f4 58 {
javiersing 0:232c507002f4 59 pc.baud(115200);
javiersing 0:232c507002f4 60 DQ.output();
javiersing 0:232c507002f4 61 DQ = 0;
javiersing 0:232c507002f4 62 DQ.input();
javiersing 0:232c507002f4 63 pc.printf("All Sensors Test \r\n");
javiersing 0:232c507002f4 64 pc.printf("Memory allocated for %d DS18B20.\r\n",MaxROMs);
javiersing 0:232c507002f4 65 pc.printf("Scanning for devices...\r\n");
javiersing 0:232c507002f4 66 ow_reset();
javiersing 0:232c507002f4 67 FindDevices();
javiersing 0:232c507002f4 68 pc.printf("Scanning completed.\r\n");
javiersing 0:232c507002f4 69
javiersing 0:232c507002f4 70
javiersing 0:232c507002f4 71 while(1) {
javiersing 0:232c507002f4 72 //Leer Sensores
javiersing 0:232c507002f4 73 wait(1);
agrosmart 1:7f1e6470cc93 74 ReadSensors(); //No hace lectura de la Temperatura con la ds18b20??
agrosmart 1:7f1e6470cc93 75 pc.printf("Direction: %s\n",windDir);
javiersing 0:232c507002f4 76 pc.printf("Depth: %f\n",rainfall);
javiersing 0:232c507002f4 77 pc.printf("Current speed: %f\n", windSpeed);
javiersing 0:232c507002f4 78 pc.printf("Maximum speed: %f\n", maxWindSpeed);
javiersing 0:232c507002f4 79 pc.printf("200ss Centibar: %2.2f\n", centibar);
javiersing 0:232c507002f4 80 pc.printf("DHT22 Humidity: %.1f \n\r",humdht22);
javiersing 0:232c507002f4 81 pc.printf("DHT22 Temp: %.1f C",tempdht22);
javiersing 0:232c507002f4 82 pc.printf("EC-5 VWC: %2.2f VMC\r\n", VWCEC5);
javiersing 0:232c507002f4 83 pc.printf("10HS VWC: %2.2f\r\n", VWC10HS);
javiersing 0:232c507002f4 84 pc.printf("Light: %3.2f \r\n", lightLvl);
agrosmart 2:a13c531579dd 85
agrosmart 2:a13c531579dd 86 //Convierto a Hex
agrosmart 2:a13c531579dd 87 lightLvlh = float2dHex(lightLvl); // 2 - 1 int 1 dec
agrosmart 2:a13c531579dd 88 VWC10HSh = float2dHex(VWC10HS); // 2 - 1 int 1 dec
agrosmart 2:a13c531579dd 89 VWCEC5h = float2dHex(VWCEC5); // 2 - 1 int 1 dec
agrosmart 2:a13c531579dd 90 tempdht22h = float4Hex(tempdht22); // 4 - 1 signo (1 negativo, 0 positivo) 2 enteros 1 dec
agrosmart 2:a13c531579dd 91 tempDS18B20h = float4Hex(tempDS18B20); // 4 - 1 signo (1 negativo, 0 positivo) 2 enteros 1 dec
agrosmart 2:a13c531579dd 92 humdht22h = float2Hex(humdht22); // 2 - 2 enteros
agrosmart 2:a13c531579dd 93 rainfallh = float2Hex(rainfall); // 2 - 2 enteros
agrosmart 2:a13c531579dd 94 centibarh = float3dHex(centibar); // 3 - 2 enteros, 1 dec
agrosmart 2:a13c531579dd 95 windDirh = float3dHex(windDir); // 3 - 2 enteros, 1 dec
agrosmart 2:a13c531579dd 96 windSpeedh = float3Hex(windSpeed); // 3 - 3 enteros
agrosmart 2:a13c531579dd 97 maxWindSpeedh = float3Hex(maxWindSpeed); // 3 - 3 enteros
agrosmart 2:a13c531579dd 98 //Creo las cadenas de Hex
agrosmart 2:a13c531579dd 99 snprintf(buffer1, 12, "%s%s%s%s", rainfallh, windDirh, windSpeedh, maxWindSpeedh); //con %.4s puedo definir cuantos caracteres se pasan
agrosmart 2:a13c531579dd 100 snprintf(buffer2, 12, "%s%s%s%s", centibarh, VWC10HSh, VWCEC5h, lightLvlh);
agrosmart 2:a13c531579dd 101 snprintf(buffer3, 12, "%s,%s,%s", tempDS18B20h, tempdht22h, humdht22h);
javiersing 0:232c507002f4 102 wait(5.0f);
javiersing 0:232c507002f4 103 }
javiersing 0:232c507002f4 104 }
javiersing 0:232c507002f4 105
agrosmart 1:7f1e6470cc93 106 /*
agrosmart 1:7f1e6470cc93 107
agrosmart 1:7f1e6470cc93 108
agrosmart 1:7f1e6470cc93 109 Las definiciones de la placa tienen que estar como externas, para poder exportar el ejemplo e integrarlo con otros (algo así como el marlin) hay ejemplos
agrosmart 1:7f1e6470cc93 110 de como se hace
agrosmart 1:7f1e6470cc93 111 */
agrosmart 1:7f1e6470cc93 112 void ReadSensors()
agrosmart 1:7f1e6470cc93 113 {
agrosmart 1:7f1e6470cc93 114 lightLvl = readLightSensor(light,lightref); //Sensor de Luz
agrosmart 1:7f1e6470cc93 115 VWC10HS = Moist10HS(moisture10HS); //Sensor 10HS
agrosmart 1:7f1e6470cc93 116 VWCEC5 = MoistEC5(moistureEC5); //Sensor EC-5
agrosmart 1:7f1e6470cc93 117 tempdht22 = dht22.ReadTemperature(CELCIUS); //Sensor DHT22
agrosmart 1:7f1e6470cc93 118 humdht22 = dht22.ReadHumidity(); //Sensor DHT22
agrosmart 1:7f1e6470cc93 119 centibar = Moist200ss(moisture200ss); //Sensor WaterMark 200ss
agrosmart 1:7f1e6470cc93 120 CWeatherMeters::SMeasurements Measurements; //Weather Station
agrosmart 1:7f1e6470cc93 121 WeatherMeters.GetMeasurements(&Measurements); //Weather Station
agrosmart 1:7f1e6470cc93 122 rainfall = Measurements.Rainfall; //Weather Station
agrosmart 1:7f1e6470cc93 123 windSpeed = Measurements.WindSpeed; //Weather Station
agrosmart 1:7f1e6470cc93 124 maxWindSpeed = Measurements.MaximumWindSpeed; //Weather Station
agrosmart 1:7f1e6470cc93 125 windDir = Measurements.WindDirectionAngle; //Weather Station
agrosmart 2:a13c531579dd 126 ConvT(); // Todos los DS18B20 inician la conversión a temp
agrosmart 2:a13c531579dd 127 wait_ms(750); // Tiempo minimo de conversion a 12-bit
agrosmart 2:a13c531579dd 128 for(int i=1; i<=numROMs; i++) { // Bucle para todos los DS18B20
agrosmart 2:a13c531579dd 129 tempDS18B20 = Get_Temp(i);
agrosmart 2:a13c531579dd 130 pc.printf("DS18B20 Temp: %08.4f Device: %02X%02X%02X%02X%02X%02X %03d\r\n",tempDS18B20,FoundROM[i][6],FoundROM[i][5],FoundROM[i][4],FoundROM[i][3],FoundROM[i][2],FoundROM[i][1],i);
agrosmart 1:7f1e6470cc93 131 }
agrosmart 2:a13c531579dd 132 pc.printf("\r\n");
agrosmart 1:7f1e6470cc93 133 }
agrosmart 1:7f1e6470cc93 134
agrosmart 1:7f1e6470cc93 135 /* CALL char *temphex = temp2Hex(dht22);
agrosmart 1:7f1e6470cc93 136
agrosmart 1:7f1e6470cc93 137
agrosmart 1:7f1e6470cc93 138 */