Mejorando las capacidades del PLC Raspberry Pi con UPS y RTC
Descubre cómo los PLC basadas en Raspberry Pi integran funcionalidades cruciales como la Fuente de Alimentación Ininterrumpida (UPS) y el Reloj en Tiempo Real (RTC), mejorando tanto la fiabilidad como la precisión para tus proyectos de automatización. Estas funcionalidades se configuran automáticamente a través de los scripts de instalación proporcionados: uno para el RPI PLC V4 otro para el RPI PLC V6. Cada script (install.sh) configura estas funciones junto con otros componentes esenciales. Sin embargo, cuando se utiliza UPSafePI, estos scripts no son necesarios. Este post explicará cómo configurar las características de UPS y RTC y cómo utilizarlas eficazmente. Para más información y especificaciones técnicas sobre UPS Shield, consulta este post.
UPS Shield: maximizando el tiempo de actividad del PLC Raspberry Pi
Todos los PLC basados en Raspberry Pi incluyen el UPS Shield. Es un Smart Shield que proporciona 5 segundos de energía en caso de un corte de suministro. Este tiempo extra permite que la Raspberry realice un apagado correcto, evitando la corrupción de la tarjeta SD. El tiempo de recarga del UPS es menor de 1 minuto, y el tiempo de reconexión es inferior a 20 segundos.
¿Cómo habilitar el apagado controlado para el PLC basado en Raspberry Pi?
Los PLC basados en Raspberry Pi pueden realizar un apagado controlado cuando el UPS detecta que se ha cortado el suministro de energía principal. Esto asegura que todos los procesos activos finalicen y que la imagen de la tarjeta SD y los archivos estén protegidos.
Para habilitar el apagado controlado en Raspberry Pi, sigue estos pasos:
- Modifica el archivo de configuración: Este proceso ahora se gestiona mediante superposiciones del árbol de dispositivos. Agrega las siguientes dos líneas al archivo the /boot/firmware/config.txt file:
- The gpio-poweroff overlay ensures the system powers off gracefully using GPIO pin 23.
- The gpio-shutdown overlay detects when the system should shut down using GPIO pin 24.
- Guarda y reinicia: Después de editar y guardar el archivo, reinicia el Raspberry Pi para aplicar los cambios.
Para todos los dispositivos Raspberry PLC, excepto el UPSafePI, la configuración del UPS se puede realizar ejecutando el script de instalación para V4 o V6. Sigue tutorial para obtener más información sobre cómo instalar un sistema operativo en Raspberry Pi y sobre la ejecución del script de instalación.
El sistema ahora realizará un apagado controlado cuando se pierda la alimentación principal, garantizando la protección de los datos y los procesos.
Comandos previos al apagado: protegiendo tus datos
Antes de que tu sistema se apague, asegúrate de que todas las operaciones críticas se completen utilizando los "hooks" de pre-apagado. Esta guía proporciona pasos detallados sobre la creación de directorios, la descarga de los archivos de servicio necesarios y los scripts para automatizar tareas cruciales antes del apagado.
- Crear el directorio necesario: Crea el directorio requerido para almacenar los "hooks" de pre-apagado
- Descargar el archivo de servicio y el script de hook: Obtén los archivos necesarios para el servicio de pre-apagado y el script de verificación.
- Conceder permisos de ejecución: Haz que el script de pre-apagado sea ejecutable.
- Habilitar e iniciar el servicio de pre-apagado: Recarga el systemd daemon y habilita el nuevo servicio:
Cualquier tipo de archivo (scripts Bash, Python, C++, etc.) puede ejecutarse, pero lo más importante es que el archivo debe llamarse "pre-poweroff" sin ninguna extensión (y debes indicar el tipo de archivo con el correspondiente "Shebang"). El tiempo de ejecución del script no puede superar los ~6 segundos, ya que ese es el período de apagado de la Raspberry.
This setup ensures that any custom commands in the check-pre-poweroff script will be executed before the system powers off.
Real-Time Clock (RTC) setup: ensuring time precision
Integrating the DS3231 RTC with your Raspberry Pi PLC can be a game-changer, especially for low-power applications where time accuracy is paramount. Follow these detailed steps to enable and configure the RTC module, ensuring your system keeps accurate time, even when powered down.
Benefits of using an RTC:
- Low power consumption, ideal for systems running on alternate power sources.
- Frees the main system from handling time-keeping tasks.
- Can be more accurate than other time-keeping methods.
Follow these steps to enable RTC functionality on your Raspberry based PLC:
- Update your system: Make sure your system has the latest updates by running:
- Enable I2C on the Raspberry Pi: Open the configuration file based on your system version:
- For Bullseye: /boot/config.txt
- For Bookworm or later: /boot/firmware/config.txt
- Enable the RTC overlay: Add the following line at the end of the file, after the [all] section:
- Restart the device: Save the changes and reboot the system to apply the configuration.
Uncomment the following line if it's commented:
As for the UPS service, for all Raspberry PLC devices except UPSafePI, the set up of the UPS can be done by executing the installation script for V4 or for V6. Follow tutorial for more information about how to install an operative system to the Raspberry and about execution of the installation script.
Leveraging UPS and RTC for advanced Raspberry Pi projects
Capitalize on the full potential of your Raspberry Pi PLC by implementing UPS and RTC functionalities. This setup not only enhances reliability but also expands the capabilities of your projects. Dive deeper into technical specifications and additional resources to maximize your PLC's performance.
References and Further Reading
For those looking to expand their knowledge or troubleshoot potential issues, this section provides links to additional resources and detailed documentation, ensuring you have access to all the information you need to succeed with your Raspberry Pi PLC projects.

Cómo trabajar con UPS y RTC en Raspberry PLC