2010年11月30日火曜日

For Patrick, check this sample program for your purpose

//sample progrma with shiftresiostors and photosensors
// this program is very basic. you can use one photosensor and upto two shiftresistor so that you can control upto 16 LED with only 3 digital pins of Arduino

//connect photosensor to analog pin 0
int analogData0;


//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;

//regure variables
int RadomVal0;


void setup(){
//Start Serial for debuging purposes
Serial.begin(9600);
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
}

void loop(){
//read data from analog pin 0
analogData0=analogRead(0);
//scale down the value form 0-1023 to 0-255 which works with shift resistor.
analogData0=analogData0/4;
//put a randomize value into variable RadomVal0 this value take form "0" to "the scaled value" so that the new value still reflect the photosensor's value
// this code is optional
RadomVal0 = random(0,analogData0);
// tell shiftresistor to start
digitalWrite(latchPin, 0);
// actual data
shiftOut(dataPin, clockPin,MSBFIRST, RadomVal0);
//if you have second shift resistor. elase // and activate the program
//shiftOut(dataPin, clockPin,MSBFIRST, RadomVal0);
//tell shiftresistor to edn
digitalWrite(latchPin, 1);

// duration of the led light
delay(1000);
}

/*

the following program is optional.
if you want to use the following program replace "void loop" to the following program

void loop(){
//read data from analog pin 0
analogData0=analogRead(0);
//scale down the value form 0-1023 to 0-255 which works with shift resistor.
analogData0=analogData0/4;
// tell shiftresistor to start
//this will enable to light up LED more interestingly
for (int j = 0; j < analogData0; j++) {
digitalWrite(latchPin, 0);
// actual data
shiftOut(dataPin, clockPin,MSBFIRST, RadomVal0);
//if you have second shift resistor. elase // and activate the program
//shiftOut(dataPin, clockPin,MSBFIRST, RadomVal0);
//tell shiftresistor to edn
digitalWrite(latchPin, 1);

// duration of the led light for each led pattern
delay(300);
}
}

*/

2010年11月24日水曜日

high volate control

http://itp.nyu.edu/physcomp/Tutorials/HighCurrentLoads

2010年11月20日土曜日

Arduino Daisy Chain 03


I finally fined a way of daisy chain Arduino.


Prepare two Arduino

Connect USB cable to one of Arduino

Put one side of a wire to 5V of the Arduino that USB is connected to.

The other side of the wire go to vin of the other Arduino.

Connect Tx to Rx of the other Arduino.

Connect Rx to TX of the other Arduino.



2010年8月17日火曜日

Card

Technical detail of my artwork


Arduino 1

/*
Name of Arduino COM4
Program for Art Work
Version 1.4
Huge 7 segment controller with Shift registor.
Made by Shotaro N 2010

note:
Somehow,you need Serial.print(); in a function of block();.
It does not do anything, but without having it, the program does not work properly.
Ver 1.1 added relay control and LEDcontrol
Ver 1.2 fixed a relay proglem
Ver 1.3 added a daisy chain pulse controller
Ver 1.4 change daisy chain controller from transistor to relay
*/

//reguler variable to store data
int c;
int rec1, rec2, rec3, rec4;
// error checking counter
int checkND=0;
//controller variables
long vTime=45000;
int amount7S =4;
//Shift Registor
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
int latchPin2 = 2;
int clockPin2 = 4;
int dataPin2 = 3;
int ledPin =13;
int relayPin =6;
int daisyChainPin = 7;

void setup()
{
Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(latchPin2, OUTPUT);
pinMode(clockPin2, OUTPUT);
pinMode(dataPin2, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(relayPin, OUTPUT);
pinMode(daisyChainPin, OUTPUT);
digitalWrite(daisyChainPin, LOW);
delay(10);
digitalWrite(relayPin, LOW);
delay(10);
}

void loop(){
digitalWrite(relayPin, HIGH);
delay(10);
if(Serial.available()>0){
//reading validity of words
block1();
block2();
block3();
block4();
Serial.println("");
Serial.print("CheckND value");
Serial.println(checkND);
//to ignore words with EXtra
EXchecker();
Serial.print("CheckND value");
Serial.println(checkND);
//main checking process
if (checkND ==amount7S){
Serial.println("start light LEDs section");
digitalWrite(relayPin, LOW);
digitalWrite(daisyChainPin, HIGH);
delay(1);
Serial.print("Sending a pulse to the second Arduino");
Serial.print(".");
Serial.print(".");
Serial.println(".");
digitalWrite(ledPin, HIGH);
//main LED
digitalWrite(latchPin, LOW);
c = rec4;
process();
c = rec3;
process();
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin2, LOW);
c = rec2;
processSEC();
c = rec1;
processSEC();
digitalWrite(latchPin2, HIGH);
delay(vTime);
checkND = 0;
reset();
digitalWrite(ledPin, LOW);
digitalWrite(daisyChainPin, LOW);
digitalWrite(relayPin, HIGH);
delay(1);
}
//checkND = 0;
//reset();
}//main if end
//protection reset
checkND = 0;
reset();
}

//EDN OF VOID LOOP


//first block
void block1(){
rec1=Serial.read();
c = rec1;
Cprocess();//check prosecc
Serial.print("block1");
}
//second block
void block2(){
rec2=Serial.read();
c = rec2;
Cprocess();
Serial.print("block2");
}
//third block
void block3(){
rec3=Serial.read();
c = rec3;
Cprocess();
Serial.print("block3");
}
//Fourth block
void block4(){
rec4=Serial.read();
c = rec4;
Cprocess();
Serial.print("block4");
}

// checker
void Cprocess(){
if(c=='8'){
checkND = checkND + 1;
}
else if(c=='0'){
checkND = checkND + 1;
}
else if(c=='1'){
checkND = checkND + 1;
}
else if(c=='2'){
checkND = checkND + 1;
}
else if(c=='3'){
checkND = checkND + 1;
}
else if(c=='4'){
checkND = checkND + 1;
}
else if(c=='5'){
checkND = checkND + 1;
}
else if(c=='6'){
checkND = checkND + 1;
}
else if(c=='7'){
checkND = checkND + 1;
}
else if(c=='9'){
checkND = checkND + 1;
}
else{
}
}

//judgement & lighting
void process(){
if(c=='8'){
shiftOut(dataPin, clockPin, MSBFIRST, 254);
}
else if(c=='0'){
shiftOut(dataPin, clockPin, MSBFIRST, 250);
}
else if(c=='1'){
shiftOut(dataPin, clockPin, MSBFIRST, 96);
}
else if(c=='2'){
shiftOut(dataPin, clockPin, MSBFIRST, 220);
}
else if(c=='3'){
shiftOut(dataPin, clockPin, MSBFIRST, 244);
}
else if(c=='4'){
shiftOut(dataPin, clockPin, MSBFIRST, 102);
}
else if(c=='5'){
shiftOut(dataPin, clockPin, MSBFIRST, 182);
}
else if(c=='6'){
shiftOut(dataPin, clockPin, MSBFIRST, 62);
}
else if(c=='7'){
shiftOut(dataPin, clockPin, MSBFIRST, 226);
}
else if(c=='9'){
shiftOut(dataPin, clockPin, MSBFIRST, 230);
}
}

//judgement & lighting
void processSEC(){
if(c=='8'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 254);
}
else if(c=='0'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 250);
}
else if(c=='1'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 96);
}
else if(c=='2'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 220);
}
else if(c=='3'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 244);
}
else if(c=='4'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 102);
}
else if(c=='5'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 182);
}
else if(c=='6'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 62);
}
else if(c=='7'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 226);
}
else if(c=='9'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 230);
}
}


// EXchecker. protect system from invalid value
void EXchecker(){
if(Serial.available()>0){
int reader = Serial.read();
if(reader == -1){
}
else{
checkND = checkND +10;// protect from hack
}
}
}


void reset(){
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0);
shiftOut(dataPin, clockPin, MSBFIRST, 0);
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin2, LOW);
shiftOut(dataPin2, clockPin2, MSBFIRST, 0);
shiftOut(dataPin2, clockPin2, MSBFIRST, 0);
digitalWrite(latchPin2, HIGH);
}




Arduino 2

  


/*
Program for second Arduino
Ver 1.3

Serial in Watcher "1" got data from daisy chain
Serial in Watcher "2" got data from ultrasonic range finder
Serial in Watcher "3" got data from motion sensor

Ver 1.0 basic
Ver 1.1 error correction about values
added while loop to fix communication Arduino and Isadora
Ver 1.2 fixed motion sensor value
Ver 1.3 fixed problem especially reset commend
Ver 1.4 take out motion sensor and reduce pressure to a computer
*/

//regular variable
//int alarmValue = 1;
int val=0;
int defaultLength=330; // max value of sonic range finder

//analog pins
//int alarmPin = 1;//motion sensor
int daisyChainPin = 0;
//digital pins
int ledPin = 13;
const int pingPin = 7;//Ultrasonic

//loop speed
int delayTime = 200;


void setup () {
Serial.begin (9600);
pinMode(ledPin, OUTPUT);
//pinMode(alarmPin, INPUT);
//delay (2000); //wait for a motion sensor to be ready to go
digitalWrite(ledPin, LOW);
}

void loop ()
{
val = analogRead(daisyChainPin);
if (val>100){

//turn on LED while the second arduino got pulse from the first arduino
digitalWrite(ledPin, HIGH);


val =1;//to activate Isadora
Serial.print(1,DEC);
Serial.print (val, DEC);
Serial.println();
val = analogRead(daisyChainPin);
while(val>100){
/*
for ultrasonic range finder. source from
http://www.arduino.cc/en/Tutorial/Ping

created 3 Nov 2008
by David A. Mellis
modified 30 Jun 2009
by Tom Igoe
*/

long duration, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
cm = microsecondsToCentimeters(duration);

//ignore crazy value

if(cm>330){
cm = 330;
}

//send this value to use for something

Serial.print(2,DEC);
Serial.print (cm, DEC);
Serial.println();


//motion sensor
//based on http://www.eathertons.com/blog/?p=73
//Shotaro fixed the code little bit
/*
alarmValue = analogRead(alarmPin);
if (alarmValue < 100){
alarmValue =1;
sendPulse();
}
else{
}
*/
delay(delayTime);

val = analogRead(daisyChainPin);//Value for While
}//While loop
digitalWrite(ledPin, LOW);
dataReset();
}
}
//END of void loop




//culculation from microsecond to length
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}



/*
//send a data from motion sensor to Isadora
//This value will control "counter" of Isadora
void sendPulse() {
Serial.print(3,DEC);
Serial.print (alarmValue, DEC);
Serial.println();
}
*/

void dataReset(){
Serial.print(1,DEC);
Serial.print (0, DEC);
Serial.println();
Serial.print(2,DEC);
Serial.print (defaultLength, DEC);
Serial.println();
//Serial.print(3,DEC);
//Serial.print (0, DEC);
//Serial.println();
}



Arduino 3



int alarmPin = 1;//motion sensor
int alarmValue = 1;
int delayTime = 200;


void setup(){
Serial.begin(9600);
pinMode(alarmPin, INPUT);
delay (2000); //wait for a motion sensor to be ready to go
}
void loop(){
alarmValue = analogRead(alarmPin);
if (alarmValue < 100){
//alarmValue =1;
sendPulse();
}
else{
}
delay(delayTime);
}

//send a data from motion sensor to Isadora
//This value will control "counter" of Isadora
void sendPulse() {
Serial.print(3,DEC);
Serial.print (alarmValue, DEC);
Serial.println();
}

2010年8月9日月曜日

program for the second Arduino(Isadora controller)

This program will light led when the second Arduino got a pulse from the first Arduino, and 

send data of sensors to Isadora

/*

Program for second Arduino
Ver 1.0 unchecked

Serial in Watcher "1" got data from daisy chain
Serial in Watcher "2" got data from ultrasonic range finder
Serial in Watcher "3" got data from motion sensor
*/

//regular variable
int alarmValue = 1;
int val=0;

//analog pins
int alarmPin = 1;
int daisyChainPin = 0;
//digital pins
int ledPin = 13;
const int pingPin = 7;


void setup () {
Serial.begin (9600);
pinMode(ledPin, OUTPUT);
pinMode(alarmPin, INPUT);
delay (2000); //wait for a motion sensor to be ready to go
digitalWrite(ledPin, LOW);
}

void loop ()
{
val = analogRead(daisyChainPin);
if (val>100){

//turn on LED while the second arduino got pulse from the first arduino
digitalWrite(ledPin, HIGH);


val =1;//to activate Isadora
Serial.print(1,DEC);
Serial.print (val, DEC);
Serial.println();

/*
for ultrasonic range finder. source from
http://www.arduino.cc/en/Tutorial/Ping

created 3 Nov 2008
by David A. Mellis
modified 30 Jun 2009
by Tom Igoe
*/
long duration, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
cm = microsecondsToCentimeters(duration);
//send this value to use for something
Serial.print(2,DEC);
Serial.print (cm, DEC);
Serial.println();

//motion sensor
//based on http://www.eathertons.com/blog/?p=73
//Shotaro fixed the code little bit

alarmValue = analogRead(alarmPin);
if (alarmValue < 100)
{
alarmValue =1;
sendPulse();
}
delay(100);
digitalWrite(ledPin, LOW);
}
}
//END of void loop




//culculation from microsecond to length
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}




//send a data from motion sensor to Isadora
//This value will control "counter" of Isadora
void sendPulse() {
Serial.print(3,DEC);
Serial.print (alarmValue, DEC);
Serial.println();
}
}

