sylvie-2024

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

esp32_motor-pcb-x3_final.py (8866B)


      1 from skidl import *
      2 
      3 # Set the default tool to KiCad 7 for footprint management.
      4 set_default_tool(KICAD)
      5 
      6 # Create ESP32 and TMC5160 headers with updated part names
      7 esp32_header1 = Part("Connector_Generic", "Conn_01x15", footprint="PinSocket_1x15_P2.54mm_Vertical", ref="ESP32_HEADER1")
      8 esp32_header2 = Part("Connector_Generic", "Conn_01x15", footprint="PinSocket_1x15_P2.54mm_Vertical", ref="ESP32_HEADER2")
      9 
     10 tmc5160_header1 = Part("Connector_Generic", "Conn_01x08", footprint="PinSocket_1x08_P2.54mm_Vertical", ref="TMC5160_HEADER1")
     11 tmc5160_header2 = Part("Connector_Generic", "Conn_01x08", footprint="PinSocket_1x08_P2.54mm_Vertical", ref="TMC5160_HEADER2")
     12 
     13 tmc5160_header1b = Part("Connector_Generic", "Conn_01x08", footprint="PinSocket_1x08_P2.54mm_Vertical", ref="TMC5160_HEADER1B")
     14 tmc5160_header2b = Part("Connector_Generic", "Conn_01x08", footprint="PinSocket_1x08_P2.54mm_Vertical", ref="TMC5160_HEADER2B")
     15 
     16 tmc5160_header1c = Part("Connector_Generic", "Conn_01x08", footprint="PinSocket_1x08_P2.54mm_Vertical", ref="TMC5160_HEADER1C")
     17 tmc5160_header2c = Part("Connector_Generic", "Conn_01x08", footprint="PinSocket_1x08_P2.54mm_Vertical", ref="TMC5160_HEADER2C")
     18 
     19 # Create 1x4 connector for stepper motor connections
     20 stepper_motor_header = Part("Connector_Generic", "Conn_01x04", footprint="PinHeader_1x04_P2.54mm_Vertical", ref="STEPPER_HEADER")
     21 stepper_motor_header_b = Part("Connector_Generic", "Conn_01x04", footprint="PinHeader_1x04_P2.54mm_Vertical", ref="STEPPER_HEADER")
     22 stepper_motor_header_c = Part("Connector_Generic", "Conn_01x04", footprint="PinHeader_1x04_P2.54mm_Vertical", ref="STEPPER_HEADER")
     23 
     24 # Create 1x4 connector for CAN Bus connections
     25 can_bus_header = Part("Connector_Generic", "Conn_01x04", footprint="PinHeader_1x04_P2.54mm_Vertical", ref="CAN_BUS_HEADER")
     26 
     27 # Create 100uF 63V capacitor with correct footprint
     28 capacitor = Part("Device", "C", value="100uF", voltage="63V", footprint="Capacitor_THT:CP_Radial_D10.0mm_P5.00mm")
     29 capacitor_b = Part("Device", "C", value="100uF", voltage="63V", footprint="Capacitor_THT:CP_Radial_D10.0mm_P5.00mm")
     30 capacitor_c = Part("Device", "C", value="100uF", voltage="63V", footprint="Capacitor_THT:CP_Radial_D10.0mm_P5.00mm")
     31 
     32 # Define resistor
     33 #resistor1 = Part("Device", "R", value="220", footprint="R_0603_1608Metric")
     34 
     35 # Create 1x2 horizontal header for limit switch connections
     36 # limit_switch_header = Part("Connector_Generic", "Conn_01x02", footprint="PinHeader_1x02_P2.54mm_Horizontal", ref="LIMIT_SWITCH_HEADER")
     37 
     38 # Create a 3-pin terminal block for 36V connections
     39 terminal_block = Part("Connector_Generic", "Conn_01x03", footprint="TerminalBlock_Phoenix_PT-1,5-2-5.0-H_1x02_P5.00mm_Horizontal", ref="TERMINAL_BLOCK")
     40 
     41 # Create through-hole solder pads for 36V+ and 36V_GND connections with 2.54mm spacing
     42 terminal_block_2 = Part("Connector_Generic", "Conn_01x02", footprint="TerminalBlock_Phoenix_MPT-0,5-2-2.54_1x02_P2.54mm_Horizontal", ref="TERMINAL_BLOCK_2")
     43 
     44 # Create 36V_V+ and 36V_GND nets.
     45 V_plus_36V = Net("36V_V+")
     46 GND_36V = Net("36V_GND")
     47 
     48 # Define the GPIO pins according to ESP32 30pin version.
     49 esp32_vin = esp32_header1[1]
     50 esp32_gnd1 = esp32_header1[2]
     51 esp32_3v3 = esp32_header2[1]
     52 esp32_gnd2 = esp32_header2[2]
     53 esp32_gpio2 = esp32_header2[4]
     54 esp32_gpio4 = esp32_header2[5]
     55 esp32_gpio5 = esp32_header2[8]
     56 esp32_gpio12 = esp32_header1[4]
     57 esp32_gpio13 = esp32_header1[3]
     58 esp32_gpio14 = esp32_header1[5]
     59 esp32_gpio15 = esp32_header2[3]
     60 esp32_gpio16 = esp32_header2[6]
     61 esp32_gpio17 = esp32_header2[7]
     62 esp32_gpio18 = esp32_header2[9]
     63 esp32_gpio19 = esp32_header2[10]
     64 esp32_gpio21 = esp32_header2[11]
     65 esp32_gpio22 = esp32_header2[14]
     66 esp32_gpio23 = esp32_header2[15]
     67 esp32_gpio25 = esp32_header1[8]
     68 esp32_gpio26 = esp32_header1[7]
     69 esp32_gpio27 = esp32_header1[6]
     70 esp32_gpio32 = esp32_header1[10]
     71 esp32_gpio33 = esp32_header1[9]
     72 
     73 # Define the pins for TMC5160
     74 tmc5160_pins = {
     75     'gnd2': tmc5160_header1[8], 
     76     '3v3': tmc5160_header1[7],
     77     'm2b': tmc5160_header1[6],
     78     'm1b': tmc5160_header1[5],
     79     'm1a': tmc5160_header1[4],
     80     'm2a': tmc5160_header1[3],
     81     'gnd1': tmc5160_header1[2],
     82     'vmot': tmc5160_header1[1],
     83     'en': tmc5160_header2[1],
     84     'sdi': tmc5160_header2[2],
     85     'sck': tmc5160_header2[3],
     86     'csn': tmc5160_header2[4],
     87     'sdo': tmc5160_header2[5],
     88     'step': tmc5160_header2[7],
     89     'dir': tmc5160_header2[8]
     90 }
     91 
     92 # Define the pins for TMC5160b
     93 tmc5160b_pins = {
     94     'gnd2': tmc5160_header1b[8], 
     95     '3v3': tmc5160_header1b[7],
     96     'm2b': tmc5160_header1b[6],
     97     'm1b': tmc5160_header1b[5],
     98     'm1a': tmc5160_header1b[4],
     99     'm2a': tmc5160_header1b[3],
    100     'gnd1': tmc5160_header1b[2],
    101     'vmot': tmc5160_header1b[1],
    102     'en': tmc5160_header2b[1],
    103     'sdi': tmc5160_header2b[2],
    104     'sck': tmc5160_header2b[3],
    105     'csn': tmc5160_header2b[4],
    106     'sdo': tmc5160_header2b[5],
    107     'step': tmc5160_header2b[7],
    108     'dir': tmc5160_header2b[8]
    109 }
    110 
    111 # Define the pins for TMC5160c
    112 tmc5160c_pins = {
    113     'gnd2': tmc5160_header1c[8], 
    114     '3v3': tmc5160_header1c[7],
    115     'm2b': tmc5160_header1c[6],
    116     'm1b': tmc5160_header1c[5],
    117     'm1a': tmc5160_header1c[4],
    118     'm2a': tmc5160_header1c[3],
    119     'gnd1': tmc5160_header1c[2],
    120     'vmot': tmc5160_header1c[1],
    121     'en': tmc5160_header2c[1],
    122     'sdi': tmc5160_header2c[2],
    123     'sck': tmc5160_header2c[3],
    124     'csn': tmc5160_header2c[4],
    125     'sdo': tmc5160_header2c[5],
    126     'step': tmc5160_header2c[7],
    127     'dir': tmc5160_header2c[8]
    128 }
    129 
    130 # Create VIN and GND nets.
    131 vin = Net("VIN")
    132 gnd = Net("GND")
    133 
    134 # Create 3.3v gnd net.
    135 vcc_gnd = Net("VCC_GND")
    136 
    137 # Connect 36V_V+ and 36V_GND to the terminal block
    138 V_plus_36V += terminal_block[1]  # Connect 36V_V+ to the first pin of the PT terminal block slot 1
    139 GND_36V += terminal_block[2]     # Connect 36V_GND to the third pin of the PT terminal block slot 2
    140 
    141 # Connect VIN and GND to ESP32 header 2.
    142 vin += terminal_block_2[1] # Connect VIN to the MPT TerminalBlock slot 1
    143 gnd += terminal_block_2[2] # Connect GND to the MPT TerminalBlock slot 2
    144 
    145 # Connect capacitor between 36V_V+ and 36V_GND nets
    146 capacitor[1, 2] += V_plus_36V, GND_36V
    147 capacitor_b[1, 2] += V_plus_36V, GND_36V
    148 capacitor_c[1, 2] += V_plus_36V, GND_36V
    149 
    150 # Connect one pin of the limit switch header to the resistor and the other pin to ESP32 3.3v (Pull-down Resistor!)
    151 # limit_switch_header[1] += resistor1[2], esp32_header1[5]  # Connect pin 1 of limit switch header to one pin of the resistor, and pin 5 on esp32 header 1
    152 # limit_switch_header[2] += esp32_header2[1]           # Connect pin 2 of limit switch header to ESP32 3.3v pin
    153 
    154 # Connect VIN and GND to ESP32 and TMC5160 pins.
    155 vin += esp32_vin
    156 gnd += esp32_gnd1
    157 
    158 vcc_gnd += esp32_gnd2
    159 
    160 # vcc_gnd += resistor1[1] # GND connected to Resistor pin 1
    161 
    162 # Connect all the CAN Bus headers to the ESP32 Header 2
    163 can_bus_header[1] += esp32_3v3 # 3.3v
    164 can_bus_header[2] += esp32_gnd2 # GND
    165 can_bus_header[3] += esp32_gpio4 # CAN TX
    166 can_bus_header[4] += esp32_gpio5 # CAN RX
    167 
    168 # First TMC5160 Instance
    169 esp32_3v3 += tmc5160_pins['3v3']
    170 esp32_gnd2 += tmc5160_pins['gnd2']
    171 V_plus_36V += tmc5160_pins['vmot']
    172 GND_36V += tmc5160_pins['gnd1']
    173 vcc_gnd += tmc5160_pins['gnd2']
    174 esp32_gpio13 += tmc5160_pins['dir']
    175 esp32_gpio12 += tmc5160_pins['step']
    176 esp32_gpio15 += tmc5160_pins['en']
    177 esp32_gpio23 += tmc5160_pins['sdi']
    178 esp32_gpio19 += tmc5160_pins['sdo']
    179 esp32_gpio18 += tmc5160_pins['sck']
    180 esp32_gpio14 += tmc5160_pins['csn']
    181 stepper_motor_header[1] += tmc5160_pins['m2a']
    182 stepper_motor_header[2] += tmc5160_pins['m1a']
    183 stepper_motor_header[3] += tmc5160_pins['m1b']
    184 stepper_motor_header[4] += tmc5160_pins['m2b']
    185 
    186 # Second TMC5160 Instance
    187 esp32_3v3 += tmc5160b_pins['3v3']
    188 esp32_gnd2 += tmc5160b_pins['gnd2']
    189 V_plus_36V += tmc5160b_pins['vmot']
    190 GND_36V += tmc5160b_pins['gnd1']
    191 vcc_gnd += tmc5160b_pins['gnd2']
    192 esp32_gpio27 += tmc5160b_pins['dir']
    193 esp32_gpio26 += tmc5160b_pins['step']
    194 esp32_gpio17 += tmc5160b_pins['en']
    195 esp32_gpio23 += tmc5160b_pins['sdi']
    196 esp32_gpio19 += tmc5160b_pins['sdo']
    197 esp32_gpio18 += tmc5160b_pins['sck']
    198 esp32_gpio25 += tmc5160b_pins['csn']
    199 stepper_motor_header_b[1] += tmc5160b_pins['m2a']
    200 stepper_motor_header_b[2] += tmc5160b_pins['m1a']
    201 stepper_motor_header_b[3] += tmc5160b_pins['m1b']
    202 stepper_motor_header_b[4] += tmc5160b_pins['m2b']
    203 
    204 # Third TMC5160 Instance
    205 esp32_3v3 += tmc5160c_pins['3v3']
    206 esp32_gnd2 += tmc5160c_pins['gnd2']
    207 V_plus_36V += tmc5160c_pins['vmot']
    208 GND_36V += tmc5160c_pins['gnd1']
    209 vcc_gnd += tmc5160c_pins['gnd2']
    210 esp32_gpio32 += tmc5160c_pins['dir']
    211 esp32_gpio2 += tmc5160c_pins['step']
    212 esp32_gpio22 += tmc5160c_pins['en']
    213 esp32_gpio23 += tmc5160c_pins['sdi']
    214 esp32_gpio19 += tmc5160c_pins['sdo']
    215 esp32_gpio18 += tmc5160c_pins['sck']
    216 esp32_gpio33 += tmc5160c_pins['csn']
    217 stepper_motor_header_c[1] += tmc5160c_pins['m2a']
    218 stepper_motor_header_c[2] += tmc5160c_pins['m1a']
    219 stepper_motor_header_c[3] += tmc5160c_pins['m1b']
    220 stepper_motor_header_c[4] += tmc5160c_pins['m2b']
    221 
    222 generate_netlist()
    223