two arduinos

i have read all the posts - i fhope - concerning connections between two boards and didn't find what i need. as kg4wsv said on the 05.12.2006 :

the FT232 is only powered from the USB connector, not from external power. Switch the PWR_SEL jumper to EXT, the hook 'em up to an external power source (and disconnect the USB cables), and it should work.

effectively when i use on both arduinos an external power source they can communicate alright (between pins which are not necessarily tx /rx). unfortunately, i need the usb connection to pass serially some data to the pc and then it doesn't work. is there a way around?


you can only use the serial for one purpose.. to talk to the USB chip, or to talk to something else. It can't talk to two different devices simultaneously. One option would be to use software serial to talk between the two Arudinos.

Out of curiosity, why do you need two Arduinos?


i wanted board #1 to drive an ultrasonic transmitter and board #2 to measure the time-of-flight to the ultrasonic receivers. but i think now it would be much better if the same board do both! thanks for your help.

Funny. I was just watching the phase measurements for my ultrasonic time of flight measurement system on an Arduino when I read this post. I'm working on a sonic anemometer.

In case it helps.. with my piezo elements I gave up on detecting the front of a pulse stream. It takes the receiver a few cycles to ramp up to a detectable voltage swing which leads to an ambiguity in the time. I am currently operating by taking two measurements at slightly different frequencies and comparing the phase differences. From there and knowing the approximate time of flight I can work out the actual time quite accurately. The phase detection was too noisy in software so I have stolen timer 1 from the PWM code and am using it to generate the transmitting signal and detect the receiver phase with its input capture register. With a little prodding that timer can me made to swing arduino pins 9 and 10 in opposite directions which is nice for driving the piezo. Arduino digital pin 8 is the trigger to the input capture register.

Now I'm deciding if I go down the multiple AVR route. I either build glue to multiplex the 3 piezos to the input logic and output logic (while still keeping enough pins for my other required functions, it will be tight, always need more pins), or dedicate an AVR to each transducer and put them on some sort of serial bus and a central clock distribution to keep clock drift out of my calculations.

int piezoPlus = 9;
int piezoMinus = 10;
int piezoIn = 8;

int period = 400;   // clock cycles. 16MHz clock, 400 cycles is 40kHz

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

void setup()
  digitalWrite(piezoPlus, 0);  
  pinMode(piezoPlus, OUTPUT);
  digitalWrite(piezoMinus, 0);  
  pinMode(piezoMinus, OUTPUT);
  pinMode(piezoIn, INPUT);

  // Set timer 1 stuff
  // Timer 1 is free running, the OCR1A and OCR1B are set to toggle out of phase to better drive the piezo./
  // ICR1 is used to capture the phase of the received signal.
  TCCR1B = 0;  /* stop timer, and mess up a bunch of stuff we fix later */
  TCCR1A = 0;  /* force a non-PWM mode for the output forcig */
  TCCR1A = (_BV(COM1A1) /* clear a */ | _BV(COM1B1) | _BV(COM1B0) /* set b */ | _BV(FOC1A) | _BV(FOC1B) /* set outputs */);
  // I'm not clear why I have to repeat this, but I do.
  TCCR1A = (_BV(COM1A1) /* clear a */ | _BV(COM1B1) | _BV(COM1B0) /* set b */ | _BV(FOC1A) | _BV(FOC1B) /* set outputs */);
  TCCR1A = (_BV(COM1A0) | _BV(COM1B0) /* toggle outputs on match */ | 0 /* normal counting mode */ );
  TCNT1 = 0;
  OCR1A = 199; // half a period less 1 for the zero count
  OCR1B = 199;
  ICR1 = 0xffff;
  cbi( TIMSK, TICIE1);
  cbi( TIMSK, OCIE1A);
  cbi( TIMSK, OCIE1B);
  cbi( TIMSK, TOIE1);
  cbi( TIFR, ICF1);
  // this next line starts the timer again, among other stuff
  TCCR1B = (_BV(ICNC1) /* noise canceler */ | 0 /* falling edge */ | _BV(WGM12) /* Clear timer at OCR1A match */ | _BV(CS10) /* unscaled clock */  );

void loop()
  volatile uint16_t phase;
  while( !(TIFR & _BV(ICF1)));  // wait for input capture
  cbi( TIFR, ICF1);
  phase = ICR1;

  Serial.print("P: ");
  Serial.print(phase, DEC);