motion sensor information

Since we have two different motion sensor this link will help to use the motion sensor which I did not make tutorial.

Check below link to see the first motion sensor tutorial.

http://art-research2010summer.blogspot.com/2010/06/sensor-motion-sensor.html


http://www.eathertons.com/blog/?p=73



The most different point of these two motion sensor is that the colors of the wire are different so that we need to change the connection of the wire and the motion sensor that is talked in the link require a resistor.


I think it is a good idea to reduce the delay  time in a program that was introduced in the link so that the motion sensor works more ideally.  Also I preferred to use a more higher resistor that the resistor that was used in a tutorial so that you can get more good data from the motion sensor. 

 

2010年8月8日日曜日

Isadora setup

Serial In watcher will control everything, so that Arduino can control everything.

Somehow Isadora's picture player does not work properly. Even I send a value 0 to turn off visibility, it does not work. Only wave generator can controll on and off.

 Also "Gate" does not work for picture player.

Arduino Daisy Chain 2


Program for Arduino Daisy Chain

This program is specifically designed to communicate with Isadora.

You can use this program as a switch in Isadora.



Program for a host Arduino

/*

this program is just send on and off signal to client Arduino every 2 second

*/

int signalPin=3;
void setup(){
pinMode(signalPin, OUTPUT);

digitalWrite(signalPin, LOW);
}
void loop(){
 
digitalWrite(signalPin, HIGH);
delay(2000);
digitalWrite(signalPin, LOW);
delay(2000);
}


Program for a Client

int ReadingPin = 0;
int val;
void setup(){
Serial.begin(9600);

}
void loop(){
val = analogRead(ReadingPin);

/*

with this "if" commend, Arduino does not send any data to Isadora when an analog pin receive nothing.

*/
  if (val>100){
  val=1;//you can change value to anything you want 
Serial.print(1,DEC);
Serial.print (val, DEC);
Serial.println();
delay(50);
}
}






Projector test











2010年8月6日金曜日

Program for LED controller Ver 1.0(Updated from Ver 0.11 and checked)

/*
Program for Art Work
Version 1.0
Huge 7 segment controller with Shift registor.
Made by Shotaro N 2010

note:
Somehow,you need Serial.print(); in a function of block();.
It does not do anything, but without having it, the program does not work properly.
*/

//reguler variable to store data
int c;
int rec1, rec2, rec3, rec4;
// error checking counter
int checkND=0;
//controller variables
int vTime=25000;
int amount7S =4;
//Shift Registor
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
int latchPin2 = 2;
int clockPin2 = 4;
int dataPin2 = 3;


void setup()
{
Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(latchPin2, OUTPUT);
pinMode(clockPin2, OUTPUT);
pinMode(dataPin2, OUTPUT);
}
void loop(){
if(Serial.available()>0){
//reading validity of words
block1();
block2();
block3();
block4();
Serial.print("this is first");
Serial.println(checkND);
//to ignore words with EXtra
EXchecker();
Serial.print("this is second");
Serial.println(checkND);
//main checking process
if (checkND ==amount7S){
Serial.println("start light LEDs");
//main LED
digitalWrite(latchPin, LOW);
c = rec4;
process();
c = rec3;
process();
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin2, LOW);
c = rec2;
processSEC();
c = rec1;
processSEC();
digitalWrite(latchPin2, HIGH);
delay(vTime);
checkND = 0;
reset();
}
//checkND = 0;
//reset();
}//main if end
//protection reset
checkND = 0;
reset();
}

//EDN OF VOID LOOP


//first block
void block1(){
rec1=Serial.read();
c = rec1;
Cprocess();//check prosecc
Serial.print("block1");
}
//second block
void block2(){
rec2=Serial.read();
c = rec2;
Cprocess();
Serial.print("block2");
}
//third block
void block3(){
rec3=Serial.read();
c = rec3;
Cprocess();
Serial.print("block3");
}
//Fourth block
void block4(){
rec4=Serial.read();
c = rec4;
Cprocess();
Serial.print("block4");
}

// checker
void Cprocess(){
if(c=='8'){
checkND = checkND + 1;
}
else if(c=='0'){
checkND = checkND + 1;
}
else if(c=='1'){
checkND = checkND + 1;
}
else if(c=='2'){
checkND = checkND + 1;
}
else if(c=='3'){
checkND = checkND + 1;
}
else if(c=='4'){
checkND = checkND + 1;
}
else if(c=='5'){
checkND = checkND + 1;
}
else if(c=='6'){
checkND = checkND + 1;
}
else if(c=='7'){
checkND = checkND + 1;
}
else if(c=='9'){
checkND = checkND + 1;
}
else{
}
}

