From 9ffb1ff1739f5169bc76aca5016c2c06c48012ab Mon Sep 17 00:00:00 2001 From: phschoen Date: Sun, 18 Dec 2022 00:13:24 +0100 Subject: [PATCH] add trackball --- config.scad | 21 ++++ constant.scad | 77 ++++++++++++- pcb/pmw3360_sensor.scad | 37 ++++++ pcb/rp2040.scad | 21 ++++ trackball/trackball.scad | 236 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 391 insertions(+), 1 deletion(-) create mode 100644 pcb/pmw3360_sensor.scad create mode 100644 trackball/trackball.scad diff --git a/config.scad b/config.scad index b272a53..7db1ae8 100644 --- a/config.scad +++ b/config.scad @@ -19,6 +19,19 @@ switch_r=[ // row 1 [ [0,0,0], [0,0,-10] ] ]; + +switch_thumb_t=[ + // colum 2 + [ [0,70,50], [37,60,20] , [37,60,20] ], + // colum 1 + [ [0,40,40], [32,40,10], [32,40,10] ], + ]; + +switch_thumb__r=[ + [ [0,0,0], [10,0,-10] , [10,0,-10] ], + // row 1 + [ [0,0,0], [10,0,-10] , [0,0,-10] ] + ]; switch_keycap=[ [["mt3", 1], ["SA", 1], ], [["mt3", 1], ["SA", 1], ], @@ -26,6 +39,14 @@ switch_keycap=[ [["mt3", 1], ["SA", 1], ], ]; +// the trackball diameter itself +ball_dia = 38.0; +ball_h = 15; + +// the typcial 3 static balls which are the glide contacts of the trackball +roller_dia = 3.0; +roller_count = 3; + $switch_with_pcb=true; $show_switches=true; $show_keycaps=true; diff --git a/constant.scad b/constant.scad index 1495940..7973089 100644 --- a/constant.scad +++ b/constant.scad @@ -2,6 +2,9 @@ $c=0.1; $fn=60; $e=0.01; +// ####################### +// ## cherry switches ## +// ####################### switch_cutout_width = 14; switch_dim_x=13.98; switch_dim_y=13.98; @@ -17,9 +20,81 @@ switch_cutout_side_offset = 1; switch_cutout_side_width = 3.5; switch_cutout_side_dept = 1.2; +// ####################### +// ## metric screw cuts ## +// ####################### +m3_thread_tight=2.7; +m3_thread_lose=2.9; -amoeba_royale_pcb_h = 1.6; +m2_thread_tight=1.8; +m2_thread_lose=2.2; m2_head_d=4; m2_head_h=0.75; m2_screw_d=2; + +// ####################### +// ## trackball ## +// ####################### +roller_ball_h = 8; + +// ####################### +// ## amoeba royale ## +// ####################### +amoeba_royale_pcb_h = 1.6; amoeba_royale_pcb_screw_h=5; + +// ####################### +// ## 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; + diff --git a/pcb/pmw3360_sensor.scad b/pcb/pmw3360_sensor.scad new file mode 100644 index 0000000..a94ffba --- /dev/null +++ b/pcb/pmw3360_sensor.scad @@ -0,0 +1,37 @@ + +include <../config.scad> +include <../constant.scad> + +pmw3360_sensor(); +module pmw3360_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); +} diff --git a/pcb/rp2040.scad b/pcb/rp2040.scad index d046301..39f6f1b 100644 --- a/pcb/rp2040.scad +++ b/pcb/rp2040.scad @@ -1,6 +1,27 @@ + +include <../config.scad> +include <../constant.scad> module rp2040_pcb() { rotate([90,0,0]) import("../stl/pcb/rp2040.stl"); } rp2040_pcb(); + +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); + } +} diff --git a/trackball/trackball.scad b/trackball/trackball.scad new file mode 100644 index 0000000..039ebe7 --- /dev/null +++ b/trackball/trackball.scad @@ -0,0 +1,236 @@ +/* + * 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 . + */ + +include <../config.scad> +include <../constant.scad> + +use <../pcb/pmw3360_sensor.scad> +use <../pcb/rp2040.scad> + +// ###################### +// ## Rendering Select ## +// ###################### + +//roller_holder(); +//roller_mount_test(); +//roller_mount_tri(); +//ball_and_roller(); +trackball(); + +// ####################### +// #### Configuration #### +// ####################### + +base_dia = pico_l + 9; +wall = 3.0; + +cut_roller_holder = false; + + +// ###################### +// ## 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 = roller_dia + 5.0; +roller_h = roller_dia + 7.0; +roller_ball_h_off = 0.4; +roller_ball_hold_off = 0.5; +roller_thread_hole = roller_dia - 1; +roller_small_hole = sphere_r_at_h(roller_ball_hold_off, roller_dia / 2) * 2; + +roller_ridge_h = 1.5; +roller_mount_angle_off = 90; +roller_mount_dia = roller_thread_dia + 2.0; + +function sphere_r_at_h(h, r) = r * sin(acos(h / r)); +function sphere_angle_at_rh(h, r) = acos(h / r); + + +module roller_holder() { + + echo(roller_h); + translate([0, 0, -roller_h + roller_dia / 2]) + difference() { + color("magenta") + union() { + // top screw part + translate([0, 0, roller_h-roller_dia/2 + roller_ball_h_off-3]) + cylinder(d1 = roller_mount_dia, d2=roller_dia+1, h = 3); + cylinder(d = roller_mount_dia, h = roller_h-roller_dia/2 + roller_ball_h_off-3); + + } + + translate([0, 0, -$e]) { + cylinder(d = roller_thread_hole, h = $e+ roller_h - roller_dia / 2 + roller_ball_h_off + roller_ball_hold_off); + } + + translate([0, 0, roller_h - roller_dia / 2]) + sphere(d = roller_dia , $fn=$fn*4 ); + + + 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); +} + +module roller_mount() { + echo(roller_h); + translate([0, 0, -1-roller_h + roller_dia / 2]) { + difference() { + cylinder(d=roller_mount_dia+wall,h=roller_h/2); + translate([0,0,1]) + cylinder(d=roller_mount_dia+$c*2,h=roller_h/2+$e); + } + } +} + +module roller_mount_test() { + roller_holder(); + roller_mount(); +} + +module roller_mount_tri() { + +difference() { + union(){ + difference() { + hull() { + translate([0, 0, 0]) + 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_h]) + cylinder(d=roller_mount_dia+wall+1,h=roller_h+1); + + translate([0,0,-ball_dia/2-5]) + cylinder(d=base_dia,h=$e); + } + + 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_h]) + cylinder(d=roller_mount_dia+0.2,h=ball_dia/2+roller_h); + + sphere($fn=$fn*4, d=ball_dia+$c*2+1); + + } + 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, 0]) + roller_mount(); + } + + translate([0, 0, 0]) + 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_h/2]) + rotate([0,-90,0]) + translate([0,0,2]) + { + cylinder(d=m2_thread,h=ball_dia); + translate([0,0,roller_mount_dia/4+wall]) + cylinder(d=m2_thread+1,h=ball_dia); + } +} + + +} + +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 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]) + pmw3360_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); +}