Go Down

Topic: Troubleshooting "undefined reference to setup/loop" error  (Read 64 times) previous topic - next topic

ChemE_James

I am trying to upload a flow meter sensor code to an Arduino Uno, but I keep getting there error messages:

"C:\Users\JAMESH~1\AppData\Local\Temp\ccQD5VAy.ltrans0.ltrans.o: In function `main':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:43: undefined reference to `setup'

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:46: undefined reference to `loop'

collect2.exe: error: ld returned 1 exit status"

I am using a code that comes from DIYhacking.com: https://diyhacking.com/projects/FlowMeterDIY.ino
I have little to no experience writing C++
I have indeed looked up my error online and I have found solutions to the error codes, but I have no idea how to implement the solution into my code. This is the forum that describes this solution: https://github.com/arduino/Arduino/issues/2397

If anyone can point me in the right direction that would be great!

UKHeliBob

Does your program have loop() and setup() functions ?

If not then why not ?

Please post your complete program here using code tags (</>) when you do.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

ChemE_James

Code: [Select]
/* 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 sensorPin = 2; // The hall-effect flow sensor outputs approximately 4.5 pulses per second per // litre/minute of flow. float calibrationFactor = 4.5; volatile byte pulseCount; float flowRate; unsigned int flowMilliLitres; unsigned long totalMilliLitres; unsigned long oldTime; void setup() { // Initialize a serial connection for reporting values to the host Serial.begin(38400); // Set up the status LED line as an output pinMode(statusLed, OUTPUT); digitalWrite(statusLed, HIGH); // We have an active-low LED attached pinMode(sensorPin, INPUT); digitalWrite(sensorPin, HIGH); pulseCount = 0; flowRate = 0.0; flowMilliLitres = 0; totalMilliLitres = 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); } /** * 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); // 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. flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / 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. flowMilliLitres = (flowRate / 60) * 1000; // Add the millilitres passed in this second to the cumulative total totalMilliLitres += flowMilliLitres; unsigned int frac; // Print the flow rate for this second in litres / minute Serial.print("Flow rate: "); Serial.print(int(flowRate)); // Print the integer part of the variable Serial.print("."); // Print the decimal point // Determine the fractional part. The 10 multiplier gives us 1 decimal place. frac = (flowRate - int(flowRate)) * 10; Serial.print(frac, DEC) ; // Print the fractional part of the variable Serial.print("L/min"); // Print the number of litres flowed in this second Serial.print(" Current Liquid Flowing: "); // Output separator Serial.print(flowMilliLitres); Serial.print("mL/Sec"); // Print the cumulative total of litres flowed since starting Serial.print(" Output Liquid Quantity: "); // Output separator Serial.print(totalMilliLitres); Serial.println("mL"); // Reset the pulse counter so we can start incrementing again pulseCount = 0; // Enable the interrupt again now that we've finished sending output attachInterrupt(sensorInterrupt, pulseCounter, FALLING); } } /* Insterrupt Service Routine */ void pulseCounter() { // Increment the pulse counter pulseCount++; }

AWOL

And now with newlines, please.
The compiler will give up at the first //.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

kenwood120s

I copied the code from the link you gave and it compiled for me.

I copied the code from your second post, where it's all in one long line, and got your errors, even though it has setup() and loop() in there.

So AWOL must be right about it stopping at the first // since most of your code is a comment.


ChemE_James

And now with newlines, please.
The compiler will give up at the first //.

yeah that fixed it my simple error thanks

Go Up