Ok, I have to admit, I may be an evil genius – or just plain sadistic; I’m not sure which.

On my Christmas vacation I decided to work on a project that I have had in the queue for about 2+ years.  When I had my last model railroad, I had a carnival on one side of the layout.  The main attraction of the carnival, besides the massive Ferris Wheel, was a ride called “Top Spin“.  It was a complicated ride to build and the build-out was even more complicated due to one of the main parts being broken when I received the kit.  Of course I didn’t know the part was broken until I was 50% complete with the kit – too far to send it back.

After fixing the broken part and finishing the kit, I added it to the layout and tested it out.  I didn’t work very well and seemed to only partially work right.  More fiddling and more fixing lead to a kit that mostly worked. Here’s a picture of the ride shortly after placing it on the layout:

Top Spin

I’ve never been completely happy with the results and have always wanted to dig into why the kit didn’t seem to work quite right. Well, after 2+ years of waiting, today was they day.  Well, it actually started yesterday, but I finished today. I took a deep dive into the mechanics of the Top Spin and built a new controller to completely figure out what the problems were. Well, not really. The new controller seemed to work much better than the stock controller, so I can only speculate on the problems.

I used a SN754410 half H driver coupled to an Arduino to control the motors on the Top Spin. After figuring out how to set up the pulse width modulation (PWM) capabilities of the Arduino, I set out to control the Top Spin.

My initial attempts actually went very well, but the motors moved fairly slowly – much more slow than what I remembered. I’m pretty sure the motors are 5V DC, and I was using the 5V from the Arduino, but things didn’t move as quickly as I remembered with the stock controller. A little investigation lead to the 1.1V-1.5V drop across the H-bridge circuitry. That means the highest voltage that can be applied to the motors tops out at about 3.5-4 volts rather than 5. Hmpfh.

A little digging into my spare parts led to a variable voltage regulator and a 12V DC power supply.  I quickly whipped up a variable voltage regulator using a surface mount version of a LM317.  The new power supplied fixed the speed problem and yielded a full 5 volts across the motor.  With that problem solved I set out to fully build out the code to drive the animations.

I needed to control 2 motors, read 2 reed switches, and output to two status LEDs.  The LEDs are optional, but helps debugging.  To adequately control the animations I will need to read the status of the reed switches while keeping the motors going.  That requires continuously reading the inputs while changing the outputs. Seems like I’ll need to read the inputs in the “background” using interrupts while driving the motors in the main loop.

Pulsing the motors is easy with the built-in capabilities of the Atmel part used in the Arduino; however, it wasn’t entirely clear which timers where used to control the PWM and which were available to use for other purposes. A little spelunking into the ATMEGA328P data sheet identified Timer 2 as an appropriate timer for interrupts.

To simplify my code, I used a timer library called FlexiTimer2 from the Arduino website. I’ve used it in the past and it has worked well.  Loading the code into my project was easy and the timer worked the first time, so I was off to the races.  I started with a simple sequence of spinning around with the main arm and then rotating the chair where the people will sit.  After some time playing around I quickly realized I need to ensure the animations start from the same place every time or the timing will be off – the arm and chair will end up in different place each time.

Using the reed switches and some fine tuning, I was able to return the chair to the “home” position reliably every time.  From there I continued to randomly build animation sequences without a lot of regard to timing or position of the chair. Without a lot of thought, I ended up with a pretty scary ride. A lot of upside down, backward spinning. After watching it run a few times, I have to say, if I was on that ride, I’d be scared sh*tless. I am an evil genius :)

Here’s a short video of the setup and the ride.

You’ll notice the Arduino on the far right and the breadboard with the motor controller and voltage regulator next to it. The ride was connected to the controller with spring clips and jumpers I had laying around.

I noticed after some playing around the voltage regulator seems to drop out if I run both motors at the same time. I’m guessing it’s because the SMD part does not have any sort of heat sink. Hopefully that will be fixed when the whole thing is soldered together.

You can also see in the video where the arms hit the sides and cause the gears to grind a bit. That’s what all the tape is for – to try and hold the sides completely vertical. I know once it’s cemented into place it will work fine (experience speaking), but on my desk it’s a little more difficult to pull off.

So after 16 or so hours fiddling around, I have to say I’m quite pleased with the outcome and the ease of getting everything to behave like I wanted. I guess the next step is to whip up some schematics and a PCB to act as a shield for the Arduino.

