Geen omschrijving
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 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. * The "Threads" library used by this project is:
  19. * Copyright 2022 Dan Kirshner - dan_kirshner@yahoo.com
  20. *
  21. * This program is free software: you can redistribute it and/or modify
  22. * it under the terms of the GNU General Public License as published by
  23. * the Free Software Foundation, either version 3 of the License, or
  24. * (at your option) any later version.
  25. *
  26. * This program is distributed in the hope that it will be useful,
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. * GNU General Public License for more details.
  30. *
  31. * See <http://www.gnu.org/licenses/>.
  32. */
  33. // https://www.thingiverse.com/thing:421524
  34. use <external/cherry_mx.scad>
  35. // https://dkprojects.net/openscad-threads/
  36. use <external/threads.scad>
  37. //use <threadlib.scad>
  38. // ######################
  39. // ## Rendering Select ##
  40. // ######################
  41. //ball_and_roller();
  42. //pico();
  43. //sensor();
  44. //mx_switch_cutout(wall);
  45. //mx_switch_test();
  46. //roller_mount_test();
  47. roller_mount_tri();
  48. //roller_holder();
  49. //trackball();
  50. // #######################
  51. // #### Configuration ####
  52. // #######################
  53. ball_dia = 38.0;
  54. roller_dia = 3.0;
  55. roller_ball_h = 8;
  56. roller_count = 3;
  57. wall = 3.0;
  58. cut_roller_holder = false;
  59. draw_threads = true;
  60. $c = 0.1;
  61. $e = 0.01;
  62. // #######################
  63. // ## Raspberry Pi Pico ##
  64. // #######################
  65. pico_w = 21;
  66. pico_l = 51;
  67. pico_d = 1.6; // todo
  68. pico_hole_d = 2.1;
  69. pico_hole_x = 4.8;
  70. pico_hole_y = 2.0;
  71. pico_hole_d_x = 11.4;
  72. pico_hole_d_y = pico_l - 2 * pico_hole_y;
  73. pico_usb_w = 8.0;
  74. pico_usb_h = 3.0; // todo
  75. pico_usb_d = 10.0; // todo
  76. pico_usb_off = 1.3;
  77. pico_h = pico_d + 1; // todo
  78. // ######################
  79. // ### PMW3360 Sensor ###
  80. // ######################
  81. // https://github.com/jfedor2/pmw3360-breakout
  82. sensor_w = 22;
  83. sensor_l = 34;
  84. sensor_pcb_h = 1.6;
  85. sensor_hole_dia = 2.2;
  86. sensor_hole_off_x = 3.0;
  87. sensor_hole_off_y = 3.0;
  88. sensor_hole_dist_x = 16.0;
  89. sensor_hole_dist_y = 24.5;
  90. sensor_cut_w = 8.0 + 0.5;
  91. sensor_cut_h = 17.26;
  92. sensor_cut_off_x = 7.0 - 0.25;
  93. sensor_cut_off_y = 5.27;
  94. sensor_cut_edge_to_pin1 = 2.75;
  95. sensor_edge_to_pin1 = 1.52;
  96. sensor_ball_to_lens_top = 2.4;
  97. sensor_ball_to_chip_bottom = 9.81;
  98. sensor_chip_w = 9.1;
  99. sensor_chip_l = 16.2;
  100. sensor_chip_h = 2.21;
  101. sensor_pin_w = 0.5;
  102. sensor_pin_h = 4.51;
  103. sensor_pin_d = 0.2;
  104. sensor_pin_dist = 10.7;
  105. sensor_pin_off_top = 0.5;
  106. sensor_pin_pitch = 0.89;
  107. sensor_pin1_to_optical_center = 5.66;
  108. // ######################
  109. // ## MX Switch Cutout ##
  110. // ######################
  111. // https://geekhack.org/index.php?topic=70654.0
  112. mx_co_w = 14.0;
  113. mx_co_w_add = 0.8;
  114. mx_co_h = 14.0;
  115. mx_co_h_off_1 = 1.0;
  116. mx_co_h_off_2 = 3.5;
  117. mx_co_h_off_3 = mx_co_h - 2 * (mx_co_h_off_1 + mx_co_h_off_2);
  118. mx_co_r = 0.4;
  119. // https://geekhack.org/index.php?topic=71550.0
  120. mx_co_th = 1.5 - 0.1;
  121. mx_co_b_add = 1.0;
  122. mx_co_b_w = mx_co_w + mx_co_b_add;
  123. mx_co_b_h = mx_co_h + mx_co_b_add;
  124. mx_travel = 3.9;
  125. // ######################
  126. // ### Implementation ###
  127. // ######################
  128. m3_thread=2.7;
  129. m2_thread=1.8;
  130. roller_thread_dia = roller_dia + 5.0;
  131. roller_thread_pitch = 2.0;
  132. roller_h = roller_dia + 7.0;
  133. roller_ball_h_off = 0.4;
  134. roller_ball_hold_off = 0.5;
  135. roller_thread_hole = roller_dia - 1;
  136. roller_small_hole = sphere_r_at_h(roller_ball_hold_off, roller_dia / 2) * 2;
  137. roller_ridge_h = 1.5;
  138. roller_mount_angle_off = 90;
  139. roller_mount_dia = roller_thread_dia + 2.0;
  140. ball_h = 15; // todo
  141. switch_test_w = 25;
  142. $fn = 42;
  143. function sphere_r_at_h(h, r) = r * sin(acos(h / r));
  144. function sphere_angle_at_rh(h, r) = acos(h / r);
  145. module mx_switch_cutout(h) {
  146. translate([-mx_co_w / 2 - mx_co_w_add, -mx_co_h / 2, 0]) {
  147. linear_extrude(h + 1) {
  148. translate([mx_co_w_add, 0]) {
  149. square([mx_co_w, mx_co_h]);
  150. for (x = [mx_co_r / 2, mx_co_w - mx_co_r / 2])
  151. for (y = [mx_co_r / 2, mx_co_h - mx_co_r / 2])
  152. translate([x, y])
  153. circle(r = mx_co_r);
  154. }
  155. for (x = [0, mx_co_w + mx_co_w_add])
  156. for (y = [0, mx_co_h_off_2 + mx_co_h_off_3])
  157. translate([x, mx_co_h_off_1 + y, 0])
  158. square([mx_co_w_add, mx_co_h_off_2]);
  159. }
  160. translate([mx_co_w_add - mx_co_b_add / 2, -mx_co_b_add / 2, -1])
  161. cube([mx_co_b_w, mx_co_b_h, h - mx_co_th + 1]);
  162. }
  163. }
  164. module mx_switch_test() {
  165. difference() {
  166. translate([-switch_test_w / 2, -switch_test_w / 2, 0])
  167. cube([switch_test_w, switch_test_w, wall]);
  168. mx_switch_cutout(wall);
  169. translate([0, -switch_test_w / 2 + 1, wall - 1.0])
  170. linear_extrude(1.1)
  171. text("switch test", size = 3, halign = "center");
  172. }
  173. %translate([0, 0, wall])
  174. rotate([0, 0, 180])
  175. mx_switch($t);
  176. }
  177. module pico() {
  178. translate([-pico_w / 2, -pico_l / 2, 0])
  179. difference() {
  180. union() {
  181. color("green")
  182. cube([pico_w, pico_l, pico_d]);
  183. translate([(pico_w - pico_usb_w) / 2, pico_l - pico_usb_d + pico_usb_off, pico_d])
  184. cube([pico_usb_w, pico_usb_d, pico_usb_h]);
  185. }
  186. for (x = [0, pico_hole_d_x])
  187. for (y = [0, pico_hole_d_y])
  188. translate([pico_hole_x + x, pico_hole_y + y, -1])
  189. cylinder(d = pico_hole_d, h = pico_d + 2);
  190. }
  191. }
  192. module sensor() {
  193. translate([-sensor_w / 2, -sensor_l / 2, 0])
  194. difference() {
  195. color("green")
  196. cube([sensor_w, sensor_l, sensor_pcb_h]);
  197. translate([sensor_cut_off_x, sensor_cut_off_y, -1])
  198. cube([sensor_cut_w, sensor_cut_h, sensor_pcb_h + 2]);
  199. for (x = [0, sensor_hole_dist_x])
  200. for (y = [0, sensor_hole_dist_y])
  201. translate([sensor_hole_off_x + x, sensor_hole_off_y + y, -1])
  202. cylinder(d = sensor_hole_dia, h = sensor_pcb_h + 2);
  203. }
  204. color("#303030")
  205. 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])
  206. cube([sensor_chip_w, sensor_chip_l, sensor_chip_h]);
  207. translate([0, -sensor_l / 2 - 15 * sensor_pin_pitch + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1, 0])
  208. for (p = [0 : 15])
  209. translate([0, p * sensor_pin_pitch, 0])
  210. for (x = [-sensor_pin_dist / 2, sensor_pin_dist / 2])
  211. if (((p % 2 == 0) && (x < 0))
  212. || ((p % 2 == 1) && (x > 0)))
  213. translate([-sensor_pin_d / 2 + x, -sensor_pin_w / 2, -sensor_chip_h + sensor_pin_off_top])
  214. cube([sensor_pin_d, sensor_pin_w, sensor_pin_h]);
  215. color("cyan")
  216. translate([0, -sensor_l / 2 + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1 - sensor_pin1_to_optical_center, -sensor_chip_h + 1])
  217. cylinder(d = 0.2, h = sensor_ball_to_chip_bottom - 1);
  218. }
  219. module ball_and_roller() {
  220. color("red")
  221. sphere(d = ball_dia, $fn = 200);
  222. for (r = [0 : roller_count - 1])
  223. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  224. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  225. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  226. translate([0, 0, -roller_dia / 2])
  227. roller_holder();
  228. }
  229. module roller_holder() {
  230. echo(roller_h);
  231. translate([0, 0, -roller_h + roller_dia / 2])
  232. difference() {
  233. color("magenta")
  234. union() {
  235. // top screw part
  236. translate([0, 0, roller_h-roller_dia/2 + roller_ball_h_off-3])
  237. cylinder(d1 = roller_mount_dia, d2=roller_dia+1, h = 3);
  238. cylinder(d = roller_mount_dia, h = roller_h-roller_dia/2 + roller_ball_h_off-3);
  239. }
  240. translate([0, 0, -$e]) {
  241. cylinder(d = roller_thread_hole, h = $e+ roller_h - roller_dia / 2 + roller_ball_h_off + roller_ball_hold_off);
  242. }
  243. translate([0, 0, roller_h - roller_dia / 2])
  244. sphere(d = roller_dia , $fn=$fn*4 );
  245. if (cut_roller_holder) {
  246. translate([-roller_thread_dia / 2 - 1, -roller_thread_dia, -1])
  247. cube([roller_thread_dia + 2, roller_thread_dia, roller_h + 2]);
  248. }
  249. }
  250. %color("blue")
  251. sphere(d = roller_dia);
  252. }
  253. module roller_mount() {
  254. echo(roller_h);
  255. translate([0, 0, -1-roller_h + roller_dia / 2]) {
  256. difference() {
  257. cylinder(d=roller_mount_dia+wall,h=roller_h/2);
  258. translate([0,0,1])
  259. cylinder(d=roller_mount_dia+$c*2,h=roller_h/2+$e);
  260. }
  261. }
  262. }
  263. module roller_mount_test() {
  264. roller_holder();
  265. roller_mount();
  266. }
  267. module roller_mount_tri() {
  268. difference() {
  269. union(){
  270. difference() {
  271. hull() {
  272. translate([0, 0, 0])
  273. for (r = [0 : roller_count - 1])
  274. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  275. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  276. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  277. translate([0, 0, -roller_h])
  278. cylinder(d=roller_mount_dia+wall+1,h=roller_h+1);
  279. translate([0,0,-ball_dia/2-5])
  280. cylinder(d=base_dia,h=$e);
  281. }
  282. for (r = [0 : roller_count - 1])
  283. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  284. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  285. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  286. translate([0, 0, -roller_h])
  287. cylinder(d=roller_mount_dia+0.2,h=ball_dia/2+roller_h);
  288. sphere($fn=$fn*4, d=ball_dia+$c*2+1);
  289. }
  290. for (r = [0 : roller_count - 1])
  291. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  292. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  293. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  294. translate([0, 0, 0])
  295. roller_mount();
  296. }
  297. translate([0, 0, 0])
  298. for (r = [0 : roller_count - 1])
  299. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  300. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  301. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  302. translate([0, 0, -roller_h/2])
  303. rotate([0,-90,0])
  304. translate([0,0,2])
  305. {
  306. cylinder(d=m2_thread,h=ball_dia);
  307. translate([0,0,roller_mount_dia/4+wall])
  308. cylinder(d=m2_thread+1,h=ball_dia);
  309. }
  310. }
  311. }
  312. base_dia = pico_l + 9;
  313. module trackball() {
  314. %translate([0, 0, ball_dia / 2 + ball_h])
  315. ball_and_roller();
  316. %rotate([0, 180, 0])
  317. pico();
  318. %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])
  319. sensor();
  320. translate([0, 0, ball_dia / 2 + ball_h])
  321. for (r = [0 : roller_count - 1])
  322. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  323. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  324. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  325. translate([0, 0, -roller_dia / 2])
  326. translate([0, 0, -roller_h + roller_dia / 2 - roller_ball_h_off])
  327. roller_mount();
  328. color("grey")
  329. translate([0, 0, -8])
  330. cylinder(d = base_dia, h = wall);
  331. }