0

Problem

I have an Arduino Duemilanove which needs to communicate with an Ardiuno Mega. The only pin available on the Duemilanove is D13. The Duemilanove is in charge of driving state on my robot, and the Mega is in charge of sensor readings and navigation. The Mega needs to send drive state updates to the Duemilanove. I2C, PWM, Serial, anything requiring different pins on the Duemilanove is out of the question at this point.

Idea I plan to have the Duemilanove send the "pipe" pin high, triggering an interrupt on the Mega. The ISR will send the current drive state to the Duemilanove which will change pinmode and read a digital pulse. The length of the pulse is the drive state.

Roadblock I am having trouble finding an example of how to set this up. I can't get the ISR to fire, and I'm not sure why.

Mega Code

int pipe = 18;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(pipe, INPUT);
  attachInterrupt(digitalPinToInterrupt(pipe), driveStateISR, CHANGE);
}

void loop() {
  // put your main code here, to run repeatedly:

}

void driveStateISR(){

  Serial.println("ISR fired");
  pinMode(pipe, OUTPUT);

  digitalWrite(pipe, HIGH);
  delay(50);
  digitalWrite(pipe, LOW);

  Serial.println("Pulse sent!");

  pinMode(pipe, INPUT);

}

Duemilanove Code

int pipe = 13;

void setup() {
  // put your setup code here, to run once:
  pinMode(pipe, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(pipe, HIGH);
  delay(30);
  pinMode(pipe, INPUT);

  unsigned long duration = pulseIn(pipe, HIGH);

  Serial.println(duration);

  delay(3000);
}

Nothing happens at all. I'm thinking the main framework is here, but since there aren't many examples of this out there I'd love to get some other eyes on the issue. Thanks!

2

You should not do delay() or Serial.print() inside an ISR. That would cause it to hang. For more information see my page about interrupts and also How do interrupts work on the Arduino Uno and similar boards?

| improve this answer | |
0

since it is one-way communication, it should be fairly simple, as long as you decide what the protocol you intend to use.

it could be pwm for example -> the duty cycle is the encoded data; or analog output; or uart tx; ...

after that, pick who the master is and who the slave is. generally it is (much) harder to code a slave so pick the slave that has the necessary hardware on the pin you have and go from there.

| improve this answer | |
  • PWM would be nice, but I don't have an available analog input on the Duemilanove. As far as I know I can't read an PWM signal using pin D13, which is the only I have available – trademark Dec 2 '17 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.