|
| 1 | +Temperature Controller Application |
| 2 | +================================== |
| 3 | + |
| 4 | +This sample application demonstrates a basic Temperature Controller using the |
| 5 | +:adi:`AD-AD-RPI-T1LPSE-SL-RPIZ` board, two :adi:`AD-SWIOT1L-SL` boards, a |
| 6 | +Raspberry Pi, a fan actuator and a temperature sensor. The system reads |
| 7 | +temperature data and adjusts fan speed (via SWIOT1L output) based on |
| 8 | +configurable thresholds and hysteresis. |
| 9 | + |
| 10 | +Prerequisites |
| 11 | +------------- |
| 12 | + |
| 13 | +- Python 3.8 or newer (3.8–3.11 tested with pyadi-iio). Ensure that a |
| 14 | + compatible version is installed on your system before continuing. Older |
| 15 | + versions (<3.8) may not work reliably with pyadi-iio. |
| 16 | + |
| 17 | +- Git command-line tools installed. |
| 18 | + |
| 19 | +- Raspberry Pi with :adi:`Kuiper 2` image installed. Follow the instructions in |
| 20 | + the :external+adi-kuiper-gen:doc:`index` documentation to prepare the |
| 21 | + Raspberry Pi. |
| 22 | + |
| 23 | +- Ensure that the first two **Software Setup** steps described in |
| 24 | + :ref:`software-setup` (*Downloading and Flashing the Micro-SD Card* and |
| 25 | + *Configuring the Micro-SD Card*) are performed **with the Kuiper 2 image**, |
| 26 | + not with previous Kuiper releases. These steps must be redone after flashing |
| 27 | + Kuiper 2 to ensure proper compatibility before continuing. |
| 28 | + |
| 29 | + |
| 30 | +Hardware Setup |
| 31 | +-------------- |
| 32 | + |
| 33 | +.. figure:: temperature_controller_system.png |
| 34 | + :align: center |
| 35 | + :width: 500 |
| 36 | + |
| 37 | + Temperature Controller System |
| 38 | + |
| 39 | +**Equipment Needed** |
| 40 | + |
| 41 | +- 1x :adi:`AD-AD-RPI-T1LPSE-SL-RPIZ` Board |
| 42 | +- 2x :adi:`AD-SWIOT1L-SL` Boards |
| 43 | +- 1x Raspberry Pi 4 Model B running Kuiper 2 |
| 44 | +- 1x :adi:`TMP01` Temperature Sensor |
| 45 | +- 1x MC002103 DC Axial Fan |
| 46 | +- 1x Raspberry Pi USB Type-C Power Supply (5V, 3A) |
| 47 | + |
| 48 | +**Setup Procedure** |
| 49 | + |
| 50 | +1. Connect the :adi:`AD-AD-RPI-T1LPSE-SL-RPIZ` board to the Raspberry Pi via the |
| 51 | + 40-pin header |
| 52 | + |
| 53 | +2. Connect the two :adi:`AD-SWIOT1L-SL` boards to the |
| 54 | + :adi:`AD-AD-RPI-T1LPSE-SL-RPIZ` board via the T1L connectors |
| 55 | + |
| 56 | +3. Connect the first :adi:`AD-SWIOT1L-SL` board to the :adi:`TMP01` temperature |
| 57 | + sensor |
| 58 | + |
| 59 | + The first SWIOT1L-SL board is used to both power the TMP01 sensor and |
| 60 | + measure its analog output voltage (VPTAT), which encodes the temperature. |
| 61 | + |
| 62 | + - **Channel 3 (CH3)** is configured as a **Voltage Output** and provides |
| 63 | + the sensor supply voltage. Connect: |
| 64 | + |
| 65 | + - ``CH3 SWIO`` → ``TMP01 V+`` |
| 66 | + - ``CH3 GND`` → ``TMP01 GND`` |
| 67 | + |
| 68 | + - **Channel 4 (CH4)** is configured as a **Voltage Input** to measure the |
| 69 | + TMP01 analog output. Connect: |
| 70 | + |
| 71 | + - ``CH4 SWIO`` → ``TMP01 VOUT`` |
| 72 | + - ``CH4 GND`` → ``TMP01 GND`` |
| 73 | + |
| 74 | + .. note:: |
| 75 | + |
| 76 | + CH3 provides a regulated 5 V supply to power the TMP01, while CH4 is |
| 77 | + configured as a high-impedance voltage input with a 0–5 V range to measure |
| 78 | + the TMP01 VOUT signal. Both channels must share the same ground reference |
| 79 | + with the sensor. |
| 80 | + |
| 81 | +4. Connect the second :adi:`AD-SWIOT1L-SL` board to the fan actuator |
| 82 | + |
| 83 | + The second SWIOT1L-SL board drives the fan according to the control loop. |
| 84 | + |
| 85 | + - The fan is powered directly from channel 0, configured as a |
| 86 | + **Voltage Output**: |
| 87 | + |
| 88 | + - ``CH0 SWIO`` → ``Fan +`` |
| 89 | + - ``CH0 GND`` → ``Fan −`` |
| 90 | + |
| 91 | + - Connect the tachometer output to channel 1 to monitor fan speed (optional): |
| 92 | + |
| 93 | + - ``CH1 SWIO`` → ``Fan Tach Out`` |
| 94 | + |
| 95 | +5. Power the Raspberry Pi with a 5V, 3A USB Type-C power supply. |
| 96 | + |
| 97 | + |
| 98 | +Software Setup |
| 99 | +-------------- |
| 100 | + |
| 101 | +Repository Cloning |
| 102 | +~~~~~~~~~~~~~~~~~~ |
| 103 | + |
| 104 | +1. Clone the repository and checkout the *swiot* branch: |
| 105 | + |
| 106 | + .. shell:: |
| 107 | + :user: analog |
| 108 | + :group: analog |
| 109 | + :show-user: |
| 110 | + |
| 111 | + $ git clone https://github.com/analogdevicesinc/pyadi-iio.git |
| 112 | + $ cd pyadi-iio |
| 113 | + $ git checkout swiot |
| 114 | + |
| 115 | +2. Install Python dependencies: |
| 116 | + |
| 117 | + .. shell:: |
| 118 | + :user: analog |
| 119 | + :group: analog |
| 120 | + :show-user: |
| 121 | + |
| 122 | + $ python3 -m venv ./venv |
| 123 | + $ source venv/bin/activate |
| 124 | + $ pip install -e . |
| 125 | + |
| 126 | + |
| 127 | +Firmware Flashing |
| 128 | +~~~~~~~~~~~~~~~~~ |
| 129 | + |
| 130 | +Each :adi:`AD-SWIOT1L-SL` must be updated with the provided firmware image. |
| 131 | + |
| 132 | +1. Follow the official update instructions here: |
| 133 | + `Updating the AD-SWIOT1L-SL firmware <https://analogdevicesinc.github.io/documentation/solutions/reference-designs/ad-swiot1l-sl/software-guide/index.html#updating-the-ad-swiot1l-sl-firmware>`_. |
| 134 | + |
| 135 | +2. Repeat the process for **both boards**. |
| 136 | + |
| 137 | +3. Use the firmware images provided below. These images configure the boards with |
| 138 | + static IP addresses: |
| 139 | + |
| 140 | + - The first board will have the ``192.168.97.40`` IP address |
| 141 | + - The second board will have the ``192.168.97.41`` IP address |
| 142 | + |
| 143 | + .. ADMONITION:: Download |
| 144 | + |
| 145 | + :download:`Firmware for temperature controller application <swiot1l_firmware.zip>` |
| 146 | + |
| 147 | + Four different firmware images are provided. We recommend using the ones |
| 148 | + mentioned above. You may use the other two images if you wish to change the |
| 149 | + IP addresses of the boards or to extend the application. |
| 150 | + |
| 151 | + |
| 152 | +Network Setup |
| 153 | +~~~~~~~~~~~~~ |
| 154 | + |
| 155 | +The Raspberry Pi has two Ethernet interfaces connected to the two |
| 156 | +:adi:`AD-SWIOT1L-SL` boards. We will create two persistent NetworkManager |
| 157 | +connections with autoconnect enabled for each interface in order to communicate |
| 158 | +with the boards: |
| 159 | + |
| 160 | +- ``eth1`` will use ``192.168.97.30/32`` and route to the SWIOT1L board at ``192.168.97.41`` |
| 161 | +- ``eth2`` will use ``192.168.97.31/32`` and route to the SWIOT1L board at ``192.168.97.40`` |
| 162 | + |
| 163 | +Open the terminal and run the following commands. |
| 164 | + |
| 165 | +1. Add the wired connection interfaces: |
| 166 | + |
| 167 | + .. shell:: |
| 168 | + :user: analog |
| 169 | + :group: analog |
| 170 | + :show-user: |
| 171 | + |
| 172 | + $ sudo nmcli connection add \ |
| 173 | + type ethernet \ |
| 174 | + ifname eth1 \ |
| 175 | + con-name "Wired connection 2" \ |
| 176 | + ipv4.method manual \ |
| 177 | + ipv4.addresses 192.168.97.30/32 \ |
| 178 | + ipv4.routes "192.168.97.41/32" \ |
| 179 | + ipv6.method disabled \ |
| 180 | + connection.autoconnect yes |
| 181 | + |
| 182 | + $ sudo nmcli connection add \ |
| 183 | + type ethernet \ |
| 184 | + ifname eth2 \ |
| 185 | + con-name "Wired connection 3" \ |
| 186 | + ipv4.method manual \ |
| 187 | + ipv4.addresses 192.168.97.31/32 \ |
| 188 | + ipv4.routes "192.168.97.40/32" \ |
| 189 | + ipv6.method disabled \ |
| 190 | + connection.autoconnect yes |
| 191 | + |
| 192 | +2. Activate the new connections: |
| 193 | + |
| 194 | + .. shell:: |
| 195 | + :user: analog |
| 196 | + :group: analog |
| 197 | + :show-user: |
| 198 | + |
| 199 | + $ sudo nmcli connection up "Wired connection 2" |
| 200 | + $ sudo nmcli connection up "Wired connection 3" |
| 201 | + |
| 202 | +3. Reboot the Raspberry Pi to ensure autoconnect is applied: |
| 203 | + |
| 204 | + .. shell:: |
| 205 | + :user: analog |
| 206 | + :group: analog |
| 207 | + :show-user: |
| 208 | + |
| 209 | + $ sudo reboot |
| 210 | + |
| 211 | +4. Verify that the new connections are active: |
| 212 | + |
| 213 | + .. shell:: |
| 214 | + :user: analog |
| 215 | + :group: analog |
| 216 | + :show-user: |
| 217 | + |
| 218 | + $ nmcli connection show |
| 219 | + |
| 220 | + .. figure:: ad-rpi-t1lpse-rpiz-sample-application-nmcli-conn-show.png |
| 221 | + :align: center |
| 222 | + :width: 500 |
| 223 | + |
| 224 | + Example of active NetworkManager connections |
| 225 | + |
| 226 | +5. Verify routing and connectivity to the boards: |
| 227 | + |
| 228 | + .. shell:: |
| 229 | + :user: analog |
| 230 | + :group: analog |
| 231 | + :show-user: |
| 232 | + |
| 233 | + $ ip route |
| 234 | + $ ping 192.168.97.40 |
| 235 | + $ ping 192.168.97.41 |
| 236 | + |
| 237 | + |
| 238 | +Application Execution |
| 239 | +~~~~~~~~~~~~~~~~~~~~~ |
| 240 | + |
| 241 | +When executed, the demo continuously reads the temperature from the :adi:`TMP01` |
| 242 | +sensor and compares it against the configured thresholds. The fan is |
| 243 | +automatically turned **ON** once the temperature rises above ``TEMP_ON`` |
| 244 | +(default 27 °C) and turned **OFF** once the temperature falls below |
| 245 | +``TEMP_OFF`` (default 26 °C). This hysteresis prevents rapid switching when the |
| 246 | +temperature hovers around the threshold. |
| 247 | + |
| 248 | +During runtime, the application prints sensor readings and fan state in the |
| 249 | +console, and displays two plots: |
| 250 | + |
| 251 | +- **Temperature vs Time** — TMP01 and ADT75 temperature measurements with ON/OFF |
| 252 | + thresholds. |
| 253 | +- **Fan State vs Time** — graphical representation of when the fan is active. |
| 254 | + |
| 255 | +Run the Temperature Controller example: |
| 256 | + |
| 257 | + .. shell:: |
| 258 | + :user: analog |
| 259 | + :group: analog |
| 260 | + :show-user: |
| 261 | + |
| 262 | + $ cd examples/rpi_t1lpse |
| 263 | + $ python3 temperature_controller.py |
| 264 | + |
| 265 | + .. figure:: ad-rpi-t1lpse-rpiz-sample-application-console-output.png |
| 266 | + :align: center |
| 267 | + :width: 500 |
| 268 | + |
| 269 | + Example Console Output of the Temperature Controller Application |
| 270 | + |
| 271 | + .. figure:: ad-rpi-t1lpse-rpiz-sample-application-plot-output.png |
| 272 | + :align: center |
| 273 | + :width: 500 |
| 274 | + |
| 275 | + Example Plot Result of the Temperature Controller Application |
| 276 | + |
| 277 | + |
| 278 | +Use Cases |
| 279 | +^^^^^^^^^ |
| 280 | + |
| 281 | +This demo illustrates how the :adi:`AD-AD-RPI-T1LPSE-SL-RPIZ` platform together |
| 282 | +with :adi:`AD-SWIOT1L-SL` boards can be applied in: |
| 283 | + |
| 284 | +- **Thermal management** - automatically controlling fans in enclosures or test |
| 285 | + setups |
| 286 | +- **Process monitoring** - maintaining temperature ranges in small-scale |
| 287 | + industrial or lab equipment |
| 288 | +- **Educational examples** - demonstrating closed-loop control |
0 commit comments