It's weird, it worked without doing that. I have updated my code to reflect your detachinterrupts() comment also. My goal is to try and understand why pins 20 & 21 do not function like the other pins.Ī stretch goal may be to try and get them to function like the other pins. It is pin 20 (and 21) that do not function as I expected. The setup works perfectly for pin 18 and pin 19 ( 2 & 3 as well ). The interactive board viewer appears to indicate that those pins on the MEGA 2560 are fixed to 5V with 10kOhm resistors? Trans_pin_CR (pin 20) is constantly HIGH. I want the voltage set high on those pins. Trans_pin_CL (pin 18) and Trans_pin_CC (pin 19) are set High, otherwise there is no voltage at those pins at all. I then spotted this discrepancy between how I thought the external interrupt pins worked on the MEGA 2560 and how they actually work. There is a large sketch that I am working with that uses interrupts and I am just trying to learn how they work. I am trying to understand how interrupts work on the MEGA 2560. PhotoTrans_IR_LED_board layout.pdf (715 KB) PhotoTrans_IR_LED_CircuitSchematic.pdf (565 KB) I only did it it for one IR_LED/Phototransistor pair though (and it was of the pins I am having trouble with!)Īs regards to question about polling vs interrupts, this sketch is to help me understand the functionality of another project that needs interrupts.Īny other thoughts or suggestions are greatly appreciated! I've also attached a fritizing drawings for what the board looks like. I hope this code snippet helps (for my sake. Serial.println("No Trans Pin Triggered") Serial.println("CR Trans Pin Triggered") Serial.println("CC Trans Pin Triggered") Serial.println("CL Trans Pin Triggered") Return float(analogRead(adPin)) * 5.0 / 1024.0 Serial.print(volts(IRMN)) // Display measured A3 voltsįloat volts(int adPin) // Measures volts at adPin Serial.print("IR Neg Pin = ") // Display "A3 = " Serial.print(volts(IRMP)) // Display measured A3 volts Serial.print("IR Pos Pin = ") // Display "A3 = " the loop function runs over and over again until power down or reset the setup function runs once when you press reset or power the boardĮIFR = bit(INTF5) // clear flag for interrupt 0ĮIFR = bit(INTF4) // clear flag for interrupt 1ĮIFR = bit(INTF3) // clear flag for interrupt 1ĮIFR = bit(INTF2) // clear flag for interrupt 1ĮIFR = bit(INTF1) // clear flag for interrupt 1ĮIFR = bit(INTF0) // clear flag for interrupt 1ĪttachInterrupt(digitalPinToInterrupt(Trans_pin_CL),ĪttachInterrupt(digitalPinToInterrupt(Trans_pin_CC),ĪttachInterrupt(digitalPinToInterrupt(Trans_pin_CR), Is there some reason you need to use interrupts rather than polling? Have you written a simple sketch that just displays the state of those pins to make sure they are actually changing when the IR is blocked?Īlso, it sounds like a rather simple application. Is there a way to get the same functionality as the other two pins?Īrduino Mega 2560 Rev3 - Arduino Official StoreĬan't really help much without seeing your sketch. Is there something different about these two pins that prevents them from being used like the other four. Not sure what to make of it other than these pins can't have a low setting? For pins 20 (SDA) and 21 (SCL), it does not.įrom looking at the interactive board viewer, these two pins appear to be a little different. For pins 2,3,18 and 19, the setup works as expected. When the voltage rises, an interrupt routine is executed. When the IR light which shines on the phototransistor is blocked, the transistor causes an open circuit and the voltage at the pin rises. I am using an IR phototransistor and an IR LED as motion detector.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |