Trouble in Arduino Paradise

(This is another article I wrote a year or more ago but never got around to publishing until now)

I’ve been helping an ecologist make a “compass bearing data logger” using an Arduino Uno. Actually, I’ve been doing most of the implementation while Erik has defined the requirements based on his many years doing field work with other logging tools. (It is pure joy to have crisp requirements so you know your solution happens to match the problem at hand!) Erik picked the Uno and it seemed like an excellent choice because it was very easy for him to combine bits and pieces from Adafruit to create a solution. We quickly became aware of off the shelf software libraries that either come with the Arduino IDE or that are available as add-ons from the main Arduino repositories to support the hardware. At the start of the project it seemed unimaginable to exhaust the Uno’s memory capacity with such a simple application. Does that sound familiar?

After getting about 98% of the functionality in place the IDE still reported only about 24 kilobytes of text usage along side the Uno’s 32 kilobyte capacity figure. But after the addition of the last hundred or so lines of C++ the system became unstable. It wasn’t unstable in the usual sense that the new code didn’t work right the first time. (My batting average up to that point had been excellent, but there had been a number of surprises.) The system was unstable in the sense that only the first sliver of initialization code was executing, but it was executing over and over forever. The CPU was reseting after just a little bit of the application code had executed.

When I was much younger I might have thrashed with this a long time, struggling to determine what broken code fragment I’d added somehow explained the failure. Instead I got out the machete and gutted the bodies of several functions until the overall code size was similar to what it had been the last time the system had run properly. Sure enough, it ran properly again. Replacing stub code with full function bodies in various combinations proved that it was simply the amount of code involved that caused the instability. I should point out that this program has very little “variable” storage in relation to the Uno’s 2kb of RAM. That is, it has maybe a dozen scalar variables, one small character array for building file pathnames, and a couple of objects to do with the clock/calendar and compass chips and the SPI interface to the SD card used for the actual data logging. Also, there are no recursive routines and very few local variables and very shallow call nesting, so stack demands are trivial too. In short, the bad magic was to do with undiagnosed overflow of “something” to do with the amount of text (machine instructions produced by the C++ compiler).

Except that C semantics require initialized string constants to be put into the data segment, and this has to be mutable, and therefore in RAM vs flash memory. Duh. So I was overflowing RAM, causing the stack to walk over the top of variable storage as it nested during routine calls.

The trouble in paradise is that in my world it’s just not acceptable that overflow of a statically allocated memory segment would go unnoticed by the tool chain. In my world this kind of misbehavior forces the Arduino IDE into the “piece of sh*t” bucket and I’m only persevering with this tool chain now for the sake of Erik’s target user group being able to make this logger with user-friendly tools. The Arduino IDE is fantastically user-friendly for making an Arduino blink LEDs. Going much beyond that in my experience has given appreciation for the “get what you paid for” adage.

But the other trouble is that it appears that some combination of Linux, the USB library “RXTX”, and the Arduino IDE are conspiring to ruin my system’s uptime record. If I had a nickle for every time a failure to do with the USB connection between the IDE and my Uno has forced a reboot I could buy another several TI MSP430 Launchpads. More on this here.

 

 

Hand soldering TSSOP packages with MSP430G2955 example

SAMSUNG CAMERA PICTURES

While researching an alternative to the Atmel 328p for the Pathfinder (compass data logger) project I decided I just had to try out the latest, greatest chip in the Texas Instruments “value line” G series, which is the MSP430G2955. This chip features 56k of flash, 4k of RAM, and more I/O than you can shake a stick at. This chip was only released a few months ago and none of the sources I can access had any stock yet. I’d been using the TI developer web site a lot the past couple years and decided to order a sample part for the first time. TI sent one immediately by FedEx. Hopefully this article will serve as a small, initial thank you. I’ve loved the folks at TI for 35 years since I was part of a company that OEM’d their computer systems. I still have fond memories of visiting the R&D sites in Dallas and Austin.

The problem, however, is that the least impractical package this device comes in is a 38 pin TSSOP package with .025″ lead spacing. Notice in the picture above there are four leads in the .1″ spacing between protoboard holes. Notice the bypass cap leads look like the Alaskan pipeline. (I used wire wrap wire to connect to the power and ground pins.) The most pointy soldering iron tip I own looks like the end of an unsharpened pencil in relation to this pin spacing. What to do?

I found a Youtube video (if I can find the URL easily I’ll paste it back into this blurb). It held the big secret: you solder a chip like this and then unsolder the spaces between the pins. Physics won’t allow the solder directly under the pins to be slurped out by braid type solder wick. Wow.

Here’s how to solder a chip like this. I assume you’re very experienced with soldering except for these itty bitty components and that you’re using a temperature controlled, low power iron with a tip so sharp that it’s painful to put your finger on it (when cold). A regular, small chisel tip iron might get the job done with the right (very small) amount of solder on the tip.

  • Meticulously clean the board with alcohol
  • Apply liquid flux to the pads
  • Put the chip in place and slop more flux across two diagonal corners
  • Hold the chip EXACTLY right on the pads and touch the two corner pins with an iron holding the merest dab of solder
  • Put flux across both rows of pins
  • Put a length of very small gauge (e.g. 26 gauge) solder lengthwise across one row of pins, stopping short of the corner you tacked on.
  • Run the soldering iron across the pins, melting the solder and going at a speed such that you can see the solder wicking under the pins. IGNORE the fact that you’re soldering multiple pins together into unrecognizable blobs.
  • Put flux on some very small solder wick and lay it across a row of pins at a time
  • Put the iron across the flux and let it slurp excess solder off the pins a group at a time
  • Inspect the soldering with a decent magnifier and convince yourself there’s a nice solder joint under each pad
  • Ohm out the connections to confirm everything is right and there are no shorts or opens

That’s it. I couldn’t believe that I could do this right the first time and when my health recovery allows it I’m going to have a blast with this chip. Some back of the envelope calculations suggest I can get the total quiescent current of the logger under a milliampere, so one large (nonmagnetic) Lithium coin cell may get the job done and run the logger for an entire summer of butterfly tracking, with the big flash memory standing in for the SD card used by the current logger.

By the way, the excellent quality DIP adapter came from a firm with a presence in nearby Morrisville, NC called EZ Prototypes. They had to ship my part from Boston but it got here in two days at a very reasonable price. Update September, 2019: This link is no good any more: the domain is no longer registered. Too bad. But anybody unable to find a 38 position adapter and  interested could ping me at pete at apexprotofactory dot com about making one, as this is a simple exercise for me now.

Logic Analyzers Rule

A few months ago I was using an Open Bench Logic Sniffer v1.04 from Dangerous Prototypes to decipher a problem with an SD card controller. It sure was nice to have a $50 device that works at least as well as the $5k devices I used in the 80s, and the performance is perhaps a hundred times greater than the tools I used with Intel and Motorola processors in the datacomm devices we created at Network Products.

Do it yourself Printed Circuit Boards

Top56

Last year I taught myself how to use the Eagle computer assisted design (CAD) program, which supports design of electronic circuit schematics and corresponding printed circuit board (PCB) designs.

Then last winter I researched affordable sources of small quantities of PCBs made from Eagle files. I settled on OSH Park, a small firm in the Portland Oregon area that converts a given Eagle board description (“.brd”) file into a complete set of Gerber photoplot and CNC drill files necessary for commercial PCB production. OSH Park combines designs sent to them with surrounding “slot” specifications and joins them all together into a large “panel” design. They send the completed panel description files to their supplier. The supplier creates three finished panels of PCBs corresponding to the panel design and sends them to OSH Park, which breaks the panels up into the individual boards and mails three copies of each board design out by US mail. The turnaround time has been gradually improving and now stands at around 10 days from hitting ‘submit’ to pulling boards out of my mail box. Three boards roughly 2×2″ costs $20. The quality is astonishing. If you look closely at an Arduino Uno, for example, you’ll see very fine detail, precise solder masks and silk screening, etc. Add to this a gold finish making soldering a breeze and you can appreciate the fine quality of boards from OSH Park. They are in every respect professional quality if the design involved follows best practices for layout.

Five Days in Heaven

Sunday, September 29th, at 4:10am a drug called tikosyn converted my heart from atrial fibrillation to normal sinus rhythm after I was admitted to UNC Medical Center with low blood pressure and way too fast pulse rate. I’d had 24/7 afib for a long time, and a heavy afib “burden” (ratio of afib time/normal rhythm time) before that had kept me dragged down for years. So the switch back to normal rhythm was the very definition of pleasant surprise.

The five days in normal rhythm this week were blissful.  I’d forgotten how totally wonderful it feels to be in normal health. I walked, rode my bicycle, and did the other things allowed by the doctor as my wounds heal from a right thoracotomy epicardial ablation procedure my surgeon performed on September 19th.

