User Tools

Site Tools


raspberry_pi:projects:ultrafreezer

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
raspberry_pi:projects:ultrafreezer [2025/02/05 15:20] jmbargalloraspberry_pi:projects:ultrafreezer [2025/02/19 08:48] (current) 195.53.121.100
Line 1: Line 1:
-===== Sistema de control de temperatures del congelador de -80 (raspi)=====+===== Freezer Temperature Control System (-80) using Raspberry Pi =====
  
-==== Hardware====+==== Hardware ====
  
-Per adaptar el sensor tipus PT100 es pot utilitzar el MAX31855 que pot utilitzar SPI per comunicar amb la Raspberry Pi. +To adapt the PT100 sensor, the MAX31855 can be used, which communicates with the Raspberry Pi via SPI  
-Es pot utilitzar tan el software SPI a qualsevol dels pins GPIO o es pot fer per hardware SPI. +Both software SPI (using any GPIO pins) and hardware SPI are options  
-Si no es segur de quina opcio utilitzar es preferible utilitzar software SPI  ja que es mes flexible i la velocitat no es critica utilitzant el MAX31855.+If unsure, it is preferable to use software SPI due to its flexibility, as speed is not critical when using the MAX31855.
  
-==== Hardware per utilitzar Software SPI====+==== Hardware Setup for Software SPI ====
  
-Per utiltzar software SPI a la Raspberry Pi connectar el MAX31855 a la Raspberry Pi com es veu a la figuraEs poden utilitzar +To use software SPI, connect the MAX31855 to the Raspberry Pi as shown in the figure  
-3 digital IO pins qualsevol per CLK, CS, DO.+Any three GPIO pins can be used for CLK, CS, and DO.
  
 {{:sistema_control_de_temperatures_ultracongelador_-80c:max31855.jpg?400|}} {{:sistema_control_de_temperatures_ultracongelador_-80c:max31855.jpg?400|}}
  
-  - Connectar Pi 3.3V MAX31855 Vin. +  - Connect Pi 3.3V to MAX31855 Vin. 
-  - Connectar Pi GND MAX31855 GND. +  - Connect Pi GND to MAX31855 GND. 
-  - Connectar Pi GPIO 18 MAX31855 DO. +  - Connect Pi GPIO 18 to MAX31855 DO. 
-  - Connectar Pi GPIO 24 MAX31855 CS. +  - Connect Pi GPIO 24 to MAX31855 CS. 
-  - Connectar Pi GPIO 25 MAX31855 CLK+  - Connect Pi GPIO 25 to MAX31855 CLK.
  
 {{ :raspberry_pi:projects:max31855.jpg?600 |}} {{ :raspberry_pi:projects:max31855.jpg?600 |}}
-==== Software==== 
  
-=== Dependencies===+==== Software ====
  
-Primer executar les dependencies escribint al terminal:+=== Dependencies ===
  
-<code bash>sudo apt-get update +First, install the required dependencies by running the following commands:
-sudo apt-get install build-essential python-dev python-pip python-smbus git</code>+
  
-=== RPi.GPIO library===+<code bash> 
 +sudo apt-get update 
 +sudo apt-get install build-essential python-dev python-pip python-smbus git 
 +</code>
  
-Per estar segur de que les llibreries GPIO estan instalades escriure a terminal:+=== RPi.GPIO Library ===
  
-<code bash>sudo pip install RPi.GPIO</code>+Ensure that the GPIO libraries are installed by running: 
 + 
 +<code bash> 
 +sudo pip install RPi.GPIO 
 +</code>
  
-=== Library MAX31855===+=== MAX31855 Library ===
  
-Descarregar la llibreria Python del MAX31855 Python al home directory executant:+Download the MAX31855 Python library to the home directory by running:
  
 <code bash> <code bash>
Line 47: Line 52:
 </code> </code>
  
-=== Configuracio i prova===+=== Configuration and Testing ===
  
-Per configurar i provar el hardware/softwareTo es pot utilitzar els programes incloisos en el directori examples  i obrir  el programa simpletest.py script en un editor +To configure and test the hardware/software setup, use the example programs included in the `examples` directory and open the `simpletest.pyscript:
-<code bash> +
-sudo nano simpletest.py </code>+
  
-Baixant pantalla es poden veure comentades les diverses opcions de configuracio, cal descomentar les que es facin servir: 
 <code bash> <code bash>
 +sudo nano simpletest.py
 +</code>
 +
 +Scroll down to find the configuration options and uncomment the relevant block for your setup:
 +
 +<code python>
 # Uncomment one of the blocks of code below to configure your Pi or BBB to use # Uncomment one of the blocks of code below to configure your Pi or BBB to use
 # software or hardware SPI. # software or hardware SPI.
 +
 # Raspberry Pi software SPI configuration. # Raspberry Pi software SPI configuration.
 CLK = 25 CLK = 25
Line 62: Line 71:
 DO = 18 DO = 18
 sensor = MAX31855.MAX31855(CLK, CS, DO) sensor = MAX31855.MAX31855(CLK, CS, DO)
-# Raspberry Pi hardware SPI configuration. 
-#SPI_PORT = 0 
-#SPI_DEVICE = 0 
-#sensor = MAX31855.MAX31855(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=5000000)) 
-# BeagleBone Black software SPI configuration. 
-#CLK = 'P9_12' 
-#CS = 'P9_15' 
-#DO = 'P9_23' 
-#sensor = MAX31855.MAX31855(CLK, CS, DO) 
-# BeagleBone Black hardware SPI configuration. 
-#SPI_PORT = 1 
-#SPI_DEVICE = 0 
-#sensor = MAX31855.MAX31855(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=5000000)) 
- 
- 
 </code> </code>
  
-En el nostre cas fem servir les opcions Software SPI amb la asignacio de pins que hem muntat fisicament a: +Make sure the uncommented configuration matches your physical wiring.   
- +Save and exit the text editorthen test the setup by running:
- +
-Per defecte la configuracio per fer servir Raspberry Pi amb software SPI esta no comentadasi s´han fet canvis o s´han conectat altres pins es precis modificar la configuracio en consecuencia. +
- +
-Un cop la configuracio esta correctament (des)comentada es pot guardar el fitxer i sortir de l éditor de texte. +
- +
-Es pot provar el funcionament correcte escribint:+
  
 <code bash> <code bash>
-sudo python simpletest.py </code>+sudo python simpletest.py 
 +</code>
  
-Si tot es correcte es podra veure una sortida com la seguent:+If everything is correct, you will see output like this:
  
-<code >+<code>
 Press Ctrl-C to quit. Press Ctrl-C to quit.
 Thermocouple Temperature: 22.000*C / 71.600*F Thermocouple Temperature: 22.000*C / 71.600*F
 Internal Temperature: 23.312*C / 73.963*F Internal Temperature: 23.312*C / 73.963*F
-Thermocouple Temperature: 22.250*C / 72.050*F +</code>
-Internal Temperature: 23.375*C / 74.075*F +
-Thermocouple Temperature: 27.500*C / 81.500*F +
-Internal Temperature: 23.312*C / 73.963*F +
-... +
- </code>+
  
-Per entendre el programa es pot obrir simpletest.py amb un editor de texte.El primer que es troba es:+==== MySQL Configuration for Storing Temperature Data ====
  
-<code python>import Adafruit_MAX31855.MAX31855 as MAX31855</code>+Install MySQL/MariaDB and necessary modules:
  
-Es la importacio de la llibreria a traves de una comanda Python. A continuacio hi ha la configuracio del programa: +<code> 
- +sudo apt-get install mysql-server python-mysqldb
-<code python+
-# Uncomment one of the blocks of code below to configure your Pi or BBB to use +
-# software or hardware SPI. +
-# Raspberry Pi software SPI configuration. +
-CLK = 25 +
-CS = 24 +
-DO = 18 +
-sensor = MAX31855.MAX31855(CLK, CS, DO) +
-# Raspberry Pi hardware SPI configuration. +
-#SPI_PORT = 0 +
-#SPI_DEVICE = 0 +
-#sensor = MAX31855.MAX31855(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=5000000)) +
-# BeagleBone Black software SPI configuration. +
-#CLK = 'P9_12' +
-#CS = 'P9_15' +
-#DO = 'P9_23' +
-#sensor = MAX31855.MAX31855(CLK, CS, DO) +
-# BeagleBone Black hardware SPI configuration. +
-#SPI_PORT = 1 +
-#SPI_DEVICE = 0 +
-#sensor = MAX31855.MAX31855(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=5000000))+
 </code> </code>
  
-La part no comentada ha de coorespondre amb el hardware.+Log into the MySQL console:
  
-Finalment el exemple entra a  un bucle on llegeix mesures de temperatura i les imprimeix cada segon. El detall important es que hi han dues funcions de mesura de la temperatura, readTempC() y readInternalC(). +<code> 
- +sudo mysql -u root -p -h localhost
-<code python+
-# Loop printing measurements every second. +
-print 'Press Ctrl-C to quit.' +
-while True: +
-temp = sensor.readTempC() +
-internal = sensor.readInternalC() +
-print 'Thermocouple Temperature: {0:0.3F}*C / {1:0.3F}*F'.format(temp, c_to_f(temp)) +
-print ' Internal Temperature: {0:0.3F}*C / {1:0.3F}*F'.format(internal, c_to_f(internal)) +
-time.sleep(1.0)+
 </code> </code>
  
-La funcio readTempC() llegeix la temperatura de la sonda, la funcio readInternalC() llegeix la temperatura del integrat MAX31855. +Create a database named "temperatures":
- +
-==== configuracio MySql/creacio base de dades per guardar dades Temperatura==== +
- +
-Instalar Mysql/MariaDb y els complements necesaris: +
- +
-<code>sudo apt-get install mysql-server python-mysqldb</code> +
- +
-Entrar al mode consola de sql. +
- +
-<code>sudo mysql -u root -p -h localhost</code> +
- +
-Pulsar Enter per password (buit)y entrarem en la consola MariaDb  +
- +
-Sobre consola +
- +
-Primer, crear base de dades temperatures: +
- +
-<code sql>CREATE DATABASE temperatures;</code> +
- +
-Seleccionar la base de dades creada: +
- +
-<code sql>USE temperatures;</code> +
- +
-Crear usuari i garantir acces a la base de dades a aquest usuari: +
- +
-<code sql>CREATE USER 'logger'@'localhost' IDENTIFIED BY 'password';+
  
 +<code sql>
 +CREATE DATABASE temperatures;
 +USE temperatures;
 +CREATE USER 'logger'@'localhost' IDENTIFIED BY 'password';
 GRANT ALL PRIVILEGES ON temperatures.* TO 'logger'@'localhost'; GRANT ALL PRIVILEGES ON temperatures.* TO 'logger'@'localhost';
 +FLUSH PRIVILEGES;
 +</code>
  
-FLUSH PRIVILEGES;</code>+Create a table to store temperature and timestamp data:
  
-El usuari/privilegis estan creats. Ara es possible cambiar de l´usuari root a aquest nou usuari:+<code sql> 
 +CREATE TABLE temperaturedata (dateandtime DATETIME, sensor VARCHAR(32), temperature DOUBLE, humidity DOUBLE); 
 +</code>
  
-<code sql>quit</code>+Restart MySQL to apply changes:
  
-Tornar a conectar amb el nou usuari+<code> 
 +sudo /etc/init.d/mysql restart 
 +</code>
  
-<code>sudo mysql -u logger -p -h localhost</code>+=== Reading Sensor Data and Writing to the Database ===
  
-Donar la contrasenya implementada al pas anterior. +The `simpletest2.py` program reads sensor data and writes it to the database:
- +
-Crear  Temperaturedata per guardar les dades del sensor data/hora . +
- +
-Per crear la taula: +
- +
-<code sql>USE temperatures;</code> +
- +
-Crear la primera taula amb les columnes dateandtime, sensor, temperature y humidity: +
- +
-<code sql>CREATE TABLE temperaturedata (dateandtime DATETIME, sensor VARCHAR(32), temperature DOUBLE, humidity DOUBLE);</code> +
- +
- +
-Es pot confirmar, que la taula buida esta creada amb: +
- +
-<code sql >SELECT * FROM temperaturedata;</code> +
- +
-Si la taula exiteix, es veura: "Empty Set (0.00 sec)" +
- +
-La base de dades esta configurada es pot sortir de mysql: +
- +
-<code>quit</code> +
- +
-Reiniciar mysql perque els canvis tinguin efecte: +
- +
-<code>sudo /etc/init.d/mysql restart</code> +
- +
- +
-=== Software de lectura de la sonda i escritura a base de dades==? +
- +
-El programa simpletest2.py llegeix la temperatura de la sonda i l´escriu a la base de dades .+
  
 <code python> <code python>
Line 225: Line 133:
 import Adafruit_GPIO.SPI as SPI import Adafruit_GPIO.SPI as SPI
 import Adafruit_MAX31855.MAX31855 as MAX31855 import Adafruit_MAX31855.MAX31855 as MAX31855
-import sys 
-import urllib2 
 import mysql.connector import mysql.connector
  
 # Raspberry Pi software SPI configuration. # Raspberry Pi software SPI configuration.
 CLK = 25 CLK = 25
-CS  = 24 +CS = 24 
-DO  = 18+DO = 18
 sensor = MAX31855.MAX31855(CLK, CS, DO) sensor = MAX31855.MAX31855(CLK, CS, DO)
  
- 
-# Loop printin measurements every second. 
-#print('Press Ctrl-C to quit.') 
-#while True: 
 temp = sensor.readTempC() temp = sensor.readTempC()
-internal = sensor.readInternalC() 
-print('Temperatura: {0:0.2F} C grados '.format(temp)) 
-#   print('    Internal Temperature: {0:0.3F}*C / {1:0.3F}*F'.format(internal, c_to_f(internal))) 
-print("Temperature Data Logger\n") 
-#Open Log File 
-f=open('tempdata.txt','a') 
 now = datetime.datetime.now() now = datetime.datetime.now()
 timestamp = now.strftime("%Y/%m/%d %H:%M") timestamp = now.strftime("%Y/%m/%d %H:%M")
-outvalue = temp +print('Temperature: {0:0.2F} degrees'.format(temp))
-outstring = str(timestamp)+"  "+str(outvalue)+" "+"\n" +
-print outstring +
-f.write(outstring) +
-f.close() +
-# time.sleep(1.0)+
  
-conexion1=mysql.connector.connect(host="localhost", +conexion1 = mysql.connector.connect(host="localhost", user="logger", passwd="password", database="temperatures"
-                                  user="jmbargallo", +cursor1 = conexion1.cursor()
-                                  passwd="antaviana92", +
-                                  database="temperatures"+
-cursor1=conexion1.cursor()+
  
-sql="insert into temperaturedata(dateandtime, sensor, temperature, humidity) values (%s,%s,%s,%s)" +sql = "insert into temperaturedata(dateandtime, sensor, temperature, humidity) values (%s,%s,%s,%s)" 
-datos=(timestamp, 2,outvalue,20.0) +data = (timestamp, "sensor_1"temp, 20.0) 
-cursor1.execute(sql, datos)+cursor1.execute(sql, data) 
 +conexion1.commit()
 </code> </code>
  
-=== Software per enviar les dades a Thingspeak===+==== Sending Data to Thingspeak ====
  
-El programa IOT.py serveix per enviar les dades un compte de thingspeak.+The `IOT.py` program sends data to Thingspeak account:
  
 <code python> <code python>
-import sys 
 import urllib2 import urllib2
-import RPi.GPIO as GPIO 
-import Adafruit_GPIO.SPI as SPI 
 import Adafruit_MAX31855.MAX31855 as MAX31855 import Adafruit_MAX31855.MAX31855 as MAX31855
  
-# Raspberry Pi software SPI configuration. 
 CLK = 25 CLK = 25
-CS  = 24 +CS = 24 
-DO  = 18+DO = 18
 sensor = MAX31855.MAX31855(CLK, CS, DO) sensor = MAX31855.MAX31855(CLK, CS, DO)
  
-# Write API Key ThingSpeak.com +miWriteAPIKey = "YOUR_API_KEY"
-miWriteAPIKey = "R2QX9L6O060V7ZFL"+
  
 def getSensorData(): def getSensorData():
-   T = sensor.readTempC() +    T = sensor.readTempC() 
-   return str(T))+    return str(T) 
 def main(): def main():
-   print 'Iniciando...' +    baseURL = 'https://api.thingspeak.com/update?api_key=%s' % miWriteAPIKey 
-   baseURL = 'https://api.thingspeak.com/update?api_key=%s' % miWriteAPIKey +    while True: 
-   while True: +        try: 
-       try: +            T = getSensorData() 
-           T = getSensorData() +            f = urllib2.urlopen(baseURL + "&field1=%s" % T) 
-           f = urllib2.urlopen(baseURL + "&field3=%s&" % (T)+            print(f.read()
-           print f.read() +            f.close() 
-           f.close() +            time.sleep(5) 
-           sleep(5) +        except: 
-       except: +            print('Error sending data') 
-           print 'Terminado.+            break
-           break +
-if __name__ == '__main__': +
-   main()+
  
 +if __name__ == '__main__':
 +    main()
 </code> </code>
  
raspberry_pi/projects/ultrafreezer.1738768833.txt.gz · Last modified: 2025/02/05 15:20 by jmbargallo