add fan connection setup and explanation

This commit is contained in:
2024-11-23 11:58:30 +05:30
parent ff51a6ee7c
commit dead0ea51e

View File

@@ -160,9 +160,10 @@ This example uses `gpio_get_out_level` to to get the output level for gicen give
sleep_ms(500);
```
---
## ParallelBlinky
use gpio_put_masked and gpio_set_dir_masked, set_dir_in_masked and set_dir_out_masked
In this example, the init and set dir operations are performed simultaneously using `gpio_init_mask` and `gpio_set_dir_masked` calls. These take a integer value called mask, where each bit represents one GPIO pin. The above example can be simplified and replicated with the code below.
```c
@@ -193,9 +194,33 @@ Here, the `pinMask` variable represents the gpio pins. The position from the rig
For this example, the init mask functions will initialize GP11 to GP15, because they are highlighted by `pinMask`. The set dir mask function will focus on GP11 to GP15, because they are highlighted by `pinMask`, take the bits in highlighted locations from `dirMask` and set the direction if they are 1 or 0.
---
## Line Control
This experiment showcases how digital output pin can control a DC appliance, a fan in this case, using a particular IC. The code stays the same as `Blinky`, only the hardware changes. This example showcases real world use case for digital output.
For this example, a `IRLZ44N` MOSFET is used for controlling a 12v DC fan. A 12v voltage module is used as power source for the fan. Positive of the module is connected to the fan's positive pin. The `Gate` pin of the mosfet is connected to a GPIO pin, `Source` is connected to ground and `Drain` is connected to -ve pin of the fan. It is important to note that ALL THE GROUND MUST BE CONNECTED, forming whats knows as **Common Ground**. [Explanaion provided in Arduino Forum](https://forum.arduino.cc/t/common-ground-and-why-you-need-one/626215). The ground of the 12v module is connected to ground of the pico.
For this example, a `IRLZ44N` MOSFET is used for controlling a 12v DC fan. This MOSFET acts as a switch, which can be digitally controlled using the digital out pin on the pico.
A 12v voltage module is used as power source for the fan. Positive of the module is connected to the fan's positive pin. The `Gate` pin of the mosfet is connected to a GPIO pin, `Source` is connected to ground and `Drain` is connected to -ve pin of the fan.
It is important to note that ALL THE GROUND MUST BE CONNECTED, forming whats knows as **Common Ground**. [Explanaion provided in Arduino Forum](https://forum.arduino.cc/t/common-ground-and-why-you-need-one/626215). The ground of the 12v module is connected to ground of the pico. This should result in connections like below.
<img src="https://a.l3n.co/i/LgYGpM.png" width="300">
Code to turn the fan on and off with a 2 second delay:
```c
{
stdio_init_all();
const uint FANPIN = 22;
gpio_init(FANPIN);
gpio_set_dir(FANPIN, GPIO_OUT);
while (true){
gpio_put(FANPIN, true);
sleep_ms(2000);
gpio_put(FANPIN, false);
sleep_ms(2000);
}
}
```