raspberry_pi:projects:ultrafreezer
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| raspberry_pi:projects:ultrafreezer [2025/02/05 15:20] – jmbargallo | raspberry_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 | + | To adapt the PT100 sensor, the MAX31855 |
| - | 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 | + | If unsure, it is preferable to use software SPI due to its flexibility, |
| - | ==== Hardware | + | ==== Hardware |
| - | Per utiltzar | + | To use software SPI, connect the MAX31855 |
| - | 3 digital IO pins qualsevol per CLK, CS, y DO. | + | Any three GPIO pins can be used for CLK, CS, and DO. |
| {{: | {{: | ||
| - | - Connectar | + | - Connect |
| - | - Connectar | + | - Connect |
| - | - Connectar | + | - Connect |
| - | - Connectar | + | - Connect |
| - | - Connectar | + | - Connect |
| {{ : | {{ : | ||
| - | ==== Software==== | ||
| - | === Dependencies=== | + | ==== Software ==== |
| - | Primer executar les dependencies escribint al terminal: | + | === Dependencies === |
| - | <code bash> | + | First, |
| - | sudo apt-get | + | |
| - | === RPi.GPIO library=== | + | <code bash> |
| + | sudo apt-get update | ||
| + | sudo apt-get install build-essential python-dev python-pip python-smbus git | ||
| + | </ | ||
| - | Per estar segur de que les llibreries | + | === RPi.GPIO Library === |
| - | <code bash> | + | Ensure that the GPIO libraries are installed by running: |
| + | |||
| + | <code bash> | ||
| + | sudo pip install RPi.GPIO | ||
| + | </ | ||
| - | === Library | + | === MAX31855 |
| - | Descarregar la llibreria Python del MAX31855 Python | + | Download the MAX31855 Python |
| <code bash> | <code bash> | ||
| Line 47: | Line 52: | ||
| </ | </ | ||
| - | === Configuracio i prova=== | + | === Configuration and Testing |
| - | Per configurar i provar el hardware/softwareTo es pot utilitzar els programes incloisos en el directori | + | To configure and test the hardware/software setup, use the example programs included in the `examples` directory and open the `simpletest.py` script: |
| - | <code bash> | + | |
| - | sudo nano simpletest.py </ | + | |
| - | Baixant pantalla es poden veure comentades les diverses opcions de configuracio, | ||
| <code bash> | <code bash> | ||
| + | sudo nano simpletest.py | ||
| + | </ | ||
| + | |||
| + | 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, | sensor = MAX31855.MAX31855(CLK, | ||
| - | # Raspberry Pi hardware SPI configuration. | ||
| - | #SPI_PORT = 0 | ||
| - | #SPI_DEVICE = 0 | ||
| - | #sensor = MAX31855.MAX31855(spi=SPI.SpiDev(SPI_PORT, | ||
| - | # BeagleBone Black software SPI configuration. | ||
| - | #CLK = ' | ||
| - | #CS = ' | ||
| - | #DO = ' | ||
| - | #sensor = MAX31855.MAX31855(CLK, | ||
| - | # BeagleBone Black hardware SPI configuration. | ||
| - | #SPI_PORT = 1 | ||
| - | #SPI_DEVICE = 0 | ||
| - | #sensor = MAX31855.MAX31855(spi=SPI.SpiDev(SPI_PORT, | ||
| - | |||
| - | |||
| </ | </ | ||
| - | 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 editor, then test the setup by running: | |
| - | + | ||
| - | Per defecte la configuracio per fer servir Raspberry Pi amb software SPI esta no comentada, si 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 </ | + | sudo python simpletest.py |
| + | </ | ||
| - | Si tot es correcte es podra veure una sortida com la seguent: | + | If everything is correct, you will see output like this: |
| - | <code > | + | < |
| Press Ctrl-C to quit. | Press Ctrl-C to quit. | ||
| Thermocouple Temperature: | Thermocouple Temperature: | ||
| Internal Temperature: | Internal Temperature: | ||
| - | Thermocouple Temperature: | + | </ |
| - | Internal Temperature: | + | |
| - | Thermocouple Temperature: | + | |
| - | Internal Temperature: | + | |
| - | ... | + | |
| - | </ | + | |
| - | 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> | + | 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: | + | < |
| - | + | sudo apt-get install mysql-server python-mysqldb | |
| - | < | + | |
| - | # 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, | + | |
| - | # Raspberry Pi hardware SPI configuration. | + | |
| - | #SPI_PORT = 0 | + | |
| - | #SPI_DEVICE = 0 | + | |
| - | #sensor = MAX31855.MAX31855(spi=SPI.SpiDev(SPI_PORT, | + | |
| - | # BeagleBone Black software SPI configuration. | + | |
| - | #CLK = ' | + | |
| - | #CS = ' | + | |
| - | #DO = ' | + | |
| - | #sensor = MAX31855.MAX31855(CLK, | + | |
| - | # BeagleBone Black hardware SPI configuration. | + | |
| - | #SPI_PORT = 1 | + | |
| - | #SPI_DEVICE = 0 | + | |
| - | #sensor = MAX31855.MAX31855(spi=SPI.SpiDev(SPI_PORT, | + | |
| </ | </ | ||
| - | 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, | + | < |
| - | + | sudo mysql -u root -p -h localhost | |
| - | < | + | |
| - | # Loop printing measurements every second. | + | |
| - | print 'Press Ctrl-C to quit.' | + | |
| - | while True: | + | |
| - | temp = sensor.readTempC() | + | |
| - | internal = sensor.readInternalC() | + | |
| - | print ' | + | |
| - | print ' Internal Temperature: | + | |
| - | time.sleep(1.0) | + | |
| </ | </ | ||
| - | 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/ | + | |
| - | + | ||
| - | Instalar Mysql/ | + | |
| - | + | ||
| - | < | + | |
| - | + | ||
| - | Entrar al mode consola de sql. | + | |
| - | + | ||
| - | < | + | |
| - | + | ||
| - | Pulsar Enter per password (buit)y entrarem en la consola MariaDb | + | |
| - | + | ||
| - | Sobre consola | + | |
| - | + | ||
| - | Primer, crear base de dades temperatures: | + | |
| - | + | ||
| - | <code sql> | + | |
| - | + | ||
| - | Seleccionar la base de dades creada: | + | |
| - | + | ||
| - | <code sql>USE temperatures;</ | + | |
| - | + | ||
| - | Crear usuari i garantir acces a la base de dades a aquest usuari: | + | |
| - | + | ||
| - | <code sql> | + | |
| + | <code sql> | ||
| + | CREATE DATABASE temperatures; | ||
| + | USE temperatures; | ||
| + | CREATE USER ' | ||
| GRANT ALL PRIVILEGES ON temperatures.* TO ' | GRANT ALL PRIVILEGES ON temperatures.* TO ' | ||
| + | FLUSH PRIVILEGES; | ||
| + | </ | ||
| - | FLUSH PRIVILEGES;</ | + | 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), | ||
| + | </code> | ||
| - | <code sql> | + | Restart MySQL to apply changes: |
| - | Tornar a conectar amb el nou usuari | + | < |
| + | sudo / | ||
| + | </ | ||
| - | < | + | === 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 | + | |
| - | + | ||
| - | Per crear la taula: | + | |
| - | + | ||
| - | <code sql>USE temperatures;</ | + | |
| - | + | ||
| - | Crear la primera taula amb les columnes dateandtime, | + | |
| - | + | ||
| - | <code sql> | + | |
| - | + | ||
| - | + | ||
| - | Es pot confirmar, que la taula buida esta creada amb: | + | |
| - | + | ||
| - | <code sql >SELECT * FROM temperaturedata;</ | + | |
| - | + | ||
| - | Si la taula exiteix, es veura: "Empty Set (0.00 sec)" | + | |
| - | + | ||
| - | La base de dades esta configurada es pot sortir de mysql: | + | |
| - | + | ||
| - | < | + | |
| - | + | ||
| - | Reiniciar mysql perque els canvis tinguin efecte: | + | |
| - | + | ||
| - | < | + | |
| - | + | ||
| - | + | ||
| - | === 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, | sensor = MAX31855.MAX31855(CLK, | ||
| - | |||
| - | # Loop printin measurements every second. | ||
| - | # | ||
| - | #while True: | ||
| temp = sensor.readTempC() | temp = sensor.readTempC() | ||
| - | internal = sensor.readInternalC() | ||
| - | print(' | ||
| - | # | ||
| - | print(" | ||
| - | #Open Log File | ||
| - | f=open(' | ||
| now = datetime.datetime.now() | now = datetime.datetime.now() | ||
| timestamp = now.strftime(" | timestamp = now.strftime(" | ||
| - | outvalue = temp | + | print(' |
| - | outstring = str(timestamp)+" | + | |
| - | print outstring | + | |
| - | f.write(outstring) | + | |
| - | f.close() | + | |
| - | # time.sleep(1.0) | + | |
| - | conexion1=mysql.connector.connect(host=" | + | conexion1 = mysql.connector.connect(host=" |
| - | | + | cursor1 = conexion1.cursor() |
| - | | + | |
| - | | + | |
| - | cursor1=conexion1.cursor() | + | |
| - | sql=" | + | sql = " |
| - | datos=(timestamp, | + | data = (timestamp, |
| - | cursor1.execute(sql, | + | cursor1.execute(sql, |
| + | conexion1.commit() | ||
| </ | </ | ||
| - | === Software per enviar les dades a Thingspeak=== | + | ==== Sending Data to Thingspeak |
| - | El programa | + | The `IOT.py` program sends data to a 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, | sensor = MAX31855.MAX31855(CLK, | ||
| - | # Write API Key ThingSpeak.com | + | miWriteAPIKey = "YOUR_API_KEY" |
| - | miWriteAPIKey = "R2QX9L6O060V7ZFL" | + | |
| def getSensorData(): | def getSensorData(): | ||
| - | T = sensor.readTempC() | + | |
| - | | + | return str(T) |
| def main(): | def main(): | ||
| - | print ' | + | |
| - | baseURL = ' | + | while True: |
| - | | + | try: |
| - | | + | T = getSensorData() |
| - | | + | f = urllib2.urlopen(baseURL + "&field1=%s" % T) |
| - | | + | print(f.read()) |
| - | | + | f.close() |
| - | | + | time.sleep(5) |
| - | | + | except: |
| - | | + | print('Error sending data') |
| - | | + | break |
| - | | + | |
| - | if __name__ == ' | + | |
| - | | + | |
| + | if __name__ == ' | ||
| + | main() | ||
| </ | </ | ||
raspberry_pi/projects/ultrafreezer.1738768833.txt.gz · Last modified: 2025/02/05 15:20 by jmbargallo
