Even More Segments

The next logical step from yesterdays 7 segment project was to add another display.  So that is what I did.  Instead of using 8 more pins on the Arduino, I connected the displays together and used transistors to switch between them.  This means that I can't have both displays on at the same since if they were then they would display the same number.  To get around this, one display turns on, pauses, then turns off and the same goes for the other.  That routine was packaged into a function and is called very routinely to avoid flickering.
void loop()
{
  for(j=0;j<100;j++){ //count up
    time = millis();
    while(millis()-time < 500){
      printNum2(j);
    }
  }
  for(j=98;j>0;j--){ //count down
    time = millis();
    while(millis()-time < 500){
      printNum2(j);   
    }
  }
}
void printNum2(int num)
{
  int temp = num / 10;  //get tens place digit
  num = num % 10; // remove tens from number, left with ones place
  for(i=2;i<=9;i++){   // set up ones digit
    digitalWrite(i,numbers[num][i-2]);
  }
  digitalWrite(ones,HIGH);  //display ones
  delay(1);                 //pause
  digitalWrite(ones,LOW);   //turn off
  for(i=2;i<=9;i++){   // set up tens digit
    digitalWrite(i,numbers[temp][i-2]);
  }
  digitalWrite(tens,HIGH);  //display tens
  delay(1);
  digitalWrite(tens,LOW);  //turn off
}
To see what was happening, I increased the pause amount until the flickering was very noticeable.
video
One thing that I am learning with this microcontroller business is that things can't be on at the same time but you can make them look like they are and that they are good at doing sequential things fast.

7 Segments of Power!

What is that mess!  Well its one of the 7 segment displays that I picked up at that awesome garage sale.  As you can tell it uses 8 pins on the Arduino.  I could probably use a MUX so that it would not take up so many pins.  Since it is a common anode, you set a pin to LOW to turn on one of the segments and HIGH to it turn off.  The resistors are there because the max reverse voltage the display can take is 3V and the HIGH outputs 5V, so the resistors drop some voltage.

I set up an array with the HIGHs and LOWs that were needed to light each number.  The number corresponded to the index of the array.  When I wanted to display a number, a for loop sent the correct output to the correct pin.  The code is insanely simple.
int i,j;
int numbers[][8] ={{0,0,0,1,0,0,0,1}, //0
                   {1,1,0,1,0,1,1,1}, //1
                   {0,0,1,1,0,0,1,0}, //2
                   {1,0,0,1,0,0,1,0}, //3
                   {1,1,0,1,0,1,0,0}, //4
                   {1,0,0,1,1,0,0,0}, //5
                   {0,0,0,1,1,0,0,0}, //6
                   {1,1,0,1,0,0,1,1}, //7
                   {0,0,0,1,0,0,0,0}, //8
                   {1,1,0,1,0,0,0,0} //9
                   };
void setup()
{
for (i = 2; i<=9; i++){
  pinMode(i,OUTPUT);
  digitalWrite(i,HIGH);
  }
}
void loop()
{
  for(j=0;j<=9;j++){ //count up
   printNum(j);
   delay(1000);
   }
  for(j=8;j>0;j--){ //count down
   printNum(j);
   delay(1000);
   }
}
void printNum(int num)
{
  for(i=2;i<=9;i++){
   digitalWrite(i,numbers[num][i-2]);
   }
}
Yeah! Cool video time.
On to the handlebar mount.  The slots are cut.  They give it a nice look and decrease the weight quite a bit.  The only thing left now are the mounting holes. 
Its finished!  I just need to get some 1/4-20s so it can be put together.  Here is a lesson I'm going to keep in mind.  If you're going cut the piece in half, drill the holes that go through both before you cut it in half.

Handlebar Mount Progress

Here's an update with what I've done on the mount in the past 2 days. The hole was finished with the boring head.  Then the part was halved with a hacksaw.
Then it was cleaned up and brought down to the final thickness.  Finally a cut out was milled in the back of the piece.  You can see it in the pictures.   
Not that much as you can see but thats really all I felt like doing.  I'll finish it up tomorrow.

