Ultrasonic Ruler Created by Ruiz Brothers Last updated on 2014-12-11 11:00:50 AM EST
Guide Contents Guide Contents Overview Beast Rabban's Lost Pistol 3D Printing Movie Replicas Prerequisite Guides Parts Tools & Supplies Circuit Diagram Ultrasonic + Trinket Programming Trinket Code Ultrasonic Distance Sensor for Tirnket and Quad Alphanumeric LED Display 3D Printing PLA Filament Prop Details Finish Part Surface Assembly Add JST to Trinket Trinket JST Connector Assemble Quad Alphanumeric Display Assembled 14-Segment Quad Alphanumeric Display Solder Wires to LED Matrix LED Matrix Connections Measure LED Matrix Connections Wire EZ Rangefinder Slide Switch Adapter Wired Components Build Insert LED Matrix to Enclosure Install Sensor to Barrel Add Trinket to Enclosure 2 4 4 4 4 5 5 6 6 6 7 7 10 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 24 25 26 https://learn.adafruit.com/ultrasonic-ruler Page 2 of 47
Mount Trinket to Enclosure Connect Switch to Trinket Add Screws to Trigger Add Switch to Enclosure Connect Battery to Switch Add Battery to Enclosure Add Barrel to Enclosure Position LED Matrix Wiring Install Trigger Add Cover to Enclosure Secure Enclosure Add Handle to Enclosure Adjust LED Matrix Wiring Add Cover to Handle Check Trigger Placement Secure Handle Secure Bottom Handle to Enclosure Secure Top Handle to Enclosure Secure LED Enclosure to Handle Secure LED Matrix to Enclosure Add Cover to LED Enclosure Measure In Style 27 28 29 30 31 32 33 34 34 35 36 37 38 39 40 41 42 43 44 45 46 47 https://learn.adafruit.com/ultrasonic-ruler Page 3 of 47
Overview Beast Rabban's Lost Pistol In this guide, we're building a Dune inspired movie replica using 3D Printing and electronics. Beast Rabbon's pistol is a unqiue harkonnen weapon that was never seen in David Lench 1984's Dune. There are only two images of the pistol on the net and currently isn't anyway to get one. 3D Printing Movie Replicas This project combines the original pistol with functional features. A Trinket micro-controller reads an EZ4 rangefinder and writes the distance in centimeters onto a 14-segment LED display. Prerequisite Guides Be sure to walk through the following guides to get yourself familiar with the Trinket microcontroller, LED Backpacks, and distance sensor. Introducing Trinket (http://adafru.it/duc) Adafruit LED Backpacks (http://adafru.it/dyb) Trinket Ultrasonic Rangefinder (http://adafru.it/dyc) Collin's Lab: Soldering (http://adafru.it/dyd) https://learn.adafruit.com/ultrasonic-ruler Page 4 of 47
Parts MaxBotix LV-EZ Ultrasonic rangefinder (http://adafru.it/eg7) Trinket Micro-Controller (http://adafru.it/dyv) (3V or 5V) Quad Alphanumberic Display (http://adafru.it/dye) - 0.54" 14-segment LED 3 x AAA battery holder (http://adafru.it/dyf) Slide Switch (http://adafru.it/805) Tools & Supplies 3D Printer (http://adafru.it/dtm) + PLA Filament (http://adafru.it/dyg) Soldering Iron (http://adafru.it/dto) + Solder (http://adafru.it/dyh) JST Battery extension cable (http://adafru.it/1131) 30AWG Wire Wrap (http://adafru.it/dyi) Heat Shrink Tubbing (http://adafru.it/1649) Wire Strippers (http://adafru.it/ddi) Diagonal Wire Cutters (http://adafru.it/dxq) Panavise Jr. (http://adafru.it/151) Third Helping Hand (http://adafru.it/dxr) https://learn.adafruit.com/ultrasonic-ruler Page 5 of 47
Circuit Diagram Ultrasonic + Trinket Follow the circuit diagram above for referencing how to wire up the circuit. Use a breadboard to prototype this circuit. Programming Trinket You will need to download and install special libraries in order to get the Trinket to work with the Adurino IDE. Check out the link below for setting that up. Configure Trinket for Arduino http://adafru.it/djb https://learn.adafruit.com/ultrasonic-ruler Page 6 of 47
Code Ultrasonic Distance Sensor for Tirnket and Quad Alphanumeric LED Display Copy and paste the following code into a new sketch in the Arduino IDE. Select the Adafruit Trinket 8MHz in the board section under the Tools menu. Make sure the Programmer section is set to USBTinyISP. Once those are confirmed, plug in the Trinket via USB to your computer and hit upload while the trinket is blinking red. #include <TinyWireM.h> //#include <avr/power.h> #include "Adafruit_LEDBackpack.h" #include "Adafruit_GFX.h" #define EZ1pin 1 // Trinket GPIO #1 Adafruit_AlphaNum4 alpha4 = Adafruit_AlphaNum4(); char printme[3]; String str; int8_t arraysize = 9; // quantity of values to find the median (sample size). Needs to be an odd number uint16_t rangevalue[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint16_t mode; // calculated median distance void setup() { pinmode(ez1pin, INPUT); // Sey ultrasonic sensor pin as input //if (F_CPU == 16000000) clock_prescale_set(clock_div_1); alpha4.begin(0x70); // pass in the address alpha4.writedisplay(); // clear display } void loop() { int16_t pulse; // number of pulses from sensor int i=0; while( i < arraysize ) { pulse = pulsein(ez1pin, HIGH); // read in time for pin to transition rangevalue[i]=pulse/58; // pulses to centimeters (use 147 for inches) if( rangevalue[i] < 645 && rangevalue[i] >= 15 ) i++; // ensure no values out of range delay(10); // wait between samples } isort(rangevalue,arraysize); // sort samples mode = mode(rangevalue,arraysize); // get median https://learn.adafruit.com/ultrasonic-ruler Page 7 of 47
str=string(mode); str.tochararray(printme,3); alpha4.writedigitascii(0, printme[0]); alpha4.writedigitascii(1, printme[1]); alpha4.writedigitascii(2, 'C'); // write to LCD alpha4.writedigitascii(3, 'M'); alpha4.writedisplay(); delay(500); // Read every half second } // Sorting function (Author: Bill Gentles, Nov. 12, 2010) void isort(uint16_t *a, int8_t n){ for (int i = 1; i < n; ++i) { uint16_t j = a[i]; int k; for (k = i - 1; (k >= 0) && (j < a[k]); k--) { a[k + 1] = a[k]; } a[k + 1] = j; } } // Mode function, returning the mode or median. uint16_t mode(uint16_t *x,int n){ int i = 0; int count = 0; int maxcount = 0; uint16_t mode = 0; int bimodal; int prevcount = 0; while(i<(n-1)){ prevcount=count; count=0; while( x[i]==x[i+1] ) { count++; i++; } if( count > prevcount & count > maxcount) { mode=x[i]; maxcount=count; bimodal=0; } if( count == 0 ) { i++; } https://learn.adafruit.com/ultrasonic-ruler Page 8 of 47
} if( count == maxcount ) { //If the dataset has 2 or more modes. bimodal=1; } if( mode==0 bimodal==1 ) { // Return the median if there is no mode. mode=x[(n/2)]; } return mode; } } https://learn.adafruit.com/ultrasonic-ruler Page 9 of 47
3D Printing Download STLs http://adafru.it/dyj PLA Filament We recommend printing the parts in PLA filament. Follow our slice settings as a reference point. Settings will vary from printer to printer, so you'll need to adjust your printers settings accordingly. Each part is optimized to print with no support material and saved in the best oriention to print. dhp-barrel.stl dhp-bottom-box.stl dhp-bottom-handle.stl dhp-dot.stl dhp-grip-botom.stl dhp-grip-top.stl dhp-led-cover.stl dhp-led.stl dhp-top-box.stl PLA @230 No support 0.2mm Layerheight 3 Shells 90/120 Speeds 10% Infill Takes about 8 hours to print all pieces https://learn.adafruit.com/ultrasonic-ruler Page 10 of 47
dhp-top-handle.stl dhp-trigger.stl Edit/Modify Design http://adafru.it/dyk Prop Details We recommend printing the dhp-grip-bo tto m.stl and dhp-grip-to p.stl parts together in a set. The dhp-do t.stl pieces can also be printed in one set to speed up the process. Most slicing software can allow you dubplicate STLs. This project uses 12 dots, 6 on each side. https://learn.adafruit.com/ultrasonic-ruler Page 11 of 47
Finish Part Surface We added a light coat of silver spray paint to the parts to give it a metal look. Using sand paper and a brass sponage, we smoothed out the surface and added abasion to the parts giving it a worn and aged textured. https://learn.adafruit.com/ultrasonic-ruler Page 12 of 47
Assembly https://learn.adafruit.com/ultrasonic-ruler Page 13 of 47
Add JST to Trinket First step is to get a JST connector onto the Trinket so we can easily remove any JST compatible power source. We'll grab the JST battery exnsion cable and measure the length like in the photo. Cut and strip the wires from the JST cable. Tin the postive and negative pads on the bottom of the Trinket and solder the red wire from the JST cable to the postive pad, and the black wire to the negative pad. https://learn.adafruit.com/ultrasonic-ruler Page 14 of 47
Trinket JST Connector Adding a JST female connector to the Trinket micro-controller makes it easy to swap out capatible power sources. Most of our battery holders, rechargable lithium polymer and lithium ion batteries use JST connectors. Soldering a battery directly to the Trinket is not recommended. https://learn.adafruit.com/ultrasonic-ruler Page 15 of 47
Assemble Quad Alphanumeric Display The quad alphanumeric display comes in a kit that requires assembly. Add the LED matrixes to the driver with the dots lined up for proper orientation. Bend the terminals on the far end aparts so it keeps the LED matrix in place while you solder. Secure the LED backpack to a panavise and solder the 18 pins. Use a diagonal cutters to remove the excess leads. https://learn.adafruit.com/ultrasonic-ruler Page 16 of 47
Assembled 14-Segment Quad Alphanumeric Display Double check all of the pins have been soldered. https://learn.adafruit.com/ultrasonic-ruler Page 17 of 47
Solder Wires to LED Matrix Tin the five pins on the top of the LED Matrix. Solder one 30AWG wire to each pin. Use either a long strand of wire (about 20meters long) or the whole wire spool. https://learn.adafruit.com/ultrasonic-ruler Page 18 of 47
LED Matrix Connections Try using a different color for each wire so that you can easily tell them apart. https://learn.adafruit.com/ultrasonic-ruler Page 19 of 47
Measure LED Matrix Connections Position the LED matrix over the parts and measure the length required to make a connection. Cut the wires and add a piece of heat shrink tubing to bundle the wires. Insert the bundle wire through the opening in the dhp-led.stl part. https://learn.adafruit.com/ultrasonic-ruler Page 20 of 47
Wire EZ Rangefinder Solder a 30AWG wire to the GND, 5V and PWM pin on the EZ distance rangefinder. If you solder to the leads of the header, be sure to add a piece of heat shrink tubing to secure the connection. Position the sensor over the parts and measure the length of wire required for connecting to the Trinket. Gently insert the distance sensor into the dhpbarrel.stl part with the black plastic part going in first. https://learn.adafruit.com/ultrasonic-ruler Page 21 of 47
Slide Switch Adapter Shorten a JST extension cable to about 10mm long by cutting the positive and negative cables with wire cutters. Use wire stripers to strip the ends of the positive and negative wires. Apply a bit of rosin to the stripped ends and tin the tips of the wires. Add a piece of shrink tubing to the positive wire and solder them together by holding them in place with a third-helping-hand. https://learn.adafruit.com/ultrasonic-ruler Page 22 of 47
Wired Components Yay! All of the components are wired and ready for installing to the enclosure. The trinket and LED matrix will be secured to the printed parts with machine screws. The next page will walk you through the build process. https://learn.adafruit.com/ultrasonic-ruler Page 23 of 47
Build Insert LED Matrix to Enclosure Insert the wiring from the LED Matrix through the opening in the dhp-led.stl part. Fit the LED Matrix into the dhp-led.stl part with the triangle part lined up with the top of the LED (The noticable dots indicate the LED's orientation). https://learn.adafruit.com/ultrasonic-ruler Page 24 of 47
Install Sensor to Barrel Place the sensor over the barrel and line up the orientation. Carefully insert the distance sensor into the dhp-barrel.stl part with the plastic part going in first. https://learn.adafruit.com/ultrasonic-ruler Page 25 of 47
Add Trinket to Enclosure Insert the Trinket into the dhp-bo x-bo tto m.stl part with the USB port facing the port opening. Line up the two mounting holes on the trinket with the holes on the part. https://learn.adafruit.com/ultrasonic-ruler Page 26 of 47
Mount Trinket to Enclosure Add two #4-40 flat phillips screws to the dhp-bo x-bo tto m.stl part and fasten it together while holding the Trinket down to the part. https://learn.adafruit.com/ultrasonic-ruler Page 27 of 47
Connect Switch to Trinket Insert the male JST connector from the slide switch adapter to the female JST conncetor on the Trinket. https://learn.adafruit.com/ultrasonic-ruler Page 28 of 47
Add Screws to Trigger Fasten two #4-40 flat philips screws into the holes with stand-offs. These need to be inserted so that the heads of the screws are on the opposite end of the stand off. https://learn.adafruit.com/ultrasonic-ruler Page 29 of 47
Add Switch to Enclosure Insert the Slide Switch adapter into the dhp-bo tto m-bo x.stl part. https://learn.adafruit.com/ultrasonic-ruler Page 30 of 47
Connect Battery to Switch Insert the male JST connector to the female JST connector on the slide switch adapter. https://learn.adafruit.com/ultrasonic-ruler Page 31 of 47
Add Battery to Enclosure Insert the 3 x AAA battery holder in the dhp-bottom-box.stl and gently position the cables in between the sides. https://learn.adafruit.com/ultrasonic-ruler Page 32 of 47
Add Barrel to Enclosure Insert the dhp-barrel.stl part onto the dph-bo tto m-bo x.stl part with the bottom edge fitting into the opening on the enclosure. https://learn.adafruit.com/ultrasonic-ruler Page 33 of 47
Position LED Matrix Wiring Place the wiring from the LED Matrix through the opening near the top of the battery like in the photo. This wire needs to route through the opening near the triggne and out the handle. Install Trigger Place the trigger on the enclosure with the heads of the scews resting inside the indents of walls. https://learn.adafruit.com/ultrasonic-ruler Page 34 of 47
Add Cover to Enclosure Place the dhp-to p-bo x.stl part over the dhp-bo tto m-bo x.stl part and make sure wires are not covering the standoffs. https://learn.adafruit.com/ultrasonic-ruler Page 35 of 47
Secure Enclosure Add #4-40 flat phillips screw to the three mounting holes. Hold down the top and bottom parts together so both pieces are flush when they're secured together. https://learn.adafruit.com/ultrasonic-ruler Page 36 of 47
Add Handle to Enclosure Position the dhp-bo tto m-handle.stl part to the battery+trinket enclosure like shown in the photo. https://learn.adafruit.com/ultrasonic-ruler Page 37 of 47
Adjust LED Matrix Wiring Press down the excess wiring and bend it behind the standoff in the handle. https://learn.adafruit.com/ultrasonic-ruler Page 38 of 47
Add Cover to Handle Place the dhp-to p-handle.stl part over the dhp-bo tto m-handle.stl part and line up the mounting holes and standoffs. https://learn.adafruit.com/ultrasonic-ruler Page 39 of 47
Check Trigger Placement Ensure the two screws in trigger are properly positioned inside the enclosure. https://learn.adafruit.com/ultrasonic-ruler Page 40 of 47
Secure Handle Join the top and bottom handle parts together with machine screws. Fasten three #4-40 flat philips screws while tightly holding the two parts together. https://learn.adafruit.com/ultrasonic-ruler Page 41 of 47
Secure Bottom Handle to Enclosure Line up the mount holes on the bottom of the handle and add two #4-40 flat phillips screws to the bottom. Fasten these screws tightly to join the bottom of the handle to the enclosure. https://learn.adafruit.com/ultrasonic-ruler Page 42 of 47
Secure Top Handle to Enclosure Line up the holes on the top of the handle and add two #4-40 flat phillips screws to the top. Fasten these screws tightly to join the top of the handle to the enclosure. https://learn.adafruit.com/ultrasonic-ruler Page 43 of 47
Secure LED Enclosure to Handle Postion the dhp-led.stl part over the top of the handle and line up the mounting holes. Make sure the triangle piece is pointing towards the barrel. This serves as line of sight. Add two #4-40 flat phillips screws to join the part to the handle. https://learn.adafruit.com/ultrasonic-ruler Page 44 of 47
Secure LED Matrix to Enclosure Flip the part over and fasten 4 #2-56 flat phillips screws to secure the LED Matrix to the enclosure. https://learn.adafruit.com/ultrasonic-ruler Page 45 of 47
Add Cover to LED Enclosure Snap the dhp-led-cover.stl part on top of the LED Matrix to cover it up. https://learn.adafruit.com/ultrasonic-ruler Page 46 of 47
Measure In Style Now you ready to test out your shiney Ultrasonic Ruler. Last Updated: 2014-12-11 11:00:54 AM EST Page 47 of 47