Show Posts
Pages: [1]
1  Using Arduino / Interfacing w/ Software on the Computer / Control multiple FDD drives via PD on: May 22, 2012, 11:53:25 am
I can fully control single FDD. When send "20" by object "comport" from the PD then run a line of code:
Code:
if (incomingByte == 20) vibe (40, 4291);
and so on

My problem is that I connected two FDD and I would like to have played two different sounds simultaneously that is run two commands at once. Unfortunately, it works like this:

  • 20 launches drive A
  • 30 launches both drives, despite the fact that should work only drive B
  • 20 and 30 simultaneously - launches first drive A and B after a long delay


I Make a mistake somewhere, but I do not understand where.

Arduino code:

Code:
/*
SETTINGS
 */

#define StepA 2
#define DirA 3
#define SelA 4
#define StepB 5
#define DirB 6
#define SelB 7

int incomingByte = 0;

/*
START
 */
 
void setup() {
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  pinMode(DirA, OUTPUT);
  pinMode(StepA, OUTPUT);
  pinMode(SelA, OUTPUT);
  digitalWrite(SelA, HIGH);
  pinMode(DirB, OUTPUT);
  pinMode(StepB, OUTPUT);
  pinMode(SelB, OUTPUT);
  digitalWrite(SelB, HIGH);
  initHead();  // move header half way
}

void initHead() {
  digitalWrite(StepA, HIGH);
  digitalWrite(DirA, HIGH);
  doSteps(80, 1911);  // move header to start position wherever it is, 80 steps at ~261 step/s
  digitalWrite(DirA, LOW);
  doSteps(40, 1911);

  digitalWrite(StepB, HIGH);
  digitalWrite(DirB, HIGH);
  doSteps(80, 1911);  // move header to start position wherever it is, 80 steps at ~261 step/s
  digitalWrite(DirB, LOW);
  doSteps(40, 1911);
}

void doSteps(int steps, int stepDelay) {
  digitalWrite(SelA, LOW);
  for(int i=0;i<steps; i++) {
    digitalWrite(StepA,LOW);
    delayMicroseconds(stepDelay);
    digitalWrite(StepA,HIGH);
    delayMicroseconds(stepDelay);
    digitalWrite(StepB,LOW);
    delayMicroseconds(stepDelay);
    digitalWrite(StepB,HIGH);
    delayMicroseconds(stepDelay);

  }
  digitalWrite(SelA, HIGH);
}

/*
VIBE VIBE VIBE
 */
 
void vibeA(int count, int period) {
  for(int l=0;l<count; l++) {
    digitalWrite(DirA, HIGH);
    doSteps(1, period);
    digitalWrite(DirA, LOW);
    doSteps(1, period);
  }
}

void vibeB(int count, int period) {
  for(int l=0;l<count; l++) {
    digitalWrite(DirB, HIGH);
    doSteps(1, period);
    digitalWrite(DirB, LOW);
    doSteps(1, period);
  }
}

/*
FIRST FDD
 */

void loop() {
  if (Serial.available()>0) {
    incomingByte=Serial.read();
  
  if (incomingByte == 20) vibeA(40, 4291);  //C
  if (incomingByte == 21) vibeA(40, 4050);
  if (incomingByte == 22) vibeA(40, 3823);
  if (incomingByte == 23) vibeA(40, 3609);

   /*
SECOND FDD
 */
    
  if (incomingByte == 30) vibeB(40, 4291); //C
  if (incomingByte == 31) vibeB(40, 4050);
  if (incomingByte == 32) vibeB(40, 3823);
  if (incomingByte == 33) vibeB(40, 3609);
  
  }
}
2  Using Arduino / Interfacing w/ Software on the Computer / Re: Floppy disc controlled by Pure Pata on: May 13, 2012, 07:20:45 pm
OK, two hours RTFM'ing (good reading during the trip by train), I wrote the code and it works as it should.
Thank you PaulS for your wise help, I learned a lot.

Here is the code. For some time I will post a video here  smiley

Code:
#define Dir 3
#define Step 6
#define Sel 4
int incomingByte = 0;

 
void setup() {
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  pinMode(Dir, OUTPUT);
  pinMode(Step, OUTPUT);
  pinMode(Sel, OUTPUT);
  digitalWrite(Sel, HIGH);
  initHead();  // move header half way
}

void initHead() {
  digitalWrite(Step, HIGH);
  digitalWrite(Dir, HIGH);
  doSteps(80, 1911);  // move header to start position wherever it is, 80 steps at ~261 step/s
  digitalWrite(Dir, LOW);
  doSteps(40, 1911);
  delay(1000);
}

void doSteps(int steps, int stepDelay) {
  digitalWrite(Sel, LOW);
  for(int i=0;i<steps; i++) {
    digitalWrite(Step,LOW);
    delayMicroseconds(stepDelay);
    digitalWrite(Step,HIGH);
    delayMicroseconds(stepDelay);

  }
  digitalWrite(Sel, HIGH);
}

void vibe(int count, int period) {
  for(int l=0;l<count; l++) {
    digitalWrite(Dir, HIGH);
    doSteps(1, period);
    digitalWrite(Dir, LOW);
    doSteps(1, period);
  }
}

void loop() {
  if (Serial.available()>0) {
    incomingByte=Serial.read();

   
 if (incomingByte == 1) vibe(30, 3823);
 if (incomingByte == 2) vibe(40, 1823);
 if (incomingByte == 3) vibe(43, 1223);
 if (incomingByte == 4) vibe(50, 823);
 if (incomingByte == 5) vibe(50, 423);

/*   
and so on..
   */
 
  }
 
  }



3  Using Arduino / Interfacing w/ Software on the Computer / Re: Floppy disc controlled by Pure Pata on: May 12, 2012, 10:24:44 am
The problem is that I don't know what message sends PD and how to combine it with Arduino code. I made a clumsy code based on two examples:

http://nf-interactive.blogspot.com/2011/02/pure-data-to-arduino.html
http://arduino.cc/forum/index.php/topic,74232.msg565254.html#msg565254
Code:
#define Dir 3
#define Step 6
#define Sel 4
int incomingByte = 0;
void setup() {
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  pinMode(Dir, OUTPUT);
  pinMode(Step, OUTPUT);
  pinMode(Sel, OUTPUT);
  digitalWrite(Sel, HIGH);
  initHead();  // move header half way
}

void initHead() {
  digitalWrite(Step, HIGH);
  digitalWrite(Dir, HIGH);
  doSteps(80, 1911);  // move header to start position wherever it is, 80 steps at ~261 step/s
  digitalWrite(Dir, LOW);
  doSteps(40, 1911);
  delay(1000);
}

void doSteps(int steps, int stepDelay) {
  digitalWrite(Sel, LOW);
  for(int i=0;i<steps; i++) {
    digitalWrite(Step,LOW);
    delayMicroseconds(stepDelay);
    digitalWrite(Step,HIGH);
    delayMicroseconds(stepDelay);

  }
  digitalWrite(Sel, HIGH);
}

void vibe(int count, int period) {
  for(int l=0;l<count; l++) {
    digitalWrite(Dir, HIGH);
    doSteps(1, period);
    digitalWrite(Dir, LOW);
    doSteps(1, period);
  }
}

void loop() {
  if (Serial.available()>0) {
    incomingByte=Serial.read();
    analogWrite(Dir, incomingByte);
   
 if (incomingByte == 50);
   
 { vibe(30, 3823); }
 
  }
 
  }


At this point, it works in such way, that clicking anything in the PD runs what is written there. I'd like to send a single messages which will run for example:

some message: vibe (30, 3823);
another message: vibe (30, 6542);
yet another message: vibe (50, 4279);

and so on...
4  Using Arduino / Interfacing w/ Software on the Computer / Re: Floppy disc controlled by Pure Pata on: May 12, 2012, 07:22:11 am
ok, I will begin study "if" smiley
5  Using Arduino / Interfacing w/ Software on the Computer / Floppy disc controlled by Pure Pata on: May 12, 2012, 04:24:52 am
Hi all,
I am trying to build a floppy disk, controlled by Pure Data. I'm new to Arduino and quite experienced in Pure Data.

Based on code fragments found on this forum, I have created working code:

Code:
#define Dir 3
#define Step 6
#define Sel 4
int incomingByte = 0;
void setup() {
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  pinMode(Dir, OUTPUT);
  pinMode(Step, OUTPUT);
  pinMode(Sel, OUTPUT);
  digitalWrite(Sel, HIGH);
  initHead();  // move header half way
}

void initHead() {
  digitalWrite(Step, HIGH);
  digitalWrite(Dir, HIGH);
  doSteps(80, 1911);  // move header to start position wherever it is, 80 steps at ~261 step/s
  digitalWrite(Dir, LOW);
  doSteps(40, 1911);
  delay(1000);
}

void doSteps(int steps, int stepDelay) {
  digitalWrite(Sel, LOW);
  for(int i=0;i<steps; i++) {
    digitalWrite(Step,LOW);
    delayMicroseconds(stepDelay);
    digitalWrite(Step,HIGH);
    delayMicroseconds(stepDelay);

  }
  digitalWrite(Sel, HIGH);
}

void vibe(int count, int period) {
  for(int l=0;l<count; l++) {
    digitalWrite(Dir, HIGH);
    doSteps(1, period);
    digitalWrite(Dir, LOW);
    doSteps(1, period);
  }
}

void loop() {
  if (Serial.available()>0) {
    incomingByte=Serial.read();
    digitalWrite(Step, incomingByte);
   
   
   
  vibe(30, 3823); //D
  vibe(35, 3214);
  vibe(40, 2552);
 
  }
 
  }

By sending any number from PD, it runs a sequence of three sounds.

vibe (30, 3823);
vibe (35, 3214);
vibe (40, 2552);

(d minor, BTW)

I just need to find a way to send a specific number from PD to run a specific line of code, rather than all at once.

Thanks in advance for your help!
Pages: [1]