But now I’m back in the “oh oh” state, and if I’m loaded with digoxin and more carvedilol I’ll be in the precurser state I was in almost exactly a week ago when I suddenly had to prop myself against a wall while I determined just how dizzy I was going to get. Ugh.

I have no choice but to “hang in there.” I’ll upload the detailed EKG data being captured by a Medtronic  “loop recorder” implanted near my left collar bone, send an email to one of the specialists, and be caller number 1 when the electrophysiologist’s office opens at 8:30. And this time, unlike last Friday morning, I won’t eat any breakfast. So if they want to do a cardioversion I won’t have to lay on a gurney for eight hours while my stomach empties.

But I’m almost entirely the same guy that went to bed with sinus rhythm, and my new found enthusiasm for life is still clear in my memory. Hopefully I’ll still be back to work on two embedded computer projects soon as I “stay stable” until I’m ready for the final step of my afib cure, an endocardial ablation procedure.

 

 

Moving phone numbers from one cell phone to another

What could be easier? Uh, actually, what could be harder? Here’s a great example of how the lack of standards or any real regulatory influence on US cell phone vendors has resulted in the situation where I’m sure it will be easier to write down my current phone contacts and then enter them into the new phone vs finding the magic to transfer them via SIM/Bluetooth/etc. Or at least that’s my conclusion after a half hour poking around through the old/new phone menus, searching the Internet, etc.

I know, this is why you pay the bucks and have somebody at a carrier office or Radio Shack take this off your hands. It’s hard being cheap.

 

Boycotting news.google.com for a month

After reading news.google.com as I try to do once a day I was totally annoyed by the “Gargling Sugar Water Gives You Superhuman Strength Of Will.” I really should have been tipped off by the basic lack of literacy in the use of capitals in the title, and I promise to never ever click on a link where I notice thegloss.com in the URL. But as I came to realize,  a chunk of the content on news.google.com is not just plain crap, it’s extraordinarily low grade crap. I’m going to skip this site until mid-December and see if I can still get my news fix every day.

[Fast forward to November, 2016: Could not look at news, listen to radio, look at TV for a week after the election. Then subscribed to the New York Times, The Washington Post, and began donating regularly to The Guardian (UK) newspaper. I now (2019) very occasionally visit news.google.com to see what the current button-pushing headlines are, but stick to the three newspapers and vetted blog sites and podcasts with occasional visits to their conservative counterparts while also chatting with an ultra-conservative soulmate (high school best friend) to peer outside my silo. But the indiscriminate blend of editorializing and news in my three main newspapers is grinding me down!]

[Fast forward to January 24, 2022: I’ve been degooglifying myself for the past many months. Signal replaced Hangouts. Staying as far away from other tools as possible. Phone has the least Googlified Android I could find in a mainstream phone (LG Wing). But hypocrisy with respect to YouTube until I can get permission to point to a local copy of a song. Needless to say I haven’t looked at news.google.com in a L O N G  T I M E.]

Bitser? 1970s NASA-funded behavioral research

I just happened to google “bitser” and found two collisions. It appears that in 2009, somebody or some group created a Windows archival program called Bitser, and it’s been living at bitser.org for a long time. I was oblivious to this. I also discovered that a “bitser” is the term for a mixed-breed dog.

I don’t mind my domain being associated with dogs, despite being a cat person.  But call me a religious nut if necessary: I just can’t have my web site confused with anything even obliquely related to Microsoft Windows. I’m going to switch domains and move/rename this blog.  (This added in July, 2018: Never underestimate laziness. So I never got around to a domain move, and in the meantime my religious fervor about Microsoft being terrible has evaporated (I feel sorry for them now). I’ve even forgiven Intel for nearly killing Network Products with their dishonest treatment of us vis a vis the 80186 chip availability. Now we resume the original post.) But that will take a while, and in the meantime, folks may be asking themselves what I mean when I use the label “bitser.” The rest of this is my explanation.

