Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.


Bug Report? Rant? Request for help? Running Bluetooth Low Energy from Arduino

I'm with a group working on a thing. What that thing will do is not important to this discussion at the moment. What is important is that I'm expecting a flood of data from the thing (think QS/IoT) to a phone. Plus, I'll have a second thing, doing the same thing.

The current demo hardware is using wireless ethernet, which is proving slightly problematic. It's built with the idea of being used by hobbyists who want to put the chip in a thing, not for a group of many developers to prototype and develop on the hardware. I'm also unsure about the ease of setting up WiFi Direct on two devices with simplified user interfaces, and whether it'll block your phone.

So, I'm looking into Bluetooth Low Energy. I got two BLE breakout boards from Adafruit, had a friend solder in the header pins, and hooked everything up according to the docset with my Arduino Uno R2. I installed the Nordic UART app on my phone and got bi-directional communication going from my phone to my laptop and vice versa.

Then, I tried to wire up my $9 Arduino, a Leonardo clone. No go. (I did it wrong. More later.)

Then, I bought an Arduino Uno R3 at half-price from Radio Shack. No go.

Then, I borrowed an Arduino Mega and started to look into the pins. By the code, the pins not set in software are the ones providing the breakout board with CLK, MISO and MOSI. This is my first time talking to a breakout board, so I'm a neophyte to the ways of SPI. The Leonardo moved the SPI controls to another set of pins, so now that I'm slightly less dumb, I get why that failed. But the fact that the Mega and Uno R3 failed still confuses me. I timed out at midnight — had more things to do the next day than time — so I don't know if I'm stupid or what, but I had others verify I had the wiring right, and I think I plugged the second board into the first breadboard, just to ensure both were working.

I think.

Ultimately, getting this working with my R3 (or whatever) is a means to an end. It gives me behavior similar to what I expect from the things, so I can begin to work on the part that's receiving. I want to listen to two BLE devices at once. Or four. Or five. Or more. These things will be our things, perhaps coded in Arduino or not, but will certainly not be Leonardo or Uno boards, so understanding how SPI works differently on these boards is ultimately useless.

Except it absolutely must happen to move on to the next step.

Contributing to this frustration is the fact that I don't know enough about the problem domain to ask an intelligent question. I'm coming into the world of Arduino as a programmer, and in essence, what I have are variables I can set high or low, or sometimes somewhere in between, and variables I can check that are high or low, or sometimes somewhere in between. Between the set and ground, or 5V and checking is a circuit, and there's a lot about wires and resistors and the process of handing variables around that I just do not understand. With the Leonardo, the step after next (after being sure the second board works) would be to find female-to-female jumper wires, as all I have are male-to-male, then wiring to those SPI pins should be cake.

But it strikes me that someone else has failed to get this working on R3 Unos before, and I'm not seeing that person's cries for help, maybe because I'm not looking in the right place. Neither Stack Overflow nor the EE Stack Exchange site seem to really be good places, and as useful as the Adafruit Learn page is (written by the man who wrote the book on BLE), there's no way to engage back, to get clarification.

Anyway, I'll beat some more on it this evening. We'll see how far I get.


2014 Body Goals - Way Late Post-Mortem

My goals, you might remember, were:

  • Significantly greater range of motion for my right foot, less pain from both feet (Feet)
  • Weight of less than 200 lbs. Waist of 32 inches or less. (Weight/Body Fat) 
  • Meeting daily steps goal of 6000 daily. Raising to AHA-standard 10,000 steps and meeting that. (Feet,Stamina/Endurance) 
  • At least one 5K race completed in 40 minutes or less. (Stamina/Endurance) 
  • A set of ten standard push-ups (Strength) 
  • One successful pull-up or chin-up (Strength) 
How did I do?

At least one 5K race? Done.

Push-ups? Forgotten about early.

Pull-up or chin up? Again, dropped early.

Range of motion? Take a guess.
I raised my goal of daily steps to 10K, and for at least one day each week, for most of the year, I made my step goal. Then, in December, things just fell apart. I tell you, most of my vacation, all I did was rearrange my bedroom and play XCOM on XBox. I'm sure that burn-out is unrelated to exercise, but it was something I dropped.

Weight? I've been between 212 and 204 lbs for most of the year, and while I'd like to be under 200 lbs, I'm okay with this. I'm sure there will be a drop in weight again as soon as it's warm enough for me to be mobile.

So, one goal out of six. Not good. Still, by nearly all objective measures, I'm in the best shape of my life. As a teen, I swam a mile, twice, and felt exhausted and heavy as I climbed out of the lake. Yesterday and today, I swam a mile in the school's pools, and I only stopped because I felt some cramping in my calves. Nothing too bad, just enough to make me think "I should stop now".

I don't have big goals. I'd still like to do a pull-up. I still want to get back on the running thing, although I'm thinking I'll have to throw HIIT sprints early into the run to get my stamina up. I will almost certainly do at least one 5K. Maybe two. And I'll try to do dead-lifting, because playing guitar a long time can cause pain in my back and shoulders. I'll develop a goal, digest into a plan, work the plan and forget that goal.

And sleep. Sleep is good. Good night.


Deep Syntax in DBI