//judgement & lighting
void process(){
if(c=='8'){
shiftOut(dataPin, clockPin, MSBFIRST, 254);
}
else if(c=='0'){
shiftOut(dataPin, clockPin, MSBFIRST, 250);
}
else if(c=='1'){
shiftOut(dataPin, clockPin, MSBFIRST, 96);
}
else if(c=='2'){
shiftOut(dataPin, clockPin, MSBFIRST, 220);
}
else if(c=='3'){
shiftOut(dataPin, clockPin, MSBFIRST, 244);
}
else if(c=='4'){
shiftOut(dataPin, clockPin, MSBFIRST, 102);
}
else if(c=='5'){
shiftOut(dataPin, clockPin, MSBFIRST, 182);
}
else if(c=='6'){
shiftOut(dataPin, clockPin, MSBFIRST, 62);
}
else if(c=='7'){
shiftOut(dataPin, clockPin, MSBFIRST, 226);
}
else if(c=='9'){
shiftOut(dataPin, clockPin, MSBFIRST, 230);
}
}
//judgement & lighting
void processSEC(){
if(c=='8'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 254);
}
else if(c=='0'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 250);
}
else if(c=='1'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 96);
}
else if(c=='2'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 220);
}
else if(c=='3'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 244);
}
else if(c=='4'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 102);
}
else if(c=='5'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 182);
}
else if(c=='6'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 62);
}
else if(c=='7'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 226);
}
else if(c=='9'){
shiftOut(dataPin2, clockPin2, MSBFIRST, 230);
}
}


// EXchecker. protect system from invalid value
void EXchecker(){
if(Serial.available()>0){
int reader = Serial.read();
if(reader == -1){
}
else{
checkND = checkND +10;// protect from hack
}
}
}


void reset(){
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0);
shiftOut(dataPin, clockPin, MSBFIRST, 0);
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin2, LOW);
shiftOut(dataPin2, clockPin2, MSBFIRST, 0);
shiftOut(dataPin2, clockPin2, MSBFIRST, 0);
digitalWrite(latchPin2, HIGH);
}

fixed a troble of a LEDs controller




LED controller is made by 4 8-bit shift resistors, 28 transistors and 28 resistors.





2010年8月2日月曜日

2010年7月19日月曜日

2010年7月13日火曜日

Making my artwork



Circuit for my art work (almost finished)

TouchOSC


Emily and I worked with TouchOSC.

Program for my artwork Ver 0.1 (unckecked)

/*
Program for Art Work
Version 0.1
Huge 7 segment controller with Shift registor.
Made by Shotaro N 2010
*/

//reguler variable
int c;
int rec1, rec2, rec3, rec4;
// error checker
int checkND=0;
//controller variables
int vTime=500;
int amount7S =4;
//Shift Registor
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;


