fredag 9 oktober 2015

Hack lab - Almost working product

We continued to try and get the Arduinos to work again and was given a new Arduino to swap out the one that broke. By updating the code with more or less the same one but in a fresh file we managed to get one of the cubes to work. The LED light in the second cube broke all colors but the blue one when we put it inside the cube. After that we put tape on all the electronics so that they wouldn't touch accidentally.

A platform was assembled made of tree and fabric to hide the Arduino and the pressure sensor and paper was put on the inside to hide the Arduinos. At the end of the session on Arduino for the cubes was working properly and the color change from green if one cube were placed and blue if two cubes were placed but the second cube didn't light up at all.


By: Car0lina, Josefine, Lennart, Julius

onsdag 7 oktober 2015

The breakdown

We started this session with assembling the cubes. The acrylic glass squares was put together with a glue gun. It was a little bit tricky to get the sides to stick on straight but we managed decently in the end.

But when we were about to try the Arduinos inside the cubes suddenly nothing was working even tough everything worked fine the day before. One of the Arduinos "exploded" and we spent the rest of the day trying to get the one that didn't break to work, without success.

By: Car0lina, Josefine, Lennart, Julius

tisdag 6 oktober 2015

Lab - Soldering and Laser cutting

With our new materials we continued to create two sets of Arduino setups. We soldered the new Arduino together and also the battery contact to an adapter so that it could be connected directly to the Arduino. This eliminates the need to connect the Arduinos to another power source and the cubes can run on the batteries without external cables.



We also wanted to cut acrylic glass with the laser cutter which we had some trouble with, but it seemed to be working toward the end of the session. We will continue working on this.

By: Carolina, Lennart, Josefine, Julius

måndag 5 oktober 2015

Crit 5/10

During the crit we had a small discussion with Mattias on how to solve the problem how the cubes should know what light to turn on. He suggested that we should use infra red. However we felt that it would be easier to till use the pressure sensor for our purposes but decided to only make use of one pressure sensor instead of one in each cube. This sensor would be placed on a mat or a platform of some kind and the cubes could only be placed on top of the pressure sensor in the prototype.

Because of these changes we had to modify the code somewhat. The cubes do not need to decide on the color of the lights anymore but only receive information from the server. The platform sends the current color to the server which passes the information on to the cubes.


Code for the Arduinos:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 16); // RX, TX

int r = 2;
int g = 3;
int b = 4;
char light;

void setup() {

  Serial.begin(9600);
  
  pinMode(r,OUTPUT);
  pinMode(g,OUTPUT);
  pinMode(b,OUTPUT);
  
  mySerial.begin(9600);
}

void loop()
{
     while(mySerial.available()){
        light = mySerial.read();
        digitalWrite(r,LOW);
        digitalWrite(g,LOW);
        digitalWrite(b,LOW);
        Serial.println(light);
        if(light == 'r'){
          digitalWrite(r,HIGH);
          }
          else if(light == 'b'){
          digitalWrite(b,HIGH);
          }
          else if(light == 'g'){
          digitalWrite(g,HIGH);
          }        
      }
}


Code for the platform:

#include <SoftwareSerial.h>

//SoftwareSerial mySerial(8, 9); // RX, TX

int test;
char check;

void setup() {

  Serial.begin(9600);

  
  //mySerial.begin(9600);
}

void loop()
{
    int sensorValue = analogRead(A0);
    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    float voltage = sensorValue * (3 / 1023.0);
    
    char test_sensor;
    if(voltage>=2){
      test_sensor = 'r';
      }
    else if(voltage>=1){
      test_sensor = 'b';
      }
    else if(voltage>=0){
      test_sensor = 'g';
      }
    //char test = mySerial.read();
    
    if(check != test_sensor){

      
    if(test_sensor == 'r')
    {
      Serial.print(test_sensor);
      check = test_sensor;
    }
    else if(test_sensor == 'b')
    {
      Serial.print(test_sensor);
      check = test_sensor;
    }
    else if(test_sensor == 'g')
    {
      Serial.print(test_sensor);
      check = test_sensor;
    }
    }
}


Code for the server:

# Imports
import time
import serial
from Tkinter import *

# Serial port parameters
serial_speed1 = 9600
serial_speed2 = 9600
serial_speed3 = 9600

serial_port1 = '/dev/tty.banana-DevB'
serial_port2 = '/dev/tty.HC-06-DevB'
serial_port3 = '/dev/tty.usbmodem1411'

ser1 = serial.Serial(serial_port1, serial_speed1, timeout=1)
ser2 = serial.Serial(serial_port2, serial_speed2, timeout=1)
ser3 = serial.Serial(serial_port3, serial_speed3, timeout=1)


colors=['r','b','g']
for i in range (3):
for j in range (3):
ser1.write(colors[j])
time.sleep(0.05)
ser2.write(colors[j])
time.sleep(0.05)

print("Ready!")

while 1:
data = ser3.read()
print(data)
ser1.write(data)
ser2.write(data)




After the crit Carolina and Lennart went to Kjell & Company to buy the rest of the material we needed to build two cubes. We bought one more Arduino Pro Micro, one RGB LED light, two 9V batteries and two batterie contacts.

By: Carolina, Lennart, Josefine, Julius

fredag 2 oktober 2015

Hack lab: Server

This hack lab we tried to get the server to work for both the Arduinos at the same time. We started off by changing the program so that the lights changes color depending on the pressure that are sent from the server, this did not work the last time.

At first we could only make use of the data from one of the Arduinos on the server. By sending the data we could use the pressure from one sensor to turn on the correct light on both Arduinos. However, when we tried to use the data from both Arduinos at the same time the program ran incredibly slow. This took some time to solve but we finally managed.

So this is how the system works:

  • The Arduinos takes the current pressure, converts it to the matching color, checks if the color has changed from before and if it has sends it to the server.
  • The server compares the data from both Arduinos and sends out the highest ranking color to both Arduinos.
  • The Arduino turns off all lights and turns on the right one if data is collected from the server.



Code for Arduino:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 16); // RX, TX

int r = 4;
int g = 3;
int b = 2;
int test;
char check;
char light;

void setup() {

  Serial.begin(9600);
  
  pinMode(r,OUTPUT);
  pinMode(g,OUTPUT);
  pinMode(b,OUTPUT);
  
  mySerial.begin(9600);
}

void loop()
{
   int sensorValue = analogRead(A0);
    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    float voltage = sensorValue * (3 / 1023.0);
    
    char test_sensor;
    if(voltage>=2){
      test_sensor = 'r';
      }
    else if(voltage>=1){
      test_sensor = 'b';
      }
    else if(voltage>=0){
      test_sensor = 'g';
      }
    //char test = mySerial.read();
    
Serial.println(voltage);
    
    if(check != test_sensor){
      
    if(test_sensor == 'r')
    {
      mySerial.print(test_sensor);
      Serial.println(voltage);
      check = test_sensor;
    }
    else if(test_sensor == 'b')
    {
      mySerial.print(test_sensor);
      Serial.println(voltage);
      check = test_sensor;
    }
    else if(test_sensor == 'g')
    {
      mySerial.print(test_sensor);
      Serial.println(voltage);
      check = test_sensor;
    }
    }
     while(mySerial.available()){
        light = mySerial.read();
        digitalWrite(r,LOW);
        digitalWrite(g,LOW);
        digitalWrite(b,LOW);
        Serial.println(light);
        if(light == 'r'){
          digitalWrite(r,HIGH);
          }
          else if(light == 'b'){
          digitalWrite(b,HIGH);
          }
          else if(light == 'g'){
          digitalWrite(g,HIGH);
          }
      }
}

Code for server:

# Imports
import time
import serial
from Tkinter import *

# Serial port parameters
serial_speed1 = 9600
serial_speed2 = 9600
serial_port1 = '/dev/tty.banana-DevB'
serial_port2 = '/dev/tty.HC-06-DevB'