When I registered the bitser.net domain in 2000, it was to create a web site that the Java JSR-121 Java standards project could use, as a couple week’s wrestling with Sun Microsystems red tape sumo wrestlers made it clear that the JSR-121 Expert Group couldn’t make practical use of Sun web resources (“Fill out this form; expect your web site change to be accomplished in one to two weeks. Heck no, you can’t administer it directly!”) As the JSR-121 “Spec Lead,” it fell on me to handle record keeping, and an easy-to-maintain web site that could be divided between private and public areas seemed the best way to go, along with a couple of GNU Mailman lists maintained by Doug Lea. Anyway, I needed a domain name, and “bitser” popped into my head and seemed as good as any. So I registered bitser.net and set up a web site hosted by QTH.com, an outstanding ISP based in Wisconsin owned by fellow amateur radio contester KA9FOX. This was all on my nickel, and I couldn’t afford to register bitser.{org,com}, which was, of course, the fatal flaw. (bitser.com is some kind of Internet store front based in Thailand. Update September, 2019: bitser.com is available but I’m still too cheap!)

But what is “bitser?” Bitser is the name of the first non-trivial computer program I  wrote. I worked for the University of Alabama in Huntsville in the 1970s as a “research assistant” and then “research analyst,” and apart from helping build and run a human factors research laboratory within the psychology department, my primary contribution was software development aimed at data collection, reduction, and analysis. We did  experiments to do with behavior in settings relevant to NASA, like living and working in a simulated spacecraft. In later stages four men and women spent 10 days in a very small  set of rooms that could be transformed from “bare walls and concrete floor” to “the lap of luxury”, or anything in between, depending on how productive they were. As part of this, we gathered fine-grained data describing the behavior of the experimental subjects. In addition to keeping track of all the work they accomplished and the “money” they earned and spent within our artificial micro-economy (the monetary unit was the ‘bit’), every six minutes two observers recorded what the experimental subjects were doing in terms of their senses and actions. We’d invented a “BInary OBservation System” (BIOBS) that just required an observer to make a series of choices to traverse binary decision trees, for example, rooted at “what the subject is looking at.” By making a series of “this or that” decisions, the state of a subject could be recorded as a set of nine four-bit binary numbers, each requiring four “this or that” decisions. That’s 64 billion combinations with 36 observational decision for each subject. It was actually less because some of the trees were not fully populated, and if you have the impression that designing those trees was very hard, you’d be right. But after a bit of training and a few hours practice, the lab staff got extremely fast. In practice the subject’s behavior tended to be about the same from one observation to the next, and we could memorize the commonly-used portions of the decision trees, and those of us involved with designing the trees tended to have them burned into our brains anyway. This scheme beat the hell out of all the alternatives we used  early on, but implementing it efficiently was a challenge, as computers were horribly expensive and hard to use at the time.

Bitser was the interactive analysis program for BIOBS data. Because all the behavior could be connected to things that had been bought with the artificial money we called BITS, naming the analysis program “BITSer” made sense. It allowed staff and students to query experimental data and ask questions like, “How often did three out of four subjects listen to music while eating something and working on their stats course?” (The “work” the subjects did during many experiments was a statistics course that gave three semester-hours credit in 10 days flat! Every subject in every experiment except one passed the course, most with an A or B. In the outlier experiment, the “money” normally earned from course work that was necessary to buy almost everything in their environment was instead made non-contingent. That is, “BITS’ were put into the subjects account each hour no matter what was happening in that one special experiment. In that case, none of the four subjects did any significant work at all, and all failed the course. We called that experiment the “welfare paradigm” and it drove me to the conclusion that one open secret of a satisfying life is meaningful work.) Bitser was a few thousand lines of Fortran V that ran on a Univac 1110 mainframe with a 300 baud remote terminal, and my last listing is dated October 1973. Back then I wrote extremely dense code (I made a graphic version of Conway’s “Game of Life” program with 80 lines of code and a Tektronix graphics terminal  soon after Conway published the game). But I was young and Bitser was of course write-only code. I can hardly bear to look at the listings now.

[Update September, 2019: Looking back at this, and reflecting on what I’ve learned about the welfare system in this country, I realize naming the above non-contingent paradigm with the word “welfare” was regrettable. I, and perhaps all the folks in that research lab were clueless about the reality of welfare and the little detail Kahneman and later researchers determined that for somebody in poverty the “reference point” is unobtainable and regular dollar amounts of compensation may be perceived as losses, not gains!]

Anyway, so much for the “bitser” name. I’ll leave this domain in place so the JSR-121 interest link is stable (it’s referenced by a handful of journal articles and other sites), and this blog URL will redirect to the new place at the point I do the move.

