Exit Full View
Up

/Printer/Pi3Case.foocad

Pi3Case
FooCAD Source Code
import static uk.co.nickthecoder.foocad.extras.v1.Extras.*
import static uk.co.nickthecoder.foocad.chamferedextrude.v1.ChamferedExtrude.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.*

/**
    A basic case for a Raspberry Pi 3.
    Comes in two pieces (top and bottom), which are held together using 4 screws.
    
    I used the following design as inspiration :
    https://www.myminifactory.com/object/3d-print-raspberry-pi-3-case-51864
    But I created this from scratch. Improvements made :

    + Ventalation holes
    + Option to cover the header pins and/or ribbon cable connectors
    + Option to add places for magnets, so that the pi can stick to the side
        of my 3D printers. (I use the Pi as an OctoPrint server).
    - Uses 16mm M3 bolts, but I really should have used M2 (but I didn't have any),
        so I needed to widen the holes on the PI.
*/

class Pi3Case : Model {
    
    @Custom
    var thickness = 1.6

    @Custom
    var cableSlots = true

    @Custom
    var headerSlot = false

    @Custom
    var magnetD = 11.0

    @Custom
    var magnetT = 1.0

    fun profile() = Square( 86, 57 ).center().roundAllCorners(3.5)

    fun arrangeMounts( shape : Shape3d ) = shape
        .translate( -39,24.5, 0 )
        .mirrorY().also()
        .translateX(58).also()

    @Piece
    fun bottom() : Shape3d {
        val profile : Shape2d = profile()
        val thumb = Circle( 10 ).rightTo( profile.left + 3.5 )
        
        val post = Cylinder( 3, 4, 2.5 ).translateZ(thickness-0.01) - Cylinder( 10, 1.5 )
        val posts = arrangeMounts( post )
 
        val screwHoles = arrangeMounts(
            Circle(3.3).sides(6).chamferedExtrude(3.5, 0, 1).translateZ(-0.01)
        )

        var result : Shape3d = (profile - thumb).extrude(thickness).color("Orange") +
            posts -
            screwHoles

        
        if (magnetD > 0 && magnetT > 0) {
            result -= Cylinder( magnetT, magnetD/2 )
                .translate( 28, 14, 0 )
                .mirrorX().also()
                .mirrorY().also()
        }



        return result
    }

    @Piece
    fun top() : Shape3d {
        var profile : Shape2d = profile()

        if ( cableSlots == true ) {
            val slot = Square( 2.5, 22 ).roundAllCorners(1)
            profile -= slot.center()
                .translate(-37.75,0)
                .translate(39.75,16.5).also()
        }

        if (headerSlot) {
            profile -= Square( 52, 6 ).center().translate(-10,-24.5)
        }
    
        profile -= Square( 22, 16.5 ).translate( 23, 9.5 )
        profile -= Square( 18, 14 ).translate( 27, -8 ).translateY(-18).also()


        val airHole = Circle( 1 ).sides(6).rotate(30)
        val airHoles = airHole +
            airHole.repeatCircular(3,6) +
            airHole.repeatCircular(6,12) +
            airHole.repeatCircular(9,18)

        profile -= airHoles.scale(1.7).translateX(-17)

        val post = Cylinder( 3, 4, 2.5 ).translateZ(thickness) +
             Cylinder( 8.5, 2.5 ).translateZ(thickness) -
             Cylinder( 11, 1.5 )
        val posts = arrangeMounts( post )

        val headerSpace = Cube( 52, 6, 8 ).centerXY().translate(-10,-24.5,thickness)

        val screwHoles = arrangeMounts( Cylinder(10,1.5) )

        return profile.chamferedExtrude(thickness, 0.5,0).color("Orange") +
            posts -
            headerSpace -
            screwHoles
    }

    override fun build() : Shape3d {
        val bottom : Shape3d = bottom()
        return bottom + top().mirrorZ().bottomTo( bottom.top + 1 )
    }
}