Sunday, November 24, 2019

The Gamified Timed Static Contractions Extended

Quite a while ago, when I had hit a stubborn plateau with my counter-weight assisted Chin-Ups, I decided to replace them - at least for a while - with "gamified" Timed Static Contraction (TSC) Pull-Downs and Pull-Overs as per Drew Baye's book "Timed Static Contraction Training", since it had worked very well for me with my gamified TSC Squats.


Above, you can see my combined rig for the Gamified TSC Pull-Downs and -Overs. The Phidgets' load-cells are the same as I use with my Squats, as are the off-picture bridge to my laptop. The DIY handles (PVC pipe, chains, and carabiners) I use with a underhand grip for the Pull-Downs are old ones from another, ancient project. I added the webbing loops for the Pull-Overs (left in Swedish is vänster and right is höger, hence the V and H - they need to be marked as if they are switched, they won't be level with each other, due to differences in the hooks and chains...).

Only this week, I also got around to craft myself a piece of webbing for Chest-Presses - yepp, I've kinda-sorta hit a plateau with my Dumbbell Bench Presses lately...


It was tailored to be of the right length for Baye-style TSC Chest-Presses but - by sheer luck - it also work for me for his TSC Compound Row. I wonder if that is generally true for the majority of people or if it is more specific to my anatomy?

On the photo, you can also see my newish Phidgets Wheatstone Bridge and Vint Hub taped together with silver tejp. My old bridge, that could be connected directly to a computer, was dead as a Dodo one morning workout (not a good workout, spent waaaay to long trying to revive the Phidgets bridge...). The new Vint Hub also forced me to upgrade to the Phidget22 library and - since it doesn't have any official Ruby support - hunt down a third-party integration in order to adopt my existing Ruby script to work with the new Phidgets library version and hardware. On the plus side, it seems like the new ones are a bit more stable.

With equipment to do gamified TSC Squats, Pull-Downs, Compound Rows, and Chest Presses, I'm only lacking one for Standing Presses - then I would be able to do a complete Big Five workout of the Doug McGuff/John Little "Body By Science" variety but in a Baye:esque TSC interpretation. Perhaps I should dig out the old sewing machine again? ;-)

Tuesday, January 1, 2019

Gamifying Timed Static Contractions with Phidgets Load Cells, revisited

So, I've been on my "gamified" Timed Static Contraction (TSC) Squats I outlined in an earlier post almost weekly for half a year now and thought I should to a write-up on my experiences so far.

The Executive Summary would be: has been overall successful but there is still some room for improvements.

I've modified one of the example Ruby scripts that ships with libphidget21 to output measurements from both load-cells as soon as they're available for 95 seconds and are using the following scheme,

while (1) {
        replot
        pause 0.2
}
to five times a second re-plot the graph of my load-cells output in a Gnuplot script, to get the interactive feedback needed to be able to adjust the force I'm exercising against the unyielding band to stay at or near the target level.

The very first time,  in mid June, I didn't have any target resistance to try to meet but just used the set-up to measure how I really did on a conventional, "blind" TCS Squat:


You can see that I've opted for 45 seconds, 30 seconds, 15 seconds phases rather than the more normal 30-30-30 ones. That can always be a future progression, to use equal length phases. Basically, I just scrapped the initial pair of phases on this try-out and only estimated the last phase to have come in on around 50 units on both load-cells (hopefully, the S-cells should measure kilograms but let's just speak about generic units in case the calibration is off or the cells inaccurate). Hence, the following week, I set the new target to 55 units for the final phase and half of it (27.5) for the first pre-exhaustion phase and three quarters of it (41.25) for the second:


Now I had to, over a couple of seconds, ease into the target resistance of each phase and stay at it, as indicated by the horizontal blue target lines. As you can see, the green load-cell tracked the targets better than the red one. Later in the year, I would have considered this workout a bust due to the wanting red line, but as this still was during the trial weeks of the Phidgets TSC Squats, I allowed it and set the target of 60 units for the next week:


Still questionable results for the red load-cell. However, I also noticed that my stance was way too high in the last phases, so for the fourth workout, I shortened the loop around my waist with about 10 centimeters, but still quite optimistically/aggressively increased the target with another 5 units to 65 for the following workout:


This time, the overall result was more on track, despite the shorter loop/lower stance. Let's fast forward to the seventh workout, the first time I clearly failed to match the target of 80 units:


Following that, I redid 75 units successfully next week and but then failed again at 77.5, so I then settled for 1 unit increments - 76, 77, 78, ... - which worked well until the 15th time and the target of 81 units:


Here it wasn't really I that failed but my equipment. One cable attaching the red load-cell to the bridge broke... So I had to re-attached the cables properly to the bridge and then secure the cables with duct-tape to prevent future material exhaustion in the cable cores... The week after, I successfully passed 81 units and have been increasing one unit a week ever since, up to the last workout before the holidays, the 23rd one with the Phidgets, where I did 88 units:


