informatica:arduino:invernadero
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| informatica:arduino:invernadero [2021/02/03 20:46] – [Arduino] jose | informatica:arduino:invernadero [2021/02/09 11:10] (current) – jose | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| Arduino Mega y raspberry 4 | Arduino Mega y raspberry 4 | ||
| - | ===== Arduino ===== | + | ====== Arduino |
| Sensor de temperatura digital DHT11 | Sensor de temperatura digital DHT11 | ||
| Line 132: | Line 132: | ||
| | Cable Blanco (NV) | SIN CONEXIÓN | | | Cable Blanco (NV) | SIN CONEXIÓN | | ||
| | Cable Amarillo (SIG) | PIN 2 | | | Cable Amarillo (SIG) | PIN 2 | | ||
| + | |||
| + | En Tools > Board seleccionamos: | ||
| + | Arduino Mega 2560 | ||
| + | Seleccionamos también Tools > Serial Port | ||
| + | |||
| + | Pulsamos el botón de compilar y el de upload. | ||
| + | |||
| + | Si va bien, abrimos la ventana para ver los resultados, Tools > Serial Monitor (o Ctrl+Shit+M) | ||
| + | |||
| + | Nos tiene que salir algo así: | ||
| + | Temperature: | ||
| + | Humidity: 36.00% | ||
| | | ||
| + | Modifico el script para que tenga una salida en una línea del tipo: | ||
| + | |||
| + | 36.00 22.00 | ||
| + | |||
| + | Código de Arduino | ||
| + | < | ||
| + | #include " | ||
| + | |||
| + | #define DHTPIN 2 // what digital pin we're connected to | ||
| + | |||
| + | #define DHTTYPE DHT11 // DHT 11 | ||
| + | DHT dht(DHTPIN, DHTTYPE); | ||
| + | |||
| + | void setup() { | ||
| + | Serial.begin(9600); | ||
| + | dht.begin(); | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | delay(2000); | ||
| + | |||
| + | // Reading temperature or humidity takes about 250 milliseconds! | ||
| + | // Sensor readings may also be up to 2 seconds ' | ||
| + | float h = dht.readHumidity(); | ||
| + | // Read temperature as Celsius (the default) | ||
| + | float t = dht.readTemperature(); | ||
| + | // Read temperature as Fahrenheit (isFahrenheit = true) | ||
| + | float f = dht.readTemperature(true); | ||
| + | |||
| + | // Check if any reads failed and exit early (to try again). | ||
| + | if (isnan(h) || isnan(t) || isnan(f)) { | ||
| + | Serial.println(" | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | // Compute heat index in Fahrenheit (the default) | ||
| + | float hif = dht.computeHeatIndex(f, | ||
| + | // Compute heat index in Celsius (isFahreheit = false) | ||
| + | float hic = dht.computeHeatIndex(t, | ||
| + | |||
| + | Serial.print(h); | ||
| + | Serial.print(" | ||
| + | Serial.println(t); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Conecto arduino a la raspberry por usb y le pongo este código. Escribe en el fichero lecturas.txt una línea con la fecha, humedad y temperatura: | ||
| + | 03/02/2021 23:30:04 43.00 13.00 | ||
| + | |||
| + | Código de fichero leer.py | ||
| + | < | ||
| + | import serial | ||
| + | import time | ||
| + | from time import localtime, strftime | ||
| + | |||
| + | ser = serial.Serial('/ | ||
| + | |||
| + | f = open(" | ||
| + | x=ser.readline().split() | ||
| + | print x[0] | ||
| + | print x[1] | ||
| + | f.write(strftime(" | ||
| + | f.write(x[0]) | ||
| + | f.write(" | ||
| + | f.write(x[1]) | ||
| + | f.write(" | ||
| + | f.close() | ||
| + | </ | ||
| + | |||
| + | Pongo en el crontab: | ||
| + | */10 * * * * python / | ||
| + | |||
| + | ===== Sensor humedad tierra ===== | ||
| + | Sensor YL-38 y YL-69 | ||
| + | |||
| + | https:// | ||
| + | |||
| + | Dimensiones YL-38: 30 x 16 mm | ||
| + | Dimensiones YL-69: 60 x 30 mm | ||
| + | |||
| + | Leémos el pin analógico y normalizamos el valor de 0-1024 a 0-100 | ||
| + | |||
| + | < | ||
| + | void setup() { | ||
| + | // initialize serial communication at 9600 bits per second: | ||
| + | Serial.begin(9600); | ||
| + | } | ||
| + | |||
| + | |||
| + | void loop() { | ||
| + | // read the input on analog pin 0: | ||
| + | int sensorValue = analogRead(A0); | ||
| + | int humedad = map(sensorValue, | ||
| | | ||
| + | Serial.println(humedad); | ||
| + | delay(5000); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Cámara ===== | ||
| + | Con la integrada: | ||
| + | |||
| + | Tomar foto | ||
| + | raspistill -o foto.jpg | ||
| + | Grabar vídeo | ||
| + | raspivid -o Desktop/ | ||
| + | | ||
| + | ==== Camara HP por USB: ==== | ||
| + | |||
| + | |||
| + | La cámara HP es 1280x720. -i es input, 0 es / | ||
| + | fswebcam -i 0 -r 1280x720 --jpeg 85 -D 1 fswebcam.jpg | ||
| + | |||
| + | Para la cámara genérica he instalado guvcview y reiniciado. La resolución es de 640x480 | ||
| + | |||
| + | ==== Cámara amazon ==== | ||
| + | streamer -f jpeg -o nueva_streamer_01.jpeg | ||
| + | Resolución 1280x960 | ||
| + | |||
| + | ===== Orange PI ===== | ||
| + | Hacemos nmap | ||
| + | Nmap scan report for OrangePi.home (192.168.1.133) | ||
| + | Host is up (0.0048s latency). | ||
| + | MAC Address: 02: | ||
| + | |||
| + | Usuario: root/ | ||
| + | |||
| + | Configuración wifi. Añadimos este fichero y reiniciamos: | ||
| + | / | ||
| + | < | ||
| + | auto wlan0 | ||
| + | iface wlan0 inet dhcp | ||
| + | wpa-ssid <mi red wifi> | ||
| + | wpa-psk ************ | ||
| + | </ | ||
| + | |||
| + | ==== Camara USB HP ==== | ||
| + | lsusb | ||
| + | |||
| + | Bus 003 Device 002: ID 03f0:a707 HP, Inc | ||
| + | |||
| + | Funciona en la raspberry | ||
| + | fswebcam -r 1280x720 --jpeg 85 -D 1 fswebcam.jpg | ||
| + | streamer -f jpeg -o image.jpeg | ||
| + | |||
| + | ====== Grafana ====== | ||
| + | Creamos BBDD en influx | ||
| + | curl -i -XPOST http:// | ||
| + | |||
| + | Si quisieramos borar la BBDD: | ||
| + | curl -i -XPOST http:// | ||
| + | |||
| + | Para meter datos: | ||
| + | curl -i -XPOST ' | ||
| + | |||
| + | El fichero todos.txt tiene este formato: | ||
| + | < | ||
| + | invernadero, | ||
| + | invernadero, | ||
| + | invernadero, | ||
| + | invernadero, | ||
| + | invernadero, | ||
| + | invernadero, | ||
| + | invernadero, | ||
| + | invernadero, | ||
| + | </ | ||
| + | |||
| + | Podemos consultarlos: | ||
| + | curl -i -XPOST http:// | ||
| + | |||
| + | La gráfica la creamos así. Para que se rellene tenemos que poner en GROUP BY fill(linear) | ||
| + | {{: | ||
informatica/arduino/invernadero.1612385177.txt.gz · Last modified: by jose
