Advertisement
Guest User

Untitled

a guest
Mar 9th, 2025
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.11 KB | None | 0 0
  1. esphome:
  2. name: esphome-web-2e08d0
  3. friendly_name: basement-heater-stepper-2
  4. min_version: 2024.11.0
  5. name_add_mac_suffix: false
  6. on_boot:
  7. - tmc2209.configure:
  8. microsteps: 8
  9. interpolation: true
  10. - tmc2209.stallguard:
  11. threshold: 50
  12. - tmc2209.currents:
  13. standstill_mode: freewheeling
  14. irun: 16
  15. ihold: 0
  16. tpowerdown: 0
  17. iholddelay: 0
  18.  
  19.  
  20.  
  21. esp32:
  22. board: esp32dev
  23. framework:
  24. type: esp-idf
  25.  
  26. # Enable logging
  27. logger:
  28. baud_rate: 0
  29.  
  30. # Enable Home Assistant API
  31. api:
  32.  
  33. # Allow Over-The-Air updates
  34. ota:
  35. - platform: esphome
  36.  
  37. wifi:
  38. ssid: ""
  39. password: ""
  40.  
  41.  
  42. external_components:
  43. - source: github://slimcdk/esphome-custom-components
  44. components: [ tmc2209_hub, tmc2209, stepper ]
  45.  
  46. globals:
  47. - id: has_homed
  48. type: bool
  49. initial_value: "true"
  50. restore_value: no
  51.  
  52. uart:
  53. tx_pin: GPIO16 #tx 1K OHM RESISTOR
  54. rx_pin: GPIO17 #rx
  55. baud_rate: 500000 # 9600 -> 500k
  56.  
  57. stepper:
  58. - platform: tmc2209
  59. id: driver
  60. max_speed: 900 steps/s
  61. acceleration: 1500 steps/s^2
  62. deceleration: 500 steps/s^2
  63. config_dump_include_registers: true
  64. rsense: 110 mOhm
  65. vsense: False
  66. # address: 0x00
  67. enn_pin: GPIO25 #D7
  68. diag_pin: GPIO34 #D2
  69. index_pin: GPIO12 #d5
  70. step_pin: GPIO26 #D2
  71. dir_pin: GPIO14 #D5
  72. on_stall:
  73. - logger.log: "Motor stalled!"
  74. - stepper.stop: driver
  75. - if:
  76. condition:
  77. lambda: return !id(has_homed);
  78. then:
  79. - stepper.report_position:
  80. id: driver
  81. position: 0
  82. - globals.set:
  83. id: has_homed
  84. value: "true"
  85. - logger.log: "Home position set"
  86. on_status:
  87. - logger.log:
  88. format: "Driver is reporting an update! (code %d)"
  89. args: ["code"]
  90. - if:
  91. condition:
  92. lambda: return code == tmc2209::DIAG_TRIGGERED;
  93. then:
  94. - logger.log: DIAG_TRIGGERED
  95. - if:
  96. condition:
  97. lambda: return code == tmc2209::DIAG_TRIGGER_CLEARED;
  98. then:
  99. - logger.log: DIAG_TRIGGER_CLEARED
  100. - if:
  101. condition:
  102. lambda: return code == tmc2209::RESET;
  103. then:
  104. - logger.log: RESET
  105. - if:
  106. condition:
  107. lambda: return code == tmc2209::RESET_CLEARED;
  108. then:
  109. - logger.log: RESET_CLEARED
  110. - if:
  111. condition:
  112. lambda: return code == tmc2209::DRIVER_ERROR;
  113. then:
  114. - logger.log: DRIVER_ERROR
  115. - if:
  116. condition:
  117. lambda: return code == tmc2209::DRIVER_ERROR_CLEARED;
  118. then:
  119. - logger.log: DRIVER_ERROR_CLEARED
  120. - if:
  121. condition:
  122. lambda: return code == tmc2209::CP_UNDERVOLTAGE;
  123. then:
  124. - logger.log: CP_UNDERVOLTAGE
  125. - if:
  126. condition:
  127. lambda: return code == tmc2209::CP_UNDERVOLTAGE_CLEARED;
  128. then:
  129. - logger.log: CP_UNDERVOLTAGE_CLEARED
  130. - if:
  131. condition:
  132. lambda: return code == tmc2209::OVERTEMPERATURE_PREWARNING;
  133. then:
  134. - logger.log: OVERTEMPERATURE_PREWARNING
  135. - if:
  136. condition:
  137. lambda: return code == tmc2209::OVERTEMPERATURE_PREWARNING_CLEARED;
  138. then:
  139. - logger.log: OVERTEMPERATURE_PREWARNING_CLEARED
  140. - if:
  141. condition:
  142. lambda: return code == tmc2209::OVERTEMPERATURE;
  143. then:
  144. - logger.log: OVERTEMPERATURE
  145. - if:
  146. condition:
  147. lambda: return code == tmc2209::OVERTEMPERATURE_CLEARED;
  148. then:
  149. - logger.log: OVERTEMPERATURE_CLEARED
  150. - if:
  151. condition:
  152. lambda: return code == tmc2209::TEMPERATURE_ABOVE_120C;
  153. then:
  154. - logger.log: TEMPERATURE_ABOVE_120C
  155. - if:
  156. condition:
  157. lambda: return code == tmc2209::TEMPERATURE_BELOW_120C;
  158. then:
  159. - logger.log: TEMPERATURE_BELOW_120C
  160. - if:
  161. condition:
  162. lambda: return code == tmc2209::TEMPERATURE_ABOVE_143C;
  163. then:
  164. - logger.log: TEMPERATURE_ABOVE_143C
  165. - if:
  166. condition:
  167. lambda: return code == tmc2209::TEMPERATURE_BELOW_143C;
  168. then:
  169. - logger.log: TEMPERATURE_BELOW_143C
  170. - if:
  171. condition:
  172. lambda: return code == tmc2209::TEMPERATURE_ABOVE_150C;
  173. then:
  174. - logger.log: TEMPERATURE_ABOVE_150C
  175. - if:
  176. condition:
  177. lambda: return code == tmc2209::TEMPERATURE_BELOW_150C;
  178. then:
  179. - logger.log: TEMPERATURE_BELOW_150C
  180. - if:
  181. condition:
  182. lambda: return code == tmc2209::TEMPERATURE_ABOVE_157C;
  183. then:
  184. - logger.log: TEMPERATURE_ABOVE_157C
  185. - if:
  186. condition:
  187. lambda: return code == tmc2209::TEMPERATURE_BELOW_157C;
  188. then:
  189. - logger.log: TEMPERATURE_BELOW_157C
  190. - if:
  191. condition:
  192. lambda: return code == tmc2209::OPEN_LOAD;
  193. then:
  194. - logger.log: OPEN_LOAD
  195. - if:
  196. condition:
  197. lambda: return code == tmc2209::OPEN_LOAD_CLEARED;
  198. then:
  199. - logger.log: OPEN_LOAD_CLEARED
  200. - if:
  201. condition:
  202. lambda: return code == tmc2209::OPEN_LOAD_A;
  203. then:
  204. - logger.log: OPEN_LOAD_A
  205. - if:
  206. condition:
  207. lambda: return code == tmc2209::OPEN_LOAD_A_CLEARED;
  208. then:
  209. - logger.log: OPEN_LOAD_A_CLEARED
  210. - if:
  211. condition:
  212. lambda: return code == tmc2209::OPEN_LOAD_B;
  213. then:
  214. - logger.log: OPEN_LOAD_B
  215. - if:
  216. condition:
  217. lambda: return code == tmc2209::OPEN_LOAD_B_CLEARED;
  218. then:
  219. - logger.log: OPEN_LOAD_B_CLEARED
  220. - if:
  221. condition:
  222. lambda: return code == tmc2209::LOW_SIDE_SHORT;
  223. then:
  224. - logger.log: LOW_SIDE_SHORT
  225. - if:
  226. condition:
  227. lambda: return code == tmc2209::LOW_SIDE_SHORT_CLEARED;
  228. then:
  229. - logger.log: LOW_SIDE_SHORT_CLEARED
  230. - if:
  231. condition:
  232. lambda: return code == tmc2209::LOW_SIDE_SHORT_A;
  233. then:
  234. - logger.log: LOW_SIDE_SHORT_A
  235. - if:
  236. condition:
  237. lambda: return code == tmc2209::LOW_SIDE_SHORT_A_CLEARED;
  238. then:
  239. - logger.log: LOW_SIDE_SHORT_A_CLEARED
  240. - if:
  241. condition:
  242. lambda: return code == tmc2209::LOW_SIDE_SHORT_B;
  243. then:
  244. - logger.log: LOW_SIDE_SHORT_B
  245. - if:
  246. condition:
  247. lambda: return code == tmc2209::LOW_SIDE_SHORT_B_CLEARED;
  248. then:
  249. - logger.log: LOW_SIDE_SHORT_B_CLEARED
  250. - if:
  251. condition:
  252. lambda: return code == tmc2209::GROUND_SHORT;
  253. then:
  254. - logger.log: GROUND_SHORT
  255. - if:
  256. condition:
  257. lambda: return code == tmc2209::GROUND_SHORT_CLEARED;
  258. then:
  259. - logger.log: GROUND_SHORT_CLEARED
  260. - if:
  261. condition:
  262. lambda: return code == tmc2209::GROUND_SHORT_A;
  263. then:
  264. - logger.log: GROUND_SHORT_A
  265. - if:
  266. condition:
  267. lambda: return code == tmc2209::GROUND_SHORT_A_CLEARED;
  268. then:
  269. - logger.log: GROUND_SHORT_A_CLEARED
  270. - if:
  271. condition:
  272. lambda: return code == tmc2209::GROUND_SHORT_B;
  273. then:
  274. - logger.log: GROUND_SHORT_B
  275. - if:
  276. condition:
  277. lambda: return code == tmc2209::GROUND_SHORT_B_CLEARED;
  278. then:
  279. - logger.log: GROUND_SHORT_B_CLEARED
  280.  
  281. button:
  282. - platform: template
  283. name: Home
  284. on_press:
  285. - logger.log: "Going home!"
  286. - globals.set:
  287. id: has_homed
  288. value: "false"
  289. - stepper.set_target:
  290. id: driver
  291. target: -9999999
  292.  
  293. - platform: template
  294. name: 1000 Steps forward
  295. on_press:
  296. - stepper.set_target:
  297. id: driver
  298. target: !lambda return id(driver)->current_position +1000;
  299.  
  300. - platform: template
  301. name: 1000 Steps backward
  302. on_press:
  303. - stepper.set_target:
  304. id: driver
  305. target: !lambda return id(driver)->current_position -1000;
  306.  
  307. - platform: template
  308. name: Stop
  309. on_press:
  310. - stepper.stop: driver
  311.  
  312. number:
  313. - platform: template
  314. name: Target position
  315. min_value: -100000
  316. max_value: 100000
  317. step: 100
  318. lambda: return id(driver)->current_position;
  319. update_interval: 1s
  320. set_action:
  321. - stepper.set_target:
  322. id: driver
  323. target: !lambda "return x;"
  324.  
  325. sensor:
  326. - platform: tmc2209
  327. type: motor_load
  328. name: Motor load
  329. update_interval: 5s
  330.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement