Wednesday, February 20, 2013

Linux & Arduino UNO Development


During my latest foray into Arduino development, it became obvious that many of the things I want to do are easier to do in the Linux environment.  This is due to the fact that many Arduino developers are Mac users.  MacOS is based on Linux. 

Professionally, I program in Windows exclusively.  So, up until recently, I have stuck with programming my Arduino sketch editor, compilter and uploader in Windows.  Having said that, I used Unix throughout my undergrad years and early in my professional career.  Even after moving to Windows, I have attempted to use Linux several times over the years.  Unfortunately, each of my earlier attempts with Linux was abandoned for some reason or another. 

For my most recent attempt, I have installed Ubuntu 12.10.  The install on my Acer One (Windows 7 64-bit) laptop went smoothly.  Ubuntu installation is easy and straight-forward.  I opted for a 10G partition for Ubuntu.  After that, it was a matter of searching the web for a handful of Linux tools for a text editor as well as the Linux Arduino software development kit (SDK).  I am still re-learning my Unix/Linux shell control and command.   But, so far, I am pretty happy with Ubuntu and being reminded of how much fun it is to write simple but powerful scripts that can be run from the terminal window.

Frankly, I am not certain I would have been able to figure out how to get the Arduino UNO USB keyboard firmware up-and-running without  moving to Linux.  So, if you are interested in doing this, I recommend you make the move to Linux too.



Sunday, February 17, 2013

Arduino UNO as USB Keyboard "Emulator" : Motivation

Earlier this year, I built a nice gaming PC.  (More about this in a later post.)

While playing my current favorite FPS, I had the thought that it would be really cool if I had a customizable keyboard/controller.

Any experienced gamer can tell you, there are a handful of keystroke sequences that you use over and over again.  Some are pretty simple, like fire (L-mouse) then reload (R).  Others are more complicated.  One example is during stealth sniping in Crysis or Crysis 2.  In both of these games you often need to uncloak, fire, re-cloak.  If you fire while cloaked, your cloaking energy is rapidly depleted.  The faster you fire, the faster it is depleted.  So, one strategy is to first uncloak then start firing.  Then to ensure you remain undetected, immediately re-cloak as a defensive measure while seeking a new attack position.  The complexity of this maneuver has been reduced in Crysis 2. But, this idea of an Arduino UNO -based mouse + keyboard "macro" came to mind while I was playing Crysis. 

Having that said, I know there are some excellent gaming keyboards and controller systems commercially available.  So, if so motivated, I can buy one, but I found this idea so compelling that I finally had something new to explore with my old Arduino UNO.

Wow! It's been a while...

It has been over year since my last post.  What can I say?  I've been busy and frankly, I got a little too ambitious with my Arduino software plans.  My ambitious ideas led to a lot of "mental intertia" leading to a sense of foreboding preventing me from continuing any more work on the UNO-controlled cell phone project.

So, I have pretty much given up on my overly ambitious UNO project.  Instead, I have spent my time on less time-consuming, simpler experiments and home projects.  I will spend some time over the next few weeks describing these here.

For instance, I have recently built a decent mid-end gaming PC.  It took about two weeks from initial spec to final build and test.  I'll describe some of my inspiration and thinking as I was doing this and share some thoughts on what I might have done differently.

Over the past year I have built a couple of LED lighting projects that I would like to share.  There is also a bit of DIY home-improvement I will share.

Finally, over the past week or two, I have dusted off the Arduino UNO and played around with programming it to behave as a USB keyboard device.  Despite the lack of respect for chronological coherence, that is where I plan to start.

Monday, February 13, 2012

Engineering Notation in VBA/VB6

I do a lot of work using MS Excel and VBA.  To help me quickly judge magnitudes of values in standard SI units, I like to see my measurement values listed in "Engineering Notation".  That is to say a customized for of Scientific notation where exponents are a multiples of 3 (etc. ... -9 (nano), -6 (micro), -3 (milli), 0 (unit), 3 (kilo), 6 (mega), etc...).  I have found it impossible to use the VB6 Format$() function to achieve this.   So, here is a short little function to convert a double floating-point number to an "Engineering Notation" string.

For the uninitiated, the format string that works in an Excel custom cell format, does not work the same way in VB.  Specifically, using the VB function, Format$(0.001, "##.0.0E+0") does not yield the same output as formatting the cell: Custom > ##.0.0E+0.  The cell format is what we want... it just can't seem to replicate this output using the Format$() function in VB  (You'd think it would.)  But, I assure you, it does not!

Years ago, when faced with this perplexing behavior, I wrote a similar function that used a series of If/ElseIf/Else statements; it is long and kind of kludgy, but it works.  However, this time around I wanted something more compact that would not need an If condition for each range of 10^(k3) numbers. 

In this most recent attempt, I've made use of logarithm functions to make one that is much shorter (in lines-of-code) as well as more extensible.  As is, this will cover a very wide range of values.  It is pretty much limited by the precision of the OS and/or CPU floating point processors.    I am sure there are even more efficient ways to code this, but I think in addition to being fairly compact (for VB) this code is very easy to understand.  The only caveat is know that the VB Log() is the natural log (a.k.a. Ln() or LN() or "log-base-e")  Not log-base-10 (a.k.a. log())).  So "log-base-e to log-base-10 conversion" is needed.

