-

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

Fork of testgeneral by Javier Sing

Committer:
agrosmart
Date:
Wed Dec 14 09:49:17 2016 +0000
Revision:
1:7f1e6470cc93
Parent:
0:232c507002f4
Child:
2:a13c531579dd
_

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"
javiersing 0:232c507002f4 11
javiersing 0:232c507002f4 12
javiersing 0:232c507002f4 13 //Declaración de Puertos para cada sensor
javiersing 0:232c507002f4 14 AnalogIn moisture10HS(A0); //Decagon 10HS en el A0
javiersing 0:232c507002f4 15 AnalogIn light(A1); //ALS-PT19LIGHT en el A1
javiersing 0:232c507002f4 16 AnalogIn moistureEC5(A2); //Decagon EC-5 en el A2
javiersing 0:232c507002f4 17 AnalogIn lightref(A3); //Referencia 3.3V en el A3
javiersing 0:232c507002f4 18 AnalogIn moisture200ss(A4); //WaterMark200ss en el A4
javiersing 0:232c507002f4 19
javiersing 0:232c507002f4 20 /*El sensor DS18B20 se
javiersing 0:232c507002f4 21 define el pin en la
javiersing 0:232c507002f4 22 librería DHT*/ //Ds18B20 en el D2
javiersing 0:232c507002f4 23 DHT dht22(PB_3,DHT22); //DHT22 en el D3
javiersing 0:232c507002f4 24 CWeatherMeters WeatherMeters(D4, D5, A5); //Weather Station Anemómetro D4, Veleta D5, Pluviómetro A5
javiersing 0:232c507002f4 25
agrosmart 1:7f1e6470cc93 26 //Declaración variables para sensores:
agrosmart 1:7f1e6470cc93 27 float lightLvl = 0; // Sensor LUZ //Rango: 0.0 a 3.3 //2
agrosmart 1:7f1e6470cc93 28 float VWC10HS = 0; // Sensor 10HS //Rango: 0.0 a 3.4 //2
agrosmart 1:7f1e6470cc93 29 float VWCEC5 = 0; // Sensor EC-5 //Rango: 0.0 a 4 //2
agrosmart 1:7f1e6470cc93 30 float tempdht22 = 0; // Sensor DHT22 //Rango: -40.0 a 80 //4
agrosmart 1:7f1e6470cc93 31 float humdht22 = 0; // Sensor DHT22 //Rango: 0 a 100% //2
agrosmart 1:7f1e6470cc93 32 float tempDS18B20 = 0; // Sensor DS18B20 //Rango: -55.0 a 125.0 //3
agrosmart 1:7f1e6470cc93 33 float centibar = 0; // Sensor WaterMark 200ss //Rango: 0 a 240 //2
agrosmart 1:7f1e6470cc93 34 float rainfall = 0; // Weather Station //Rango: 0 a 100 //3
agrosmart 1:7f1e6470cc93 35 float windSpeed = 0; // Weather Station //Rango: 0 a 2000 //3
agrosmart 1:7f1e6470cc93 36 float maxWindSpeed = 0; // Weather Station //Rango: 0 a 2000 //3
agrosmart 1:7f1e6470cc93 37 float windDir = 0; // Weather Station //Rango: 0 a 337.5 //3
agrosmart 1:7f1e6470cc93 38 float value;
javiersing 0:232c507002f4 39
agrosmart 1:7f1e6470cc93 40 void ReadSensors();
javiersing 0:232c507002f4 41
javiersing 0:232c507002f4 42 int main()
javiersing 0:232c507002f4 43 {
javiersing 0:232c507002f4 44 pc.baud(115200);
javiersing 0:232c507002f4 45 DQ.output();
javiersing 0:232c507002f4 46 DQ = 0;
javiersing 0:232c507002f4 47 DQ.input();
javiersing 0:232c507002f4 48 pc.printf("All Sensors Test \r\n");
javiersing 0:232c507002f4 49 pc.printf("Memory allocated for %d DS18B20.\r\n",MaxROMs);
javiersing 0:232c507002f4 50 pc.printf("Scanning for devices...\r\n");
javiersing 0:232c507002f4 51 ow_reset();
javiersing 0:232c507002f4 52 FindDevices();
javiersing 0:232c507002f4 53 pc.printf("Scanning completed.\r\n");
javiersing 0:232c507002f4 54
javiersing 0:232c507002f4 55
javiersing 0:232c507002f4 56 while(1) {
javiersing 0:232c507002f4 57 //Leer Sensores
javiersing 0:232c507002f4 58 wait(1);
agrosmart 1:7f1e6470cc93 59 ReadSensors(); //No hace lectura de la Temperatura con la ds18b20??
agrosmart 1:7f1e6470cc93 60 pc.printf("Direction: %s\n",windDir);
javiersing 0:232c507002f4 61 pc.printf("Depth: %f\n",rainfall);
javiersing 0:232c507002f4 62 pc.printf("Current speed: %f\n", windSpeed);
javiersing 0:232c507002f4 63 pc.printf("Maximum speed: %f\n", maxWindSpeed);
javiersing 0:232c507002f4 64 pc.printf("200ss Centibar: %2.2f\n", centibar);
javiersing 0:232c507002f4 65 pc.printf("DHT22 Humidity: %.1f \n\r",humdht22);
javiersing 0:232c507002f4 66 pc.printf("DHT22 Temp: %.1f C",tempdht22);
javiersing 0:232c507002f4 67 pc.printf("EC-5 VWC: %2.2f VMC\r\n", VWCEC5);
javiersing 0:232c507002f4 68 pc.printf("10HS VWC: %2.2f\r\n", VWC10HS);
javiersing 0:232c507002f4 69 pc.printf("Light: %3.2f \r\n", lightLvl);
javiersing 0:232c507002f4 70 ConvT(); // Todos los DS18B20 inician la conversión a temp
javiersing 0:232c507002f4 71 wait_ms(750); // Tiempo minimo de conversion a 12-bit
javiersing 0:232c507002f4 72 for(int i=1; i<=numROMs; i++) { // Bucle para todos los DS18B20
javiersing 0:232c507002f4 73 tempDS18B20 = Get_Temp(i);
javiersing 0:232c507002f4 74 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);
javiersing 0:232c507002f4 75 }
javiersing 0:232c507002f4 76 pc.printf("\r\n");
javiersing 0:232c507002f4 77 wait(5.0f);
javiersing 0:232c507002f4 78 }
javiersing 0:232c507002f4 79 }
javiersing 0:232c507002f4 80
agrosmart 1:7f1e6470cc93 81 /*
agrosmart 1:7f1e6470cc93 82 Hay que organizar con funciones, una para petición de datos, otra para cambiarlos a HEX todo
agrosmart 1:7f1e6470cc93 83
agrosmart 1:7f1e6470cc93 84 Hay que definir los datos en HEX, para que ocupen lo menos posibles, la temperatura x2 y a hex, y cosas así, para ocupar los menores bytes posibles uniendo
agrosmart 1:7f1e6470cc93 85 todos y generando un buffer de envío
agrosmart 1:7f1e6470cc93 86
agrosmart 1:7f1e6470cc93 87 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 88 de como se hace
agrosmart 1:7f1e6470cc93 89 */
agrosmart 1:7f1e6470cc93 90 void ReadSensors()
agrosmart 1:7f1e6470cc93 91 {
agrosmart 1:7f1e6470cc93 92 lightLvl = readLightSensor(light,lightref); //Sensor de Luz
agrosmart 1:7f1e6470cc93 93 VWC10HS = Moist10HS(moisture10HS); //Sensor 10HS
agrosmart 1:7f1e6470cc93 94 VWCEC5 = MoistEC5(moistureEC5); //Sensor EC-5
agrosmart 1:7f1e6470cc93 95 tempdht22 = dht22.ReadTemperature(CELCIUS); //Sensor DHT22
agrosmart 1:7f1e6470cc93 96 humdht22 = dht22.ReadHumidity(); //Sensor DHT22
agrosmart 1:7f1e6470cc93 97 centibar = Moist200ss(moisture200ss); //Sensor WaterMark 200ss
agrosmart 1:7f1e6470cc93 98 CWeatherMeters::SMeasurements Measurements; //Weather Station
agrosmart 1:7f1e6470cc93 99 WeatherMeters.GetMeasurements(&Measurements); //Weather Station
agrosmart 1:7f1e6470cc93 100 rainfall = Measurements.Rainfall; //Weather Station
agrosmart 1:7f1e6470cc93 101 windSpeed = Measurements.WindSpeed; //Weather Station
agrosmart 1:7f1e6470cc93 102 maxWindSpeed = Measurements.MaximumWindSpeed; //Weather Station
agrosmart 1:7f1e6470cc93 103 windDir = Measurements.WindDirectionAngle; //Weather Station
agrosmart 1:7f1e6470cc93 104 }
agrosmart 1:7f1e6470cc93 105 char *float2Hex(float value)
agrosmart 1:7f1e6470cc93 106 {
agrosmart 1:7f1e6470cc93 107 int signo; // para las temperaturas
agrosmart 1:7f1e6470cc93 108 int ent1;
agrosmart 1:7f1e6470cc93 109 int dec1;
agrosmart 1:7f1e6470cc93 110 char value2[5];
agrosmart 1:7f1e6470cc93 111
agrosmart 1:7f1e6470cc93 112 if(value<0) {
agrosmart 1:7f1e6470cc93 113 signo = 1; // 1 es negativo, 0 es positivo
agrosmart 1:7f1e6470cc93 114 value = value * -1;
agrosmart 1:7f1e6470cc93 115 } else {
agrosmart 1:7f1e6470cc93 116 signo = 0;
agrosmart 1:7f1e6470cc93 117 }
agrosmart 1:7f1e6470cc93 118 ent1 = value;
agrosmart 1:7f1e6470cc93 119 dec1 = (value - ent1)*16;
agrosmart 1:7f1e6470cc93 120 sprintf(value2, "%.1X.%.2X.%.1X\n\r", signo, ent1,dec1); //solo queda un decimal. para que queden dos decimales hay que multiplicar decimal por 10
agrosmart 1:7f1e6470cc93 121 return value2;
agrosmart 1:7f1e6470cc93 122 }
agrosmart 1:7f1e6470cc93 123
agrosmart 1:7f1e6470cc93 124 /* CALL char *temphex = temp2Hex(dht22);
agrosmart 1:7f1e6470cc93 125
agrosmart 1:7f1e6470cc93 126 FUNCTION
agrosmart 1:7f1e6470cc93 127
agrosmart 1:7f1e6470cc93 128 char * createStr() {
agrosmart 1:7f1e6470cc93 129
agrosmart 1:7f1e6470cc93 130 char char1= 'm';
agrosmart 1:7f1e6470cc93 131 char char2= 'y';
agrosmart 1:7f1e6470cc93 132
agrosmart 1:7f1e6470cc93 133 char *str = (char *) malloc(sizeof(char) * 3);
agrosmart 1:7f1e6470cc93 134 str[0] = char1;
agrosmart 1:7f1e6470cc93 135 str[1] = char2;
agrosmart 1:7f1e6470cc93 136 str[2] = '\0';
agrosmart 1:7f1e6470cc93 137
agrosmart 1:7f1e6470cc93 138 return str;
agrosmart 1:7f1e6470cc93 139
agrosmart 1:7f1e6470cc93 140 }
agrosmart 1:7f1e6470cc93 141 */