The populist undermining of scientific consensus

I’m in awe of the decision by Popular Science to shut off the comments on its online articles. Suzanne LaBarre words their reasoning[1] so eloquently:

Suzanne LaBarre, Popular Science, “Why We’re Shutting Off Our Comments”

A politically motivated, decades-long war on expertise has eroded the popular consensus on a wide variety of scientifically validated topics. Everything, from evolution to the origins of climate change, is mistakenly up for grabs again. Scientific certainty is just another thing for two people to “debate” on television. And because comments sections tend to be a grotesque reflection of the media culture surrounding them, the cynical work of undermining bedrock scientific doctrine is now being done beneath our own stories, within a website devoted to championing science.

I think it’s time to declare an end to popular journalism. At the intersection of journalism and social media is a desire on the part of many to share their opinions; but anonymous commentary on subjects, like science, that dwell in the province of evidence really doesn’t work.


Set an ivar via the Objective-C runtime

Generally, I don’t like to use a lot of runtime trickery, swizzling and the like - but there are use cases where knowing how to do it can solve an immediate problem.

For my current project, I’ve temporarily incorporated a hidden feature that is brought up by a application-wide UIGestureRecognizer added to the main window. It allows me to
do things with the Core Data objects that I don’t necessarily want to expose to the user; but I’d like to be able to test quickly in real-world settings. For example, deleting
all of a particular group of managed objects so that I can test what empty table views look like. Or generating sample data so that I can see what really full table views look like.

One function that I needed to test in the field was a long-running timer. Not wanting to wait 15 or 30 minutes for an event to happen, I decided to create a developer-only functionality that would advance the timer to within 15 seconds of completion. Not something I want to expose to the end-user; but nice to have for testing. To do this, we need to manipulate an ivar _currentSeconds, resetting its value to 15. But let’s take a more general case with a class named Foo.

@interface Foo : NSObject

@property (nonatomic, readonly) NSInteger count;


@implementation Foo

Since the class interface only provides readonly access to the count property and its backing ivar _count, we can’t use the public interface to manipulate count. But the Objective-C runtime API will let us do so:

#import <objc/runtime.h>

// create the instance whose count property we'll change
Foo *myFoo = [[Foo alloc] init];

Now get a reference to the Ivar via the runtime:

Ivar ivar = class_getInstanceVariable(Foo.class, "_count");

Now the tricky part, since we’re changing a scalar, we can’t use object_setIvar because it takes an id. So we’re forced to set the ivar by using an offset into the class ivar layout. Something like this:

int *ivarPtr = (int *)((uint8_t *)myFoo + ivar_getOffset(ivar));

This is perfectly legal under reference counted memory management; but under ARC, it won’t compile because ARC doesn’t know how to manage the memory of the pointer we’ve created. The workaround is this:

CFTypeRef myFooRef = CFBridgingRetain(myFoo);
int *ivarPtr = (int *)((uint8_t *)myFooRef + ivar_getOffset(ivar));

Now all that’s left is to set our ivar and release the CFTypeRef

*ivarPtr = 15;

Showing the whole thing:

@interface Foo : NSObject
@property (nonatomic, readonly) NSInteger counter;

@implementation Foo


// Now we'll access the ivar from another class

#import <objc/runtime.h>

Foo *myFoo = [[Foo alloc] init];

Ivar ivar = class_getInstanceVariable(Foo.class, "_counter");
CFTypeRef myFooRef = CFBridgingRetain(myFoo);
int *ivarPtr = (int *)((uint8_t *)myFooRef + ivar_getOffset(ivar));
*ivarPtr = 15;

See also:

Comments? I’m @NSBum

Why I stopped buying DRM music from iTunes

DRM, officially ‘digital rights management’[1] - but I’m calling it ‘digital restrictions management’ is a technology that lets copyright holders restrict the use of digital content after they sell it to you. With the rise of the internet, DRM has become ubiquitous, though philosophically flawed. I’ve bought thousands of dollars worth of DRM content over the years; but I’m done.

