Modern-day Twilight Zone

Imagine that the typical money-for-ransom is traded with a weird request like: “If you want to get your dear princess back, the prime-minister will have to have sexual intercourse with a pig on live television.” Will the prime-minister do it? Or more importantly, in a heavily socialized society where viral content dominates the people’s attention span, would they want him to do it and would they watch?

Or imagine that you live in a future where the most common way of making an income is to work on huge energy-production buildings where people pedal specialized stationary bikes to produce the energy that the rest of the world will consume. The alternative of leading this boring and tiresome life is to become a star in worldwide-broadcast reality shows that range from singing or pornography to physical abuse. Is everything better than the bike?

Or imagine instead that everyone has a brain implant that allows recording and reviewing every memory they have ever had and, by using a small external device, people can simply rewind and fast-forward to a particular memory and display it on a nearby TV for everyone to see. Now imagine you suspect your wife is cheating on you and you over-analyse every memory that you have of her with the guy you suspect she’s having the affair with. How long would it take you to go insane?

BlackMirrorTitleCard

(Image source)

These stories are the plots of the 3 episodes of the first season of BBC’s wonderful series Black Mirror, a techno-paranoia drama where each episode features a different story, a different cast and a different reality. In a modern-day Twilight Zone-like setting, each story brings us a potential future for our society that, albeit seeming a bit extremist, will definitely leave you thinking if this is really what you want for your future.

I definitely recommend everyone to see it. I dare say it’s mandatory for anyone with any kind of technology enthusiastic view of the society.

Are we close to simulate the human brain?

Back in 2007, US researchers have simulated half a virtual brain of a mouse on a supercomputer. Interestingly, Ray Kurzweil, in his 2005 book “The Singularity is Near“, accurately predicted the amount of computing power necessary for that scientific achievement.

What’s really interesting is the prediction that he made for 2013. Check this graphic:

Supercomputer power

(Image source)

2013 is portrayed as the year where the human race will have enough computing power, according to Kurzweil’s predictions, to simulate an entire virtual human brain.

I still believe that the challenge regarding simulating the human brain is in the software, not in the hardware[1], but this will sure be an interesting year for artificial intelligence research.

  1. There’s still too much about the inner works of the human brain that we don’t know []

Should we start worrying about this asteroid?

I know this is old news[1], but I guess it’s worth the consideration: asteroid 2011 AG5, an asteroid roughly the size of a football stadium, is thought to be in a (albeit improbable) collision course to Earth.

(image source)

Before you start panicking, let me explain: this asteroid is currently cruising through our Solar System and is orbiting our Sun pretty much the same way as our 8 planets[2] are. It will pass by our planet in 2023 but in a completely safe trajectory. The problem is when it is planned to pay us a visit again in 2040. According to scientists, there is a 1 in 625 chance that the asteroid will hit Earth.

Scientists will know more about the asteroid (and its trajectory) once it comes out of the other side of the Sun, which should be later this year. Future observations will probably reveal that there’s no reason to worry. But… what if? The chances are really slim, but after seeing what an (estimated) 15 meters asteroid did in Russia, I think we should consider what our plan is going to be.

Don’t you?

  1. In Internet Years™, it’s ancient really! []
  2. Sorry, Pluto! []

Pulse Sensing with the Raspberry Pi

Continuing the work with analog sensors on the Raspberry Pi, I decided to test the PulseSensor‘s behavior in building a pulse sensing application. The Pulse Sensor (quick-start guide here) is a well-designed plug-and-play heart-rate sensor for Arduino but considering that it’s a simple analog sensor that sends values between 0 and 1023, it’s easy enough to use  with the MCP3008 ADC on the RPi.

This slideshow requires JavaScript.

Here’s the python code that can be used to make a simple pulse sensing application:


#!/usr/bin/env python
import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

# read SPI data from MCP3008 chip, 8 possible adc's (0 thru 7)
def readadc(adcnum, clockpin, mosipin, misopin, cspin):
        if ( (adcnum > 7) or (adcnum < 0) ):
                return -1
        GPIO.output(cspin, True)

        GPIO.output(clockpin, False)  # start clock low
        GPIO.output(cspin, False)     # bring CS low

        commandout = adcnum
        commandout |= 0x18  # start bit + single-ended bit
        commandout <<= 3    # we only need to send 5 bits here
        for i in range(5):
                if (commandout & 0x80):
                        GPIO.output(mosipin, True)
                else:
                        GPIO.output(mosipin, False)
                commandout <<= 1
                GPIO.output(clockpin, True)
                GPIO.output(clockpin, False)

        adcout = 0
        # read in one empty bit, one null bit and 10 ADC bits
        for i in range(12):
                GPIO.output(clockpin, True)
                GPIO.output(clockpin, False)
                adcout <<= 1
                if (GPIO.input(misopin)):
                        adcout |= 0x1

        GPIO.output(cspin, True)

        adcout >>= 1       # first bit is 'null' so drop it
        return adcout

# change these as desired - they're the pins connected from the
# SPI port on the ADC to the Raspberry Pi
SPICLK = 18
SPIMISO = 23
SPIMOSI = 24
SPICS = 25

GPIO.setwarnings(False)

# set up the SPI interface pins
GPIO.setup(SPIMOSI, GPIO.OUT)
GPIO.setup(SPIMISO, GPIO.IN)
GPIO.setup(SPICLK, GPIO.OUT)
GPIO.setup(SPICS, GPIO.OUT)

# pulse sensor connected to adc #0
pulse_adc = 0

# Threshold for pulse sensing (half of values between 0-1023)
THRESH = 512

# pulse detection
pulse = False

while True:
        # read the analog pin
        analog_value = readadc(pulse_adc, SPICLK, SPIMOSI, SPIMISO, SPICS)

        # draw the equivalent number of points in an attempt to draw a vertical pulse sensing graph
        for i in range(analog_value / 100):
                print ".",

        # detect beats
        if (analog_value > THRESH):
                if (pulse == False):
                        pulse = True
                        print "Beat"
                else:
                        print ""
        else:
                pulse = False
                print ""

        # hang out and do nothing for a tenth of a second
        time.sleep(0.1)

The application simply processes the values received in the ADC’s channel #0 and if the value is greater than a certain threshold (in this case 512, considering that is half of 1024 values) it senses a beat. It also ignores subsequent beats above that threshold and it only considers a new beat once the values go beneath the threshold again.

Running this code should produce a similar output to this (depending on your heart beat):


. . .
. .
. . .
. . . . . . Beat
. . . . . . . . .
. . . . . . . . .
. .
. . .
. . .
. . .
. . . .
. . . . . . . . . Beat
. . . . . . . .
. .
. . .
. . .
. . .
. . . .
. . . . . . . . . Beat
. . . . . . . . .
. . .
. . .
. . .
. . .
. . .
. . . . . . . . . Beat
. . . . . . . . .
. . .
. . .
. . .
. . .
. . .
. . . . . . . . . Beat
. . . . . . . . .
. . .
. . .
. . .
. . .
. . .

You can also create a more interesting application by having the RPi send the raw pulse sensor data through some sort of channel (web server, sockets, serial, etc…) and graphically present the results on another computer.

Conway’s Game of Life in Javascript

I know that there are probably a bunch of other implementations of the Conway’s Game of Life in Javascript out there, but I wanted to try to create a new version that included (properly enjoyable) music that would be generated by the evolution of the cells in the game.

Conway's Game of Life

However, the use of the Web Audio API (I didn’t want to use MP3 or WAV) for this end proved somehow useless mainly because the sounds it generates are only comparable to those of the good old days of dial-up connections. Moreover, the API is only available (for now) in Google Chrome and Mac OS X’s Safari’s latest version.

Perhaps, in the future, I’ll change it once there’s some more interesting way of doing that and that works across more browsers.

So, for now, enjoy only the visual aspect of the game.