Week16. Interface and application programming

This week, we will create a program for the UI using the circuit we have already created.

Group Assignment

The content of our group assignment is here.
Week16 Group Assignment

Impressions

Unity is a development environment for game production.
I think that more play will be created if the input devices created by myself etc. are connected to the game.

Individual Assignment

Display temperature graph for debugging FinalProject.

Circuit to use

Overview
overview

Programming

I created a program using Arduino.
And Use Processing in the GUI.

Arduino

The following program was created by Arduino and written.

The process to calculate the temperature of the Grove-TemperatureSensor uses the following sample.

// Using GroveConnectors
#define GROVE_R1 PA2 // Right 1
#define GROVE_R2 PA3 // Right 2
#define GROVE_L1 PA7 // Left 1
#define GROVE_L2 PB2 // Left 2

// Using Serial I/O
// ATTiny44 is not available Serial
// Alternative SoftwareSerial Library
#include <SoftwareSerial.h>
SoftwareSerial softSerial(0,1); // RX, TX

// for reading GroveThermoSensorV1.2 value
const int B = 4275;               // B value of the thermistor
const int R0 = 100000;            // R0 = 100k

void setup() {
  // put your setup code here, to run once:
  pinMode(GROVE_L1,INPUT);
  pinMode(GROVE_R2,OUTPUT);
  softSerial.begin(19200);
}

void loop() {
  // read the value from the sensor:
  // analogRead
  int temperature = getTemperature(); 
  // write x value  

  // Convert from float type (4 bytes) to int type (2 bytes).
  // Multiply by 100 to use decimal places.
  softSerial.write((int16_t)(temperature * 100) >> 8);
  softSerial.write((int16_t)(temperature * 100) & 0xFF);
  softSerial.write('\n');
  // wait 500 mill second
  delay(500);
}

/**
 * calculate Temperature Value
 * return temperature -40 ~ +125 ℃
 */
float getTemperature(){
  // read the value
  int val = analogRead(GROVE_L1);
  float R = 1023.0/val-1.0;
  R = R0*R;
  float temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature
  return temperature;
}

Processing

The following program was created using Processing.
Receive data from Arduino via serial communication.
Display received data as a line graph.

import processing.serial.*;
import java.util.ArrayList;

// checkPort Flag
boolean isCheckPort = false;
int portNumber = 0;
// SerialClass object
Serial port;

ArrayList thermoValueArray = null;

// setupDisplay
void setup() {
  thermoValueArray = new ArrayList();
  size(800, 600);
  frameRate(2); // reflesh per 500ms
  String[] ports = Serial.list();
  if(isCheckPort){
    for(int i = 0; i < ports.length; i++){
      println(i + ": " + ports[i]);
    }
  }else{
    // port
    port = new Serial(this, ports[portNumber], 19200);
  }
}

void draw() {
  drawInit();
  if(thermoValueArray.size() > 1){
    for(int i = 1; i < thermoValueArray.size() && i < 60; i++){
      line((i-1) * 10 + 100, 590 - (float)thermoValueArray.get(i-1) * 10, i * 10 + 100, 590 - (float)thermoValueArray.get(i) * 10);
    }
  }
}

// Initialize Display
void drawInit(){
  clear();
  background(255);
  // startLine
  line(100,10,100,590);
  // endLine
  line(700,10,700,590);
  // bottomLine
  line(100,590,700,590);
  // Vertical unit (°C)
  textSize(16);
  fill(0, 102, 153, 204);
  text("(°C)",30,20);
  //Vertical scale (temperature)
  for(int i = 0; i < 51; i++){
    if(i % 10 == 0){
      line(85,590 - (i * 10), 100, 590 - (i * 10));
      textSize(16);
      fill(0, 102, 153, 204);
      text(i,60,590 - (i * 10));
    }else if( i % 5 == 0){
      line(90,590 - (i * 10), 100, 590 - (i * 10));
    }else{
      line(95,590 - (i * 10), 100, 590 - (i * 10));
    }
  }
}


// serialEvent
void serialEvent(Serial port){
  if(port.available() >= 3){
    byte[] vals = port.readBytes(3);
    println(vals[0]);
    println(vals[1]);
    float val = (vals[0] << 8) + (vals[1] & 0Xff);
    println(val/100); 
    if(vals[2] == '\n'){
      thermoValueArray.add(0,val/100);
    }
  }
}

Result

I touched it with my finger to raise the temperature.
A chilled stone cube was used to lower the temperature.

  • icestone

Implessions

I wanted to try a lot, but the right side connector on the circuit was broken.
Data could be acquired by using the left side connector.
I spent a lot of time finding out that it was broken.

Files