True story. One of my sons bought a new iPod to replace a broken model. Like many kids who live a mostly mobile lifestyle, he never backed up his iPod. No worry, we’ll just redownload the content (apps, music, etc.) onto the new device from the ‘cloud’. The problems began when Apple requires you to use multi-factor authentication to prove that the person using the new device is the same person who used the old device to purchase the content. It requires you to answer a series of questions whose answers may be long forgotten. “Who is your favorite teacher?” Hmmm. What grade was I in when I got this iPod. Don’t guess because you only have a limited number of tries before it locks up your account for 24 hours. Keep trying after that and it will lock you out forever. No matter, we’ll give a call to tech support and give them our story. After minutes of explaining and pleading about the plight of a 13 year-old kid, no joy. In the end, he lost all of the content that we had ever purchased. Thanks for making the world a safer, better place, Apple.

The fragility of DRM

For me that was the final blow to my waning enthusiasm for DRM-encumbered music. Let’s get one thing straight. On the whole I enjoy the convenience of digital music. It’s really exemplary of the massive conveniences that we enjoy in the 21st century. Take a moment to ponder just how amazing it is to access any book, image, piece of music instantaneously. Want to listen to the Górecki Third Symphony? Poof! Purchased and downloaded. But the convenience doesn’t come for free; and although you’ve purchased the right to own a copy of the recording, what you’ve really purchased is a copy of a recording containing a very detailed set of rules about who can play it, on what device, etc. Although restrictions on the use of copyrighted content is nothing unusual, DRM takes the concept to a new level, in which the enforcement of the restrictions is embedded in the medium. It’s also remarkably fragile, as the experience with my son points out.

The purchasing experience

iTunes Store clutter and spectacle I use iTunes to play music, largely because it's free and convenient, and because I've never taken the time to look for more suitable alternatives. Since version 4, iTunes has contained an embedded store from which you can purchase DRM-containing music. Over the years, the iTunes Store has become more an more florid. I'm not a music snob. _(Well, I'm sort of a music snob.)_ I have reasonably eclectic musical interests; but I'm a classically-trained musician. The spectacle and commercialism of popular music doesn't interest me. But this is front-and-center in the iTunes Music Store. You can't find music without having to wade through album covers from Drake, Kings of Leon, Icona Pop, Dream Theater, and (amusingly) Dog Blood. I'm sure all of these albums are fine for their genre; but no matter how often you put a cover of Dog Blood's _Middle Finger, Pt. 2_ in front on me, I'm not going to buy it. You can always navigate to the classical category; but it's not much better. The view is still dominated by album covers as if the picture on the virtual "front cover" is what's important. I appreciate knowing what's new, but just show me a list. In short, the purchasing experience is heavily tuned to music whose enjoyment is attended by spectacle. It's off-putting to purchase classical music in this way; and for now I'll just use iTunes as a way of reverse showrooming[^2].

The device limitation

Apple limits you five devices onto which you can load music you’ve purchased. They provide you with no way of actually identifying what those devices are. If you go over the 5 devices, you just need to find one them and deauthorize it. You can’t get a list of the currently authorized devices. As I said, I don’t shared music I’ve purchased in an illegal way. So the five device limit on my use of the music is an unnecessary encumbrance on my freedom.

Album notes

Album notes

Many serious artists go to great length to write or commission extensive, well-researched, authoritative commentary on the works they’ve recorded. These are all but completely missing on iTunes. I suspect the same is true of other sources of DRM-encumbered music. I realize that actually reading printed material has become unfashionable; but this is a serious omission. My CD case of Glenn Gould’s recording of Bach’s The Well-Tempered Clavier contains detailed notes about the experience of recording the eccentric artist. It lends a sense of humanity to the humming Gould. I miss this too much. For me, the enjoyment of music, whether on my instruments or while listening to recordings is an experience that works on both sides of the brain. It’s an intellectual, as much as emotional, exercise. The album notes are an important part of the latter; and their loss in electronic content is lamentable.

Resources and waste

I would be remiss if I didn’t raise the issue of resources. Physical CD’s represent only a small amount of material; but it’s not neglible. The case is larger, has more plastic mass and is more expensive to produce. The incremental cost and resource expenditure for distributing music electronically is almost infinitely small. All other things being equal (which they are not) electronically-distributed music would be preferable from the perspective of natural resource conservation. However, purchasing used CD’s is one way to avoid incurring additional production costs.

Intangibility, value, and je ne sais quoi

There is something about physical, tangible objects that makes us value them more. Perhaps it’s because we evolved in, and inhabit a physical world. Music is so incredibly important to me that it’s hard to dissociate from something physical - whether it’s a printed score, my instruments, or a recording on physical media. I wonder whether music is trivialized not only by associating it with the visual intensity of modern performance but by selling and distributing it in a way that’s completely ethereal and dissociated from physical world.

Now CD’s seem like old friends; and I’m happy to be reacquainted.

Comments? I’m @NSBum


Controversy and creationism

The New York Times ran a Room for Debate column entitled Should Creationism Be Controversial? Several authors on both sides of the issue wrote responses. I found one response, “Science, Too, Calls for a Leap of Faith” by Trevin Wax, particularly problematic.

Here are his claims, dissected:

“Science neither proves nor disproves the existence of a creator”

This is true. But in both formal logic and in our daily lives, the burden of proof is on the claimant. As individuals, anything more than the most trivial of claims requires something objective to back it up. That’s why the car dealer won’t let me take home a shiny new car on the promise that I’ll send payment when the bill comes. No, first I have to backup my claim that I have enough cash flow to warrant their trust.

“Even non-creationists live as if the creation story is true”

I found this the most puzzling of the claims. Mr. Wax sees Christian religious faith as the only source of purpose and morality in life. Undoubtedly, many derive a sense of purpose from their faith. But that says nothing about the sense of purposefulness among the faith-less. People derive purpose from all sorts of sources; and if he were correct, you would expect atheists to run amok in society, given that they could not possibly have any moral foundations. But they don’t. They don’t commit more crimes. (Actually, they appear to commit fewer crimes.) They raise their children just as responsibly as anyone else. In short, humans are purpose- and meaning-seeking animals. We want to see patterns and significance in things that happen around us. If the creation narrative endows some people with a sense of meaning and belonging, then by all means they should hold onto it. But they shouldn’t use it as a club with which to beat those of us who don’t.

He goes on to explain why altruistic behavior observed in humans does not fit with evolution by natural selection. After all, it seems to conflict with “survival of the fittest.” First, the common distillation of Darwinian evolution as “survival of the fittest” is problematic in this, and most contexts. More accurately stated, the genes for an adaptive trait become more frequent in a population because of differential rates of survival. There is nothing about altruistic behavior among humans that is maladaptive. Humans are social primates that have a strong need for altruistic patterns of behavior. The survival of the species is closely linked to the cohesion of the group.

Natural selection doesn’t work on a conscious level anyway. It is a feature of the way DNA changes through random mutation and recombination.

How does science prove itself?

The argument Mr. Wax puts forward here is that there is no scientific evidence to prove that science is the only reliable way to discover truth. I would absolutely agree. But his error is in the conclusion that because science cannot prove itself as the sole source of truth, that the creation story must be true. This is an enormous logical leap. Perhaps science is not the sole source of truth and the creation story is false. My response to his challenge to the reliability of science is pragmatic. {“Science works.”} It predicts certain phenomena in the observable world, is repeatable, and can be harnessed to solve problems. And its process inherently helps it approach the truth through peer review, criticism, openness, and self-correction.

Revisiting Gould

Stephen Jay Gould famously characterized science and religion as “non-overlapping magesteria” - disciplines that answered completely separate questions. But an existence claim is a scientific claim and as a practical matter the magesteria overlap more than some would like. Nonetheless, we can’t have it both ways. Religious adherents should have the right to believe what they like, gather, and worship in the way they see fit. But they can’t claim that their faith answers a different set of questions than those answered by science but then demand to teach those answers in a science class. It’s no different than a demand by academic scientists to teach evolution in worship services.

Comments? I’m on Twitter @NSBum.

What motivates climate change deniers?

The Intergovernmental Panel on Climate Change just released a draft summary of a report to the UN. Unsurprisingly, the panel concluded both that the Earth’s warming is unequivocal but now expressed near certainty that human activity is the cause of the observed and predicted climate shifts.

Given the near universality of scientific opinion on climate change, I’ve begun to wonder what motivates climate change deniers. After all, on most topics, reasonable people who are inexpert in a discipline look to the opinions of experts to gain a better understanding. So what’s behind the extreme rejection of scientific consensus among climate change deniers.


Climate change deniers are a particular type of denialist. Denialists form fixed, unshakable beliefs about a subject and are unmoved by contradictory findings. Instead, denialists adopt one of several approaches to undermining the contradictory claims. In the case of climate change, for example, denialists point out that the Earth has not substantially warmed for about a decade and a half. (That’s true, but 16 years in geologic time is short indeed; the long timescale of geologic time, makes short-term leveling of trends basically just noise in the data.)

Climate change denial and the free market

A recent study published in Psychological Science shed light on two important viewpoints strongly held by climate change deniers. In this study Full text PDF, led by Professor Stephan Lewandowsky from the University of Western Australia, researchers examined over 1000 responses to a questionnaire posted on a blog dedicated to the discussion of climate change. Among the findings in this study was a striking correlation between the rejection of climate science and the endorsement of a laissez-faire conception of free-market economics. Certain responses to questions about free-market economics were even more strikingly correlated with reject of climate science. For example, the correlation between agreement with the statement “The free market system is likely to promote unsustainable consumption.” and reject of the accepted theory of anthropogenic climate change was 0.892. Thus, persons who have a strong opinion in the rightness of unrestrained capital markets are very likely to reject the science behind anthropogenic climate change.

Conspiracy theories

The study also found that persons who reject climate science endorse a number of conspiracy theories. For example, the correlation coefficient between agreement with the statement “Area 51 in Nevada is a secretive military base that contains hidden alien spacecraft and or alien bodies.” and the rejection of climate science was 0.891. Numerous other conspiracy theories were examined in the study and showed high rates of correlation with the rejection of climate science.

A theory of climate science rejection

The striking correlation between endorsement of widely varying conspiracy theories suggests a deep psychological condition or style of relating to the world that generates suspicion. As Viren Swami, professor of psychology at the University of Westminster, notes: {“The best predictor of belief in a conspiracy is belief in other conspiracy theories.”} Other studies have shown that conspiracy theorists have high levels of cynicism about the world in general and about politics, specifically. They have lower ratings of self-worth than non-conspiracy theorists; and they appear to be reacting to a loss of agency in the world.

I believe that a high level of distrust and low level of self-esteem leave persons vulnerable to irrational theories that give them a sense of agency in a confusing world. They are ripe for messaging from groups financed by billionaire industrialists such as the Koch brothers who stand to lose if we were to take real action on climate change. Furthermore, the Filter Bubble effect is likely to amplify the opinions of such individuals and create a highly polarized - though errant - viewpoint about climate change.

The climate is unequivocally changing. There is near certainty (~95%) that human activities are the cause.

Comments? Find me on Twitter: @NSBum

HAB telemetry system chosen

As mentioned before I’m planning on launching a high-altitude balloon later this year. Most of the sensor technology is already finished; but we were stalled on the telemetry. Mainly you must be able to find the payload in order to get the sensor data, the pictures, and the hardware.

To reduce the complexity somewhat, I settled on using APRS for this first flight. Later I might try some more interesting possibilities like an HF beacon that uses CW to broadcast its position.

For the APRS tracker, we’re going to use the Argent Data Systems tracker version OpenTracker+ SMT which looks to be a nice compact solution for the HAB payload. Equally compact is the VHF transmitter SRB MX145 which is capable of putting out between 350 and 500 mW.

While reading about the SRB MX145 in its manual I noticed a comment about the modulation deviation:

“Most trackers have high impedance outputs and the resulting signal level at the modulation input of the SRB-MX14 will not give sufficient deviation. In addition they usually have significant harmonic content which will lead to an unwanted broad spectrum of the transmitted signal” Therefore, they suggest the addition of an impedance converter combined with a low pass filter with a ~2.7kHz cutoff frequency."

