Posted on Leave a comment

How to use GPIO of Raspberry Pi Pico as Output Pins

One of the most important features of the Raspberry Pi Pico is its General-Purpose Input/Output (GPIO) pins. These pins can be used to control external devices, such as LEDs, motors, and relays.

The Raspberry Pi Pico has 26 GPIO pins, numbered from GP0 to GP25.
Each pin can be individually programmed to perform a specific task.

Steps to Use GPIO as Output Pins

To use the GPIO pins of Raspberry Pi Pico as output pins, follow these steps:

Step 1: Set up your Raspberry Pi Pico board and connect it to your computer via USB.

You can make the KiCad project like following.
Connect a LED via a 220 ohm resistor to the GP4 pins.

You can download and use the symbol and footprint from link below

Raspberry Pi Pico Symbol in KiCad 7 Project Library

To calculate the value of resistor you can use the Ohm’s Law Calculator
Use the following values
V (voltage): 3.3
A (Current) : 0.015
when you press calculate it will give you a resistance value of 220 ohm.

Remember never exceed the current value of 0.015A or 15mA for small leds as higher current may damage the component.

Schematic Diagram Showing LED connected to GP4 Pin via a 220 ohm resistor.

Step 2: Open your preferred code editor and create a new Python script.

Step 3: Import the required libraries by adding the following lines of code at the beginning of your script:

import machine
import utime

The “machine” library provides access to the GPIO pins of Raspberry Pi Pico, and the “utime” library allows us to add delays in our code.

Step 4: Define the pin number you want to use as an output pin. For example, if you want to use GP5 as an output pin, add the following line of code:

led_pin = machine.Pin(4, machine.Pin.OUT)

Here, we are using the “machine.Pin” class to define the pin number (4) as an output pin.

Step 5: Turn on the LED by setting the output value of the pin to 1. Add the following line of code:

led_pin.value(1)

This will set the output value of the GP4 pin to 1, which will turn on the LED connected to it.

Step 6: Add a delay in your code to keep the LED on for a specific time. For example, if you want to keep the LED on for 2 seconds, add the following line of code:

utime.sleep(2)

This will add a 2-second delay in your code.

Step 7: Turn off the LED by setting the output value of the pin to 0. Add the following line of code:

led_pin.value(0)

This will set the output value of the GP4 pin to 0, which will turn off the LED connected to it.

Step 8: Save your code and run it on your Raspberry Pi Pico board. You should see the LED turn on for 2 seconds and then turn off.

Complete Code

import machine
import utime

led_pin = machine.Pin(4, machine.Pin.OUT)

led_pin.value(1)

utime.sleep(2)

led_pin.value(0)

Example Code to try

import machine
import time

led_pin = machine.Pin(4, machine.Pin.OUT)

led_pin.value(1)  # turn on the LED
time.sleep(1)     # wait for a second
led_pin.value(0)  # turn off the LED
time.sleep(1)     # wait for a second

for i in range(10):
    led_pin.value(1)  # turn on the LED
    time.sleep(0.5)   # wait for half a second
    led_pin.value(0)  # turn off the LED
    time.sleep(0.5)   # wait for half a second
Posted on 1 Comment

Raspberry Pi Pico Symbol in KiCad 7 Project Library

This project has all the files necessary to make a project using it.

In this project i have included a symbol library and a footprint library. It is a custom library. You can use this in another project by adding it into the project library list.

This project is made using the KiCad 7.

Symbol library name : RP2040_parts.kicad_sym

Footprint library name: Library.pretty

This project also has the 3d STEP file in it.

Posted on Leave a comment

FreeCAD and KiCAD workflow for Product Design

They are two software packages designed by two independent teams. Both of them are free to use.

To create a product you will need an enclosure that will house all the essential components inside it. And this enclosure can be built in FreeCAD.

I am using FreeCAD 0.20.1

There are some Addons that I have installed.

You can install Addon from “Tools > Addon Manager”

  1. KiCad StepUP workbench
  2. Glass
  3. PieMenu
  4. A2Plus (for making assembly from different individual parts)
  5. Fasteners Workbench (Easy to use the preconstructed model of many standard nuts, bolts, screws, washers, etc.)

KiCad StepUP workbench provides an ECAD-MCAD collaboration tool.

From what I learned in FreeCAD you create Sketch that can be exported to KiCad PCB.

The KiCad uses the Sketch created in the FreeCAD as Edge Cuts.

Edge Cuts are the outline of the PCB in which all your components along with all the tracks, via, hole, and other miscellaneous items must reside.

Youtube video from user mathcodeprint

This video demonstrates a basic example.

It is not a perfect collaborating tool. There are other software tools available from big companies but they are not affordable for a budding engineer.

The ECAD/MCAD collabration proccess:

  1. Design your schematic in Kicad.
  2. Assign Footprint and make sure that each footprint have a 3d model assigned to its footprint.
  3. make a pcb and update the component from the schematics.
    place a grid origin. Using the grid origin draw a rectangle in the edge cut layer.
  4. Save the pcb.
  5. After doing the above steps open the PCB in the FreeCAD KiCadStepUp workbench.
  6. Load the PCB into the freecad environment using the
    “ksu PushPull > Load Board” option
  7. Make changes to the sketch and the 3d model.

If you select a 3d model and make changes to its position.

To make changes to the 3d model. You have to select that particular model. And then you have to select the model from the Model view. Right click on the model in the Model view and select Transform.

Three orthogonal arrow will be preseneted to you in three different color.
You can move the model by selecting the conical arrow heads.

You have to push the changes by selecting that model into the kicad pcb.

After you have saved the kicad will automatically adust its footprint automatically.

It is this PUSH PULL method of making the changes to your pcb dimension and component positions.