Closed DaMicrok closed 6 years ago
Hello, no problem... we've all been there. You have a line detachInterrupt(7);
which needs to be changed to disableInterrupt(7);
. That will fix your sketch.
You can use Serial.print()... as a matter of fact, my examples do so. You just shouldn't put it inside an Interrupt Service Routine. Your technique of updating the pulse counters is just fine, as is your using Serial.print() to display output.
Oh my, haha, what a schoolboy error! Thank you GreyGnome, I will test this out asap 👍
Yep, tried and tested. Works like a dream.
I am amazed and full of gratitude that you took time out to respond to such a newbie mistake and you did so very quickly. Thank you so so much. :1st_place_medal:
Using radiohead rh_ask.h the exact same thing happens. I don't know of this error.
This must be because you are not excluding the interrupts properly in enable interrupt. Have you, double checked the documentation on how to exclude interrupts?
On Tue, Mar 23, 2021, 8:30 PM dukepow @.***> wrote:
Using radiohead rh_ask.h the exact same thing happens. I don't know of this error.
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/GreyGnome/EnableInterrupt/issues/45#issuecomment-805402416, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2KFGJUOY54QBBBQXFRVSTTFE6CBANCNFSM4D76V6IA .
Massive apologies in advance, first time I've posted a problem. Like the title says I get a compiling error due to attachInterrupt and multiple definition of vector 1 and 2. I've tried using different digital pins and including #define EI_NOTINT0 and #define EI_NOTINT1 in my sketch but I do not know what is going wrong. I've read that you are not meant to use serial.print but that surely can't be the problem? because serial print is a major function of Arduino prototyping.
I am using 3 pins to read 3 Hall effect sensors and migrated from using attachInterrupt to enableInterrupt as the prior does not accommodate more than 2 pins.
Below is the error message
Arduino: 1.8.3 (Linux), Board: "Arduino/Genuino Uno"
In file included from /local/XXXX/Arduino/flow_oct_v1/flow_oct_v1.ino:1:0: /local/XXXX/Arduino/libraries/EnableInterrupt-master/EnableInterrupt.h:22:125: note: #pragma message: NOTICE: EnableInterrupt library version pre-0.9.6. This is not a problem. Keep calm, and carry on.
pragma message("NOTICE: EnableInterrupt library version pre-0.9.6. This is not a problem. Keep calm, and carry on. ")
WInterrupts.c.o (symbol from plugin): In function
attachInterrupt': (.text+0x0): multiple definition of
__vector_1' sketch/flow_oct_v1.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here WInterrupts.c.o (symbol from plugin): In functionattachInterrupt': (.text+0x0): multiple definition of
__vector_2' sketch/flow_oct_v1.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here collect2: error: ld returned 1 exit status exit status 1 Error compiling for board Arduino/Genuino Uno.-------------------------------------------------------------------------------------------------------------------------------------------And this is my sketch
include
define EI_NOTINT0
define EI_NOTINT1
/* Liquid flow rate sensor -DIYhacking.com Arvind Sanjeev
Measure the liquid/water flow rate using this code. Connect Vcc and Gnd of sensor to arduino, and the signal line to arduino digital pin 2.
*/
byte statusLed = 13;
// byte sensorInterrupt = 0; // 0 = digital pin 2 byte sensorPin1 = 5;
// The hall-effect flow sensor outputs approximately 4.5 pulses per second per // litre/minute of flow. float calibrationFactor = 4.5;
volatile byte pulseCount1;
float flowRate1; unsigned int flowMilliLitres1; unsigned long totalMilliLitres1;
unsigned long oldTime;
byte sensorPin2 = 4; // The hall-effect flow sensor outputs approximately 4.5 pulses per second per // litre/minute of flow.
volatile byte pulseCount2;
float flowRate2; unsigned int flowMilliLitres2; unsigned long totalMilliLitres2;
byte sensorPin3 = 7;
volatile byte pulseCount3;
float flowRate3; unsigned int flowMilliLitres3; unsigned long totalMilliLitres3;
void setup() {
// Initialize a serial connection for reporting values to the host Serial.begin(9600);
// Set up the status LED line as an output pinMode(statusLed, OUTPUT); digitalWrite(statusLed, HIGH); // We have an active-low LED attached
pinMode(sensorPin1, INPUT); digitalWrite(sensorPin1, HIGH);
pinMode(sensorPin2, INPUT); digitalWrite(sensorPin2, HIGH);
pinMode(sensorPin3, INPUT); digitalWrite(sensorPin3, HIGH);
pulseCount1 = 0; flowRate1 = 0.0; flowMilliLitres1 = 0; totalMilliLitres1 = 0;
pulseCount2 = 0; flowRate2 = 0.0; flowMilliLitres2 = 0; totalMilliLitres2 = 0;
pulseCount3 = 0; flowRate3 = 0.0; flowMilliLitres3 = 0; totalMilliLitres3 = 0;
oldTime = 0;
// The Hall-effect sensor is connected to pin 2 which uses interrupt 0. // Configured to trigger on a FALLING state change (transition from HIGH // state to LOW state) // attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
enableInterrupt(5, pulseCounter1, FALLING);
enableInterrupt(4, pulseCounter2, FALLING);
enableInterrupt(7, pulseCounter3, FALLING);
Serial.println("Qf,,Vf1,,Vf2,,Qr,,Vr1,,Vr2,,Qp,,Vp1,,Vp2,,"); }
/**
Main program loop */ void loop() {
if((millis() - oldTime) > 1000) // Only process counters once per second { // Disable the interrupt while calculating flow rate and sending the value to // the host //detachInterrupt(sensorInterrupt); disableInterrupt(5); disableInterrupt(4); detachInterrupt(7);
// Because this loop may not complete in exactly 1 second intervals we calculate // the number of milliseconds that have passed since the last execution and use // that to scale the output. We also apply the calibrationFactor to scale the output // based on the number of pulses per second per units of measure (litres/minute in // this case) coming from the sensor. flowRate1 = ((1000.0 / (millis() - oldTime)) pulseCount1) / calibrationFactor; flowRate2 = ((1000.0 / (millis() - oldTime)) pulseCount2) / calibrationFactor; flowRate3 = ((1000.0 / (millis() - oldTime)) * pulseCount3) / calibrationFactor;
// Note the time this processing pass was executed. Note that because we've // disabled interrupts the millis() function won't actually be incrementing right // at this point, but it will still return the value it was set to just before // interrupts went away. oldTime = millis();
// Divide the flow rate in litres/minute by 60 to determine how many litres have // passed through the sensor in this 1 second interval, then multiply by 1000 to // convert to millilitres. flowMilliLitres1 = (flowRate1 / 60) 1000; flowMilliLitres2 = (flowRate2 / 60) 1000; flowMilliLitres3 = (flowRate3 / 60) * 1000;
// Add the millilitres passed in this second to the cumulative total totalMilliLitres1 += flowMilliLitres1; totalMilliLitres2 += flowMilliLitres2; totalMilliLitres3 += flowMilliLitres3;
unsigned int frac;
// Print the flow rate for this second in litres / minute Serial.print(int(flowRate1)); // Print the integer part of the variable Serial.print(","); Serial.print("L/min"); Serial.print(",");
//Serial.print("\t"); // Print tab space
// Print the cumulative total of litres flowed since starting;
Serial.print(totalMilliLitres1); Serial.print(","); Serial.print("mL"); Serial.print(","); //Serial.print("\t"); // Print tab space Serial.print(totalMilliLitres1/1000); Serial.print(","); Serial.print("L"); Serial.print("\t");
// this migh not work**** Serial.print(","); // Print the flow rate for this second in litres / minute Serial.print(int(flowRate2)); // Print the integer part of the variable Serial.print(","); Serial.print("L/min"); Serial.print(",");
//Serial.print("\t"); // Print tab space
// Print the cumulative total of litres flowed since starting;
Serial.print(totalMilliLitres2); Serial.print(","); Serial.print("mL"); Serial.print(","); // Serial.print("\t"); // Print tab space Serial.print(totalMilliLitres2/1000); Serial.print(","); Serial.print("L"); Serial.print(","); Serial.print("\t");
// Print the flow rate for this second in litres / minute Serial.print(int(flowRate3)); // Print the integer part of the variable Serial.print(","); Serial.print("L/min"); Serial.print(",");
//Serial.print("\t"); // Print tab space
// Print the cumulative total of litres flowed since starting;
Serial.print(totalMilliLitres3); Serial.print(","); Serial.print("mL"); Serial.print(","); //Serial.print("\t"); // Print tab space Serial.print(totalMilliLitres3/1000); Serial.print(","); Serial.println("L"); //*****
// Reset the pulse counter so we can start incrementing again pulseCount1 = 0; pulseCount2 = 0; pulseCount3 = 0;
// Enable the interrupt again now that we've finished sending output //attachInterrupt(sensorInterrupt, pulseCounter, FALLING); enableInterrupt(5, pulseCounter1, FALLING);
enableInterrupt(4, pulseCounter2, FALLING);
enableInterrupt(7, pulseCounter3, FALLING); } }
/ Insterrupt Service Routine / void pulseCounter1() { // Increment the pulse counter pulseCount1++; } void pulseCounter2() { // Increment the pulse counter pulseCount2++; } void pulseCounter3() { // Increment the pulse counter pulseCount3++; }
Apologies again as I can only presume there must be a painfully obvious solution to those that know. And thanks. Michael