Let's look at some code. This uses DBI to talk to MySQL.

    my $out ;

    # This query gets everything out of the database
    my $query_all = '
        SELECT  steps 
            ,   miles 
            ,   datestamp 
            ,   DAYNAME(datestamp) day
            ,   DAYOFWEEK(datestamp) dow
        FROM fitbit_daily 
        ORDER BY datestamp 
        ' ;

    # This query used a placeholder to just get better days
    my $query_high = '
        SELECT  steps 
            ,   miles 
            ,   datestamp 
            ,   DAYNAME(datestamp) day
            ,   DAYOFWEEK(datestamp) dow
        FROM fitbit_daily 
        WHERE steps > ?
        ORDER BY datestamp 
        ' ;

    # db_hashref() is a wrapper around fetchall_hashref()
    # that looks like this :

    # sub db_hashref {
    #     my $sql = shift ;
    #     my $id = shift ;
    #     my $sth = _execute_query( $sql , @_ ) ;
    #     my $ptr = $sth->fetchall_hashref( $id ) ;
    #     return $ptr ;
    #     }

    $out = db_hashref( $query_all , 'datestamp' ) ;
    say Dumper $out ;
    # Returns all 960 values keyed by datestamp, keyed by datestamp 

    $out = db_hashref( $query_high , 'datestamp' , 18000 ) ;
    say Dumper $out ;
    # Returns the four days where I actually was that active

    $out = db_hashref( $query_all , [ qw{ steps datestamp } ] ) ;
    say Dumper $out ;
    # Returns the a multidimentional hash, with the first key 
    # being the steps and the next one being the datestamp.
    # Perhaps not the most useful, but I'm proving concepts here

The missing syntax is now that will get me the decent step days, in the cool multidimensional hashes that I've grown to love. I might have to take it back a bit to get that behavior. Suggestions?


What's On My Mind?

Thinking through the Thing: I had said that I thought this was wasteful of battery life. Now, I'm thinking that many many things are wasteful of battery life, and that's the user's decision, not mine. I mean, for myself, I'd rather run it as a crontab-based Unix tool, but not everyone is me.

So, I guess the solution is to man up and learn to develop for phone. The barriers to entry for the iThing market, for me are 1) getting a Mac and 2) getting an iThing, so looks like I should learn to develop for Android.

Which I've been telling myself regularly for the last four years.

Computer Science as a Subset of Math, and what it means for Hackers like Me: I work at a big university with a great Computer Science department, one that gave me a degree. So, I feel I should go and attend colloquia and the like, to keep expanding my mind.

Thing is, as an undergrad, the coursework was all about how to use the tools of software development. Not even software engineering, which is more about creating processes for writing, testing, and delivering code. For example, the use of git as a code repository is a software engineering question, but the use of functional or object-oriented programming is a software development question.

So, what's a computer science question? I don't know that I'm qualified to answer that. But that shouldn't stop me.

Consider the sites in Stack Exchange. There's the site they created it for, StackOverflow, which I tend to go to for syntax-related questions. If you want to code, go there. If you want to use the tools others coded, there's Ask Ubuntu, ServerFault, SuperUser, and many more. If you want to ask question s about how to live and work like a programmer, there's Programmers. And, if you have over a certain amount of reputation on one Exchange, you have proven that you're a helpful person, and you get some credit on others, except for the highly domain-specific places.

Such as Math and Theoretical Computer Science. Because your thoughts on Replicants in Blade Runner or why guitars are tuned like they are mean nothing when it comes to Set Theory, P vs NP or the Church-Turing Hypothesis.

(That might be an old rule about Stack Exchange reputation.)

In essence, if an idea is best presented as source code or pseudocode, it might be best found in StackOverflow, while if an idea is best presented as an equation, it is either Math or Computer Science.

To me, in most places where we more properly say "Computer Science", we're talking, more or less, Complexity. This can involve Machine Learning, Emergent Behavior, understanding the structure of the Genome, or the behavior of puppies. Because this is what I'm looking at from the outside, there's a lot more to it and I'm subtly, or perhaps less than subtly, wrong. In a nutshell, if we could do a science without computers, without using them to image and parse physical things, without using them to analyze greater and greater amounts of data, we would've done these things in the centuries before we turned sand into circuits. "All Science is Computer Science", I say.

In my day job, I help Science. Metadata needs to exist and be here so it can be combined with data and help us know what we're talking about, and that's what I do. I make it easy to collect the metadata and write it in ways the instruments need it. I plot out the data. But I don't do anything with the data.

This does keep me busy, but when I go to talks like today's talk on "Learning Structure from Data: Applications, Algorithms, Statistical  Efficiency and General Frameworks", it's as if they're talking another language. They are. They're speaking math, and I'm used to speaking code.

So, perhaps I should take the Coursera class on Data Science. Because I'm finding need of using next-level, "smart" tools to poke into different aspects of my life, and I'm stuck somewhere between the buzzword and the actualization.

We Need Another Number Format: Think about this.

You might think "Yeah, Javascript sucks."

Same is true with Python. With Java. With Perl 5. It's IEEE 754, the standard for handling floating point numbers. If your language doesn't fail at 0.1 + 0.2 - 0.3 == 0, it is not standards-compliant.

But, clearly, if I give you a penny, then two pennies, then take away three pennies, you end up with no pennies, not 5.551115123125783e-17 pennies.

This is the thing I'm hitting right now at work.

This, the jump between $159.95999999999998 and $159.96 is simultaneously too small for anyone to care for any specific transaction and enough, for enough transactions, to put Richard Pryor in a Ferrari in Superman III.

So, I'm thinking, for the purposes I'm needing to do it, the solution is to multiply by 100, parse as into to drop anything remaining, do what simple math needs to be done, then divide by 100, or maybe just drop a period in there.

And working myself up to doing what I know must be done is what I'm doing today.

(Pictures are mine, taken by me, trying to make this post less text-filled and grey.)