Week 11 - Input Devices

Contents

  1. What I want to make
  2. Making Satshakit
  3. Assembling and Programming
  4. Result

What I want to make

DIY 3D tracking Controller by Kyle McDonald based on measuring RC latency between your hand and aluminium foil.

Last year I modified the game and combined it with L3D cube so that I want to make another one on Satshakit.

You can follow my project here on GitHub

Making Satshakit

With Satshakit project, I was able to make a Arduino-like control board.

After milling, I started to solder Satshakit.

The art made by using suction tin

Burning bootloader with Arduino as ISP

Hot glue to protect

Assembling and Programming

All materials I need

Shielded cable which could avoid noise.

The red wire would connect to 5V to shield cable.

Using Arduino to communicate over serial port and upload codes

// By Kyle McDonald
// From the instructables project at:
// http://www.instructables.com/id/DIY-3D-Controller/

#define resolution 8
#define mains 50 // 60: north america, japan; 50: most other places
#define refresh 2 * 1000000 / mains

void setup() {
  Serial.begin(115200);

  // unused pins are fairly insignificant,
  // but pulled low to reduce unknown variables
  for(int i = 2; i < 14; i++) {
    pinMode(i, OUTPUT);
    digitalWrite(i, LOW);
  }

  // ----------------------
  // Modified by Kevin Cheng
  // On Satshakit, it does not have 5v output pin, so I use 7 pin to provide shielded voltage
  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);
  // ----------------------

  for(int i = 8; i < 11; i++)
    pinMode(i, INPUT);

  startTimer();
}

void loop() {
  Serial.print(time(8, B00000001), DEC);
  Serial.print(" ");
  Serial.print(time(9, B00000010), DEC);
  Serial.print(" ");
  Serial.println(time(10, B00000100), DEC);

} 

long time(int pin, byte mask) {
  unsigned long count = 0, total = 0;
  while(checkTimer() < refresh) {
    // pinMode is about 6 times slower than assigning
    // DDRB directly, but that pause is important
    pinMode(pin, OUTPUT);
    PORTB = 0;
    pinMode(pin, INPUT);
    while((PINB & mask) == 0)
      count++;
    total++;
  }
  startTimer();
  return (count << resolution) / total;
}

extern volatile unsigned long timer0_overflow_count;

void startTimer() {
  timer0_overflow_count = 0;
  TCNT0 = 0;
}

unsigned long checkTimer() {
  return ((timer0_overflow_count << 8) + TCNT0) << 2;
}

Result

In the video, you can see serial read pop out and the data changed when I move my hand. Cool!