123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- /*
- * Trackball
- * Copyright 2022 Thomas Buck - thomas@xythobuz.de
- *
- * Required parts:
- * - 1x Raspberry Pi Pico
- * - 5x Cherry MX compatible switches and keycaps
- * - 1x Billard ball, diameter 38mm
- * - 3x Si3N4 static bearing balls, diameter 3mm
- * - 3x spring, diameter 2mm, length 10mm
- * - 1x PMW3360 sensor with breakout board
- * - 8x M2 screw, length 5mm
- * - 8x M2 heat melt insert, length 4mm
- *
- * For the PMW3360 breakout board get this:
- * https://github.com/jfedor2/pmw3360-breakout
- *
- * The "Threads" library used by this project is:
- * Copyright 2022 Dan Kirshner - dan_kirshner@yahoo.com
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * See <http://www.gnu.org/licenses/>.
- */
-
- // https://www.thingiverse.com/thing:421524
- use <external/cherry_mx.scad>
-
- // https://dkprojects.net/openscad-threads/
- use <external/threads.scad>
-
- // #######################
- // #### Configuration ####
- // #######################
-
- ball_dia = 38.0;
- roller_dia = 3.0;
-
- roller_ball_h = 8;
- roller_count = 3;
-
- wall = 3.0;
-
- cut_roller_holder = true;
- draw_threads = false;
-
- // #######################
- // ## Raspberry Pi Pico ##
- // #######################
-
- pico_w = 21;
- pico_l = 51;
- pico_d = 1.6; // todo
- pico_hole_d = 2.1;
- pico_hole_x = 4.8;
- pico_hole_y = 2.0;
- pico_hole_d_x = 11.4;
- pico_hole_d_y = pico_l - 2 * pico_hole_y;
- pico_usb_w = 8.0;
- pico_usb_h = 3.0; // todo
- pico_usb_d = 10.0; // todo
- pico_usb_off = 1.3;
-
- pico_h = pico_d + 1; // todo
-
- // ######################
- // ### PMW3360 Sensor ###
- // ######################
-
- // https://github.com/jfedor2/pmw3360-breakout
- sensor_w = 22;
- sensor_l = 34;
- sensor_pcb_h = 1.6;
- sensor_hole_dia = 2.2;
- sensor_hole_off_x = 3.0;
- sensor_hole_off_y = 3.0;
- sensor_hole_dist_x = 16.0;
- sensor_hole_dist_y = 24.5;
- sensor_cut_w = 8.0 + 0.5;
- sensor_cut_h = 17.26;
- sensor_cut_off_x = 7.0 - 0.25;
- sensor_cut_off_y = 5.27;
- sensor_cut_edge_to_pin1 = 2.75;
- sensor_edge_to_pin1 = 1.52;
-
- sensor_ball_to_lens_top = 2.4;
- sensor_ball_to_chip_bottom = 9.81;
-
- sensor_chip_w = 9.1;
- sensor_chip_l = 16.2;
- sensor_chip_h = 2.21;
-
- sensor_pin_w = 0.5;
- sensor_pin_h = 4.51;
- sensor_pin_d = 0.2;
- sensor_pin_dist = 10.7;
- sensor_pin_off_top = 0.5;
- sensor_pin_pitch = 0.89;
-
- sensor_pin1_to_optical_center = 5.66;
-
- // ######################
- // ## MX Switch Cutout ##
- // ######################
-
- // https://geekhack.org/index.php?topic=70654.0
- mx_co_w = 14.0;
- mx_co_w_add = 0.8;
- mx_co_h = 14.0;
- mx_co_h_off_1 = 1.0;
- mx_co_h_off_2 = 3.5;
- mx_co_h_off_3 = mx_co_h - 2 * (mx_co_h_off_1 + mx_co_h_off_2);
- mx_co_r = 0.4;
-
- // https://geekhack.org/index.php?topic=71550.0
- mx_co_th = 1.5 - 0.1;
- mx_co_b_add = 1.0;
- mx_co_b_w = mx_co_w + mx_co_b_add;
- mx_co_b_h = mx_co_h + mx_co_b_add;
-
- mx_travel = 3.9;
-
- // ######################
- // ### Implementation ###
- // ######################
-
- roller_thread_dia = 9.0;
- roller_thread_pitch = 2.5;
- roller_h = roller_dia + 7.0;
- roller_ball_h_off = 0.6;
- roller_ball_hold_off = 0.5;
- roller_thread_hole = roller_dia + 1.0;
- roller_small_hole = sphere_r_at_h(roller_ball_hold_off, roller_dia / 2) * 2;
-
- roller_ridge_h = wall;
- roller_mount_angle_off = 90;
- roller_mount_dia = 11.0;
-
- ball_h = 15; // todo
-
- switch_test_w = 25;
-
- $fn = 42;
-
- function sphere_r_at_h(h, r) = r * sin(acos(h / r));
- function sphere_angle_at_rh(h, r) = acos(h / r);
-
- module mx_switch_cutout(h) {
- translate([-mx_co_w / 2 - mx_co_w_add, -mx_co_h / 2, 0]) {
- linear_extrude(h + 1) {
- translate([mx_co_w_add, 0]) {
- square([mx_co_w, mx_co_h]);
-
- for (x = [mx_co_r / 2, mx_co_w - mx_co_r / 2])
- for (y = [mx_co_r / 2, mx_co_h - mx_co_r / 2])
- translate([x, y])
- circle(r = mx_co_r);
- }
-
- for (x = [0, mx_co_w + mx_co_w_add])
- for (y = [0, mx_co_h_off_2 + mx_co_h_off_3])
- translate([x, mx_co_h_off_1 + y, 0])
- square([mx_co_w_add, mx_co_h_off_2]);
- }
-
- translate([mx_co_w_add - mx_co_b_add / 2, -mx_co_b_add / 2, -1])
- cube([mx_co_b_w, mx_co_b_h, h - mx_co_th + 1]);
- }
- }
-
- module mx_switch_test() {
- difference() {
- translate([-switch_test_w / 2, -switch_test_w / 2, 0])
- cube([switch_test_w, switch_test_w, wall]);
-
- mx_switch_cutout(wall);
-
- translate([0, -switch_test_w / 2 + 1, wall - 1.0])
- linear_extrude(1.1)
- text("switch test", size = 3, halign = "center");
- }
-
- %translate([0, 0, wall])
- rotate([0, 0, 180])
- mx_switch($t);
- }
-
- module pico() {
- translate([-pico_w / 2, -pico_l / 2, 0])
- difference() {
- union() {
- color("green")
- cube([pico_w, pico_l, pico_d]);
-
- translate([(pico_w - pico_usb_w) / 2, pico_l - pico_usb_d + pico_usb_off, pico_d])
- cube([pico_usb_w, pico_usb_d, pico_usb_h]);
- }
-
- for (x = [0, pico_hole_d_x])
- for (y = [0, pico_hole_d_y])
- translate([pico_hole_x + x, pico_hole_y + y, -1])
- cylinder(d = pico_hole_d, h = pico_d + 2);
- }
- }
-
- module sensor() {
- translate([-sensor_w / 2, -sensor_l / 2, 0])
- difference() {
- color("green")
- cube([sensor_w, sensor_l, sensor_pcb_h]);
-
- translate([sensor_cut_off_x, sensor_cut_off_y, -1])
- cube([sensor_cut_w, sensor_cut_h, sensor_pcb_h + 2]);
-
- for (x = [0, sensor_hole_dist_x])
- for (y = [0, sensor_hole_dist_y])
- translate([sensor_hole_off_x + x, sensor_hole_off_y + y, -1])
- cylinder(d = sensor_hole_dia, h = sensor_pcb_h + 2);
- }
-
- color("#303030")
- 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])
- cube([sensor_chip_w, sensor_chip_l, sensor_chip_h]);
-
- translate([0, -sensor_l / 2 - 15 * sensor_pin_pitch + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1, 0])
- for (p = [0 : 15])
- translate([0, p * sensor_pin_pitch, 0])
- for (x = [-sensor_pin_dist / 2, sensor_pin_dist / 2])
- if (((p % 2 == 0) && (x < 0))
- || ((p % 2 == 1) && (x > 0)))
- translate([-sensor_pin_d / 2 + x, -sensor_pin_w / 2, -sensor_chip_h + sensor_pin_off_top])
- cube([sensor_pin_d, sensor_pin_w, sensor_pin_h]);
-
- color("cyan")
- 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])
- cylinder(d = 0.2, h = sensor_ball_to_chip_bottom - 1);
- }
-
- module ball_and_roller() {
- color("red")
- sphere(d = ball_dia, $fn = 200);
-
- for (r = [0 : roller_count - 1])
- rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
- translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
- rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
- translate([0, 0, -roller_dia / 2])
- roller_holder();
- }
-
- module roller_holder() {
- translate([0, 0, -roller_h + roller_dia / 2 - roller_ball_h_off])
- difference() {
- color("magenta")
- union() {
- translate([0, 0, roller_h - roller_ridge_h])
- cylinder(d = roller_mount_dia, h = roller_ridge_h, $fn = 6);
-
- translate([0, 0, roller_h - roller_ridge_h])
- scale([-1, 1, -1])
- metric_thread(diameter = roller_thread_dia,
- pitch = roller_thread_pitch,
- length = roller_h - roller_ridge_h,
- internal = false, n_starts = 1,
- taper = 0.1, leadin = 2,
- test = !draw_threads);
- }
-
- translate([0, 0, -1]) {
- cylinder(d = roller_thread_hole, h = roller_h + 1 - roller_dia / 2 + roller_ball_h_off + roller_ball_hold_off);
-
- cylinder(d = roller_small_hole, h = roller_h + 2);
- }
-
- if (cut_roller_holder) {
- translate([-roller_thread_dia / 2 - 1, -roller_thread_dia, -1])
- cube([roller_thread_dia + 2, roller_thread_dia, roller_h + 2]);
- }
- }
-
- %color("blue")
- sphere(d = roller_dia, $fn = 200);
- }
-
- roller_mount_add_len = 0.5;
- roller_mount_test_bot_h = 2.0;
-
- module roller_mount() {
- difference() {
- color("cyan")
- translate([0, 0, -roller_mount_add_len])
- cylinder(d = roller_mount_dia, h = roller_h - roller_ridge_h + roller_mount_add_len);
-
- translate([0, 0, roller_h - roller_ridge_h])
- scale([-1, 1, -1])
- metric_thread(diameter = roller_thread_dia,
- pitch = roller_thread_pitch,
- length = roller_h - roller_ridge_h + roller_mount_add_len + 0.1,
- internal = true, n_starts = 1,
- taper = 0, leadin = 2,
- test = !draw_threads);
-
- if (cut_roller_holder) {
- translate([-roller_thread_dia / 2 - 2, -roller_thread_dia, -5])
- cube([roller_thread_dia + 4, roller_thread_dia, roller_h + 10]);
- }
- }
-
- translate([0, 0, -roller_mount_add_len - roller_mount_test_bot_h])
- roller_mount_bottom();
- }
-
- module roller_mount_bottom() {
- color("yellow")
- cylinder(d = roller_mount_dia, h = roller_mount_test_bot_h);
-
- color("yellow")
- translate([0, 0, roller_mount_test_bot_h])
- cylinder(d1 = 1.5, d2 = 1.0, h = 1.0);
-
- %translate([0, 0, roller_mount_test_bot_h])
- cylinder(d = 2.0, h = 8.5);
- }
-
- module roller_mount_test() {
- translate([0, 0, roller_mount_add_len + roller_mount_test_bot_h]) {
- roller_mount();
-
- translate([0, 0, roller_h - roller_dia / 2 + roller_ball_h_off])
- roller_holder();
- }
- }
-
- module ball_roller_test() {
- %translate([0, 0, ball_dia / 2 + ball_h - 10])
- ball_and_roller();
-
- difference() {
- hull() {
- cylinder(d = 60, h = 1);
-
- translate([0, 0, ball_dia / 2 + ball_h - 10])
- for (r = [0 : roller_count - 1])
- rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
- translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
- rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
- translate([0, 0, -roller_dia / 2])
- translate([0, 0, -roller_h + roller_dia / 2 - roller_ball_h_off])
- translate([0, 0, -roller_mount_add_len - roller_mount_test_bot_h])
- cylinder(d = roller_mount_dia + 2, h = roller_h - roller_ridge_h + roller_mount_add_len + roller_mount_test_bot_h - 1);
- }
-
- translate([0, 0, ball_dia / 2 + ball_h - 10])
- for (r = [0 : roller_count - 1])
- rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
- translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
- rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
- translate([0, 0, -roller_dia / 2])
- translate([0, 0, -roller_h + roller_dia / 2 - roller_ball_h_off])
- translate([0, 0, -roller_mount_add_len - roller_mount_test_bot_h])
- cylinder(d = roller_mount_dia, h = roller_h - roller_ridge_h + roller_mount_add_len + roller_mount_test_bot_h + 10);
-
- translate([0, 0, ball_dia / 2 + ball_h - 10])
- sphere(d = ball_dia + 10, $fn = 200);
- }
-
- translate([0, 0, ball_dia / 2 + ball_h - 10])
- for (r = [0 : roller_count - 1])
- rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
- translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
- rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
- translate([0, 0, -roller_dia / 2])
- translate([0, 0, -roller_h + roller_dia / 2 - roller_ball_h_off])
- roller_mount();
- }
-
- base_dia = pico_l + 9;
-
- module trackball() {
- %translate([0, 0, ball_dia / 2 + ball_h])
- ball_and_roller();
-
- %rotate([0, 180, 0])
- pico();
-
- %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])
- sensor();
-
- translate([0, 0, ball_dia / 2 + ball_h])
- for (r = [0 : roller_count - 1])
- rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
- translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
- rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
- translate([0, 0, -roller_dia / 2])
- translate([0, 0, -roller_h + roller_dia / 2 - roller_ball_h_off])
- roller_mount();
-
- color("grey")
- translate([0, 0, -8])
- cylinder(d = base_dia, h = wall);
- }
-
- // ######################
- // ## Rendering Select ##
- // ######################
-
- //ball_and_roller();
- //pico();
- //sensor();
-
- //mx_switch_cutout(wall);
- //mx_switch_test();
-
- //roller_mount_test();
- //roller_mount();
- //roller_holder();
-
- //ball_roller_test();
-
- trackball();
|