I recently converted from SVN to Git and needed to break my legacy SVN repositories into separate git repositories. This turned out to be much harder than I thought. After a lot of googling and much trial and error, here’s the process I settled on:
Posted by CRG Admin under Electronics , Software Comments Off on Evil Genius?
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:
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.
Posted by CRG Admin under Electronics , Software Comments Off on Arduino Aquarium Monitor
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 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.
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.