Arduino - Pasar datos de forma inalámbrica mediante módulo wifi ESP8622

 
Vista:

Pasar datos de forma inalámbrica mediante módulo wifi ESP8622

Publicado por María (2 intervenciones) el 19/10/2019 20:27:20
Buenas, soy nueva en esto del Arduino y me gustaría saber si es posible pasar los datos que leen unos sensores al PC de forma inalámbrica.
Compré el módulo wifi ESP8622 y ahora que me he puesto a programarlo me estoy dando cuenta de que la gente lo usa para otros propósitos.

Gracias de antemano :)
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Pasar datos de forma inalámbrica mediante módulo wifi ESP8622

Publicado por Julio (4 intervenciones) el 19/10/2019 20:53:05
Puedes hacer de todo y mucho más, eso que dices, por supuesto. Pero como lo quieres hacer, ¿wifi?, ¿bluetooth?, ¿infrarojos?, ¿RF?.


Debes de extenderte algo más y poner código, si has hecho algo.....
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Pasar datos de forma inalámbrica mediante módulo wifi ESP8622

Publicado por Maria (2 intervenciones) el 20/10/2019 11:36:35
Pues mira he hecho este codigo pero no llega a conectarse al modulo wifi ESP8266... mi idea era sustituir el cable que va del arduino al ordena por este módulo wifi.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
// Including the ESP8266 WiFi library
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <ErriezBH1750.h>
 
 
// Replace with your network details
const char* ssid = "MOVISTAR CASA";
const char* password = "wificasa";
 
// Web Server on port 80
WiFiServer server(80);
 
// ADDR line LOW/open:  I2C address 0x23 (0x46 including R/W bit) [default]
// ADDR line HIGH:      I2C address 0x5C (0xB8 including R/W bit)
//for every sensor we want to use, we need to create a different instance
BH1750 bh1750_0(LOW);
BH1750 bh1750_1(LOW);
BH1750 bh1750_2(LOW);
BH1750 bh1750_3(LOW);
BH1750 bh1750_4(LOW);
 
int delay1 = 50;
int delay2 = 100;
 
#define tcs3200_0_S0 9
#define tcs3200_0_S1 10
#define tcs3200_0_S2 11
#define tcs3200_0_S3 12
#define tcs3200_0_Out 13
 
#define tcs3200_1_S0 22
#define tcs3200_1_S1 23
#define tcs3200_1_S2 24
#define tcs3200_1_S3 25
#define tcs3200_1_Out 26
 
#define tcs3200_2_S0 27
#define tcs3200_2_S1 28
#define tcs3200_2_S2 29
#define tcs3200_2_S3 30
#define tcs3200_2_Out 31
 
#define tcs3200_3_S0 32
#define tcs3200_3_S1 33
#define tcs3200_3_S2 34
#define tcs3200_3_S3 35
#define tcs3200_3_Out 36
 
#define tcs3200_4_S0 37
#define tcs3200_4_S1 38
#define tcs3200_4_S2 39
#define tcs3200_4_S3 40
#define tcs3200_4_Out 41
 
// Stores frequency read by the photodiodes
int redFrequency0 = 0;
int greenFrequency0 = 0;
int blueFrequency0 = 0;
 
int redFrequency1 = 0;
int greenFrequency1 = 0;
int blueFrequency1 = 0;
 
int redFrequency2 = 0;
int greenFrequency2 = 0;
int blueFrequency2 = 0;
 
int redFrequency3 = 0;
int greenFrequency3 = 0;
int blueFrequency3 = 0;
 