void setup()
{
Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop(){
if(Serial.available()>0){
//reading validity of words
block1();
block2();
block3();
block4();
//to ignore words with EXtra
EXchecker();
//main checking process
if (checkND ==amount7S){
//main LED
digitalWrite(latchPin, LOW);
c = rec1;
process();
c = rec2;
process();
c = rec3;
process();
c = rec4;
process();
digitalWrite(latchPin, HIGH);
delay(vTime);
}
}//main if end
//protection reset
checkND = 0;
}

//EDN OF VOID LOOP


//first block
void block1(){
rec1=Serial.read();
c = rec1;
Cprocess();//check prosecc
}
//second block
void block2(){
rec2=Serial.read();
c = rec2;
Cprocess();
}
//third block
void block3(){
rec3=Serial.read();
c = rec3;
Cprocess();
}
//Fourth block
void block4(){
rec4=Serial.read();
c = rec4;
Cprocess();
}

// checker
void Cprocess(){
if(c=='8'){
checkND = checkND + 1;
}
else if(c=='0'){
checkND = checkND + 1;
}
else if(c=='1'){
checkND = checkND + 1;
}
else if(c=='2'){
checkND = checkND + 1;
}
else if(c=='3'){
checkND = checkND + 1;
}
else if(c=='4'){
checkND = checkND + 1;
}
else if(c=='5'){
checkND = checkND + 1;
}
else if(c=='6'){
checkND = checkND + 1;
}
else if(c=='7'){
checkND = checkND + 1;
}
else if(c=='9'){
checkND = checkND + 1;
}
else{
}
}

//judgement & lighting
void process(){
if(c=='8'){
shiftOut(dataPin, clockPin, MSBFIRST, 254);
}
else if(c=='0'){
shiftOut(dataPin, clockPin, MSBFIRST, 250);
}
else if(c=='1'){
shiftOut(dataPin, clockPin, MSBFIRST, 96);
}
else if(c=='2'){
shiftOut(dataPin, clockPin, MSBFIRST, 220);
}
else if(c=='3'){
shiftOut(dataPin, clockPin, MSBFIRST, 244);
}
else if(c=='4'){
shiftOut(dataPin, clockPin, MSBFIRST, 104);
}
else if(c=='5'){
shiftOut(dataPin, clockPin, MSBFIRST, 182);
}
else if(c=='6'){
shiftOut(dataPin, clockPin, MSBFIRST, 62);
}
else if(c=='7'){
shiftOut(dataPin, clockPin, MSBFIRST, 226);
}
else if(c=='9'){
shiftOut(dataPin, clockPin, MSBFIRST, 230);
}
}

// EXchecker. protect system from invalid value
void EXchecker(){
if(Serial.available()>0){
int reader = Serial.read();
if(reader == -1){
}
else{
checkND = checkND +10;// protect from hack
}
}
}

2010年7月9日金曜日

circuit for my art work. (progress)


Transistors  + Resistors + Shift Resistors 

2010年7月8日木曜日

Shorten program for 7 segment without Shift resister (unchecked program)

I made it for my practice of programing


int c;
int REC[]={0,0,0};
int checkND=0;
int newL[]={0,0,0};
int L=10;
int refleshT=1;
int vTime=500;
int amount7S =3;

void setup()
{
Serial.begin(9600);
for (int i=2; i<10; ++i){
pinMode(i,OUTPUT);
}
for (int i=10; i<13; ++i){
pinMode(i,INPUT);
}
for (int i=10; i<13; ++i){
digitalWrite(i,HIGH);
digitalWrite(i,LOW);
}
}

void loop()
{
if(Serial.available()>0){
BLOCK();
EXchecker();
if (checkND ==amount7S){
for(int FT=0; FT < vTime; ++FT){
for(int i=0; i<=3; i++){
L = newL[i]+10;
c = REC[i];
process();
}
}
}
nothing();
}
checkND = 0;
}

void zero(){
nothing();
digitalWrite(2,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
compress();
delay(refleshT);
}
void one(){
nothing();
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
delay(refleshT);
}
void two(){
nothing();
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
delay(refleshT);
}
void three(){
nothing();
digitalWrite(3,HIGH);
digitalWrite(5,HIGH);
compress();
delay(refleshT);
}
void four(){
nothing();
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
delay(refleshT);
}
void five(){
nothing();
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(5,HIGH);
digitalWrite(7,HIGH);
digitalWrite(9,HIGH);
delay(refleshT);
}
void six(){
nothing();
for(int i=2; i<=5; i++){
digitalWrite(i,HIGH);
}
digitalWrite(7,HIGH);
delay(refleshT);
}
void seven(){
nothing();
digitalWrite(2,HIGH);
compress();
delay(refleshT);
}
void eight(){
nothing();
for(int i=2; i<=5; i++){
digitalWrite(i,HIGH);
}
compress();
delay(refleshT);
}
void nine(){
nothing();
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
compress();
delay(refleshT);
}
void compress(){
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
}
void nothing(){
reset();
for(int i=2; i<=9; i++){
digitalWrite(i,LOW);
}
delay(refleshT);
}

void reset(){
for (int e=10; e<13; ++e){
pinMode(e,INPUT);
}
}

void process(){
if(c=='8'){
pinMode(L,OUTPUT);
eight();
}
else if(c=='0'){
pinMode(L,OUTPUT);
zero();
}
else if(c=='1'){
pinMode(L,OUTPUT);
one();
}
else if(c=='2'){
pinMode(L,OUTPUT);
two();
}
else if(c=='3'){
pinMode(L,OUTPUT);
three();
}
else if(c=='4'){
pinMode(L,OUTPUT);
four();
}
else if(c=='5'){
pinMode(L,OUTPUT);
five();
}
else if(c=='6'){
pinMode(L,OUTPUT);
six();
}
else if(c=='7'){
pinMode(L,OUTPUT);
seven();
}
else if(c=='9'){
pinMode(L,OUTPUT);
nine();
}
else{
nothing();
return;
}
}

void BLOCK(){
for (int i=0; i<=2; i++){
REC[i]=Serial.read();
c = REC[i];
Cprocess();
newL[i]=i;
}
}

void EXchecker(){
if(Serial.available()>0){
int reader = Serial.read();
if(reader == -1){
}
else{
checkND = checkND +10;
}
}
}

void Cprocess(){
if(0<=c<=9){
checkND = checkND + 1;
}

else{
nothing();
return;
}
}
 

Practice Processing

With a book "programming interactivity".



Drawing




loading image into a processing









Prototype of a circuit for my work


LEDs are connected in parallel and each one is controlled by NPN transistor and transistors are controlled by 8bit Shift resistor.

 I can use external power supply for LEDs.


plan of  technical details of art work's circuit.


click the picture to see more high resolution picture.





2010年7月7日水曜日

Transistor switch

Requirement

NPN Transistor( I used 2N3904 bought from Radio Shock )

LEDs

Arduino

Arduino program

wires

1k Ohm resistor

220 Ohm resistor

Computer


Circuit




Program

You can use sample program "Blink"

You just need to change 

int = 13;

to

int = 2;









2010年7月5日月曜日

Today's work


I made a several new drawings.

Arduino daisy-chain


I tried to connect Arduino to Arduino.

I connected pwm pin of Arduino(1) to analogPin of Arduino(2) to get a variety of values.

But I could get only on and off.  It was not useful, since it is potentially break Arduino.

Shift resister is more useful to increase the number of pins more than daisy-chain.


2010年7月4日日曜日

7 segment with Shift Resistors

I did a test of controlling 7 segment with Shift resistor 8-Bit - 74HC595.

I finally control two 7 segment with two Shift resistor 8-Bit - 74HC595.


Tutorial

Shift resistor 8-Bit - 74HC595 is very useful since Arduino have only 13 digital pins we may need more pins to make a more complex controller.

7 segment is one of a example that need a lot of pins to control.

So that I will explain Shift resistor 8-Bit - 74HC595 with two 7 segment.



Requirement

Shift Resistor 8-Bit - 74HC595

Two 7 segment

A lot of wires

14 220Ohm resistors

Breadboards(At least you need one large  Breadboard) I use one  Breadboard and two small  Breadboard.

Arduino

Arduino program

computer with USB

Calculator (you need to change decimal to binary)

Circuit

latchPin is 8.

clockPin is 12.

dataPin is 11.



When you send a value with ShiftOut, the value which transformed into
a binary data will conrespond to the red pin(Q0 ~ Q7).
Since this is a 8 bit shift resistor, the range of the value will be 0~255.
(2x2x2x2x2x2x2x2)
For example, if you send a value 96, it will transformed to 011000000.
Since number 0 means off and number 1 means on, in this case Q6 and Q5
will be HIGH.






Program


//Original program is http://arduino.cc/en/Tutorial/ShftOut11


//**************************************************************//
// Name : shiftOutCode, Hello World
// Author : Carlyn Maw,Tom Igoe, David A. Mellis
// Date : 25 Oct, 2006
// Modified: 23 Mar 2010
// Version : 2.0
// Notes : Code for using a 74HC595 Shift Register //
// : to count from 0 to 255
//****************************************************************


//I modified slightly


//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;

void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

void loop() {
//count up routine

//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, LOW);

//You can change the value.

// If you use the same circuit

// TO DISPLAY   1 is 96, 2 is 220, 3 is 244, 4 is 104, 5 is 182, 6 is 62, 7 is 226, 8 is 254, 9 is 230, 0 is  250.
shiftOut(dataPin, clockPin, MSBFIRST, 254);
   

// second shift resister

//Same as the hear
shiftOut(dataPin, clockPin, MSBFIRST, 226);


//return the latch pin high to signal chip that it
//no longer needs to listen for information

digitalWrite(latchPin, HIGH);
delay(1000);

}






Great information about Shift register

http://www.arduino.cc/en/Tutorial/ShiftOut

http://arduino.cc/en/Reference/ShiftOut

http://arduino.cc/en/Reference/Bitshift


This is a really great tutorial for beginner and and very useful. 

2010年7月3日土曜日

Practical Tutorial of How to make Aii (Arduino + Wii Nunchuk) and use it

This is a tutorial of How to make Aii(Arduino and Wii Nunchak).

This exercise enables you to connect Wii Nunchuk to Arduino.

You will also learn how to connect Aii to Isadora and how to send a OSC data over the Internet(Wi-Fi).

Wii Nunchuk is a great tool for us. It has 7 different input device(two button, two potentiometer like function and one XYZ accelerometer)

Having an Accelerometer is really great, because the cost  of accelerometer is from 19.95 to $39.95.(SparkFun.com) However, if you order Wii Nunchuk from Amazon.com, it costs only from $3.25 to $19.95. 

I connect Nintendo Will Nunchuk to Arduino and made Aii.

The program was based on the information of http://www.windmeadow.com/node/42

I added little more cords so that it works with Isadora.

To make a circuit, I referred http://todbot.com/blog/2007/10/25/boarduino-wii-nunchuck-servo/

For the information of OSC transmission with Isadora, I referred http://vjskulpture.wordpress.com/2010/01/14/basic-open-sound-control-osc-isadora-mac/

Requirement

Arduino

Arduino program

Isadora

Wii Nunchuk

Wires(you may need alligator clips and soldering iron)

Two computer that is connected to a same router.

Red LED



Circuit









Program

You can use a program from http://www.windmeadow.com/node/42

But you have to change the function of void print() in the program to following.

void
print ()
{
int joy_x_axis = outbuf[0];
int joy_y_axis = outbuf[1];
int accel_x_axis = outbuf[2] * 2 * 2;
int accel_y_axis = outbuf[3] * 2 * 2;
int accel_z_axis = outbuf[4] * 2 * 2;

int z_button = 0;
int c_button = 0;

// byte outbuf[5] contains bits for z and c buttons
// it also contains the least significant bits for the accelerometer data
// so we have to check each bit of byte outbuf[5]
if ((outbuf[5] >> 0) & 1)
{
z_button = 1;
}
if ((outbuf[5] >> 1) & 1)
{
c_button = 1;
}

if ((outbuf[5] >> 2) & 1)
{
accel_x_axis += 2;
}
if ((outbuf[5] >> 3) & 1)
{
accel_x_axis += 1;
}

if ((outbuf[5] >> 4) & 1)
{
accel_y_axis += 2;
}
if ((outbuf[5] >> 5) & 1)
{
accel_y_axis += 1;
}

if ((outbuf[5] >> 6) & 1)
{
accel_z_axis += 2;
}
if ((outbuf[5] >> 7) & 1)
{
accel_z_axis += 1;
}

// This is a section that is actually modified.

Serial.print(1,DEC);
Serial.print (joy_x_axis, DEC);
Serial.println();

Serial.print(2,DEC);
Serial.print (joy_y_axis, DEC);
Serial.println();

Serial.print(3,DEC);
Serial.print (accel_x_axis, DEC);
Serial.println();

Serial.print(4,DEC);
Serial.print (accel_y_axis, DEC);
Serial.println();

Serial.print(5,DEC);
Serial.print (accel_z_axis, DEC);
Serial.println();

Serial.print(6,DEC);
Serial.print (z_button, DEC);
Serial.println();

Serial.print(7,DEC);
Serial.print (c_button, DEC);
Serial.println();

Serial.print ("\r\n");
}

// Encode data to format that most wiimote drivers except
// only needed if you use one of the regular wiimote drivers
char
nunchuk_decode_byte (char x)
{
x = (x ^ 0x17) + 0x17;
return x;
}


For more information check my tutorial of Isadora + Arduino

http://art-research2010summer.blogspot.com/2010/06/tutorial-01-isadora-and-arduino.html


Isadora

You do not do something special for Isadora but you have to make a lot of "Serial in Watcher".

Check below again to know how to do it.

http://art-research2010summer.blogspot.com/2010/06/tutorial-01-isadora-and-arduino.html

You need 7 "Serial in Watcher" to get all of the benefit of Wii Nunchuk

All of the "Serial in Watcher" need ideal number to identify each other.

Program for Isadora's Serial in Watcher(double click and open a window)

Serial in Watcher 1

"1"

StickA: integer = 4 digits

Serial in Watcher 2

"2"

StickB:integer = 4 digits

Serial in Watcher 3

"3"

Acc1: integer = 4 digits

Serial in Watcher 4

"4"

Acc2: integer = 4 digits

Serial in Watcher 5

"5"

Acc3: integer = 4 digits

Serial in Watcher 6

"6"

ButA:interger= 4 digits

Serial in Watcher 7

"7"

ButB: integer = 4 digits


Go to the OUTPUT and Setup Serial (choose Serial such as COM4 Speed 9600) and check Enable Serial 





You can play around with Aii to see how these value will change.


Make "OSC transmit"

Setup IP address of the computer that you want to control and connect the value of the "OSC transmit" to the "Serial in Watcher" which you like.


Setup your another computer

If you do not know how to check your IP address, see my blog post about Arduino Server (below address).

http://art-research2010summer.blogspot.com/2010/06/arduino-ethernet-shield.html

Run Isadora in your another computer(in my case it is a Laptop).

Make a OSC listener, that it!.

You will get a value and you can use this value for anything that you want to use.

I use "Calculator" to adjust a value and connect it to "Dot" size.





You DONE