Friday, November 5, 2010

After hours of research......

I almost missed a super simple solution......  $9.00 worth of analog MUXs from digikey and were in buisness........ anyone who want reliable ic components quickly check out DIGIKEY.COM


analog multiplexer/demultiplexer------------------4051


A multiplexer or demultiplexer enables you to expand the in-and outputs on your Arduino board. The 4051 is an 8 channel analog multiplexer / demultiplexer, thus:
  • If you use the 4051 as a Multiplexer: You can choose between 8 different inputs and select just one you want to read at the time.
  • If you use the 4051 as a Demultiplexer you can choose between 8 different outputs and select just one you want to write at the time.
Futhermore, the 4051 is able to work with analog values; in the case of the Arduino, you are able to use the analog inputs with a voltage between 0-5V and route them to an Analog-In Pin on your Arduino.
To select the Pin we would like to read or write, we have to use the three Select Pins (S0, S1 and S2). Each of these pins have to be connected to one digital out pin on the Arduino. Every pin is representing a number (S0 = 1; S1 = 2; S2 = 4) and if we set one of these Select pins to HIGH, the number the pin is representing will be transmitted to the 4051. For example:
  • If S0 and S1 are HIGH and S2 is LOW pin y3 is selected (1+2+0 = 3).
  • If S0 and S2 is HIGH and S1 LOW pin y5 is selected (1+0+4 = 5).
It is not possible to read or write more than one pin on the 4051 at the same time, because you can only select one pin at a time. But you can read and write to the pins quite fast. There is no delay needed between selecting and read or writing the pin.
  • Z ----- common input/output (connected to Arduino Input/Output)
  • E ----- enable input (active LOW) (connected to ground (gnd))
  • Vee --- negative supply voltage (connected to ground (gnd))
  • gnd --- ground (0 V)
  • S0-S2 - select inputs (connected to three arduino digitalOut Pins)
  • y0-y7 - independent inputs/outputs
  • Vcc --- positive supply voltage (5v)
The left image above is an example how to use 9 multiplexer to read 64 analog Inputs just with one Analog-In-Pin on the arduino. The right image above is an example how to use two 4051 (one as demultiplexer and one as multiplexer) in a 8x8 Matrix to check 64 buttons or other digital Inputs just with one digital-In-Pin on the arduino (with the second setup you can just have two buttons on at the same time, otherwise you have to use the first (left) setup).
//////////////////////////////////////////////////////////////////////code example
  1. /*
  2.  * codeexample for useing a 4051 * analog multiplexer / demultiplexer
  3.  * by david c. and tomek n.* for k3 / malm� h�gskola
  4.  *
  5.  */  
  6.  
  7. int led = 13;    //just a led
  8. int r0 = 0;      //value select pin at the 4051 (s0)
  9. int r1 = 0;      //value select pin at the 4051 (s1)
  10. int r2 = 0;      //value select pin at the 4051 (s2)
  11. int row = 0;     // storeing the bin code
  12. int count = 0;    // just a count
  13. int  bin [] = {000, 1, 10, 11, 100, 101, 110, 111};//bin = bin�r, some times it is so easy
  14.  
  15. void setup(){
  16.  
  17.   pinMode(2, OUTPUT);    // s0
  18.   pinMode(3, OUTPUT);    // s1
  19.   pinMode(4, OUTPUT);    // s2
  20.  digitalWrite(led, HIGH);
  21.   beginSerial(9600);
  22. }
  23.  
  24. void loop () {
  25.  
  26.   for (count=0; count<=7; count++) {
  27.     row = bin[count];      
  28.     r0 = row & 0x01;
  29.     r1 = (row>>1) & 0x01;
  30.     r2 = (row>>2) & 0x01;
  31.     digitalWrite(2, r0);
  32.     digitalWrite(3, r1);
  33.     digitalWrite(4, r2);
  34.     //Serial.println(bin[count]);
  35.     delay (1000);
  36.   }  
  37. }

Inspirations----- this is exactly what i want to do YAY!!!




/*
 * Show messages on an 8x8 led matrix,
 * scrolling from right to left.
 *
 * Uses FrequencyTimer2 library to
 * constantly run an interrupt routine
 * at a specified frequency. This
 * refreshes the display without the
 * main loop having to do anything.
 *
 */


#include <FrequencyTimer2.h>

#define SPACE { \
    {0, 0, 0, 0, 0, 0, 0, 0},  \
    {0, 0, 0, 0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0, 0, 0, 0} \
}


#define H { \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 1, 1, 1, 1, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}  \
}


#define E  { \
    {0, 1, 1, 1, 1, 1, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 1, 1, 1, 1, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 1, 1, 1, 1, 1, 0}  \
}


#define L { \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 1, 1, 1, 1, 1, 0}  \
}


#define O { \
    {0, 0, 0, 1, 1, 0, 0, 0}, \
    {0, 0, 1, 0, 0, 1, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 0, 1, 0, 0, 1, 0, 0}, \
    {0, 0, 0, 1, 1, 0, 0, 0}  \
}


byte col = 0;
byte leds[8][8];

// pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
int pins[17]= {-1, 5, 4, 3, 2, 14, 15, 16, 17, 13, 12, 11, 10, 9, 8, 7, 6};

// col[xx] of leds = pin yy on led matrix
int cols[8] = {pins[13], pins[3], pins[4], pins[10], pins[06], pins[11], pins[15], pins[16]};

// row[xx] of leds = pin yy on led matrix
int rows[8] = {pins[9], pins[14], pins[8], pins[12], pins[1], pins[7], pins[2], pins[5]};

const int numPatterns = 6;
byte patterns[numPatterns][8][8] = {
  H,E,L,L,O,SPACE
};

int pattern = 0;

void setup() {
  // sets the pins as output
  for (int i = 1; i <= 16; i++) {
    pinMode(pins[i], OUTPUT);
  }

  // set up cols and rows
  for (int i = 1; i <= 8; i++) {
    digitalWrite(cols[i - 1], LOW);
  }

  for (int i = 1; i <= 8; i++) {
    digitalWrite(rows[i - 1], LOW);
  }

  clearLeds();

  // Turn off toggling of pin 11
  FrequencyTimer2::disable();
  // Set refresh rate (interrupt timeout period)
  FrequencyTimer2::setPeriod(2000);
  // Set interrupt routine to be called
  FrequencyTimer2::setOnOverflow(display);

  setPattern(pattern);
}

void loop() {
    pattern = ++pattern % numPatterns;
    slidePattern(pattern, 60);
}

void clearLeds() {
  // Clear display array
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      leds[i][j] = 0;
    }
  }
}

void setPattern(int pattern) {
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      leds[i][j] = patterns[pattern][i][j];
    }
  }
}

void slidePattern(int pattern, int del) {
  for (int l = 0; l < 8; l++) {
    for (int i = 0; i < 7; i++) {
      for (int j = 0; j < 8; j++) {
        leds[j][i] = leds[j][i+1];
      }
    }
    for (int j = 0; j < 8; j++) {
      leds[j][7] = patterns[pattern][j][0 + l];
    }
    delay(del);
  }
}

// Interrupt routine
void display() {
  digitalWrite(cols[col], LOW);  // Turn whole previous column off
  col++;
  if (col == 8) {
    col = 0;
  }
  for (int row = 0; row < 8; row++) {
    if (leds[col][7 - row] == 1) {
      digitalWrite(rows[row], LOW);  // Turn on this led
    }
    else {
      digitalWrite(rows[row], HIGH); // Turn off this led
    }
  }
  digitalWrite(cols[col], HIGH); // Turn whole column on at once (for equal lighting times)
}

Monday, November 1, 2010

project 2 - where our idea comes from

My group discussed several ideas.... We talked about current topics such as AIDS, oil consumption, Gay Rights, Poor Parenting skills of todays parents and even Politics.  After some discussion we decided to place all of our ideas in a hat and choose randomly.  Today's oil consumption won!! yay

Tuesday, October 19, 2010

Project 2

This is my group (minus me of course) for the second project along with our sketch of the idea for project 2.

We are trying to address energy awareness and dependence on the nonrenewable oil supply.

We are discussing the idea of routering out a relief map on a piece of MDF and adding interactive light sensors and led's that let the user see information.

Tuesday, October 5, 2010

Fun with the Arduino

Finally, we are getting to a subject that I almost feel confident about.  The C programming language is a common and very useful skill for engineers to know.  The arduino's use of "C" to operate means that I can help others..... so if you have any questions please don't hesitate to ask. 

This is my version of the blinking in response to the sensor circuit..... a buzzer was added to become a back up sensor.... lol