From 0ad46d8b85ee9f1b41401b24dacc2d802c80c5b0 Mon Sep 17 00:00:00 2001 From: "Phani Pavan K: iDellToast" Date: Fri, 8 Nov 2024 23:06:23 +0530 Subject: [PATCH] change name, add some projects --- 1_Basic_GPIO/blinky.md | 50 --------------------- 1_Basic_GPIO/digitalOut.md | 91 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 50 deletions(-) delete mode 100644 1_Basic_GPIO/blinky.md create mode 100644 1_Basic_GPIO/digitalOut.md diff --git a/1_Basic_GPIO/blinky.md b/1_Basic_GPIO/blinky.md deleted file mode 100644 index 5c6d90d..0000000 --- a/1_Basic_GPIO/blinky.md +++ /dev/null @@ -1,50 +0,0 @@ -## Blinky - -The classic, the helloWorld of embedded programming. This program turns the LED on and off periodically. - -### Initial steps: -- Create new project with project generator. -- Open the project folder in VSCode. -- Build the project by pressing the `build` button at the bottom and select the option with `arm-none-eabi`. -- Make sure the build exits with code 0. - - - -### Basic Code: - -``` C -int main() -{ - stdio_init_all(); - - const uint OnBoardLED = PICO_DEFAULT_LED_PIN; - gpio_init(OnBoardLED); - gpio_set_dir(OnBoardLED, GPIO_OUT); - while (true){ - gpio_put(OnBoardLED, true); - sleep_ms(500); - gpio_put(OnBoardLED, false); - sleep_ms(500); - } -} -``` - -#### Explanation: -`stdio_init_all()`: initialize stuff - -`OnBoardLED = PICO_DEFAULT_LED_PIN`: Get the GPIO number of onboard LED. Remember this is GPIO Number, NOT PIN NUMBER. - -`gpio_init(OnBoardLED)`: Initialize that GPIO pin. - -`gpio_set_dir(OnBoardLED, GPIO_OUT)`: Set GPIO direction (`GPIO_OUT` for writing and `GPIO_IN` for reading). - -`while (true){}`: Super loop of the program - -`gpio_put(OnBoardLED, true)`: Set `OnBoardLED` pin to `on` (`true` to turn on/set to high/voltage to VDD, `false` to turn off/set to low/voltage to GND) - -Pico logic HIGH voltage is 3.3v and LOW voltage is 0v. - -`sleep_ms(500)`: sleep for 500ms. - ---- - diff --git a/1_Basic_GPIO/digitalOut.md b/1_Basic_GPIO/digitalOut.md new file mode 100644 index 0000000..1995b51 --- /dev/null +++ b/1_Basic_GPIO/digitalOut.md @@ -0,0 +1,91 @@ +## Blinky + +The classic, helloWorld of embedded programming. This program turns the LED on and off periodically. + +### Initial steps: +- Create new project with project generator. +- Open the project folder in VSCode. +- Build the project by pressing the `build` button at the bottom and select the option with `arm-none-eabi`. +- Make sure the build exits with code 0. + + + +### Basic Code: + +``` C +int main() +{ + stdio_init_all(); + + const uint OnBoardLED = PICO_DEFAULT_LED_PIN; + gpio_init(OnBoardLED); + gpio_set_dir(OnBoardLED, GPIO_OUT); + while (true){ + gpio_put(OnBoardLED, true); + sleep_ms(500); + gpio_put(OnBoardLED, false); + sleep_ms(500); + } +} +``` + +#### Explanation: +`stdio_init_all()`: initialize stuff + +`OnBoardLED = PICO_DEFAULT_LED_PIN`: Get the GPIO number of onboard LED. Remember: this is GPIO Number, NOT PIN NUMBER. + +`gpio_init(OnBoardLED)`: Initialize that GPIO pin. + +`gpio_set_dir(OnBoardLED, GPIO_OUT)`: Set GPIO direction (`GPIO_OUT` for writing and `GPIO_IN` for reading). + +`while (true){}`: Super loop of the program + +`gpio_put(OnBoardLED, true)`: Set `OnBoardLED` pin to `on` (`true` to turn on/set to high/voltage to VDD, `false` to turn off/set to low/voltage to GND) + +Pico logic HIGH voltage is 3.3v and LOW voltage is 0v. + +`sleep_ms(500)`: sleep for 500ms. + +--- + +## Different Blinky + +This makes the pico blink like a beacon, 2 short blinks followed by long delay. A `for` loop is used for repeating the short blink twice. + +```c +for (int i = 0; i < 2; i++) +{ + gpio_put(OnBoardLED, true); + sleep_ms(50); + gpio_put(OnBoardLED, false); + sleep_ms(100); +} +sleep_ms(500); +``` + +--- + +## External Blinky + +This program blinks an LED connected to one of the GPIO(General Purpose Input/Output) ports. + +For this example, I used Pin 20 == GP15. I connected a resistor to this pin and connected an LED in series with the resistor to the ground, as shown in the image below. + +```c +const uint LEDPin = 15; +gpio_init(LEDPin); +gpio_set_dir(LEDPin, GPIO_OUT); +while (true) +{ + for (int i = 0; i < 2; i++) + { + gpio_put(LEDPin, true); + sleep_ms(50); + gpio_put(LEDPin, false); + sleep_ms(100); + } + sleep_ms(500); +} +``` + +The only change here is in line 1, `PICO_DEFAULT_LED_PIN` is changed to `15`, to represent GP15. Remember: in the program, a GPIO pin is represented by the GP number and NOT by the pin number, as shown in the [Pico's Pinout](https://pico.pinout.xyz/).