Epic Garage Sale Sesh!

Going to garage sales is an excellent way to spend a Saturday morning.  Especially when you end up at a 80 year old gentlemen who built computers and embedded systems house who is getting rid of everything!  I scored a bunch of resistors, caps, 555 timer IC's, opto isolator, 7 segment displays, a soldering iron, a desoldering iron, and some books.

There was a huge amount of IC's that I would haven't taken if I knew what they did.  I would have killed for a phone with internet access at that moment.  I could have popped over to AllDataSheets and looked everything up.  Oh well.  I might have to go back tomorrow and get some more.  However, some older gent came while I was looking around and starting piling basically everything he could find into a box so there might not be any left if I go back.

UPDATE:
I went back and snagged some more stuff for free!  Pretty awesome.  Time to figure out what everything does.   

Moar GoPed Parts

My friend wanted me to make him some parts based on some parts that his buddy had.  Specifically some triple clamps, a brake mount and a handle bar mount that mounts to the triple clamp.  I generated some plans in Inventor and then waited for my friend to get me some Al.  This project totally slipped my mind while I was waiting for him to get the Al.  I only thought that I had to make the triple clamps but when he reminded me of the other pieces I decided to use my Al. 

I began the handle bar clamp today.  Here is what I got done today.  Just the basic shape and started the hole for the bars. 
I use red permanent marker for layout marks cause I'm awesome.
Once I finish boring out the hole, I am going to part the piece in half.  From there I will finish up each half with mounting holes, decorative slots and other whatnot's. 

Whoa! I took pictures during the build! Crazy, I must be serious about getting better at documenting my projects.

The Beginnings of a Robot Car

My latest find at a garage sale was a pretty cool R/C car.  It was immediately dismantled as soon as I was home.  I checked out its h-bridge that was made out of some power transistors and the other components it had on the circuit board.  I tired finding the data sheet for the main IC on the board but I could not so I figured the next best thing was to remake the h-bridge on some protoboard.  And thats exactly what I did.

I sure the picture of the bottom will make any EE cringe; it even makes me cringe.  I definitely need to learn how to etch my own pcb's.  Anyway, I wrote a quick arduino program to test the motor.  The motor ran and the h-bridge didn't blow up.  I call that a successful test.  With control of the motor knocked out, I turned to steering.  The servo that was in the car had 5 wires.  After a quick search on the internet,  I learned that that means that all the control circuitry is on the main board and only a motor and a pot reside in the servo case.  Sure enough, when I opened the case all I found was a motor and a pot.  In order to use that servo I would of had to implement something similar to my post on position control of a DC motor.  I did not want to do that and besides I would be using 3 pins on the arduino and if i switch to a regular servo I'd only use 1 pin.  So thats exactly what I did. 

A little servo surgery had to go down.  I swapped out the final gear from the newer servo to the one from the ghetto servo.  Luckily they were the same size and after a quick bout with a hack saw and drill I was able to press it onto the potentiometer.  This was done because the old servo arm had a D-slot instead of a ribbed hole like all servo arms have these days.  Hopefully that makes an ounce of sense.  I meant to take some pictures of the switcheroo but I didn't.

Every bot needs a nice new battery pack.  So instead of using the 9.6v NiCd I've had since elementary school,  I bought some NiCd's and soldered one up.  It turned out nice for my first battery and the electrical tape cover makes it stealthy.
No electrical tape cover.
With the steering done, it was almost ready to drive around in circles, I just needed to find a reasonable speed for it to drive at.  To figure that out I wired a pot to my arduino to control the speed of the motor.  This is when everythin went down hill.  I ramped up the speed of the motor to about medium and since it was going well I decided to go to full SPEED AHEAD.  Bad idea.  The motor just stopped and turning the pot did nothing.  I concluded that I blew one of my transistors even though there was no smoke, fire, or smell.
Did I smoke one these??
The first thing I did was to figure out the stall current of the motor to see if I could have blown one of the power transistors.  I probably should have done that before but hey, if those could handle the motor and same size battery before then why couldn't they now.  I found that the stall current was around 4 amps, about half of what the transistors could handle.  But the motor wasn't stalled when it died, so it couldn't have been pulling that much current.  After that I moved on to checking all the transistors with my multimeter.  I found that 2 of the driving transistors were shot.  I have yet to replace them yet since the way I constructed my circuit board makes it extremely difficult to switch them out.  That is yet another reason to etch my own board.

This will be an on going project as I hope to make it into a test bed for various sensors and possibly make it fully autonomous.   Before I continue, I do need to learn more about motor controller circuits.

Position Control of a DC Motor, Part II

I picked up a printer at a garage sale a couple weeks ago and parted it out.  I got 2 stepper motors, 2 DC motors, a bunch of gears, a bunch of springs, a couple of optical encoders.  Pretty good hall I must say.

While I was researching for my original DC motor control project, I stumbled upon this post.  With a printer in hand, it was time to make version 2 of my position controller and use an optical encoder.

I just left the motor and encoder on the printer since it was set up nicely and I wouldn't have to make my own bracket.  After my last DC motor project, I bought some commercial h-bridges, specifically TI's SN754410.  I set up a circuit using that IC for motor control, a potentiometer to control the position and all the necessary wires for the encoder and then connected it to my arduino. 

On to the coding.  I used basically the same code from before but instead of get feedback from a pot, I was getting feedback from an encoder. I had to figure out how to read the encoder and use it as feedback.  I got some help with that by looking at the code on the site that I previously posted.  The encoder has 2 channels that output either a HIGH (1) or a LOW (0) signal depending on what it 'sees' on the code wheel (it has very fine lines).  You look for a state change and that tells you that the wheel is rotating.  Based on the the state transitions you can tell what direction you are rotating.  To keep track of the position, a variable gets incremented for a forward transition and decremented for a reverse transition.  That probably wasn't the best explanation but this pdf has a better one.  In my code all the encoder transitions are handled by the arduino's interrupt routine.

For the encoder to actually be of some use, I had to figure out how many lines were on the wheel so that I could compare the potentiometer reading with the encoder reading in my PID controller.  There was no way that I was going to count them manually so I made my arduino do it for me.  The arduino counted every transition as I rotated the wheel for a full revolution.  I did it a couple times to make sure the number I got was correct and then used that number to scale the pot position to a usable number.
I found out that this version was not effected as much as the previous version to changes it the PID gains.  That might be due to there being direct drive and not having to pass through 4 or 5 gear meshes but I'm not totally sure.  Now I just need to come up with something cool that uses this.

Bike Stem w/ a Wedge Clamping System

I was getting bored with just making parts that were only one piece.  I wanted to make something that fit together and did something.  I was looking through a Dan's Comp catalog and I stumbled upon bike stems with wedge clamping systems.  Instead of buying one, I decided I would just make one.  I loosely based my design off of the Odyssey stem.  The length of the stem was limited by width of my Al stock since I didn't want to do any unnecessary cutting with my hacksaw.  The stem design is really beefy so that there's really no chance of it breaking.  With a little Inventor work and I had a design and started cutting away.  

Just like the GoPed handle bar mount, the stem needed holes, and those took sometime.  To make it less blocky I milled down the back edges at 45 degree angles.  Next, I milled the slot for the wedge system.  As I got closer to the bottom of the slot, I was worried that I wouldn't make it to the bottom before the spindle rammed into my part.  It just barely cleared by an eighth of an inch.
With that done, I moved on to the wedge system.  That went pretty quickly.  I just squared up some small pieces, cut them at a very specific angle and then drilled some holes.   The wedge that holds the steer tube was last piece needed to complete the wedge system.  That piece also was a quick one to make. 
With all the pieces for system done it was time for a test.  Some scrap tube and a couple turns of an allen key later, the test was done.  It passed with flying colors.
One final piece was needed to complete the stem, the front piece.  I cut the corners off so that it would look nicer and match somewhat with the rest of the stem.  The front piece was drilled and counter sunk for 1/4 -20's and the base was tapped to match.
I had a completed stem that was ready for assembly on my bike.
Man! Does that look SEXY!

My First Request

My buddy requested that I make him a GoPed handlebar mount and I agreed.  I did some quick work in Inventor and checked the design over with my friend.  Then it was into the machine shop to make some chips. 
There was a lot of drilling involved in this project.  I probably spent a majority of my time drilling and then boring out the hole to the final dimension. 
Of course I had to make it OCTAGONAL!  Because everything is better by making it octagonal lol!  My 45 degree triangle got a lot of use in this project. 
I made it out of  solid block so I had to cut it into two pieces so that you could put a handlebar in it.  I drilled and counter sunk the top plate for 1/4 - 20 screws.  The bottom was then, of course tapped accordingly to accept the top plate.
Finished it just in time for dinner.  It took me a couple days to make it working a little each day. 

Hovering Arm

My next project was inspired by this video.  I didn't have an accelerometer but I did have a potentiometer.  I started with the mechanical bits.  I went out into my machine shop a.k.a garage made a motor mount for a speed 400 electric airplane motor.  It turned out nice and even has a slight octagonal shape.  Gotta love the octagons!

I added air vents later.
I also made a mounting block that would attach the arm to the pot so that the pot would rotate with the arm and output the angle of the arm.  I also needed a base to mount the pot and mount the assembly on to a tripod I have.  The base was designed on the fly while I was machining it on a pleasant Saturday morning.  It turned out great and held everything secure.

I just used a single power transistor to control the motor since I only needed one direction.  I used basically the same code as my Position Control of a DC Motor post.  Instead of setting the position of the arm manually, I coded the setpoint so that the arm was level.  Using the the output of the PID equation as the motor speed caused the motor to stop when it reached level.  I couldn't figure how to make the motor stay on when it reached level.  I thought about it for a while and came up with this, continuously add the PID output to the motor speed.  That way the motor speed would not go to zero when the arm is level and the PID output is basically zero.
That was probably the worst video ever.
I used basically the same Processing program as my other project to visualize the data.  It hovered well before the batteries started dying.  To sum everything up this was basically a first step in developing a quadrotor.  The next step would be to attach another motor to the other side of the arm and use both motors to keep it level. Oh and use an Al arm instead of a steel arm.

Position Control of a DC Motor, Part 1

Although I'm a MechE, I'm really interested in software and electronics. To fuel this interest, I got an Arduino a couple of months ago. I got busy with school and wasn't able to do any cool projects with it besides make LEDs blink. Anyway I decided to try to control a motor like a servo.

I researched how to control motors and I learned that I needed an h-bridge to control the direction of the motor and something to provide feedback of the motors position. For feedback of the position I decided on potentiometers since I didn't really care if I had continuous rotation. I searched a little longer for information on and schematics for h-bridges until I had a basic understanding of their operation and a had a schematic that I could make from RadioShack parts.

I used different but similar transistors to what was shown on the schematic. It didn't explode the first time I powered it up! It preformed exactly how it was supposed to. With motor control out of the way, I turned to some way of connecting the motor shaft to the potentiometer. While rummaging through my parts bin I found a KNEX motor and discovers that the pot shaft fit perfectly in the hole for the KNEX shaft. I quickly built a stand for it out of KNEX. I wired the feedback pot, h-bridge inputs and controller pot to my arduino and went to work on the coding.


My first control algorithm was incredible simple and I'm surprised that I thought it would work. It went like this in pseudo code:
take reading of input pot
take reading of output pot
if output less than input, move towards input
if output equals input, stop
if output greater than input, move towards input in opposite direction
That caused major oscillations, as the motor would shoot pass the input and then switch directions and shoot past again. I researched a little more and I found PID control. I read a couple post on the Arduino forums and looked at some code. I found it to be much easier than I thought and implemented it into my code.
In pseudo code, here is what I added:
take reading of input pot
take reading of output pot
error = input – output
sum of error += error * delta time
error change = (error – last error) / delta time
motor speed = Kp*error + Ki*sum of error + Kd*error change
The motor speed variable gets translated to a PWM signal that gets sent to the motor to control the speed. The Kp, Ki, Kd are gain constants. They tune the output to get the desired response from the system.

With this new code position control was achieved!  There were some slight oscillations but they eventually died out.  Adjusting the gains would help with those.

To visual the positions and the oscillations better I wrote a Processing program that displayed the angles of the input and output as lines.  I also added serial communication between my computer and the Arduino so that I could change the gains on the fly and see how they effected the motor response.  Finally! It's time for the video.

Overall it worked very well.  If I moved the control pot fast there was some lag between that and the motor position because of the large reduction in the KNEX motor.  This is another project that I wanted to iterate and make better by having a more direct connection between the motor and the feedback but I haven't gotten around to doing yet. 

Octagons > Circles

The next project that I undertook was making fork spacers for my bike.  I got a new fork and I didn't want to cut too much off my steer tube.  Spacers were the solution to that problem.  Spacers usually go below the stem on bikes with threadless headsets to adjust the stem and preload bolt position..  They can also go on top to take up extra steer tube length.  I could have bought some but where's the fun in that?  

Spacers are usually always circular but since my lathe is out of commission, I had to decide on another shape.  OCTAGONS to the rescue!  They are somewhat similar to circles and are not complicated to make on a mill.    

I began by squaring up some 1.5 x 1.5 x .625in pieces.  After drilling a 1in hole, I quickly learned how to use the boring head to bore out the hole to 1.125in.  It wasn't as complicated as I thought it was going to be.  It was a little tricky getting the hole the correct size since I still didn't have calipers.  I used a scrap piece of steer tube to test fit the hole until it slid in nicely.  To make it octagonal, I used my trusty 45 degree triangle to setup the piece. 
On my bike.  Sorry for the tilted picture.
On the second one, I made the wall a little thinner and added a decorative slot to each face.  I made the slot using a ball end mill. 
I thought about making a whole bunch and selling them on the interwebs to supplement my project fund but I never got around to it. 

A Large Amount of Aluminum

After my first machining project I was  hungry for more.  So I went to my local metal supplier and bought a good supply, hoping that it would last me through summer (which it has).


I then embarked on my next project which was a baseplate for longboard trucks.  I used to be a much more avid longboarder than I am now but I still enjoy it very much.  When I was skating a lot, I would mostly speedboard, which most of you can tell, is the art of going down a hill as fast as you can.  Anyway all the "pros" on the longboard forum I would frequent raved about precision machined trucks.  I had designed some when I was learning 3D CAD, but didn't really have the ability to make them until this mill fell into my possession.

I started cutting away at chunk of Al.  After couple slightly sketchy setups I had most a good portion of the truck done. 

I had to drill a hole for the king pin and one for the hanger pivot.  In order for the king pin not to rotate, a slot had to be milled to hold the head of the king pin.  Being somewhat lazy that day and not having any calipers (yet), I tried to measure the width of the king pin head while it was still in the skate truck.  That failed miserably so I turned to Shigley's and found that dimension rather quickly. 

I finished up the major work by milling down the sides.  After this was done, I figured I should test fit a Randal hanger since I had hopefully designed the baseplate to fit those.  I was not surprised when it didn't fit well.  It was a slight failure that I'm okay with.  It was nice to have a physical prototype that I could see what I needed to change. 
I got caught up with other projects and have yet to remake it.

Way back in the Beginning of Summer...

...I got a mill and I used it.  It had been awhile since I took my machining class at CP, so I started simple.  I found some scrap aluminum and machined this little piece.  
My nieces and nephews call it a wrench, I call it a linkage thingy but you could call it whatever you like.

I will continue to update this blog with my previous projects and hopefully catch up to where I am now.

Recent Posts