For those who are interested in the research here are links for 1974 and 1973 publications (update September, 2019: The second link gives a 404 now. I’ve hopefully stashed the file someplace but had completely forgotten I found these files on the NASA site and only realized I’d found them when reading this posting again.) (This added in July, 2018. Never underestimate laziness. So I never got around to a domain move, and in the meantime my religious fervor about Microsoft has evaporated. I’ve even forgiven Intel for nearly killing Network Products with their dishonest treatment of us vis a vis the 80186 chip availability. Now we resume the original post.)

We Love Kroger

(Read this November, 2012 update first: Kroger will discontinue it’s “fuel points” discount at the end of 2012. Sigh. Further update from the future: Kroger is no more in this part of the USA and with its departure from Apex, North Carolina went hiring of challenged individuals. I boycott Harris Teeter when possible.)

Our daughter’s basic high school band expenses are $575 per year, not including trips, dinkles, t-shirts, calendars, and music cds. This year’s trip, a cruise, will cost at least $800. Add to this about $1200 for instruments this year (including an oboe made in France in the late 1930s gotten with a killer deal and refurbished by a local saint), the ongoing cost of instrument reeds and biweekly music lessons, and the cost soon begins to get to the hair-curling level.

Enter Kroger. The area Kroger groceries offer a “magic” gift card that can be used over and over again. All the money put on this particular gift card (actually one each for my wife and me) can be spent on anything they sell, which includes gift cards for other shops and gasoline. Each dollar spent puts a nickel in our daughter’s band account. In addition, each dollar spent on general goods results in a “fuel point,” and each dollar spent on other gift cards results in either two or four fuel points depending on periodic specials. Each 100 fuel points translates to 10 cents discount on gasoline, and one gasoline purchase can fill both our vehicles with a discount of up to two dollars per gallon. On top of all this, Kroger purchases earn a second flavor of “points,” and a few times a year we get $10-20 in coupons redeemable for anything Kroger sells in return for the points. Too bad we can’t feed those coupons through the Kroger card, but we don’t want to overheat their administrative servers with some kind of compounding runaway.

But to give an example of how cool these features can get with Kroger, consider this past North Carolina tax free weekend. We’d been preparing to get our daughter her first PC, carefully searching for a laptop she wouldn’t soon outgrow, and the cost came to about $575. We put the money through the magic Kroger card to get a stack of Best Buy gift cards. This transaction put $29 into the band account and will save about $38 on the next fill up of the two vehicle’s gas tanks. In combination with saving NC sales tax, we made over $100 of effective savings on a $600 computer. Thank you, Kroger. (And thank you, state of North Carolina, and thank you, Best Buy for the $70 discount on the computer).

Update September, 2019: All 14 Kroger stores in this part of North Carolina were closed a few years back. The aspect that hurt the most is the fact that the ones we shopped at made a point of employing people with handicaps of various types (one wonderful lady had grown up deaf, a few staff had some cognitive challenges, etc). Kroger’s remaining stores here (Harris Teeter brand) have no such diversity employment.

Raspberry Pi with little SD cards

If you have an old SD card that’s less than the 2gb needed to run the blessed Raspbian (Debian Wheezy) Linux distro made for the RPi, or like me, you had a 4gb SD card but a bad spot turned it into an 870mb SD card, fear not. If you’ve got a thumb drive you can trivially carry on. Here’s how.

First thing is to copy the image file to both devices with commands like this, after:

1) BEING SURE you substitute your /dev/paths and

2) Unmounting the card and/or thumb drive before copying images over the top of them

sudo dd if=2012-07-15-wheezy-raspbian.img of=/dev/sdk ; **>>MY<<** thumb drive

sudo dd if=2012-07-15-wheezy-raspbian.img of=/dev/sdi ; **>>MY<<**SD card

If the SD card was 64mb or better, then you should have an intact copy of the FAT filesystem on the front of your card, and if you have a current Linux system it automagically mounted . If not, mount it with something like mount -t vfat /dev/sdi1 /somepath and then cd into /somepath (or the actual filesystem typically under /media).

Edit cmdline.txt to look like this:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/sda2 rootfstype=ext4 elevator=deadline rootwait

Then cd out of this filesystem and umount it, put the card into your Raspberry Pi and the thumb drive into one of it’s USB sockets (or a hub socket) and power it up. The command line above will tell the system on the SD card to mount the root filesystem on the thumbdrive instead of trying to use the (uncopied or corrupt/incomplete) 2nd partition of the SD card.