It will be a quite some time until I can get the next MRR up and running, but I now know I have a solid HW and SW platform to build from in the future.

On the eve of the 10th anniversary of 9/11 I’m sitting here wondering if we are any safer? I’ve spent 9 of the last 10 years working for the mechanism that is supposed to make us safe. Provide the peace of mind that we, as Americans, are safe from tyranny, terror, and senseless harm.

I’m not usually bothered by such things, and I generally don’t concern myself with it, but this year seems to be different. Perhaps because I’m working in one of the buildings affected by the terrorist attack. Perhaps because it has been 10 years and although I have watched all forms of patriotism, unity of action, and heroic behaviors, I still see senseless infighting, childish behavior, and empire building.

The current situation of politics is a great example of how far we have come and how far from unification we can be. Our leaders are idiots. The Republicans are pointing at the White House, blaming the President for the current financial woes. Funny, huh? It was the republican president that started 2 wars, ramped up the deficit, and fucked America in the process. Perhaps Congress needs a mirror, or perhaps a history lesson reminding them they voted for every budget increase in the last 10 years. Yeah, that’s right you fucker Boehner. You mother fucker.

And we have the Democrats. Pathetic. They roll over at every turn and continue to compromise our future because they are dickless and have no will to do what is right. They let the Tea Party fuck America, my future, and my son’s future. A small fringe group of sociopaths that have their heads stuck so far up their asses they can’t begin to understand what America really needs.

As Congress and President fight with each other, good people continue to die. Not just Americans, but people of all nationalities, races, and background.

I watched and listened to the Secretary of Defense yesterday. His words tried to express the pain and fear we felt 10 years ago. His words tried to inspire us for what lays ahead of us. Mr. Panetta was proud to be part of the recent killing of bad guy #1, but reminded us there are still people out there who want to kill us. Do us harm.

And yet we have our moronic leaders showing a lack of leadership. Senseless fighting. Politics at its worst.

We spend billions of dollars a year to keep America and our allies safe. We compromise our integrity. We do the unthinkable. We sink to their level. There are ugly people in the world that do ugly things and we have to defend against them. And so we do.

Is what we do worth it? I like to think so. Is it a slippery slope? Yes.

Are we safer? Yes. Is it worth the cost? Well, I guess that is a matter of opinion.

About a month ago we purchased a small freshwater fish tank for my son. Now, as some may know, I have a little experience with aquariums. After a month of testing the water and farting around with dipping drops of test solution in tiny little vials, I got bored with the process. Surely modern technology has come further over the last 15 years since I first stood up my last tank. Surely there is an inexpensive, reliable, and comprehensive solution on the market for monitoring/controlling aquariums? Yeah, right.

Don’t get me wrong, there are solutions. The least expensive one is $119, and $279 for what I want. I could of purchased stand alone meters, but in the end it would of cost more ($89 each). So my natural reaction was to google DIY solutions. I found a fair number of people who have built controllers around the open source Arduino platform, which I have some experience with.

So I set out to build myself a aquarium monitor that can monitor pH, temperature, and will keep track of the date/time. Turns out there is a wealth of information on the web showing how to do this, and a bunch of crafty companies have made it really easy.

This article talks about my experience, the process, and the results. Hope you enjoy it.

I stumbled across this and felt like it was something I’d like to share.   Shamelessly stolen from Lance Mindheim.

  • The ability to get along with, and work effectively with, others. I’ll put this at the top of this list.  This CAN be learned.  Sadly, it is rarely taught -odd given it’s importance. Dale Carnegie’s book, “How to Win Friends and Influence People” should be required reading for all college students.
  • Work ethic. Hard work doesn’t guarantee success but it certainly stacks the odds in your favor!
  • Drive. This is work ethic with emotion and passion attached to it.
  • Ability to prioritize. It’s not enough to work hard.  You need to work hard at the right things.  Recognizing which tasks are the most important is a critical skill.
  • Perseverance and the ability to weather adversity.  Every career goes through hard times.  Being able to weather the storm and make adjustments is critical.
  • Focus and follow through.  The ability to stay on task and see it through to completion even in the existence of chaos and boredom.
  • Ability to communicate effectively with both the written and spoken word. You need to be able to get your point across accurately and efficiently and in a manner that gives the impression that you know that the sentence, “I done seen a movie” is not correct English.   Tip: Pay attention in your English, writing, and speech classes.
  • Creativity.
  • Character. Doing the right thing, even when it’s not popular.  Treating people civilly, fairly, and with dignity.
  • Education/knowledge of the right things.  Knowing more is better than knowing less.  Your knowledge needs to be in the right areas though.

