From dead0ea51e640bf4b377b058ee3f9a7259021a63 Mon Sep 17 00:00:00 2001 From: "Phani Pavan K: iDellToast" Date: Sat, 23 Nov 2024 11:58:30 +0530 Subject: [PATCH] add fan connection setup and explanation --- 1_Basic_GPIO/digitalOut.md | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/1_Basic_GPIO/digitalOut.md b/1_Basic_GPIO/digitalOut.md index 07157d5..dc2c9c8 100644 --- a/1_Basic_GPIO/digitalOut.md +++ b/1_Basic_GPIO/digitalOut.md @@ -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. + + + +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); + } +} + +```