Author Archives: rakhavij@andrew.cmu.edu

Ramin Akhavijou- Project 2- Project sPiral

In this project, I used an accelerometer to get triple axis data in order to control different parameters in music and light. For receiving the data from the accelerometer, I connected it to the Raspberry Pi (The python code for Pi and accelerometer is written hereunder). After getting data from the microcontroller, I sent the data to my computer using wifi. In order to do that, I added some python codes which connects the Pi and computer to the same network and port. Next, I converted the received data to another format which is readable for Max by using itoa. Then, I used “fromsymbole object” in order to convert the symbol to numeric data. By using unpack, I was able to get xyz data from the accelerometer to my computer. Moreover, I helped in some parts of the music patch to have an acceptable sound which interacts with light as well.

 

 

 

Here is the python code for accelerometer:

import time
import board
import busio
import adafruit_mma8451

Initialize I2C bus.

i2c = busio.I2C(board.SCL, board.SDA)

Initialize MMA8451 module.

sensor = adafruit_mma8451.MMA8451(i2c)

Optionally change the address if it’s not the default:

#sensor = adafruit_mma8451.MMA8451(i2c, address=0x1C)

Optionally change the range from its default of +/-4G:

#sensor.range = adafruit_mma8451.RANGE_2G # +/- 2G
#sensor.range = adafruit_mma8451.RANGE_4G # +/- 4G (default)
#sensor.range = adafruit_mma8451.RANGE_8G # +/- 8G

Optionally change the data rate from its default of 800hz:

#sensor.data_rate = adafruit_mma8451.DATARATE_800HZ # 800Hz (default)
#sensor.data_rate = adafruit_mma8451.DATARATE_400HZ # 400Hz
#sensor.data_rate = adafruit_mma8451.DATARATE_200HZ # 200Hz
#sensor.data_rate = adafruit_mma8451.DATARATE_100HZ # 100Hz
#sensor.data_rate = adafruit_mma8451.DATARATE_50HZ # 50Hz
#sensor.data_rate = adafruit_mma8451.DATARATE_12_5HZ # 12.5Hz
#sensor.data_rate = adafruit_mma8451.DATARATE_6_25HZ # 6.25Hz
#sensor.data_rate = adafruit_mma8451.DATARATE_1_56HZ # 1.56Hz

Main loop to print the acceleration and orientation every second.

while True:
x, y, z = sensor.acceleration
print(‘Acceleration: x={0:0.3f}m/s^2 y={1:0.3f}m/s^2 z={2:0.3f}m/s^2’.format(x, y, z))
orientation = sensor.orientation

Orientation is one of these values:

– PL_PUF: Portrait, up, front

– PL_PUB: Portrait, up, back

– PL_PDF: Portrait, down, front

– PL_PDB: Portrait, down, back

– PL_LRF: Landscape, right, front

– PL_LRB: Landscape, right, back

– PL_LLF: Landscape, left, front

– PL_LLB: Landscape, left, back

print(‘Orientation: ‘, end=”)
if orientation == adafruit_mma8451.PL_PUF:
print(‘Portrait, up, front’)
elif orientation == adafruit_mma8451.PL_PUB:
print(‘Portrait, up, back’)
elif orientation == adafruit_mma8451.PL_PDF:
print(‘Portrait, down, front’)
elif orientation == adafruit_mma8451.PL_PDB:
print(‘Portrait, down, back’)
elif orientation == adafruit_mma8451.PL_LRF:
print(‘Landscape, right, front’)
elif orientation == adafruit_mma8451.PL_LRB:
print(‘Landscape, right, back’)
elif orientation == adafruit_mma8451.PL_LLF:
print(‘Landscape, left, front’)
elif orientation == adafruit_mma8451.PL_LLB:
print(‘Landscape, left, back’)

 

And here is the code for sending data from Pi to Max using wifi:

import socket

from time import sleep

from time import time

 

host = ‘….’

port = 5560

 

def setupSocket():

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.connect((host, port))

return s

Project 1- Brightness

For this project, I used the data getting from the brightness of camera and specified that into four different sections. This patch is going to be used as an installation in a gallery. It takes the natural light from outside and reflects it into audio and video. I used the data for triggering or controlling different things such as modifying the speed of the music, turning on/off the music, changing the color, etc.

The brightness of camera gives me numbers. Then, I separated them into four sections in order to control different parts of the project. The first section generates some sound with different harmony. When the numbers transit to the second section, the color will be changed based on numerical modifications. The third section triggers the electronic music and its speed will be modified based on the numbers gaining from the brightness.

 

 

 

Frame

I added some functions controlling by random number to this patch in order to make the frequency graph as a motion graph. Also, it triggers the record option automatically in order to make more diversity by using different parts of the piece.

 

Convolution; piano & traditional instrument

String Quartet

impulse

Santoor

impulse

Piano

 

I put the microphone inside the instrument (Santoor; Iranian traditional instrument) resonance box to get an amplified signal. Also, I did the same with the piano.