Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

trackball.scad 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. /*
  2. * Trackball
  3. * Copyright 2022 Thomas Buck - thomas@xythobuz.de
  4. *
  5. * Required parts:
  6. * - 1x Raspberry Pi Pico
  7. * - 5x Cherry MX compatible switches and keycaps
  8. * - 1x Billard ball, diameter 38mm
  9. * - 3x Si3N4 static bearing balls, diameter 3mm
  10. * - 3x spring, diameter 2mm, length 10mm
  11. * - 1x PMW3360 sensor with breakout board
  12. * - 8x M2 screw, length 5mm
  13. * - 8x M2 heat melt insert, length 4mm
  14. *
  15. * For the PMW3360 breakout board get this:
  16. * https://github.com/jfedor2/pmw3360-breakout
  17. *
  18. * This program is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation, either version 3 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * See <http://www.gnu.org/licenses/>.
  29. */
  30. // https://www.thingiverse.com/thing:421524
  31. use <external/cherry_mx.scad>
  32. // ######################
  33. // ## Rendering Select ##
  34. // ######################
  35. //ball_and_roller();
  36. //pico();
  37. //sensor();
  38. //mx_switch_cutout(wall);
  39. //mx_switch_test();
  40. //roller_mount_test();
  41. roller_mount_tri();
  42. //roller_holder();
  43. //trackball();
  44. // #######################
  45. // #### Configuration ####
  46. // #######################
  47. ball_dia = 38.0;
  48. roller_dia = 3.0;
  49. roller_ball_h = ball_dia / 2 - 5;
  50. roller_count = 3;
  51. wall = 3.0;
  52. $c = 0.1;
  53. $e = 0.01;
  54. cut_roller_holder = false;
  55. draw_supports = false;
  56. // #######################
  57. // ## Raspberry Pi Pico ##
  58. // #######################
  59. pico_w = 21;
  60. pico_l = 51;
  61. pico_d = 1.6; // todo
  62. pico_hole_d = 2.1;
  63. pico_hole_x = 4.8;
  64. pico_hole_y = 2.0;
  65. pico_hole_d_x = 11.4;
  66. pico_hole_d_y = pico_l - 2 * pico_hole_y;
  67. pico_usb_w = 8.0;
  68. pico_usb_h = 3.0; // todo
  69. pico_usb_d = 10.0; // todo
  70. pico_usb_off = 1.3;
  71. pico_h = pico_d + 1; // todo
  72. // ######################
  73. // ### PMW3360 Sensor ###
  74. // ######################
  75. // https://github.com/jfedor2/pmw3360-breakout
  76. sensor_w = 22;
  77. sensor_l = 34;
  78. sensor_pcb_h = 1.6;
  79. sensor_hole_dia = 2.2;
  80. sensor_hole_off_x = 3.0;
  81. sensor_hole_off_y = 3.0;
  82. sensor_hole_dist_x = 16.0;
  83. sensor_hole_dist_y = 24.5;
  84. sensor_cut_w = 8.0 + 0.5;
  85. sensor_cut_h = 17.26;
  86. sensor_cut_off_x = 7.0 - 0.25;
  87. sensor_cut_off_y = 5.27;
  88. sensor_cut_edge_to_pin1 = 2.75;
  89. sensor_edge_to_pin1 = 1.52;
  90. sensor_ball_to_lens_top = 2.4;
  91. sensor_ball_to_chip_bottom = 9.81;
  92. sensor_chip_w = 9.1;
  93. sensor_chip_l = 16.2;
  94. sensor_chip_h = 2.21;
  95. sensor_pin_w = 0.5;
  96. sensor_pin_h = 4.51;
  97. sensor_pin_d = 0.2;
  98. sensor_pin_dist = 10.7;
  99. sensor_pin_off_top = 0.5;
  100. sensor_pin_pitch = 0.89;
  101. sensor_pin1_to_optical_center = 5.66;
  102. sensor_lens_cutout_r = 2.0;
  103. sensor_lens_cutout_w = 4.0;
  104. sensor_lens_cutout_growth = 0.25;
  105. sensor_lens_cutout_to_chip = 6.71 - 1.60;
  106. sensor_lens_baseplate_h = 2.40;
  107. sensor_lens_d = 19.0 + 1.0;
  108. sensor_lens_w = 21.35 + 0.2;
  109. sensor_lens_off = 10.97;
  110. // ######################
  111. // ## MX Switch Cutout ##
  112. // ######################
  113. // https://geekhack.org/index.php?topic=70654.0
  114. mx_co_w = 14.0;
  115. mx_co_w_add = 0.8;
  116. mx_co_h = 14.0;
  117. mx_co_h_off_1 = 1.0;
  118. mx_co_h_off_2 = 3.5;
  119. mx_co_h_off_3 = mx_co_h - 2 * (mx_co_h_off_1 + mx_co_h_off_2);
  120. mx_co_r = 0.4;
  121. // https://geekhack.org/index.php?topic=71550.0
  122. mx_co_th = 1.5 - 0.1;
  123. mx_co_b_add = 1.0;
  124. mx_co_b_w = mx_co_w + mx_co_b_add;
  125. mx_co_b_h = mx_co_h + mx_co_b_add;
  126. mx_travel = 3.9;
  127. // ######################
  128. // ### Implementation ###
  129. // ######################
  130. base_dia = pico_l + 9;
  131. m3_thread = 2.7;
  132. m2_thread = 1.8;
  133. roller_thread_dia = roller_dia + 5.0;
  134. roller_h = roller_dia + 7.0;
  135. roller_ball_h_off = 0.4;
  136. roller_ball_hold_off = 0.5;
  137. roller_thread_hole = roller_dia - 1;
  138. roller_small_hole = sphere_r_at_h(roller_ball_hold_off, roller_dia / 2) * 2;
  139. roller_ridge_h = 1.5;
  140. roller_mount_angle_off = 90;
  141. roller_mount_dia = roller_thread_dia + 2.0;
  142. ball_h = 15; // todo
  143. switch_test_w = 25;
  144. $fn = 100;
  145. function sphere_r_at_h(h, r) = r * sin(acos(h / r));
  146. function sphere_angle_at_rh(h, r) = acos(h / r);
  147. module mx_switch_cutout(h) {
  148. translate([-mx_co_w / 2 - mx_co_w_add, -mx_co_h / 2, 0]) {
  149. linear_extrude(h + 1) {
  150. translate([mx_co_w_add, 0]) {
  151. square([mx_co_w, mx_co_h]);
  152. for (x = [mx_co_r / 2, mx_co_w - mx_co_r / 2])
  153. for (y = [mx_co_r / 2, mx_co_h - mx_co_r / 2])
  154. translate([x, y])
  155. circle(r = mx_co_r);
  156. }
  157. for (x = [0, mx_co_w + mx_co_w_add])
  158. for (y = [0, mx_co_h_off_2 + mx_co_h_off_3])
  159. translate([x, mx_co_h_off_1 + y, 0])
  160. square([mx_co_w_add, mx_co_h_off_2]);
  161. }
  162. translate([mx_co_w_add - mx_co_b_add / 2, -mx_co_b_add / 2, -1])
  163. cube([mx_co_b_w, mx_co_b_h, h - mx_co_th + 1]);
  164. }
  165. }
  166. module mx_switch_test() {
  167. difference() {
  168. translate([-switch_test_w / 2, -switch_test_w / 2, 0])
  169. cube([switch_test_w, switch_test_w, wall]);
  170. mx_switch_cutout(wall);
  171. translate([0, -switch_test_w / 2 + 1, wall - 1.0])
  172. linear_extrude(1.1)
  173. text("switch test", size = 3, halign = "center");
  174. }
  175. %translate([0, 0, wall])
  176. rotate([0, 0, 180])
  177. mx_switch($t);
  178. }
  179. module pico() {
  180. translate([-pico_w / 2, -pico_l / 2, 0])
  181. difference() {
  182. union() {
  183. color("green")
  184. cube([pico_w, pico_l, pico_d]);
  185. translate([(pico_w - pico_usb_w) / 2, pico_l - pico_usb_d + pico_usb_off, pico_d])
  186. cube([pico_usb_w, pico_usb_d, pico_usb_h]);
  187. }
  188. for (x = [0, pico_hole_d_x])
  189. for (y = [0, pico_hole_d_y])
  190. translate([pico_hole_x + x, pico_hole_y + y, -1])
  191. cylinder(d = pico_hole_d, h = pico_d + 2);
  192. }
  193. }
  194. module sensor_lens_cutout_intern() {
  195. cylinder(d = sensor_lens_cutout_r * 2, h = $e);
  196. translate([-sensor_lens_cutout_r, 0, 0])
  197. cube([sensor_lens_cutout_r * 2, sensor_lens_cutout_w, $e]);
  198. }
  199. module rounded_cube(x, y, z, r) {
  200. hull()
  201. for (tx = [r, x - r])
  202. for (ty = [r, y - r])
  203. translate([tx, ty, 0])
  204. cylinder(d = r * 2, h = z);
  205. }
  206. module sensor_lens_cutout() {
  207. translate([0, 0, sensor_lens_cutout_to_chip])
  208. hull() {
  209. translate([0, 0, sensor_lens_baseplate_h - $e])
  210. sensor_lens_cutout_intern();
  211. scale(1 + sensor_lens_cutout_growth * sensor_lens_baseplate_h)
  212. sensor_lens_cutout_intern();
  213. }
  214. translate([-sensor_lens_d / 2, -sensor_lens_w + sensor_lens_off, 0])
  215. rounded_cube(sensor_lens_d, sensor_lens_w, sensor_lens_cutout_to_chip, 6);
  216. translate([-3 / 2, -sensor_lens_w + sensor_lens_off - 0.5, 0])
  217. cube([3, 0.5, sensor_lens_cutout_to_chip]);
  218. }
  219. module sensor() {
  220. translate([-sensor_w / 2, -sensor_l / 2, 0])
  221. difference() {
  222. color("green")
  223. cube([sensor_w, sensor_l, sensor_pcb_h]);
  224. translate([sensor_cut_off_x, sensor_cut_off_y, -1])
  225. cube([sensor_cut_w, sensor_cut_h, sensor_pcb_h + 2]);
  226. for (x = [0, sensor_hole_dist_x])
  227. for (y = [0, sensor_hole_dist_y])
  228. translate([sensor_hole_off_x + x, sensor_hole_off_y + y, -1])
  229. cylinder(d = sensor_hole_dia, h = sensor_pcb_h + 2);
  230. }
  231. color("#303030")
  232. translate([-sensor_chip_w / 2, -sensor_l / 2 - sensor_chip_l + sensor_edge_to_pin1 + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1, -sensor_chip_h])
  233. cube([sensor_chip_w, sensor_chip_l, sensor_chip_h]);
  234. translate([0, -sensor_l / 2 - 15 * sensor_pin_pitch + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1, 0])
  235. for (p = [0 : 15])
  236. translate([0, p * sensor_pin_pitch, 0])
  237. for (x = [-sensor_pin_dist / 2, sensor_pin_dist / 2])
  238. if (((p % 2 == 0) && (x < 0))
  239. || ((p % 2 == 1) && (x > 0)))
  240. translate([-sensor_pin_d / 2 + x, -sensor_pin_w / 2, -sensor_chip_h + sensor_pin_off_top])
  241. cube([sensor_pin_d, sensor_pin_w, sensor_pin_h]);
  242. translate([0, -sensor_l / 2 + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1 - sensor_pin1_to_optical_center, 0]) {
  243. color("cyan")
  244. translate([0, 0, -sensor_chip_h + 1])
  245. cylinder(d = 0.2, h = sensor_ball_to_chip_bottom - 1);
  246. %color("blue")
  247. sensor_lens_cutout();
  248. }
  249. }
  250. module ball_and_roller() {
  251. color("red")
  252. sphere(d = ball_dia, $fn = $fn * 2);
  253. for (r = [0 : roller_count - 1])
  254. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  255. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  256. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  257. translate([0, 0, -roller_dia / 2])
  258. roller_holder();
  259. }
  260. module roller_holder() {
  261. translate([0, 0, -roller_h + roller_dia / 2])
  262. difference() {
  263. color("magenta")
  264. union() {
  265. // top screw part
  266. translate([0, 0, roller_h-roller_dia/2 + roller_ball_h_off-3])
  267. cylinder(d1 = roller_mount_dia, d2=roller_dia+1, h = 3);
  268. cylinder(d = roller_mount_dia, h = roller_h-roller_dia/2 + roller_ball_h_off-3);
  269. }
  270. translate([0, 0, -$e])
  271. cylinder(d = roller_thread_hole, h = $e+ roller_h - roller_dia / 2 + roller_ball_h_off + roller_ball_hold_off);
  272. translate([0, 0, roller_h - roller_dia / 2])
  273. sphere(d = roller_dia, $fn = $fn * 2);
  274. if (cut_roller_holder)
  275. translate([-roller_thread_dia / 2 - 1, -roller_thread_dia, -1])
  276. cube([roller_thread_dia + 2, roller_thread_dia, roller_h + 2]);
  277. }
  278. %color("blue")
  279. sphere(d = roller_dia, $fn = $fn * 2);
  280. }
  281. module roller_mount() {
  282. translate([0, 0, -1-roller_h + roller_dia / 2]) {
  283. difference() {
  284. cylinder(d=roller_mount_dia+wall,h=roller_h/2);
  285. translate([0, 0, 1])
  286. cylinder(d=roller_mount_dia+$c*2,h=roller_h/2+$e);
  287. if (cut_roller_holder)
  288. translate([-roller_thread_dia / 2 - 1, -roller_thread_dia, -1])
  289. cube([roller_thread_dia + 2, roller_thread_dia, roller_h + 2]);
  290. }
  291. }
  292. }
  293. module roller_mount_test() {
  294. roller_holder();
  295. roller_mount();
  296. }
  297. roller_mount_holder_gap = 0.8;
  298. sensor_pcb_mount_gap = 2.0;
  299. sensor_pcb_support_h = 1.6 + 3.4;
  300. module roller_mount_tri() {
  301. %ball_and_roller();
  302. difference() {
  303. union() {
  304. difference() {
  305. hull() {
  306. for (r = [0 : roller_count - 1])
  307. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  308. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  309. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  310. translate([0, 0, -roller_h])
  311. cylinder(d = roller_mount_dia + wall + 1, h = roller_h - 3);
  312. translate([0, 0, -ball_dia / 2 - 11])
  313. cylinder(d = base_dia, h = $e);
  314. }
  315. for (r = [0 : roller_count - 1])
  316. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  317. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  318. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  319. translate([0, 0, -roller_h])
  320. cylinder(d = roller_mount_dia + roller_mount_holder_gap, h = ball_dia / 2 + roller_h);
  321. sphere($fn = $fn * 2, d = ball_dia + $c * 2 + 4);
  322. }
  323. }
  324. for (r = [0 : roller_count - 1])
  325. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  326. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  327. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  328. translate([0, 0, -roller_h/2])
  329. rotate([0,-90,0])
  330. translate([-2, 0, 2]) {
  331. cylinder(d = m2_thread, h = ball_dia);
  332. translate([0, 0, roller_mount_dia / 4 + wall])
  333. cylinder(d = m2_thread + 1, h = ball_dia);
  334. }
  335. translate([0, 0, -ball_dia / 2 - ball_h])
  336. translate([0, sensor_l / 2 - sensor_cut_off_y - sensor_cut_h + sensor_cut_edge_to_pin1 + sensor_pin1_to_optical_center, ball_h + sensor_chip_h - sensor_ball_to_chip_bottom])
  337. translate([0, -sensor_l / 2 + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1 - sensor_pin1_to_optical_center, 0])
  338. sensor_lens_cutout();
  339. translate([-1, -1, -ball_dia / 2 - ball_h])
  340. translate([0, sensor_l / 2 - sensor_cut_off_y - sensor_cut_h + sensor_cut_edge_to_pin1 + sensor_pin1_to_optical_center, ball_h + sensor_chip_h - sensor_ball_to_chip_bottom])
  341. translate([-sensor_w / 2, -sensor_l / 2, -10])
  342. cube([sensor_w + 2, sensor_l + 2, sensor_pcb_h + 10 + sensor_pcb_mount_gap]);
  343. // TODO test cable cutout
  344. translate([-6, 0, -30.1])
  345. cube([12, 50, 2]);
  346. if (cut_roller_holder)
  347. translate([0, -base_dia / 2 - 1, -40])
  348. cube([base_dia / 2 + 1, base_dia + 2, 40]);
  349. }
  350. translate([-sensor_w / 2, -sensor_l / 2, sensor_pcb_h])
  351. translate([0, 0, -ball_dia / 2 - ball_h])
  352. translate([0, sensor_l / 2 - sensor_cut_off_y - sensor_cut_h + sensor_cut_edge_to_pin1 + sensor_pin1_to_optical_center, ball_h + sensor_chip_h - sensor_ball_to_chip_bottom])
  353. for (x = [0, sensor_hole_dist_x])
  354. for (y = [0, sensor_hole_dist_y])
  355. translate([sensor_hole_off_x + x, sensor_hole_off_y + y, 0])
  356. difference() {
  357. union() {
  358. color("magenta")
  359. cylinder(d = sensor_hole_dia + 1.5, h = sensor_pcb_mount_gap);
  360. if (draw_supports)
  361. color("black")
  362. translate([0, 0, -sensor_pcb_support_h])
  363. cylinder(d = sensor_hole_dia + 0.5, h = sensor_pcb_support_h);
  364. }
  365. cylinder(d = sensor_hole_dia - 0.2, h = sensor_pcb_mount_gap + 1);
  366. }
  367. if (draw_supports)
  368. color("black")
  369. for (x = [-5, 0, 5])
  370. for (y = [-8, 0, 6.5])
  371. if (((x == 0) && (y != 0)) || ((x != 0) && (y == 0)))
  372. translate([x, y + 2, -30])
  373. cylinder(d = sensor_hole_dia + 0.5, h = 8.5);
  374. %translate([0, 0, -ball_dia / 2 - ball_h])
  375. translate([0, sensor_l / 2 - sensor_cut_off_y - sensor_cut_h + sensor_cut_edge_to_pin1 + sensor_pin1_to_optical_center, ball_h + sensor_chip_h - sensor_ball_to_chip_bottom])
  376. sensor();
  377. }
  378. module trackball() {
  379. %translate([0, 0, ball_dia / 2 + ball_h])
  380. ball_and_roller();
  381. %rotate([0, 180, 0])
  382. pico();
  383. %translate([0, sensor_l / 2 - sensor_cut_off_y - sensor_cut_h + sensor_cut_edge_to_pin1 + sensor_pin1_to_optical_center, ball_h + sensor_chip_h - sensor_ball_to_chip_bottom])
  384. sensor();
  385. translate([0, 0, ball_dia / 2 + ball_h])
  386. for (r = [0 : roller_count - 1])
  387. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  388. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  389. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  390. translate([0, 0, -roller_dia / 2])
  391. roller_mount();
  392. color("grey")
  393. translate([0, 0, -8])
  394. cylinder(d = base_dia, h = wall);
  395. }