I vote for Character as the number one trait I like in co-workers.  It trumps nearly everything when push comes to shove.  Perhaps honesty is above all else – but that’s part of good character in my mind.

I really thought I wrote an article about this already, but I guess I’m loosing my mind.  Anyway…

A couple months ago I decided to switch from the PIC microcontroller to the AVR microcontroller.  The decision really came down to being able to develop in a higher level language than assembly.  Though I started my career programming in assembly, over the years I’ve become a fan of not having to remember which register I put that variable in, or declaring each variable, one byte at a time, or even doing my own 16 and 32-bit math.  It’s a drag.  Though I’m not particularly fond of C, it’s a step better than ASM for me, and the AVR has a very active user community.

The first step in my journey was to get my MacBook Pro configured to compile for the uC.  In the past that would of been a fairly tall order, but now with the Intel-based Mac’s, it was super easy (a lot more easy that using the PIC on a Mac).  It also “forced” me to get over my aversion of Eclipse and learn the platform.

At some point in the future I’ll fully document getting Eclipse set up for a Mac, but for now there are some various pages out there that I used.

Coming from the Java world, but having an intense background in pure C, I find C++ nauseating.  I’ve never liked it, but using the AVR I’ve learned to “work” with it and get what I need from the language without getting drug into the chaos of pointers to classes, instance variables, etc.  It helps that I’m programming on the microcontroller without a malloc function – it’s really hard to worry about memory leaks when you can’t allocate memory dynamically :)

Anyway, I just finished a short article on programming interrupt service routines for the AVR using C++.  It was not as easy as I would of liked – or as easy as using plain C – but I got it to work and I’m happy.

Now on to bigger and better projects – more on that later.

My wife decided she wants her sitting room back, so the MRR has to move. She has offered me space in the basement for my MRR, so all my MRR stuff has been moved to the basement and the new space awaits configuration.

The good news is I get to leverage all the my lessons learned from the present MRR and apply the goodness to the new one. The bad news is I basically need to start over, as the space is different enough to demand a new design. I will try to keep most of the design elements of the current layout, but I’m looking for more action on the new version. Something I can actually operate rather than just watch the trains go around and around.

More good news. I now have a dedicated workshop area, separated into three sections: computer, electronics, building. Since all the MRRing will be very near my primary computer, I’ll probably be writing here a lot more. Moreover, computer-controlled operations might be a real possibility, but that’s probably months if not a year away right now.

Look for pictures, layout design, and (hopefully) progress over the coming months…

I started a series of articles about the move and pictures.

I’ve been writing a small application to help me design sequences for an animated scene on my MRR. I have the basic application working and now I’ve been adding the ability to save/load data. Rather than using a file, I’m using a database and Hibernate. Now, I’ve used Hibernate in the past but not in any level of detail.

In the spirit of growing as developer (which I don’t do professionally anymore) I decided to exploit the magic of Hibernate and let it manage the full lifecycle of all my objects – automagically. In the process, I’ve become super frustrated at the simplest things that should just “work”. I’ve recently made a breakthrough and feel compelled to share it with everyone should someone make the same mistake I’ve made.

Long story short: I was using an int as the primary key to avoid instantiating a new Integer object for each instance of my object. Well, it seems Hibernate couldn’t figure out that my objects were new and unmanaged when I was using an int, but by converging to an Integer for the primary key, everything magically started working. I recall a property to tell Hibernate what the unsaved ID value was, but I didn’t try it as the error it was returning was hardly intuitive relative to the fix.

I was receiving the following error:

ERROR AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

All my Googling (8 tabs open right now) pointed to a transaction issue, not a primary key issue. Moreover, because the application worked fine with 2 objects, but not three, I really felt it was a state problem with the integrity of the objects, not the primary key. So, if you are getting the state error and your not modifying objects out side the transaction, it’s likely Hibernate can’t figure out if your objects are new or old, so it’s going an update for you instead of an insert. The update will fail because the object doesn’t exist. As an aside, -1 one looks like a valid primary key to the computer ;)