int redFrequency4 = 0;
int greenFrequency4 = 0;
int blueFrequency4 = 0;
 
 
#define TCAADDR 0x70
void tcaselect(uint8_t i) {
  if (i > 4) return;
 
  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();
 
}
// only runs once on boot
void setup() {
 
   // Setting the outputs
  pinMode(tcs3200_0_S0, OUTPUT);
  pinMode(tcs3200_0_S1, OUTPUT);
  pinMode(tcs3200_0_S2, OUTPUT);
  pinMode(tcs3200_0_S3, OUTPUT);
 
  pinMode(tcs3200_1_S0, OUTPUT);
  pinMode(tcs3200_1_S1, OUTPUT);
  pinMode(tcs3200_1_S2, OUTPUT);
  pinMode(tcs3200_1_S3, OUTPUT);
 
  pinMode(tcs3200_2_S0, OUTPUT);
  pinMode(tcs3200_2_S1, OUTPUT);
  pinMode(tcs3200_2_S2, OUTPUT);
  pinMode(tcs3200_2_S3, OUTPUT);
 
  pinMode(tcs3200_3_S0, OUTPUT);
  pinMode(tcs3200_3_S1, OUTPUT);
  pinMode(tcs3200_3_S2, OUTPUT);
  pinMode(tcs3200_3_S3, OUTPUT);
 
  pinMode(tcs3200_4_S0, OUTPUT);
  pinMode(tcs3200_4_S1, OUTPUT);
  pinMode(tcs3200_4_S2, OUTPUT);
  pinMode(tcs3200_4_S3, OUTPUT);
 
  // Setting the sensorOut as an input
  pinMode(tcs3200_0_Out, INPUT);
  pinMode(tcs3200_1_Out, INPUT);
  pinMode(tcs3200_2_Out, INPUT);
  pinMode(tcs3200_3_Out, INPUT);
  pinMode(tcs3200_4_Out, INPUT);
 
  // Setting frequency scaling to 20%
  digitalWrite(tcs3200_0_S0,HIGH);
  digitalWrite(tcs3200_0_S1,LOW);
  digitalWrite(tcs3200_1_S0,HIGH);
  digitalWrite(tcs3200_1_S1,LOW);
  digitalWrite(tcs3200_2_S0,HIGH);
  digitalWrite(tcs3200_2_S1,LOW);
  digitalWrite(tcs3200_3_S0,HIGH);
  digitalWrite(tcs3200_3_S1,LOW);
  digitalWrite(tcs3200_4_S0,HIGH);
  digitalWrite(tcs3200_4_S1,LOW);
 
  // Initializing serial port for debugging purposes
  Serial.begin(115200);
 
    // Connecting to WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
   Wire.begin();
 
  Serial.println(F("##############################"));
  Serial.println(F("Starting Sensor Initialization"));
  Serial.println(F("##############################"));
 //**********************************************************************
//*************INITIALIZING FIRST SENSOR*******************************   
  tcaselect(0);
  bh1750_0.begin(ModeContinuous, ResolutionHigh);
   bh1750_0.startConversion();
 
     //**********************************************************************
//*************INITIALIZING SECOND SENSOR*******************************   
  tcaselect(1);
  bh1750_1.begin(ModeContinuous, ResolutionHigh);
   bh1750_1.startConversion();
  //**********************************************************************
//*************INITIALIZING THIRD SENSOR*******************************   
  tcaselect(2);
  bh1750_2.begin(ModeContinuous, ResolutionHigh);
   bh1750_2.startConversion();
 
     //**********************************************************************
//*************INITIALIZING FOURTH SENSOR*******************************   
  tcaselect(3);
  bh1750_3.begin(ModeContinuous, ResolutionHigh);
   bh1750_3.startConversion();
   //**********************************************************************
//*************INITIALIZING FIFTH SENSOR*******************************   
  tcaselect(4);
  bh1750_4.begin(ModeContinuous, ResolutionHigh);
   bh1750_4.startConversion();
 
  //**********************************************************************
  //**********************************************************************  
  Serial.println();
  Serial.println(F("##############################"));            //30-times #
  Serial.println(F("Sensor nitialization Finished"));
  Serial.println(F("##############################"));            //30-times # 
  Serial.println();
  Serial.println();
  delay(10);
 
 
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Starting the web server
  server.begin();
  Serial.println("Web server running. Waiting for the ESP IP...");
  delay(10000);
 
  // Printing the ESP IP address
  Serial.println(WiFi.localIP());
}
 
// runs over and over again
void loop() {
  // Listenning for new clients
  WiFiClient client = server.available();
 
  if (client) {
    Serial.println("New client");
    // bolean to locate when the http request ends
    boolean blank_line = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
 
 
  uint16_t lux;
 // delay(1000);
   //**************FIRST SENSOR*****************************************//
   tcaselect(0);
    if (bh1750_0.isConversionCompleted()) {
        // Read light
        lux = bh1750_0.read();
 
   Serial.print(F("bh1750_0 Duration[s]=\t"));
   Serial.print(float(millis())/1000);
   Serial.print("\t");
   Serial.print(F("Light: "));
   Serial.print(lux / 2);
        Serial.print(F("."));
        Serial.print(lux % 10);
        Serial.println(F(" LUX"));
 
    }
    // Setting RED (R) filtered photodiodes to be read
  digitalWrite(tcs3200_0_S2,LOW);
  digitalWrite(tcs3200_0_S3,LOW);
 
  // Reading the output frequency
  redFrequency0 = pulseIn(tcs3200_0_Out, LOW);
 
  //printing time value
   Serial.print(F("TCS3200_0 Duration[s]=\t"));
   Serial.print(float(millis())/1000);
   Serial.print("\t");
 
   // Printing the RED (R) value
  Serial.print("Red = ");
  Serial.print(redFrequency0);
  delay(delay1);
 
  // Setting GREEN (G) filtered photodiodes to be read
  digitalWrite(tcs3200_0_S2,HIGH);
  digitalWrite(tcs3200_0_S3,HIGH);
 
  // Reading the output frequency
  greenFrequency0 = pulseIn(tcs3200_0_Out, LOW);
 
  // Printing the GREEN (G) value  
  Serial.print(" Green = ");
  Serial.print(greenFrequency0);
  delay(delay1);
 
  // Setting BLUE (B) filtered photodiodes to be read
  digitalWrite(tcs3200_0_S2,LOW);
  digitalWrite(tcs3200_0_S3,HIGH);
 
  // Reading the output frequency
  blueFrequency0 = pulseIn(tcs3200_0_Out, LOW);
 
  // Printing the BLUE (B) value 
  Serial.print(" Blue = ");
  Serial.println(blueFrequency0);
  delay(delay1);
 
   Serial.println();
 
  //**************SECOND SENSOR*****************************************//
     tcaselect(1);
    if (bh1750_1.isConversionCompleted()) {
        // Read light 
        lux = bh1750_1.read();
 
   Serial.print(F("bh1750_1 Duration[s]=\t"));
   Serial.print(float(millis())/1000);
   Serial.print("\t");
   Serial.print(F("Light: "));
   Serial.print(lux / 2);
        Serial.print(F("."));
        Serial.print(lux % 10);
        Serial.println(F(" LUX"));
 
    }
 
   // Setting RED (R) filtered photodiodes to be read
  digitalWrite(tcs3200_1_S2,LOW);
  digitalWrite(tcs3200_1_S3,LOW);
 
  // Reading the output frequency
  redFrequency1 = pulseIn(tcs3200_1_Out, LOW);
 
  //printing time value
   Serial.print(F("TCS3200_1 Duration[s]=\t"));
   Serial.print(float(millis())/1000);
   Serial.print("\t");
 
   // Printing the RED (R) value
  Serial.print("Red = ");
  Serial.print(redFrequency1);
  delay(delay1);
 
  // Setting GREEN (G) filtered photodiodes to be read
  digitalWrite(tcs3200_1_S2,HIGH);
  digitalWrite(tcs3200_1_S3,HIGH);
 
  // Reading the output frequency
  greenFrequency1 = pulseIn(tcs3200_1_Out, LOW);
 
  // Printing the GREEN (G) value  
  Serial.print(" Green = ");
  Serial.print(greenFrequency1);
  delay(delay1);
 
  // Setting BLUE (B) filtered photodiodes to be read
  digitalWrite(tcs3200_1_S2,LOW);
  digitalWrite(tcs3200_1_S3,HIGH);
 
  // Reading the output frequency
  blueFrequency1 = pulseIn(tcs3200_1_Out, LOW);
 
  // Printing the BLUE (B) value 
  Serial.print(" Blue = ");
  Serial.println(blueFrequency1);
  delay(delay1);
 
   Serial.println();
      //**************THIRD SENSOR*****************************************//
 
     tcaselect(2);
    if (bh1750_2.isConversionCompleted()) {
        // Read light
        lux = bh1750_2.read();
 
   Serial.print(F("bh1750_2 Duration[s]=\t"));
   Serial.print(float(millis())/1000);
   Serial.print("\t");
   Serial.print(F("Light: "));
   Serial.print(lux / 2);
        Serial.print(F("."));
        Serial.print(lux % 10);
        Serial.println(F(" LUX"));
 
    }
     // Setting RED (R) filtered photodiodes to be read
  digitalWrite(tcs3200_2_S2,LOW);
  digitalWrite(tcs3200_2_S3,LOW);
 
  // Reading the output frequency
  redFrequency2 = pulseIn(tcs3200_2_Out, LOW);
 
  //printing time value
   Serial.print(F("TCS3200_2 Duration[s]=\t"));
   Serial.print(float(millis())/1000);
   Serial.print("\t");
 
   // Printing the RED (R) value
  Serial.print("Red = ");
  Serial.print(redFrequency2);
  delay(delay1);
 
  // Setting GREEN (G) filtered photodiodes to be read
  digitalWrite(tcs3200_2_S2,HIGH);
  digitalWrite(tcs3200_2_S3,HIGH);
 
  // Reading the output frequency
  greenFrequency2 = pulseIn(tcs3200_2_Out, LOW);
 
  // Printing the GREEN (G) value  
  Serial.print(" Green = ");
  Serial.print(greenFrequency2);
  delay(delay1);
 
  // Setting BLUE (B) filtered photodiodes to be read
  digitalWrite(tcs3200_2_S2,LOW);
  digitalWrite(tcs3200_2_S3,HIGH);
 
  // Reading the output frequency
  blueFrequency2 = pulseIn(tcs3200_2_Out, LOW);
 
  // Printing the BLUE (B) value 
  Serial.print(" Blue = ");
  Serial.println(blueFrequency2);
  delay(delay1);
 
   Serial.println();
 
        //**************FOURTH SENSOR*****************************************//
 
     tcaselect(3);
    if (bh1750_3.isConversionCompleted()) {
        // Read light
        lux = bh1750_3.read();
 
   Serial.print(F("bh1750_3 Duration[s]=\t"));
   Serial.print(float(millis())/1000);
   Serial.print("\t");
   Serial.print(F("Light: "));
   Serial.print(lux / 2);
        Serial.print(F("."));
        Serial.print(lux % 10);
        Serial.println(F(" LUX"));
 
    }
 
      // Setting RED (R) filtered photodiodes to be read
  digitalWrite(tcs3200_3_S2,LOW);
  digitalWrite(tcs3200_3_S3,LOW);
 
  // Reading the output frequency
  redFrequency3 = pulseIn(tcs3200_3_Out, LOW);
 
  //printing time value
   Serial.print(F("TCS3200_3 Duration[s]=\t"));
   Serial.print(float(millis())/1000);
   Serial.print("\t");
 
   // Printing the RED (R) value
  Serial.print("Red = ");
  Serial.print(redFrequency3);
  delay(delay1);
 
  // Setting GREEN (G) filtered photodiodes to be read
  digitalWrite(tcs3200_3_S2,HIGH);
  digitalWrite(tcs3200_3_S3,HIGH);
 
  // Reading the output frequency
  greenFrequency3 = pulseIn(tcs3200_3_Out, LOW);
 
  // Printing the GREEN (G) value  
  Serial.print(" Green = ");
  Serial.print(greenFrequency3);
  delay(delay1);
 
  // Setting BLUE (B) filtered photodiodes to be read
  digitalWrite(tcs3200_3_S2,LOW);
  digitalWrite(tcs3200_3_S3,HIGH);
 
  // Reading the output frequency
  blueFrequency3 = pulseIn(tcs3200_3_Out, LOW);
 
  // Printing the BLUE (B) value 
  Serial.print(" Blue = ");
  Serial.println(blueFrequency3);
  delay(delay1);
 
   Serial.println();
      //**************FIFTH SENSOR*****************************************//
 
     tcaselect(4);
    if (bh1750_4.isConversionCompleted()) {
        // Read light
        lux = bh1750_4.read();
 
   Serial.print(F("bh1750_4 Duration [s]=\t"));
   Serial.print(float(millis())/1000);
   Serial.print("\t");
   Serial.print(F("Light: "));
   Serial.print(lux / 2);
        Serial.print(F("."));
        Serial.print(lux % 10);
        Serial.println(F(" LUX"));
 
    }
 
   // Setting RED (R) filtered photodiodes to be read
  digitalWrite(tcs3200_4_S2,LOW);
  digitalWrite(tcs3200_4_S3,LOW);
 
  // Reading the output frequency
  redFrequency4 = pulseIn(tcs3200_4_Out, LOW);
 
  //printing time value
   Serial.print(F("TCS3200_4 Duration[s]=\t"));
   Serial.print(float(millis())/1000);
   Serial.print("\t");
 
   // Printing the RED (R) value
  Serial.print("Red = ");
  Serial.print(redFrequency4);
  delay(delay1);
 
  // Setting GREEN (G) filtered photodiodes to be read
  digitalWrite(tcs3200_4_S2,HIGH);
  digitalWrite(tcs3200_4_S3,HIGH);
 
  // Reading the output frequency
  greenFrequency4 = pulseIn(tcs3200_4_Out, LOW);
 
  // Printing the GREEN (G) value  
  Serial.print(" Green = ");
  Serial.print(greenFrequency4);
  delay(delay1);
 
  // Setting BLUE (B) filtered photodiodes to be read
  digitalWrite(tcs3200_4_S2,LOW);
  digitalWrite(tcs3200_4_S3,HIGH);
 
  // Reading the output frequency
  blueFrequency4 = pulseIn(tcs3200_4_Out, LOW);
 
  // Printing the BLUE (B) value 
  Serial.print(" Blue = ");
  Serial.println(blueFrequency4);
  delay(delay1);
 
   Serial.println();
   Serial.println();
 
   delay(100);
            }
      }
    }
    // closing the client connection
    delay(1);
    client.stop();
    Serial.println("Client disconnected.");
  }
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar