Advertisement
Python253

pico_pinout2

Mar 2nd, 2024 (edited)
1,281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.58 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: pico_pinout2.py
  4. # Author: Jeoi Reqi
  5.  
  6. """
  7. Pico Pinout 2 - Raspberry Pi Pico Pinout Mapping Script
  8.  
  9. Description:
  10. This script provides a comprehensive pinout mapping for the Raspberry Pi Pico microcontroller output to the terminal in plain text.
  11. It assists users in understanding the functions associated with each GPIO pin, their aliases, and the corresponding pin types.
  12. The pin types include information on whether a pin serves as a digital input/output, analog input, or has a special function.
  13.  
  14. Usage:
  15. 1. Make sure you have CircuitPython installed on your Raspberry Pi Pico.
  16. 2. Connect your Pico to your computer via USB.
  17. 3. Run this script to generate a detailed pinout mapping for the Raspberry Pi Pico.
  18.  
  19. Requirements:
  20. - Adafruit CircuitPython library installed on your Raspberry Pi Pico.
  21. - Compatible hardware setup with Raspberry Pi Pico.
  22.  
  23. For Adafruit CircuitPython setup instructions, visit:
  24. https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython/overview
  25.  
  26. Note: Ensure your CircuitPython is properly installed before running this script.
  27.  
  28. Enjoy exploring the capabilities of your Raspberry Pi Pico with this convenient pinout mapping tool!
  29. """
  30.  
  31. import microcontroller
  32. import board
  33. from collections import OrderedDict
  34.  
  35. board_pins_mapping = OrderedDict([
  36.     ("GPIO1", 1),
  37.     ("GPIO2", 2),
  38.     ("GPIO3 (Ground)", 3),
  39.     ("GPIO4", 4),
  40.     ("GPIO5", 5),
  41.     ("GPIO6", 6),
  42.     ("GPIO7", 7),
  43.     ("GPIO8 (Ground)", 8),
  44.     ("GPIO9", 9),
  45.     ("GPIO10", 10),
  46.     ("GPIO11", 11),
  47.     ("GPIO12", 12),
  48.     ("GPIO13 (Ground)", 13),
  49.     ("GPIO14", 14),
  50.     ("GPIO15", 15),
  51.     ("GPIO16", 16),
  52.     ("GPIO17", 17),
  53.     ("GPIO18 (Ground)", 18),
  54.     ("GPIO19", 19),
  55.     ("GPIO20", 20),
  56.     ("GPIO21", 21),
  57.     ("GPIO22", 22),
  58.     ("GPIO23 (Ground)", 23),
  59.     ("GPIO24", 24),
  60.     ("GPIO25", 25),
  61.     ("GPIO26", 26),
  62.     ("GPIO27", 27),
  63.     ("GPIO28 (Ground)", 28),
  64.     ("GPIO29", 29),
  65.     ("RUN (Reset)", 30),
  66.     ("GPIO31", 31),
  67.     ("GPIO32", 32),
  68.     ("GPIO33 (Ground, Analog Ground)", 33),
  69.     ("GPIO34", 34),
  70.     ("ADC_VREF", 35),
  71.     ("3V3 (3.3V Output)", 36),
  72.     ("3V3_EN (Enable 3V3 Output)", 37),
  73.     ("GPIO38 (Ground)", 38),
  74.     ("VSYS (System Voltage)", 39),
  75.     ("VBUS (Power Input)", 40),
  76.     ("DEBUG-SWCLK", 41),
  77.     ("DEBUG-GND (Ground)", 42),
  78.     ("DEBUG-SWDIO", 43)
  79. ])
  80.  
  81. # Pin Types
  82. pin_types = {
  83.     1: "SPI0 RX, I2C0 SDA, UART0 TX",
  84.     2: "SPI0 CSn, I2C0 SCL, UART0 RX",
  85.     3: "Ground",
  86.     4: "SPI0 SCK, I2C1 SDA, UART0 CTS",
  87.     5: "SPI0 TX, I2C1 SCL, UART0 RTS",
  88.     6: "SPI0 RX, I2C0 SDA, UART1 TX",
  89.     7: "SPI0 CSn, I2C0 SCL, UART1 RX",
  90.     8: "Ground",
  91.     9: "SPI0 SCK, I2C1 SDA, UART1 CTS",
  92.     10: "SPI0 TX, I2C1 SCL, UART1 RTS",
  93.     11: "SPI1 RX, I2C0 SDA, UART1 TX",
  94.     12: "SPI1 CSn, I2C0 SCL, UART1 RX",
  95.     13: "Ground",
  96.     14: "SPI1 SCK, I2C1 SDA, UART1 CTS",
  97.     15: "SPI1 TX, I2C1 SCL, UART1 RTS",
  98.     16: "SPI1 RX, I2C0 SDA, UART0 TX",
  99.     17: "SPI1 CSn, I2C0 SCL, UART0 RX",
  100.     18: "Ground",
  101.     19: "SPI1 SCK, I2C1 SDA, UART0 CTS",
  102.     20: "SPI1 TX, I2C1 SCL, UART0 RTS",
  103.     21: "I2C0 SCL, UART1 RX",
  104.     22: "I2C0 SDA, UART1 TX",
  105.     23: "Ground",
  106.     24: "SPI0 CSn, I2C",
  107.     25: "SPI0 TX, I2C1 SCL, UART0 RTS",
  108.     26: "I2C0 SDA, UART1 TX",
  109.     27: "I2C0 SCL, UART1 RX",
  110.     28: "Ground",
  111.     29: "SPI0 SCK, I2C1 SDA, UART1 CTS",
  112.     30: "Reset Button",
  113.     31: "ADC0",
  114.     32: "ADC1, I2C1 SCL, UART1 RTS",
  115.     33: "Ground",
  116.     34: "ADC2, UART0 TX",
  117.     35: "ADC_VREF",
  118.     36: "3.3V Output",
  119.     37: "Enable 3V3 Output",
  120.     38: "Ground",
  121.     39: "System Voltage",
  122.     40: "Power Input",
  123.     41: "DEBUG",
  124.     42: "DEBUG Ground",
  125.     43: "DEBUG"
  126. }
  127.  
  128. # Print Pin Mapping
  129. print("------------------------------------------------------------------------------------------\n\t\t\t[Raspberry Pi Pico Board Pins]\n------------------------------------------------------------------------------------------\n\n\n---------\t-------------\t\t\t--------------\t\t------------------\nGPIO Pin:\tAlias:\t\t\t\tPin Functions:\t\t\tPin Types:\n---------\t-------------\t\t\t--------------\t\t------------------\n")
  130.  
  131. for pin, number in board_pins_mapping.items():
  132.     pin_alias = pin
  133.     pin_functions = pin_types.get(number, "Unknown")
  134.     print("GPIO {}: \t{}\t\t\t{}\t\t{}".format(number, pin_alias, pin_functions, pin_types[number]))
  135.  
  136. print("\n------------------------------------------------------------------------------------------\n\t\t\t\t\tEND\n------------------------------------------------------------------------------------------")
  137.  
  138.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement