Pneumatic Controller: Part 5

First some coding, then building with pictures.

As promised, I’ve started on the main part of the code and testing the pistons and sensors. Because I didn’t want to go through the entire setup process each time I checked something, I got rid of all that and just gave some initial values. Then I made a small script to print out all the variables used (such as if a piston was in or out, or how many cycles it has done) so I could keep track easily.

I ran into two problems very quickly. One was that I couldn’t seem to make cycle periods (time in between cycles) that weren’t integers (I could only do 1s, 2s, 3s and not 1.5s, 2.75s, etc). The other was that the entire script was only running about once every two seconds. This second one was particularly frightening because I had expected it to run several hundred times a second and the fact that it was so slow implied that my code was outrageously inefficient. Now as a mechanical engineer, my programming education focused less on efficiency than a computer science major’s would. We learned a bit about it, but for our purposes, the difference between a very efficient code and a kind of efficient code were minor. My worry here is that my code was doing so much (which seemed dubious) that it was crossing that border into CS land, and I would have to learn a lot more about efficiency before continuing, something I was not looking forward to for a section I thought to be pretty simple.

Turns out both problems weren’t too bad. For the first, it was an issue of variable types. Two of the types you can use for numbers are int and float. An int (like integer) is a whole number (1, 2, 300) and a float is a decimal (1.5232., 6.5, 24.23542). There are other difference but this is all we need now. Because I wanted the cycle periods to have the option of times in between whole numbers, I used floats. What I neglected to realize, however, was that if you divide a float by an int (like 3.5/10), you will get an int. This meant that my program was constantly rounding these numbers and ignoring the decimal. The fix was just to change the 1000 I was using to 1000.0.

The next problem was trickier, only because the first problem helped it along. At one point I suspected the printing function was slowing it down, but when I removed it, it was still too slow. Turns out it was still slow because of the first problem. Once that was gone, I got rid of the function and the program ran smoothly and quickly.

Now the picture part. First up was some cleaning. The box had lots of wires and components that I wouldn’t be using, and they took up real estate and made everything more confusing and messy.

So one of the first things I did was to gleefully take out anything I wouldn’t be using in my version. Besides the controller and LCD, this meant about 12 miles of wiring. I left the buttons on the face of the lid in after disconnecting them, though, in case someone wanted to use them later. All I wanted was the transformer, pressure switch, and emergency shutoff button.

Cleaned up lid

Cleaned up lid

Cleaned up inside. You didn't see it before, but it was quite a mess

Cleaned up inside. You didn’t see it before, but it was quite a mess

The other thing I did, although it was after I took the picture, was to move the pressure switch (top left of above picture; black thing on grey thing connected to blue tube) to the bottom, basically flipping along the horizontal. This changed nothing in terms of the workings of the system, but gave me a lot more room on top.

Next, the main program. To test the program, I first wired up some LEDs, since they would be much easier to work with than pistons.

Arduino testing with LEDs

Arduino testing with LEDs

More Arduino testing with LEDs

More Arduino testing with LEDs

This showed me that at least the code worked (eventually). Next was to test it with an actual piston. For this, I used code that just opened and closed the solenoid every one second. All I wanted to know was whether the circuitry worked.

Arduino testing with a single piston (IN)

Arduino testing with a single piston (IN)

Arduino testing with a single piston (OUT)

Arduino testing with a single piston (OUT)

It did.

Next up was to make the permanent circuitry for the solenoids. This would be what went into the actual box when I was done. Luckily, when I cleaned up everything, I was left with these little connector things that had been used a lot. I had planned on ignoring them, or even getting rid of them to save space, but I actually found them incredibly helpful. Besides making connections a lot easier, they hooked onto rails that were installed in the box, making everything neater.

Cool attaching things for solenoids

Cool attaching things for solenoids

I put together the breadboard and wired it all up.

Solenoid circuitry

Solenoid circuitry; wires on left go to Arduino

I do not have pictures but I did test all the solenoids and it worked beautifully. For the Arduino end of this (coming out of the above picture on the left), I used some ribbon cable with one end soldered onto the resistors (above) and the other soldered onto male headers that would plug into the Arduino (below).

Pins for solenoids

Pins for solenoids

I had wanted to plug these wires into male headers directly, but the ones I bought were too short.

Finally, I rewired everything so that the pressure switch and emergency shut off button would still disconnect power to the pistons, and began setting up the rest of the circuitry.

All in all, it was a good week. On Monday, some more transistors and resistors arrived (UL had the oddest and least helpful collection of resistors) and so I can start putting together the sensor breadboard. I’m looking to finish in the next week or so (fingers crossed), depending on my workload.

Until next time!



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: