Visar inlägg med etikett Hack lab. Visa alla inlägg
Visar inlägg med etikett Hack lab. Visa alla inlägg

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

fredag 25 september 2015

Hack Lab - Bluetooth

Carolina and Josefine started the hack lab with a bit of research on how to connect the bluetooth to the Arduino. We then realized that we had to solder the pins to the Arduino pro micro board so that it would connect properly. We had a bit of a problem with this because we didn't know the basics of soldering. Mattias helped us to correct our mistakes (thanx!). After the mistake the connections where tested so that the pins worked properly.

At this time Julius joined us and we started to actually connect the bluetooth. This didn't work as it should. We found a lot of different examples online, that looked a lot a like, but none worked for our equipment. We also tried with an Arduino Uno but the same issues occurred as with the pro micro. We got the program to run in the end but no flow of information were detected.


By: Carolina, Josefine 

fredag 18 september 2015

Hack lab - Further Arduino + Mockups

Today we continued tinkering with the Arduino but this time with a more goal oriented way of trying it out. We wanted to try out how well the pressure sensor worked and with that make different LED's light up as the sensor got pressed harder, with great success as can seen in the video below.



We also made the some early mockups with some regular paper together with markers to try out the size and feel for how they turned out to be. Colors are of course not set in stone but it is interesting to just quickly get a feel for how the size of the cubes is more graspable by just making a couple of mockups. A quick Gif below shows how one scenario of the blocks could work out, with the white block at the beginning being turned off and then how the colors changes depending on how high you stack them.



By: Lennart, Carolina, Josefine

fredag 11 september 2015

Hack lab - Arduino

We choose to start tinkering with the Arduino instead of the Phidgets. After installing the program and finding all the components we needed we looked at the examples in the program. We managed to control a LED light with a button and later tried to add another LED light controlled by a pressure sensor. This didn't work exactly like we wanted it to tough so we tried to switch the sensor to a light sensitive one. However we did't manage to make it work before the hack session was over.



By: Carolina, Lennart, Julius

fredag 4 september 2015

Hack lab disassembling

The assignment today was to disassemble an electrical item. Our group took apart a digital camera and we learned a lot about the cameras inside structure. This assignment was to learn a common language between the group members and to find the material brief of the camera.

The camera was build of for example image sensors, button sensors, circuits, microphone, speaker, buttons, shell, lens, micro controller, screen, cogwheel and a lot of screws. 



The design of the camera small because it should be easy to be held in one hand and be easy to bring with you. There is a strap to attach to the hand that holds it, to prevent damage when accidentaly dropping it. The strap, the trigger and the other buttons is on the right and the objective is on the left. Most people are right handed and therefore will not block the camera view while holding it. 

There are a speaker and a microphone which implies that the camera is capable of recording sounds which probably means that the camera can record videos. 

The battery is small and exchangeable. This is so that you would be able to carry the camera with you and not have to plug it in the wall and to buy a new battery if necessary.

There is a screen on the back of the camera so that you can see the picture both while taking it and after it's bee taken.



By: Carolina, Josefine, Lennart, Julius