Page 7 of the manual provides a schematic for the filter/impedance converter circuit.

High-altitude balloon systems

I’ve been planning a high-altitude balloon launch for a long time. Initially I was planning to launch it with an AVR-based flight computer. But when the Raspberry Pi came out I decided to switch my development efforts, like this guy and this guy. I spend my days mostly developing at a fairly high level of abstraction so I feel most confident working at that level. Being able to program the RPi in Python is huge for me.

Figure 1

The plans for the payload are still in evolution, but here’s what I have so far:

  • Raspberry Pi will be the main flight computer
  • We will get barometric pressure (and therefore altitude) data from a BMP085
  • 3-axis acceleration data will come from an ADXL335 analog accelerometer connected to an ATtiny261 chip which will connect to the RPi via the I2C bus as described here. (The diagram shows an 861. I think the memory footprint needed is much lower than that.)
  • Humidity data from inside the payload and outside will come from two analog humidity monitors also connected to the AVR ADC-I2C bridge.
  • We will get real-time clock data from a DS1307 on the I2C bus.
  • Imagery will come from a Canon PowerShot G6 connected to the RPi by USB. We’ll use gphoto to capture images.
  • Flight data will be dumped to a USB-connected giveaway flash drive that I got from a conference.

There are still design decisions to be made, mainly how to command a cutdown, and how we’ll transmit the telemetry data. As an amateur radio license holder (KD0RXD), I have a number of options but I need to sort through them systematically.

Questions? Comments? I’m on Twitter @NSBum.

Markdown anchors

TIL how to use anchors in Markdown documents. I needed to use this in a long blog post in my Octopress blog and was stymied.

As usual, I found the answer on Stack Overflow.