So what will the imminent improvements and/or tweaks be?
  • One trivial one would be to label one of the load-cells "left" and the other "right" to always use the same one with the same foot/leg - but in practice, I don't think it matters that the cells might switch foot/leg from workout to workout. After all, they're supposed to be calibrated the same.
  • I'm still in a tad too high stance in the last phase, so I need to film myself in profile during the squats and shorten the band until my thighs stay at a 45 degree angle to the floor throughout the third phase (but let's wait until after I've hit 90 units with the current length).
  • The rubber training mat I'm using to stand on actually doesn't offer enough friction for my feet to stay put during the high exertion during the third phase. When I focus on maintaining the full pressure into the band loop, my feet tend to slide a bit closer together, making the exercise easier. To combat this, I either need to switch from the training mat to something more rugged and rigid - or place a piece of plank sawed off to keep my feet shoulder-width apart when placed between them (I think I'll go for the latter - also once I've hit 90 units with the current suboptimal set-up).
  • Since my load-cells only goes to 100 kg and I never imagined that I would ever surpass 2 x 100 kg, I might have to progress to a deeper stance than thighs 45 degrees to the floor - or splash out and get new load-cells that goes beyond 100 kg (Phidgets' next larger ones go to 500 kg which surely would be a total overkill).
  • Naturally, another way to make the current load-cells last longer is also to increase the length of the third phase - that would also decrease the level of resistance I would be able to handle. The 30-30-30 second protocol Drew Baye recommends would be the natural choice, but another possibility would be to opt for maintaining the same, more conservative load for 90 seconds - i.e., no pre-exhaustion phases but just one marathon session where the challenge would be to struggle to keep the load at the target for the complete duration. Actually, it would be something fun to try but it would be hard to guess what target load to go for? Perhaps 70% of the current third phase target? Or is even less a must? Or is more possible to handle?
  • I also need to simplify re-checking the current calibration of the load-cells. Currently, I basically just run the normal workout script and hang a few dumbbell weight-plates to each load-cell while they're hung from my chin-up bar. So far, with 30 kg in weight-plates, they've always been less than 1 kg off  - but I really should check closer to the max weight, using my own body weight or so. (This is why I've written "units" rather than "kilograms" in this post - I fear they're not 100% accurate, but as long as the trending is correct and they're not too far of each other, they still work as long as one consider them as measuring generic load units rather than exakt SI kilograms).

Saturday, December 29, 2018

DIY Pure Coconut Oil Shampoo Bar

In our Occident lives, we're constantly exposed to a lot of unnatural stressors, like exhaust fumes, for instance, or processed food additives. Some are known to be toxic, some might be proven toxic in the future, but most of them are more or less harmless - except that they act as unnatural stressors to ourselves as living organism and thus, for example, make our immune system's task of keeping us healthy somewhat harder and prolongs the time it takes for our bodies to recover and super-compensate from our latest workouts a little.

The irony is, though, that worrying over these stressors might actually be more damaging for one's well-being that just ignoring the fact that they exists and go on happily with one's life in blissful ignorance! ;-)

Anyways, I don't fret over them but still prefer to cook my family's meals myself from quality ingredients over buying pre-fabricated foodstuffs and/or meals. Analogous (and due to skin rashes in my arm-pits) I've switched from conventional deodorants to pure potassium alum sticks. I've also experimented with making my own toothpaste with equal parts coconut oil and baking soda (sodium bicarbonate) and a generous amount of peppermint oil drops (still tastes terrible but you get used to it). Seems to do the job, although I'm not yet done evaluating it.

The latest experiment I've embarked on is to make my own shampoo bars. It begun with a friend pointing out the unnatural stressors in industrial shampoos and myself, probably because of that, noticing an buying a shampoo bar at one of our local area grocery stores. I've used that bar to wash my hair the last couple of weeks with good results. Cannot say I've experienced any of the transition troubles many sources on the Internet describes. But the same Internet searches also turned up an abundance of DIY recipes for shampoo bars and it seems like a cool thing to try.

However, most recipes calls for a mix of many fats and oils: olive oil, shea butter, ricin oil, etc, etc and with different saponification values for each kind of fat, that felt a bit daunting for a first-timer. Hence, I deliberately choose to listen to Mommy Potamus blog post Coconut Oil Shampoo Bar Recipe we're she herself have had good result with a superfatted shampoo bar made of just coconut oil. It's an experiment, after all. If it doesn't work out, I will be one learning experience richer and have a bunch of soaps to try to find other uses for (how was it? Pure coconut soap dries skin out too much? Does that apply to hands to the same amount as it does it for the more sensetive face skin?).

Here's a picture from when I was about to set out on my quest:


Lye (sodium hydroxide) is not something to be taken lightly but not something to be overly scared of either. Ever used a drain cleaner? Ever gotten irritated eyes and/or nose from drain cleaner vapors? That would be lye reacting with water. In theory, one could use drain cleaner granulates when making soap, but in practice, it simply feels safer to buy pure lye instead. As long as you use non-reactive bowls - glass, stainless steel or quality plastic - you can use your usual kitchen ones as long as you clean them properly before using them again, first just with water, then wash them as usual.

The saponification number of coconut fat/oil seems to be 178 - 191 but most sources has pegged it to be 184 for organic coconut oil (although the webstore, https://www.organicmakers.se/, where got my lye and coconut oil from uses 183) so I used 184. That means that for 1000 weight units of oil, 184 units of lye is needed to soapify it. However, one always want to superfat the soap a bit, to ensure that there are enough fat around to consume all of the lye. Furthermore, Mommy Potamus' recipe called for a 10% superfatted shampoo bar for normal hair, so that's what I aimed for.

I wanted to use 500 g of the coconut oil. Having it 10% superfatted makes for 500 / 1.1 = 454.54545454545454545454 g of coconut oil to saponify. With a saponification value of 184, that means we'll need 454.54545454545454545454 * (184/1000) or 83.63636363636363636363 g lye. Most soapmakers seems to be opting for a lye solution of 30% lye and 70% water, so with 83.63636363636363636363 g lye, we'll need (83.63636363636363636363 / 3) * 7 or 195.15151515151515151509 g water. But as my kitchen scale only have gram accuracy, I went for 500 g coconut oil, 84 g lye and 195 g water. Since I'm aiming for a 10% superfatted shampo, I have a good marginal for error and doesn't really need any scale with "drug-dealer accuracy".

1. I used some rapeseed oil to coat the silicon muffins tray I was going to use as soap forms. I'm not entirely sure this is actually needed, but better safe than sorry. It seems the most common modus operandi instead is to use one big rectangular form and then cut out individual bars out of it with a knife once it has settled, but I'll go for individual forms directly.

2. I weighted up 500 g coconut oil in the big bowl, 84 g lye in the measuring glass, and 195 g water in the little bowl.

3. With my glasses on and protective gloves on my hands, I went outdoor and carefully mixed the lye into the water and kept stirring with a steel whisker until the solution went clear and all of the lye granulates had been completely dissolved. Since the reaction between lye and water generates heat, my steel bowl was hot to the touch by now - which was nice since it was just below freezing outside today.

4. After waiting yet some minute to let the solution cool off a little, I went back inside and carefully poured it over the still solid chunks of coconut oil in the big bowl, then used the same steel whisker to stir until all of the coconut oil had melted.

5. Then I inserted the blending rod at an angle to trap as little air under the head as possible and ran it at full speed in short intervals, stirring the mixture with the rod head in between, to get a feel for how thick it had become. I thought it thickened a lot slower than it said it would in the different tutorials on the web, until I actually did the tracing test by lifting the rod and watching what happened with the droplets on the surface of the mixture. They stayed there without sinking down into the mixture so evidently, I had made it too thick - yet, to me, it seemed pretty thin so make a note: thick enough it actually pretty thin!

6. When pouring the mixture into the forms, pretty thin comes in quite handy. I tried to get roughly the equal amount into each of the 12 muffin molds in the silicon tray, then used the silicon spatula to try to smooth out the tops of them, which wasn't easy and got noticeably harder over the few minutes I spent on it as the mixture clearly already solidified quickly. Here's how the final result looked:


7. Rumors has it that coconut oil soaps solidify faster than other fats, so apparently, one should be able to cut out individual bars after 6 to 10 hours. However, I put the tray away under an old kitchen towel and waited six hours before trying to pry the first "muffin of soap" out of the silicon tray. That proved pretty easy, although it got a bit messy due to mixture having ended up on the sides of the muffin molds:
















Clearly, I wasn't very successful at smoothing out the tops of them... One can also see a yellow (mis-)colouring on the bottoms from the rapeseed oil. Next time, I might go for using washed cream cartons as molding forms instead and slicing out quadratic bars with a knife instead.

8. Now they're supposed to mature on the grid under the old kitchen towel for at least four weeks. That's the really frustrating part of soap-making. But before February 1st, I should be able to try to wash my hair with one of 

Thursday, June 21, 2018

Gamifying Timed Static Contractions with Phidget Load Cells

Arguably, the very best lower body resistance exercise you can do is the squat (even if it, of course, in a balanced and varied training program should be complemented with at least calf raises and deadlifts) and the very best way to perform the squat is either on a leg extension machine - if you're inclined to machines - or with a barbell in a smith rack with a well-educated trainer that you trust and respect as an extra, intelligent spotter aside of the, by comparison, rather dimwitted rack - if you're more of a fan of free weights (or why not alternate between them?).

However, both of these alternatives normally require access to a well-equipped gym. So what if you prefer to train at home? (Either because of limited time, little money, cheapness, shyness, or any other imaginable reason for not going to the gym.)

Well, if you're just starting out, or sedated, body-weight squats will take you quite far, but once you can easily handle more than 90 second under load even in the deeper, harder range of motion of the squat, the next natural progression, the unilateral one-legged squat, is still likely to be out of reach.

So what do to when your grip or arms give up before your legs do when holding heavy dumbbells to increase the resistance for the squats? Or you don't want to pre-exhaust your grip and arms during the squats when you do upper-body pulling and pushing exercises afterwards?

Try Timed Static Contractions (TSC). On http://baye.com/qa-isometrics-muscle-mass/, you can see Drew Baye perform his TSC Band Squat and on http://baye.com/qa-bodyweight-tsc-grip/ you can see Steve Maxwell perform his "hip belt squat" with a gi belt. Baye attributes the development of band squats to Maxwell. It's from Baye I've learned about TSC, especially through his thin but informative book "Timed Static Contraction Training" but when searching for the photo of Maxwell, I saw that he has written a book on functional isometrics, too.

The benefits of TSC training with a band such as a towing strap includes:
  • you just need one piece of cheap and light equipment (the towing strap) that you can easily bring with you everywhere
  • that means that you also can perform them virtually everywhere
  • as long as you ease into your contractions, it's a very safe form of training
  • if you also follow the protocol with a moderate first phase, followed by a second phase of ~75% of effort before the final, all-out, maximum effort contraction against the unyielding band, the pre-exhaustion during the first two phases make it virtually impossible for you to hurt yourself during the max-phase
  • strictly speaking, the mode of resistance training doesn't matter: you can develop increased strength, bigger muscles, and improved conditioning via all kinds of different ways of resistance training, including TSC
However, there are a couple of troublesome drawbacks with TSC as well:
  • don't get fooled by the simple set-up - they are hard to perform. If you've done them right, you should have trouble keeping the maximum effort throughout the complete last phase. You need to have the resolve to work through the pain and your brain screaming at you to ease off. Basicallly, you should be so spent afterwards that you should have trouble to remain standing.
  • furthermore - they are boooooooring as hell. Try to keep focused and concentrated on keeping up the necessary effort during 90 seconds - it's harder than you think. That's my main challenge. My mind starts to wander (what's for dinner? Mmmm, dinner... What about that deadline at work?) - and as soon as my concentration wavers even for a split-second, so does the intensity of my effort in the contraction phase I'm currently in, my muscles get some unintentional rest and sabotage the full result of the workout.
  • they don't offer any form of feedback to gauge your effort by. Hence, you have no way of knowing whether you're progressing or unconsciously holding back so you're really plateauing or even regressing.
To combat the last two drawbacks, what if we can gamify it somehow?

Enter a couple of Phidgets load-cells and a Phidget bridge to connect to one's laptop, as well as some nylon webbing, webbing lock, and carabiners to connect the load-cell to the person.

(And to be fair: I am far from the only one with this idea. For instance, "Matt Manning" wrote in his comment from January 3, 2018, on http://baye.com/qa-mmf-tsc/: "I’m measuring force via a load cell plotting a graph on a laptop." - which is pretty much exactly what I'm doing, too.)


The small loops are for one's feet, the big, loosely tied loop goes around one's waist. The webbing lock is to be able to adjust the length in order to get the right bend in the legs (thighs parallel with floor is too deep as gravity will be a too big factor to overcome, almost standing straight is too high, but thighs around 45 degrees angle to floor is a good stance). I've tried to get the webbing lock in the small of my back, in order to avoid it digging into my hip or thigh. To have it close to one of the load cell carabiners would work, too, but I find it gets a bit unbalanced.

So how do we calibrate the load cells and get a plot going to be able to perform the TSC Band Squats with feedback? That will be the topic of an future blog post (when I've had a chance to try it out for a while and workout the kinks).

Friday, November 25, 2016

Measuring the pin-out of a Commodore 64 joystick.

Let's say your old C64 joysticks are worse for wear and you neither want to buy a brand new, over-priced Competition Pro, nor any second hand joystick. Then one option is to build a new one, but to do that, you need to know the pin-out of the Commodore DSUB9 joystick port.

Of course, this information is readily available on the Internet - just google it. However, isn't it more fun to measure it oneself?


Apart from a (preferably) working joystick (I'm using my beloved Slik Stik, the TAC-2's little sibling from the same company, Suncom - you can see that it is held together with duct tape, the screw holes gave up after all the times I've opened it to clean the conductive plates...). you need a multi-meter (although a battery, small light-bulb and some wire will also work) and either probes small enough to fit the holes of the joystick's female contact or, like I have, a lose male contact. With this one, it was easy to attach the joystick and test the pins even with my chubby multi-meter probes. Then the only thing you need is some patience as you systematically test the pins, two at a time, while sequentially engaging the stick in each direction and the fire buton (or you  do like me and just verify a pin-out pulled from the net to save some time). 

So I can add my own Commodore (Atari too, by the way) joystick DSUB9 pin-out to the Internet (and vouch for the authenticity of the others):

Up  Down  Left  Right   n/a
 1        2        3       4        5
      9        8        7       6
    n/a  Ground  n/a    Fire

Monday, April 11, 2016

Making Inkscape-generated SVGs Visible in All Browsers (i.e., Internet Explorer...)

One of my many long-term, rarely worked on projects is the "Fotogenealogi" ("Photo-Genealogy") project, where me an my wife borrows old photos of our ancestors from relatives to let them be professionally scanned and sometimes a bit retouched if the original has a lot of wear and tear. By now, we have quite the collection, sometimes going back four generations to the second half of the Nineteenth century.

Recently, we processed a photo of the guests at my grandmother's brothers weeding (in which my father is a fresh teenager) and as most of the people was unknown to me, I had my father identify them for me. When trying to write a clear-to-follow caption, I realized that I needed a glossy-magazine-like silhouette version of the images, with numbered outlines of all the persons, to make the caption a breeze to write.

Thus, I loaded the high-res scanned original into Gimp, added a front layer with transparent background, painstakingly filled in the contours of each person with a broad brush (I first did it with a 1-pixel thin line, but that led to too many holes that created problems in the next step), saved just that layer as a png, ran Autotrace to vectorize the outlines into an esp, imported the esp into Inkscape to fiddle with the stroke width of the outlines, adding numbers to their heads, and differentiating the various nuclear families in the picture with different pastel fill-colours. As Inkscape nativly saves images as svg:s we're home free, since all browsers support them, right?

Wrong! It displayed just fine in Google Chrome and Firefox but in Internet Explorer, with a height-directive to the img-tag, they didn't display at all... Despair! However, after some searching, I found Triangular's illuminating blog entry https://triangle717.wordpress.com/2014/06/07/ie-inkscape-svg/ which provided me a way forward.

It's not enough to save the image as an default Inkscape svg but one need to save it as an Optimized SVG and click in "Enable Viewporting". Then it works as it should in Internet Explorer with img-tag re-scaling and all. Number 22 is my teenage father.

Tuesday, January 5, 2016

Spotify on the Kitchen Media Centre

I've held on to the free Spotify account I've had since you got to have an invite to get one (2008/2009 or so) and never bothered to upgrade since the commercials hasn't been that annoying (the more recent daily cut-off is worse). However, for convenience, on our last trip abroad, we kind of needed the ability to access a large catalogue of music and play it uninterrupted, so I did go premium (enjoying their X-mas discount).

That, in turn, led to my wife becoming hooked on Spotify on the tablet which led her to once place the tablet playing songs off Spotify on the speakers of the kitchen media centre, in front of the kitchen media centre touchscreen...Well, we can't have that, can we? 

Some googling later, I pulled the zip-archive of SpotiMC off http://azkotoki.org/downloads/ and installed it. Works well, although playing the playlist in my account seems a bit buggy with tunes falling silent in mid-song and then, sometimes after minutes of silence, all of a sudden starting on the next - everything else (searches and playing the resulting hits) works as expected. 

Though one quirk is that there is no easy access to a touchscreen friendly volume control from within the SpotiMC interface - not until the screen-saver blackens the screen, after which, if you wake it, you are in the "normal" Kodi tune-playing window with the on-screen volume control bar. As they say, patience is a virtue.

UPDATE 2016-01-19: The problems with the playlists seems to have been some gremlins in the system, now it works just fine to use playlists. Also, I've discovered that if you tap the "now playing" area decisively, you're transported from the SpotiMC view to the regular OpenElec song-plaing view and can access the Re-Touched skin volume control bar as usual.

Saturday, November 21, 2015

Kitchen Radio

My mother-in-law has got a small combined radio and CD-player that is mounted under the top row of kitchen cabinets, over the work bench, in her kitchen. My wife would like something similar, to replace the normal radio we have on a shelf in the corner of our kitchen opposite to our stove and work bench (i.e., our old radio was far away from where we do the cooking).
However, I wanted to take a stab at making something cooler, so I started to collect stuff:

Ingredients

* one Raspberry Pi 2
* one official Raspberry Pi touchscreen (7 inches)
* one Pimoroni Raspberry Pi Official Touchscreen Stand
* one IQaudIO Pi-DigiAMP+
* one 15v Power Brick (50 W / 3.3 A)
* one DIY kit for a pair of Jeff Bagby's "The Quarks Micro Desktop Speaker"

Preparations

This is not my first Raspberry Pi, so it in itself didn't pose any challenge. To assemble and attach the touchscreen was trickier. You need a steady hand and some guts but I have a suspicion that the flimsy flat cables and plastic contacts might be sturdier than they look.

Note that when installing an OS on the Pi, you need to have another monitor attached to it as most distributions doesn't support the official Touchscreen out of the box (nor do they support the DigiAMP+).

When attaching both the touchscreen and the DigiAMP, without any extra spacers and screws than the supplied ones, a bit of creativity is required. However, since the GPIO pins secure the DigiAMP to the Pi on one side, I could borrow some of the spacers from that side to secure the touchscreen instead.

After messing around with both Rasbian and OpenElec, I settled on OpenElec. I recommend that you begin with the OpenElec image for the Raspberry Pi 2 supplied by IQaudIO as it comes pre-configured with DigiAMP support (and very wisely adjusts the volume of OpenElec in order not to blow the speakers out on the first bar of the first tune you play). You then upgrade that base installation with the "Milhouse" tar-ball for the Pi 2, which comes with touchscreen support. However, I first tried the OpenELEC-RPi2.arm-6.0-Milhouse-20151009210341-#1009-ge2b6fef.tar build and in that one, the audio stuttered in a weird way when playing videos - kind of with a weird Doppler-effect. To solve that, I bought the Raspberry MPEG-2 and VC-1 licenses to enable hardware video decoding - but that didn't help. Instead, the problem went away when I upgraded to the OpenELEC-RPi2.arm-7.0-Milhouse-20151120231902-#1120-g297af74.tar build (so now I don't now whether the licenses helped or not and am too lazy to disable the licenses to check. In any case, the licenses might come in handy if I ever want to watch some more demanding video-encoding on the kitchen media centre). 

The touchscreen stand is worth a few comments as well. It is quite nicely done although it requires some puzzling to assemble. However, due to the Pi ports, they've chosen to design the stand so that you have to put the touchscreen upside down in it. This is not entirely ideal, as I got the impression that the viewing angle is better when it is not upside down - but I might be wrong here. In any case, you have to make the Pi flip the image to match the alignment of the touchscreen in the stand. My first try involved putting "display_rotate=2" in /boot/config.txt. That did rotate the screen image - but not the touch points of the screen... Imagine my surprise when poking the upper left area of the screen and the lower right area of the image reacted. To flip both screen and image, instead put "lcd_rotate=2" in /boot/config.txt.

Now we are only missing one thing - easily touchscreen accessible volume controls, something that is simply missing in the default skin Confluence (although I find that skin the more elegant one - guess I cannot have it all). So far, the best skin for controlling volume with the touchscreen is the re-Touched one. The trick here is to find a version of re-Touched matching your version of OpenElec. I ended up with skin.re-touched-3.1.0.zip from the re-touched github repository.

Result

After having built the speakers as well (but not finished them! If you look at the pictures, they aren't closed yet but only held together with rubber-bands as I want to resolder and rearrange the filters in them somewhat - but I was too impatient and wanted to try the set-up out first), we now have a fully working kitchen radio solution where we can listen to our own ripped CDs, Swedish radio as well as German and New Zealand radio (pity that they don't talk much but mostly just play music in the NZ-night time radio we get here during our daytime) and, as a bonus, YouTube videos as well!

The speakers are pretty cool. They have a full, crisp sound for their size and pair up well with the DigiAMP+. Turning the volume all the way up doesn't seem to blow the speaker but it sure gets loud, much louder than we need (except perhaps for when running the dishwasher, blender, mixer, extractor fan, and frying something violently sputtering on high heat).

So far, a really successful project with endless potential for future improvements and extensions! Much, much cooler than a fixed kitchen radio and CD-player. ;-)
 

Sunday, June 29, 2014

Approximating data in Gnuplot with the fit function and time as xdata.

Gnuplot is the shit. Normally, the biggest problem is finding out (i.e. Google-hunt for examples) how to do what you want and not to determine if it at all possible. However, I just ran into a problem where Gnuplot was buggy. I had a data-series with time-stamps (full dates) on the x-axis and my measurements (two different) on the y-axis and I wanted to approximate the trend with a simple least-square f(x) = l*x + m line. This was seemingly pretty easy to do:

#!/usr/bin/gnuplot -persist
set xdata time

set xlabel "Time"
set ylabel "Measurements" font "Arial,12"

set autoscale
set timefmt "%Y-%m-%d"

set term png xFFFFFF size 1200,700
set output "/tmp/measurements.png"
set datafile separator ";"

f(x) = a*x + b
fit f(x) './measurements.dat' using 1:2 via a, b
g(x) = c*x + d
fit g(x) './measurements.dat' using 1:3 via c, d
plot \
"./measurements.dat" using 1:3 title "Thingie A" with linespoints, \
"./measurements.dat" using 1:6 title "Thingie B" with linespoints, \
f(x) title "Least-squares f(x) = a*x + b approximation", \
g(x) title "Least-squares g(x) = c*x + d approximation"


For the first data-set ("Thingie A"), I got a believable approximation line - i.e., the line looked like it did approximate the general trend of the data-points of the set. However, where the first data-set had on average increasing data-points, the second data-set had generally decreasing points. Yet, the approximation line (g(x)) was increasing.  How could that be? Was my impression of a general decreasing trend an optical illusion? Or was Gnuplot's fit-function somehow buggy? It turned out to be the latter.

The fit-function uses "an implementation of the nonlinear least-squares
 (NLLS) Marquardt-Levenberg algorithm" (cited from the built-in help) and, apparently, that algorithm (or implementation) doesn't do well when the x and y values are very different in size. My y-points in the second data set was in a narrow range from circa 105 to 100 but what was the x values? 


Unlike Unix, Gnuplot doesn't use an Epoch starting with 00:00 January 1st 1970 but actually January 1st 2000:

gnuplot> plot strftime("%Y-%m-%d %H:%M", 0)
         warning: Skipping unreadable file "2000-01-01 00:00"
         No data in plot


Thus, since I have collected my data during this year, all my x-values where around  450.000.000 and, yes, that is quite a lot bigger than y-values around 100...

What to do? Well, the simplest thing to get the x-values closer to the y-values is to divide with the number of a seconds a day (86400) to have the fit-implementation work with x-values in the 5000 range instead.

To do this, I changed the following lines:

 fit g(x/86400) './measurements.dat' using 1:2 via c, d
...
plot \
...
f(g/86400) title "Least-squares g(x) = c*x + d approximation", \
... 

And that was enough, now the approximation line was declining just like my impression of the data-points. Success!

Thursday, May 8, 2014

About that virtual factory reset...

... it did work out in the end, after a few problems. The DVD images worked great all the way to the subsequent reboot. Then all one got was a black screen with a non-blinking low cursor in the upper-left corner of the screen. Thanks a lot - I guess the factory reset never bothered to install any MBR...

Oh well, let's boot up the virtual machine again, but this time with a Linux live CD iso image attached (Linux Mint 16 "Petra"), so that we can - from the trustworthy Linux prompt - install the mbr package ('sudo apt-get install mbr') and use it to install an MBR on the harddrive of the virtual machine (/dev/sda in my case, checked in the output of dmesg): 'sudo install-mbr-i n -p D -t 0 /dev/sda' (check the man-page of install-mbr to identify the details of those standard options, they're basically no interaction, use first bootable partition, and use a timeout of zero). (We could have used other Linux means as well, for example the mbr.bin image provided by the syslinux package.) Now let's try another reboot.

Well, it was a so called "fall forward". Instead of the solid, low-cursor it now stood "MBR" in the upper-left corner and then we got to an error screen, complaining about winload.exe being 
missing or corrupt ("Status 0xc000000e", "Windows failed to start. A recent hardware or software change might be the cause.", "File: \Windows\System32\winload.exe", "Info: The selected entry could not be loaded because the application is missing or corrupt."). Bugger... Out of ideas, I turned to Google and found this eminent guide. By luck, I already had a Windows XP virtual guest system I could attach the new machine's virtual harddrive to - otherwise, I would probably not been able to get any further. Now, I could, from XP, follow the guide, i.e., in my case, the new harddrive was mapped as E:, so I could run E:\Windows\System32\bcdedit /store F:\Boot\BCD /enum to check if I suffered from the same situation as he had. I sure did. with three unknowns. I changed them all to "boot" according to his recipe (E:\Windows\System32\bcdedit /store F:\Boot\BCD /set {X} Y boot, where (X, Y) were (bootmgr, device), (default, device), and (default, osdevice), respectively.

Upon next boot, the new machine started-up and begun configuring up itself, completing the factory reset. Cool! 

Wednesday, May 7, 2014

I Stand Humbly Corrected...

So, I've been dabbing with trying to boot a set of "XYZ" recovery DVDs in a VirtualBox guest, to see if I can get a virtual factory reset running.

The first problem I ran into is that it seems that my USB-hub cannot support both the external USB-harddrive the virtual host resides on and the USB DVD reader at the same time - and, of course, I have too little space left on my internal drive and too few USB ports to have them directly attached (well, I could direct attach one with the inconvenience of unplugging the external mouse and keyboard, but we can't have that, can we?).

Thus, I needed to convert the 4.2 GB DVD to an ISO-image - but both Copy Disk in Brasero and old, honsest dd only gave me a 120 MB small image - probably the actual boot image on the DVD or something, while mkisofs gave me a full 4.2 GB image but a non-bootable one. How annoying!

By despair (or to be systematical), I also tried a tip I had up to that point considered too naive and fault-prone: to just cat the DVD-reader device to a file (i.e., 'cat /dev/sr0 > /tmp/recovery1.iso') and do you know what? It worked! VirtualBox booted the virtual host right of it and let me choose to do a factory reset (It is currently at 65%, so I don't know if it ultimately will work yet.)

Who would have thought that simple cat would be so true to the underlying bit device that it rendered the copied image as such a perfect copy? I am sure that given the right options to mkisofs, I could get the image bootable (it has a ton of different options to set this-and-that type of bootable disk to boot from a certain file, but I would rather not have to learn how to analyse the configuration of the DVD at hand enough to be able to pick all the right mkisofs options to make a one-to-one copy of it. Shouldn't mkisofs really be able to do that itself?

Video Woes

In McGuff's and Little's excellent "Body by Science", they advocate for strength-training with slow lifts (to remove any helping momentum) and to measure the Time Under Load rather than just number of repetitions, to get a more fine-grained control over your progress (or lack thereof). However, to concentrate on the weights and the clock at the same time is, of course, a drag. Better to film oneself and analyse the video after the workout - and which is the most ubiquitous movie camera around these days? Right, your mobile phone.

This scheme worked well for a number of workouts until the camera app in my phone crashed while recording, giving me a video no player will play. Why? Because the 3gp format of my phone (basically a mp4 variant with more compression) slaps on the frame index and codec information last in the file - and when the app crashes in mid-recording, no such index is added and the file ends up an inaccessible pile of junk data...

So, would I be forced to write-off the workout as a session without any data to track? Not without a fight. Some googling revealed that Federico Ponchio's Untrunc and Grau's Video Repair Software were the two most promising candidates. Both produced something from my broken video - unfortunately, Untrunc slapped on some codec all my players were missing (and that wasn't easily installable) but, luckily, Grau's program worked well, at least for the video - the audio become unsynced.

Alas, not only are the video and audio out of sync, it seems the video is somewhat in slow motion as well, so it turned out to be unusable for my post-workout analysis anyway. Too bad, but at least I got a story to tell out of it...

Saturday, April 19, 2014

Fun with openwrt

I wanted to extend my network at home, with one router by the fibre-node downstairs and one by our desks upstairs. Also, I wanted to tryout DD-WRT. However, since there are two different versions of TP-Link WE1043ND floating around and I happened to get the black v2.1 version that are currently not supported by DD-WRT, I opted for OpenWRT instead.

It was quite scary to flash the new router with the OpenWRT image, but it worked flawlessly and in minutes I had configured it to do my bidding - despite OpenWRT looking seemingly overwhelming with all the choosable bells and whistles.

Wednesday, January 22, 2014

Scraping Fund Data of the Internet - an Orgy in Different Tools

Previously, I've used a combination of Bash and curl to scrape pages with fund statistics from investment sites and then Perl scripts to data-mine the scraped pages and analyse the data. Good so - small, customized, targeted Bash and Perl scripts.

However, recently, I wanted to also use the Norman value (an estimate on how much a fund will cost over 10 years of keeping it in a investment portfolio). The only source for these value was one popular fund comparison site, so I set out to bash and curl my way to a loop that would scrape the data off it - only to run into serious trouble...

Using the Firebug plugin in Mozilla Firefox, the built-in Developer's Tool in Google Chrome, and eventually resorting to Web-Charles to really be able to see what was going on, I was able to exactly pin-point what my browser sent the site when I navigated the pages - but I was unable to mock the request in my scripts. Unfortunately, the site relied just too much on Javascripts dynamically building form-data to be posted to the site with every request. So I had to think of something else.

Enter Selenium, the Web Automation Tool. Since it is using an ordinary browser to perform the surfing, dynamic Javascript mumbo-jumbo is no match for it. But I still wanted to script my usage and eventually choose Watir for the job, once again being surprised over how much joy it is to program in Ruby!

So, writing a short Ruby program using the Watir framework to operate on Selenium, I was able to get the data I wanted from the site in question.

However, I begun with restricting the funds to just those of the bank I am a customer off (it was my funds there that was most important to re-evaluate and perhaps exchange for others at the turn of the year). When I for kicks tried to scrape all of the 2 500++ funds of the site, I ran into new problems. The site was simply not stable enough. Now and then, one would either end up on the very first fund presentation page with a subtle "An error occurred"-message, or actually a full-fledged "An error occurred"-page, or one would seemingly be on the right track, getting to the next of the 100++ pages of 20 funds at a time, but then realizing that it had silently thrown you from the target tab back to the default tab. To battle this, I had to go heavy on error handling, turning my short and elegant Ruby script into a less nice collection of rescue blocks for this and that exception (some that I defined and raised myself, for example if browser.text.visible?("An error occurred") is true).

All in all, a quite educational and rewarding exercise.

Saturday, March 23, 2013

Using ADSL and 3G concurrently

ADSL has its limitations but is, at least, ubiquitously available and comes with flat-rate. 3G subscriptions are usually only flat-rate up to a threshold of so and so many GB, over which you have to pay extra. But a cheap 3G subscription is a good backup against ADSL outages. Of course, both of them have the drawback of asymmetrically lower upstream bandwidths compared to the downstream speed.     

Thus, when you have a lot of data to upload (for instance after an extensive photo-session) you might very well want to concurrently upload on both types of network connections to keep the overall upload time down.

This is one recipe on how to achieve that (you will have to adopt to your own IP addresses and connection types below):

  • Connect 3G dongle and initiate the connection on it
  • Check your particulars:
$ ifconfig 
eth1      Link encap:Ethernet  HWaddr c8:0a:a9:a6:5f:c1  
          inet addr:192.168.1.150  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::ca0a:a9ff:fea6:5fc1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:90315 errors:0 dropped:0 overruns:0 frame:0
          TX packets:51128 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:122726916 (122.7 MB)  TX bytes:5513301 (5.5 MB)
          Interrupt:42 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1356 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1356 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:239907 (239.9 KB)  TX bytes:239907 (239.9 KB)

ppp0      Link encap:Point-to-Point Protocol  
          inet addr:83.180.203.199  P-t-P:10.64.64.64  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:7 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3 
          RX bytes:130 (130.0 B)  TX bytes:181 (181.0 B)
  • Add a routing table for the 3g: 
# sudo echo 2 3g >> /etc/iproute2/rt_tables
  • Add to and fro routes for the 3G connection to the new table (my 3G gives me a ppp0 interface). Notice the priority of 1000, chosen to lie in between 0 and 32766:
# ip route add default via 83.180.203.199 dev ppp0 table 3g
# ip rule add from 83.180.203.199 table 3g prio 1000
  • Check what you've got: 
$ ip route show table 3g
default via 83.180.203.199 dev ppp0 
  •  And your complete routing rules:
$ ip rule
0: from all lookup local 
1000: from 83.180.203.199 lookup 3g 
32766: from all lookup main 
32767: from all lookup default 
  •  Now you can use the 3G interface concurrently with your normal network (without packet in one direction getting confused and ending up where not intended). You can, for instance, verify it by ssh:ing out on the 3G interface with  ssh -b 83.180.203.199 <some machine> and on that machine, you can verify where you're actually coming from with, for instance, w. You probably don't have wired and mobile internet from the same provider, so it should be easy to tell them apart.
  •  But what about the concurrent uploads, then? Well, I use  (in different terminals, of course):
$ rsync -e 'ssh -b 83.180.203.199' --progress -ha Pictures/2013-03* <remote-machine>:Pictures/
$ 'rsync -e 'ssh -b 192.168.1.150' --progress -ha Pictures/2013-02* <remote-machine>:Pictures/

Naturally, I would get better network utalization if I uploaded huge tar-balls of the content than rsync:ing perhaps many small files - however, I'm after rsync's capability to determine exactly what's new and needs to be uploaded and what's already there.

Also, a common use-case is, of course, to just upload the latest, massive folder of photos. Then you can use a little bash-fu to make each concurrent connection upload different files - for instance on the one the odd and on the other the even numbered photos:

$ rsync -e 'ssh -b 83.180.203.199' --progress -ha Pictures/2013-03-23/*{1,3,5,7,9}.jpg <remote-machine>:Pictures/2013-03-23/
$ 'rsync -e 'ssh -b 192.168.1.150' --progress -ha Pictures/2013-03-23/*{0,2,4,6,8}.jpg <remote-machine>:Pictures/2013-03-23/