# Test with USB-Serial connection
# serial_port = '/dev/tty.usbmodem1421'

ser1 = serial.Serial(serial_port1, serial_speed1, timeout=0.1)
ser2 = serial.Serial(serial_port2, serial_speed2, timeout=0.1)

colors=['r','b','g']
for i in range (3):
for j in range (3):
ser1.write(colors[j])
time.sleep(0.05)
ser2.write(colors[j])
time.sleep(0.05)

print("Ready!")

data1 = ''
data2 = ''

while 1:
#ser1.flushInput()
#ser2.flushInput()

temp1 = ser1.read()
temp2 = ser2.read()

if(temp1 != ''):
data1 = temp1

if(temp2 != ''):
data2 = temp2

#print("from1:" + data1)
#print("from2:" + data2)

if(data1 == 'r' or data2 == 'r'):
ser1.write('r')
ser2.write('r')
elif(data1 == 'b' or data2 =='b'):
ser1.write('b')
ser2.write('b')
else:
ser1.write('g')
ser2.write('g')


We have also been discussing how the cube should be constructed, we're thinking about using a 3D printer. But depending on which sensor we're going to use the cube might have to be air tight (if we use e.g. air pressure). This is the next challenge in cog process.

By: Caroline, Josefine, Lennart, Julius

torsdag 1 oktober 2015

Setting up a server

This work session started by researching how to get the Bluetooths to talk to each other. By doing this we want to compare the individual cubes color to each other in order to achieve that the color depend on the maximum pressure from both cubes. It took a long time to find how to do this. We started off by trying to find how a mobile can automatically send messages back to the Bluetooths in order to get this to work. However, we did not get it to work because the mobile could not send anything back automatically, a person needed to send something manually. 

The problem was resolved using a computer instead, which can run a server. The server was set up using python code. It received the messages from the Bluetooth and sent back the color the LED should be in, but the lights did not light up. The server was connected to only one Arduino at a time. 


Code for Arduino:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 16); // RX, TX

int r = 4;
int g = 3;
int b = 2;
int test;
char check;
char light;

void setup() {

  Serial.begin(9600);
  
  pinMode(r,OUTPUT);
  pinMode(g,OUTPUT);
  pinMode(b,OUTPUT);
  
  mySerial.begin(9600);
}

void loop()
{
   int sensorValue = analogRead(A0);
    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    float voltage = sensorValue * (3 / 1023.0);
    
    char test_sensor;
    if(voltage>=2){
      test_sensor = 'r';
      }
    else if(voltage>=1){
      test_sensor = 'b';
      }
    else if(voltage>=0){
      test_sensor = 'g';
      }
    //char test = mySerial.read();
    
Serial.println(voltage);
    
    if(check != test_sensor){

      digitalWrite(r,LOW);
      digitalWrite(g,LOW);
      digitalWrite(b,LOW);
      
    if(test_sensor == 'r')
    {
      mySerial.print(test_sensor);
      Serial.println(voltage);
      check = test_sensor;
    }
    else if(test_sensor == 'b')
    {
      mySerial.print(test_sensor);
      Serial.println(voltage);
      check = test_sensor;
    }
    else if(test_sensor == 'g')
    {
      mySerial.print(test_sensor);
      Serial.println(voltage);
      check = test_sensor;
    }
    }
      if(mySerial.available()){
        light = mySerial.read();
        digitalWrite(light,HIGH);
      }
}

Code for Server:

# Imports
import time
import serial
from Tkinter import *

# Serial port parameters
serial_speed = 9600
serial_port = '/dev/tty.banana-DevB'

# Test with USB-Serial connection
# serial_port = '/dev/tty.usbmodem1421'

ser = serial.Serial(serial_port, serial_speed, timeout=1)
while 1:
data = ser.readline()
print(data)
ser.write(data)


Written by: Josefine, Carolina, Lennart