Archive for April, 2015

Carmina Burana – O Fortuna

Posted: April 11, 2015 in media-culture
Tags: ,

It’s that one cool classical song they always play when something evil or scary or BADASS is going to happen! It sounds satanical, but it’s actually a religious song (pawn intended?)

Can’t actually recall when I have first heard it (most probably in an alien movie soundtrack 😛 ), but I was captivated! It was AWESOME. One of the most awesome music compositions I had heard till then and still one of the most powerful, energetic and full of strength pieces of music. The composer is a German guy, Carl Off, who took a collection of (24) medieval poems and made amazing music out of them – more precisely in 1937 – first audition was nearby, in Frankfurt Opera.

My favourite is O Fortuna, the piece which starts and ends the collection. “In this piece, the author talks about to Fortuna (the goddess of luck in the Roman mythology) – praising her greatness, as well as her malevolence”. The rest of the songs cover a wide range of topics, from the fickleness of fortune and wealth, the ephemeral nature of life, the joy of the return of Spring, and the pleasures and perils of drinking, gluttony, gambling and lust.

Well, I have recently heard it in Tonhalle, and I was not disappointed. It was as amazing, even more so, live than on YouTube!

Nearly 100 musicians, 100 brains in sync for more than 1 hour, an engineering masterpiece at the very least. Every time I hear such powerful pieces of music, there is tiny devil in my head chuckling mischievously: Beethoven would have loved this!

O Fortuna vs. Final Fantasy

1. I have minions!

2. My minions are AWESOME!

3. While I am away from my minions, I wanna make sure that they are safe and happy.

Hence, I am preparing a super (duper) tiny project to alert me of movement around my minions (as I said, only I am allowed around my minions).

Parts

1. Motion detector (PIR sensor)

2. Wires (the sensor needs 3: ground, out, vcc)

3. Arduino board

4. I had Python on my mac-mac, but I also had to install pyserial, in order to communicate to the Arduino board, via the serial port. In my case, the Arduino board is reachable via /dev/cu.usbmodem1421, on other systems it’s probably different.

Picture

20150408_200557

A bit of explanation

Basically, the “plan” is to log something to Serial port from Arduino, everytime I detect movement around my Minions. If that happens, I log “Movement!” to the Serial port. Then, from Python, I monitor the serial port, and if I read “Movement!”, then I send an email to myself, using my Gmail account, alerting me that the safety of the Minions has been compromised 🙂

Code

1. Arduino code

int pirPin = 7;

int spamInterval = 60; // send email max every 1 min

long lastSend = -spamInterval * 1000l; // measured in milliseconds

void setup()
{
pinMode(pirPin, INPUT);
Serial.begin(9600);
}

void loop()
{
long now = millis();
if (digitalRead(pirPin) == HIGH)
{
if (now > (lastSend + spamInterval * 1000l))
{
Serial.println(“Movement!”);
lastSend = now;
}
else
{
Serial.println(“Let’s not spam”);
}
}
delay(500);
}

2. Python code

import time

import serial

import smtplib

import io

TO = ‘cristina.vintila@gmail.com’

GMAIL_USER = ‘cristina.vintila@gmail.com’

GMAIL_PASS = ‘no, you cannot get this one ;)’

SUBJECT = ‘Intrusion!!’

TEXT = ‘Watch the Minions! The Minions are not safe!’

ser = serial.Serial(‘/dev/cu.usbmodem1421’, 9600)

def send_email():

    print(“Sending Email”)

    smtpserver = smtplib.SMTP(“smtp.gmail.com”,587)

    smtpserver.ehlo()

    smtpserver.starttls()

    smtpserver.ehlo

    smtpserver.login(GMAIL_USER, GMAIL_PASS)

    header = ‘To:’ + TO + \n + ‘From: ‘ + GMAIL_USER

    header = header + \n + ‘Subject:’ + SUBJECT + \n

    print header

    msg = header + \n + TEXT + \n\n

    smtpserver.sendmail(GMAIL_USER, TO, msg)

    smtpserver.close()

while True:

    message = ser.readline()

print(message)

    if message[0] == ‘M’ :

        send_email()

    time.sleep(0.5)

#ser.close()

3. Output

rbh:Arduino cristina$ python safeMinions.py

Let’s not spam

Let’s not spam

Movement!

Sending Email

To:cristina.vintila@gmail.com

From: cristina.vintila@gmail.com

Subject:Intrusion!!

Let’s not spam

And I have the email 🙂

Happily, I am right next to the Minions, and I know they are safe

Arduino – making pretty sounds

Posted: April 8, 2015 in technical
Tags: , ,

Cristina is girlie and she likes PINK! Unfortunately, the LED part is the only one I couldn’t make work 😦 😦 hence no pink display for me.

The next best thing: we make pretty sounds!

Parts

1. Piezo (I have no proper speaker): well, I use it to make the (pretty) sounds

2. Light sensor + 1K Ohm resistor

I used this only in the beginning, as I wanted to make the piezo play sounds based on the light intensity. As I am not able to control the light intensity in my room in a good-enough way to make sounds, I decided to use the distance variation to play different tones (see 3).

3. Ultrasonic sensor: well, I use it to measure the distance from the sensor to my palm and based on this variation I scale the distance from CM to Hz and play the tones within a range of musical notes:

int tones[] = {261, 277, 294, 311, 330, 349, 370, 392, 415, 440, 450};
// mid C, C#, D, D#, E, F, F#, G, G#, A, higher

How did I end up with these values?

Well, I have not. That’s just how they are. The frequency of Mid C is 261.6 Hz, and the others as above. What I tried then to ensure is that I map the distances from the Ultrasonic reader to a range of frequencies which “make sense” (between 200 and 300 Hz). As I would just flip my hand around the sensor to no longer than 100 cm, I just decided to add 200 to the distance computed by the sensor, in order to create the pitch (I am sure there are much better ways to do this).

4. Wires (the Ultrasonic sensor needs 4 – as it has 4 PINs: VCC, Trigger, Echo, Ground)

5. Yeah, and the Arduino board and breadboard, otherwise: no magic

Picture

20150408_191513

Code

v0.1 (using the Light sensor)

int speakerPin = 12;
int photocellPin = 0;

int numTones = 11;
int tones[] = {261, 277, 294, 311, 330, 349, 370, 392, 415, 440, 450};
// mid C C# D D# E F F# G G# A others

void setup()
{
for (int i = 0; i < numTones; i++)
{
tone(speakerPin, tones[i]);
delay(500);
}
noTone(speakerPin);
}

void loop()
{
int reading = analogRead(photocellPin);
int pitch = 200 + reading / 4;
if (pitch <= 261)
{
tone(speakerPin, tones[0]);
}
else if (pitch > 261 && pitch <= 277)
{
tone(speakerPin, tones[1]);
}
else if (pitch > 277 && pitch <= 294)
{
tone(speakerPin, tones[2]);
}
else if (pitch > 294 && pitch <= 311)
{
tone(speakerPin, tones[3]);
}
else if (pitch > 311 && pitch <= 330)
{
tone(speakerPin, tones[4]);
}
else if (pitch > 330 && pitch <= 349)
{
tone(speakerPin, tones[5]);
}
else if (pitch > 349 && pitch <= 370)
{
tone(speakerPin, tones[6]);
}
else if (pitch > 370 && pitch <= 392)
{
tone(speakerPin, tones[7]);
}
else if (pitch > 392 && pitch <= 415)
{
tone(speakerPin, tones[8]);
}
else if (pitch > 415 && pitch <= 440)
{
tone(speakerPin, tones[9]);
}
else
{
tone(speakerPin, tones[10]);
}
}

v0.2 (using the Ultrasonic sensor)

int speakerPin = 12;
int trigger=7;
int echo=6;
long time=0;
long dist=0;

int numTones = 11;
int tones[] = {261, 277, 294, 311, 330, 349, 370, 392, 415, 440, 450};
// mid C C# D D# E F F# G G# A others

void setup()
{
Serial.begin(9600);
pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);

for (int i = 0; i < numTones; i++)
{
tone(speakerPin, tones[i]);
delay(500);
}
noTone(speakerPin);
}

void loop()
{
digitalWrite(trigger, LOW);
delay(5);
digitalWrite(trigger, HIGH);
delay(10);
digitalWrite(trigger, LOW);
time = pulseIn(echo, HIGH);
dist = (time/2) / 29.1;

if ( dist >= 500 || dist <= 0)
{
Serial.println(“No measurement”);
}
else
{
Serial.println(dist);

int pitch = 200 + dist ;
if (pitch <= 261)
{
tone(speakerPin, tones[0]);
}
else if (pitch > 261 && pitch <= 277)
{
tone(speakerPin, tones[1]);
}
else if (pitch > 277 && pitch <= 294)
{
tone(speakerPin, tones[2]);
}
else if (pitch > 294 && pitch <= 311)
{
tone(speakerPin, tones[3]);
}
else if (pitch > 311 && pitch <= 330)
{
tone(speakerPin, tones[4]);
}
else if (pitch > 330 && pitch <= 349)
{
tone(speakerPin, tones[5]);
}
else if (pitch > 349 && pitch <= 370)
{
tone(speakerPin, tones[6]);
}
else if (pitch > 370 && pitch <= 392)
{
tone(speakerPin, tones[7]);
}
else if (pitch > 392 && pitch <= 415)
{
tone(speakerPin, tones[8]);
}
else if (pitch > 415 && pitch <= 440)
{
tone(speakerPin, tones[9]);
}
else
{
noTone(speakerPin);
}
} // end distance measurement
delay(1000);
}

Yes, I did use the Serial.println for debugging, printing is the best form of debug 🙂 🙂 🙂

So it seems that I am back on “blogging”. Long time no see, my friends 🙂 and thanks for all the messages I got in the meantime.

Most probably I won’t be able to keep up blogging as in the past (not enough time to do all the geeky stuff), but I will not abandon it anymore.

The past few days I’ve found out about the passing of a friend, one of the geekiest people I know, an elderly gentleman, who has spent most of his life in the search for knowledge (he was speaking 11 foreign languages), curiosities and geeky stuff (a BSD passionate and founder of the foundation behind EuroBSDCon). I was very sad to get the news from Gavin and Henning this week, posted via the OpenBSD lists.

RIP Paul!

So, given the fact that for the past few weeks I can only sleep till 2AM every night, with occasional nights when I can fall asleep somewhere close to the morning, I have decided to spend this time on something useful, rather than with thinking and worrying about purpose of life and ponies and butterflies. First thing at hand: my new Arduino kit.

First time playing with this toy, I’ve went through the Startup Guide, and made the lights blink, the buzzer go off etc. The ones I am going to use later on though are the following:

1. Distance detector

https://drive.google.com/file/d/0By4rOXj_UNlEdVZMVHBjb2tJOGs/view?usp=sharing

2. Light sensor

https://drive.google.com/file/d/0By4rOXj_UNlEVnpaaXJQRUQweVE/view?usp=sharing

3. Movement detector

https://drive.google.com/file/d/0By4rOXj_UNlETzN6aUhkcGhNZzQ/view?usp=sharing

4. Temperature sensor

https://drive.google.com/file/d/0By4rOXj_UNlEeUpaSHJiRTZOZ0k/view?usp=sharing

5. (for the future) Servo engine

https://drive.google.com/file/d/0By4rOXj_UNlET0FfMW90bkFRMUk/view?usp=sharing

Indeed, these are just playing around with the very basics, but at least now I get the logic of how this works, and the code itself looks a lot like C programming, with libraries you can include and work with (and have the Arduino board become unresponsive when the libraries folder has a different name than the .cpp file inside it).

https://drive.google.com/file/d/0By4rOXj_UNlEamhKOTluZllPVDA/view?usp=sharing

Aaah, the sweet smell of burned plastic when you placed the Temperature sensor backwards on the breadboard!! 😛

TemperatureSensor