Anyhow, I am posting this more for my own future reference than anything else.  Based on my own Google search on the subject, I did not find any solution to suite my needs.  So, here's my attempt to fill the gap.
 
Public Function CEngNotation(doubleValue As Double) As String
    Dim x As Double    ' --- Original Double (Floating-point)
    Dim y As Double    ' --- Mantissa
    Dim n As Long      ' --- Exponent
    Dim str As String
    Dim sign As String
'On Error GoTo error_hander   ' --- uncomment for debug; disable when bug-free!
    x = doubleValue
    If x <> 0 Then
        If x < 0 Then
            ' --- x *must* be positive for log function to work
            x = x * -1
            sign = "-"    ' --- we need to preserve the sign for output string
        End If
        n = 3 * CLng((Log(x) / Log(1000)))   ' --- calculate Exponent...
                                                           '     (Converts: log-base-e to log-base-10)
        y = x / (10 ^ n)                     ' --- calculate Mantissa.
        If y < 1 Then                        ' --- if Mantissa <1 then...
            n = n - 3                        ' --- ...adjust Exponent and...
            y = x / (10 ^ n)                 ' --- ...recalculate Mantissa.
        End If
        ' --- Create output string (special treatment when Exponent of zero; don't append "e")
        str = sign & y & IIf(n <> 0, "e" & IIf(n > 0, "+", "") & n, "")
    Else
        ' --- if the value is zero, well, return zero...
        str = "0"
    End If
    CEngNotation = str
    Exit Function
error_hander:
    ' --- this is really just for debugging suspected problems
    Resume Next
End Function

And here's a function that I used to test my CEngNotation() function:

Private Sub Test_CEngNotation()
    Dim x As Double
    x = 10500300
    Do While x > 0.000000001
        Debug.Print x, CEngNotation(x)
        x = x / 10
    Loop
End Sub

Monday, October 31, 2011

"Slo-Flo" Tree Watering Bucket

It has been a hot and dry summer in my neck of the woods.  Hot and dry enough that many of us are worried about our trees dying.  Even though the heat has more-or-less died off, the drought lingers.  So, a few months back I modified some perfectly good 5 Gal buckets to provide some slow flow watering to our most susceptible young trees.

The key to making sure that water is not wasted is to water slowly to prevent run-off.  So a small hole is drilled in the bottom.  I recommend the hole be made near the outer edge.  Odds are you will not be able to set the bucket level, so use this to help make sure all of the water drains out by rotating it so the hole is at the lowest point.  (To make this easier, I marked this point on the side of the bucket.) The lid is used to help keep out debris, the hole in the lid makes it easy to quickly refill the bucked with a hose.  Detailed instructions and hole measurements are provided in the following 45-second video/slideshow.

Simple and effective.  With the small hole I used, the 5-gal bucket will empty in under 1-hour.

video

Friday, June 24, 2011

Not for Cat Lovers

This is hack features one of the funniest hack videos I've seen yet:
 http://hackaday.com/2011/05/25/automated-hose-keeps-cats-from-watering-you/

Saturday, June 18, 2011

Keypad Controller Demo Video & Walk-through

video

Video Walk-through: 


Demo: Power-on the phone, then wait to boot.  Next, dial 0-1-2-3-4-5-6-7-8-9-#-* then key down, down, down, down, up, down, OK, wait a couple of seconds, then cancel.  Repeat dial sequence two more times.  Then power key again to turn it off.  Then a quick tour of the hardware...

Tour of the hardware:  The phone is an LG "Flare" (LX165) from Virgin Mobile.  There are 24 keypad buttons on this phone.  The phone is wired with two Cat5 wire bundles because I had some handy and I like the easily identified wires all nicely bundled together.  However, instead of using 48 wires and 24 relays to control the 24 buttons, I use only 14 wires.  These wires are soldered to specific phone keypad conductors that I determined to make up the "rows" and "columns" of  the keypad matrix.  I connected these wires to a cross-point switch circuit on my board.  For the cross-point switch, I am using 6 Vishay ILQ2 quad opto-coupler ICs instead of relays.  When compared to relays, like the OMR-C-105H used for the power control, the opto-couplers are more compact and cost about half as much per switch.  To control the opto-couplers I am using three 74HC138A ICs which are 3-to-8 bit decoders with complementary outputs.  From the decoders there are 6 wires to the Arduino UNO board.

I have posted schematics for the board design.  Click the "Appendix" tab (above).

The real trick to the entire hack is reverse-engineering the phone's keypad.  I will publish a separate post on that topic later.


What's Next?

For the most part, I think the hardware to control the phone finished.  Now I have a bunch of software to write.  To start, I am going to work on composing text messages.  To do this, I'm going to figure out how to interactively control the phone thru my PC or some other means.  I am thinking of reverse-engineering an IR remote control for this.  I know.  It is more than a little ironic.  But, since the phone's keypad is now useless,  I can no longer use it to play around with the phone and figure out how to navigate through the menus and compose text messages.  This will be much faster if I can do it interactively.