So, lesson learned: Google can answer every question you have – if you ask the right question. This is my attempt to let others ask the “obvious” question and get the non-obvious answer. Peace.

I’ve recently completed a number of printed circuit boards to help control the rides in carnival. After a few turns on the PCB due to operator error and inevitable “betterness” over time, I arrived at my final design and fully populated 4 PCBs will all the parts necessary to control the rides.

After getting all the PCBs built and mounted, I connected a few rides and tested the software. It all worked perfectly for a while, then some of the rides would randomly restart. Hmmm, clearly a software problem. Many hours ensued, many small issues resolved, but still restarting over time.

Then I noticed that two or three of the rides would reset at the same time. Clearly not a software problem, because the rides all have different sequences and different designs. Hmmm, it started looking like a hardware problem. Using my voltmeter, I determined the power supply was cutting out. I assumed with all 4 boards connected, I was approaching the limit of the regulator chip and it was shutting down. I ordered a commercial switching power supply rated at 5V, 2A. That should be good.

Not so much. Although the restarting was less frequent, it still happened. Further debugging showed it happened with only one board connected, though much less frequently. Thus, one board could not be approaching 2A.

Without access to an oscilloscope, debugging the problem much further became very problematic. A quick search on the Internet yielded tons of new and used oscilloscopes – for hundreds of dollars. Hmmm – again. I don’t really want to spend that much money, so I sought alternatives. I eventually found a low cost, PC-based oscilloscope that got good reviews in some magazines. I ordered it and was ready for detailed debugged.

Once I got the oscope, I connected it to the circuit board and was a little shocked at what I found:



Though an extreme case of considerable harmonics, the amplitude and duration of the noise was pretty consistent every time the relay released the contacts. Note the peak-to-peak voltage of 23V on a 5V circuit. Wow!

It took some debugging, but I determined the issue was not the relay de-energizing, but rather, the switching of the AC voltage for the ride motor. It seems the rapid removal of the voltage was coupling to the signals and ground plane of the PCB and causing some pretty deleterious effects.

I’m in the process of adding a snubbing circuit to the motor to see if I can quiet the noise. More when the problem is resolved or mitigated.

Update – 3.28.09

After adding a snubber to both the incoming AC and the outgoing signal, I was able to eliminate nearly all the transient noise. Here’s a picture of the noise after adding to the outgoing signal. I was not able to get the oscope to trigger at 4.8mV after adding a snubber to both in and out. I hope that means the noise is gone.

Noise Reduction

Noise Reduction

Seems like this “project” is now complete. Next step is to get all the boards wired, mounted, and we’ll be done.

OK, so I’m shopping for a new car. All the cars I want are outside my price range, but what the hell. A little debt never hurt anyone. Anyway, a couple of weeks ago I was searching the online inventory for a local Lexus dealership and I found the exact car I want – color, options, all of it. I’m sitting here today researching a variety of models and wanted to find that car again. Well, I can’t find the online inventory feature at all. OK I think, I’ll shoot them an email and ask them what happened to it. So I click on the “Contact Us” link and it pops open an email form. Name, phone, and email address are required. At the bottom there’s a statement:

“Before submitting this form, you must agree to our privacy policy. To read the privacy policy, click here”

Seems kind of ominous, no? I click on the privacy policy to see what they will be doing with my email address and phone number (can’t really trust those pesky/greedy car dealerships after all). The resultant page says this:

“Your privacy is very important to us. Please contact us to obtain information about our privacy policy.”

Which takes me back to the contact form!!!

Can you believe it? What hell kind of operation is this? Everyone has their privacy policy posted for public consumption. Fine. I’ll try another dealership. Guess what? All 5 of the damn Lexus dealerships I tried have the same GD web site! Identical (well, almost…keep reading). What a load of shit. To top it off, one of the dealership’s privacy policy actually said “Temporary Policy Text”. Nice, eh?

What a sad state the web is in these days. *sigh* All I want is to give these people my hard earned cash and they shit on me – the consumer. The people that keep them alive, well fed, and sucking from the tit of greed. Christ, it just shouldn’t be this hard.

Welcome to the first message on the new CyberRailGuru website. To save time and energy, I’ve converted the site over to a bloggish site. I won’t be blogging here per say, but the articles and such will show up like a blog.