Saturday, March 19, 2011

Output Test (Blink)

Output test: 5x5 LED grid

Construction: Clusterf&*@. Alright, so I decided to not use the breadboard because the LEDs would be too close together and it's not really set up for grid structures. The way this works is that pins 3-7 will power the rows, and pins 8-12 will be connected to the columns. I got this idea from the instructable here http://www.instructables.com/id/Yet-Another-Daft-Punk-Coffee-TableDisplay/step3/Wire-it-up/ . If you go to the link, you can find the circuit diagram that I based my build on.
The most difficult part of my construction was that I was using solid core wire, so let's do some math... 5x5 grid=25 leds, 25 ledsx2 wires each=50 connections that I had to twist together by hand, and make sure they didn't touch any other connection and create a short circuit. How did I do it? Equal parts insanity and patience. My fingers really hurt right now, but I think it was worth it.

Coding: I basically took the coding from my 2x2 grid and extended it to work with 5x5.

Result:

Input tests (Blink)

Input test: accelerometer (model adxl335)

Wiring: use 3 short wires to connect X, Y, and Z to A0, A1, and A2 respectively.
use 2 more wires (measured to fit) to connect GND (accelerometer) to GND (arduino) and VCC to 3.3V.

Coding:
//Set pins
const int X_PIN = 0;
const int Y_PIN = 1;
const int Z_PIN = 2;
const int NUM_AXES= 3;
const int PINS[NUM_AXES]={X_PIN,Y_PIN,Z_PIN};
//Input comes really fast, so set a buffer for averaging values
const int BUFFER_SIZE=16;

int buffer[NUM_AXES][BUFFER_SIZE];
int buffer_pos[NUM_AXES]={0};

void setup()
{
Serial.begin(9600);
}

int get_axis(const int axis)
{
//Give arduino time to switch pins
delay(1);
//Read values into the buffer
buffer[axis][buffer_pos[axis]]=analogRead(PINS[axis]);
buffer_pos[axis]=(buffer_pos[axis]+1)%BUFFER_SIZE;
long sum=0;
//Average buffer values
for(int i=0;i
{
sum+=buffer[axis][i];
return round(sum/BUFFER_SIZE);
}

int get_x(){return get_axis(0);}
int get_y(){return get_axis(1);}
int get_z(){return get_axis(2);}

void loop()
{
//Print values
Serial.print("X: ");
Serial.print(get_x());
Serial.print("Y: ");
Serial.print(get_y());
Serial.print("Z: ");
Serial.println(get_z());
}


Tweaking:
Values from x and y axes are between ~8 and ~800 while z is between ~200-~750
Using these values, I need to set up a bit of code to detect when the unit is rotated along one of its axes within tolerances. The output should only read once after detecting this change.

Saturday, March 12, 2011

Arduino Stuff, attempt 1

Went to the electronic's store on goodman and bought a bunch of wire and LEDs so I could just start messing around. Installed the software and drivers and booted up the program, did the blink test which was pretty straightforward. I decided that I wanted to make an array of LEDs that could be lit and dimmed individually. To do this, I started out with the simplest, 2X2. I've got 2 wires from pins 6 and 7 (anode) to control the rows, and 2 from 8 and 9 (cathode) to control the columns. To make a light turn on, I just set the power to high on the row(anode) pins, and low on column(cathode) pins so that there is a flow of electricity. To turn a light off, either apply a low charge to the row pin, or if another light in that row should be on, apply a high charge to that column. If the row and column have the same value, there will be no electricity flow. Anyways, here's the code I've got working so far, I didn't get frames working yet but maybe next time.

/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.

This example code is in the public domain.
*/
#define DIM 2
#define DIM1 (DIM-1)
typedef byte Frame[DIM];
int cols[DIM]={8,9};
int rows[DIM]={6,7};
int pinVals[DIM][DIM];
boolean lit=false;
Frame blankFrame={B00,
B00};
//Frame fullFrame={B11,
// B11};
byte *currentFrame=blankFrame;
int curFrame=0;
Frame Frames[4]={
{B10,
B00},
{B01,
B00},
{B00,
B10},
{B00,
B01}};
void setFrame()
{
curFrame++;
if(curFrame>4)
curFrame=0;
currentFrame=Frames[curFrame];

}
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
int i;
for(i=0;i {
pinMode(cols[i],OUTPUT);
pinMode(rows[i],OUTPUT);
}
}

void loop() {
int c=HIGH;
int r=LOW;
if(lit)
{
c=LOW;
r=HIGH;
}
//Just tests connections, doesn't use frames
int i;
for (i=0;i < DIM;i++)
{
digitalWrite(rows[i],LOW);
for (int j=0;j < DIM;j++) {
digitalWrite(cols[j],HIGH);
delay(250);
digitalWrite(cols[j],LOW);
}
digitalWrite(rows[i],HIGH);
}
setFrame();
delay(400); // wait for a second
}