Beam me [up](#enterprise), Scotty

<a id="enterprise"></a>

It’s a great way to move around in longer content.

2014-03-03: I no longer publish using Octopress; but this should work in most cases where Markdown is used. Bitbucket is a notable exception. For Github wiki, you’ll need something like:

# <a name="heading1" /> Heading 1 #

and for the link to that anchor:

[link to heading1](#heading1)

ADC for Raspberry Pi

I’m working on launching a high-altitude balloon later this year with a Raspberry Pi serving as its flight computer. The Raspberry Pi is an excellent tool because it allows you to do most common tasks at a higher level of abstraction than other MCU platforms. However, it lacks at least one of the major conveniences of MCU’s like the AVR that I’m accustomed to working with - the analog-to-digital converter (ADC). In this article, I’ll describe one solution to the missing ADC, albeit a little complex. For this project, I’m using an ATTinyx61 to serve as the ADC, communicating with the RPi as a slave on the I2C bus.

Why use an AVR as an ADC?

Before settling on this solution, I evaluated a few other possibilities:

  • MCP3008 is an 8-channel 10-bit ADC that comes in a DIP package. It is an SPI-only device which is fine; but the protocol that it uses requires a fair bit of bit-banging. I want to run the flight computer software in Python; so I was a little skeptical of doing this kind of low-level transction at the level.
  • ADS7830 is an 8 channel 8-bit ADC; but it’s available ony in a TSSOP-16 package. One of my goals was to build the daughter board(s) as inexpensively as possible. If I have to fabricate a custom board, then I miss that goal.
  • Gertboard is a great board for prototyping ideas; but I need something that I can send up to 100,000 feet with minimal weigh.

I’m sure there a tons of others; but in the end (a) I couldn’t invest more time in finding the rare DIP packaged, 10 bit 8 channel ADC on the I2C bus. So why not make our own?! I know AVR; so we’ll just turn an AVR into our ADC’s.

Read More

All about I2C: Part I

What the hell is really going on in I2C anyway?

If you’re used to working at the “Arduino-level” of knowledge, then you know the I2C is a two-wire peripheral interface, etc. etc. If you already know that level, but want to know more about how it works at the physical bit layer, read on. This tutorial is meant to help you understand what’s going on without the higher level of abstraction that libraries like Wire.h exposes.

For the purposes of this tutorial, we’re going to temporarily ignore the situation where there are multiple masters on the bus. Instead, we’ll assume a single master and one or more slaves. This allows us to pose the following question:

Who drives the clock - master, slave, or both?

In our typical simplified case, it’s the master that drives the clock.

Since I2C is described as a two-wire interface, what are the “two wires”?

There are indeed only two signals: SDA or serial data and the clock SCL or serial clock. The narrower bus is convenient but it requires considerable orchestration between slaves and master. The rest of this tutorial is all about this coordination.

Why are pullup resistors generally required on the I2C lines?

This is because when any device on the bus pulls the line low, the line must be low at each of the drops. Similarly, a high logic level condition on the bus requires that all devices stop drinving it.

As a brief, but important, aside, the SDA and SCL pins must be implemented as open collector outputs. Open collector schema

When the the external side of the output transistor, the collector, is connected to a pullup resistor, the pin is at a logic high when the transistor is turned off. When the transistor is turned on, the output voltage falls to a low logic level. This is why pullup resistors are use on these lines.

Starting and stopping a transfer

Since we’re talking about a bus, this is about data transfer. Since for practical reasons, the data transferred across the bus is finite, there must be a start and stop condition to bookend the interaction. Unsurprisingly, these are the START and STOP conditions.

The START condition is defined when the SCL line is high and the SDA line transitions from high to low. There is no other moment in the protocol where this is true. Normally state transitions of the SDA line occur only when the SCL line is low.

Similarly, there is a STOP condition that does not occur otherwise during data transfer. This happens when the SDA transitions from low to high while the SCL is high.

Data transfer on the bus

Every unit of data that is sent on the bus is 8 bits wide. The master is responsible for initiating and stopping the data transfer by asserting the conditions described above. At the beginning of a transfer, the master lower SDA while SCL is high, creating a START condition on the bus. Thereafter, it sends transfers 7 bits of slave address on SDA clocked via SCL. The last (least significant) bit in the stream is the read/write bit, where read is a logic 1 and write is a logic 0.

Up until now, all of the work is being done by the master. Now the master expects a response. In this case, the master lowers SCL a ninth and final time. This is when the slave that responds to the transferred address must respond by lowering SDA. This is an ACK.

Take a look at Figure 1 to visualize a typical write sequence from master to slave:

![Figure 1(i2c-master-write.001.png)

Reading data from the slave

When the master device wishes to read data from a slave, it follows the same general protocol as that for a write. First it generates a start condition followed by seven bits of address data, the followed by a read bit. This comprises a 9 bit preamble that address the device of interest. Then, the slave device sends an ACK to acknowledge the receipt of the address and read/write designator. This is immediately followed by 8 bits of data. So far it’s almost just like the situation with the master-to-slave write described above. But now, it’s the master, not the slave that most ACK the data. Each 8 bit byte of data transfered from slave to master is punctuated by an ACK from the master. That is each byte until the last one. When the master needs no more data, it sends a NACK which is the equivalent of the telling the slave device to “shut up.” We could visualize it like Figure 2.

Figure 2

How can I possibly diagnose problems on the bus?

I started this tutorial by describing a goal of taking your knowledge about the I2C/TWI bus beyond the Wire.h level. But with that comes the usual challenges presented by getting closer to silicon. My preferred approach to dealing with this is the logic analyzer. I use the Intronix Logicport analyzer I can’t say enough good things about this device although it is expensive. A less expensive alternative for listening to the I2C (and other) buses is the Bus Pirate. I have no direct experience with the Bus Pirate - but I understand the principle and it seems sound.

To give you a sample of what bus analysis looks like in the context of what we’ve been talking about, take a look at Figure 3:

Figure 3

At a glance, you can see exactly what is happening on the bus. For example, you can see the waveforms that mark the START condition. (You do remember what defines a START condition right? No? It’s when the master drives SDA low while SCL is high.) Then we see

That’s for part I. Hope that helps take one layer of mystery out I2C.