SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By Matadormac
#177889
Good day.

I am trying to integrate the code for the ML 8511 into an existing working sketch with a TSl 2561 and printing data out to a 16 x 2 LCD through an I2C controller. I am on Linux and using an Arduino Uno R3.

While trying to integrate the appropriate code from the MP8511 Read Example into my sketch I get the following error:
TSL_2561_MGM_1.ino: In function 'void loop()':
TSL_2561_MGM_1.ino:91:40: error: 'averageAnalogRead' was not declared in this scope
TSL_2561_MGM_1.ino:97:67: error: 'mapfloat' was not declared in this scope
Error compiling.

This occurs after I put the following code into the void loop(void) area of the Arduino sketch.
int uvLevel = averageAnalogRead(UVOUT);
int refLevel = averageAnalogRead(REF_3V3);

//Use the 3.3V power pin as a reference to get a very accurate output value from sensor
float outputVoltage = 3.3 / refLevel * uvLevel;

float uvIntensity = mapfloat(outputVoltage, 0.99, 2.9, 0.0, 15.0);


I think there is a conflict here but I am quite new at this coding and don't know how to error trap this. I will provide any extra information requested in order to solve this.

Thank you

Matadormac
By Mee_n_Mac
#177890
What is averageAnalogRead() ? It's not part of the standard Arduino commands. Is it part of some other library ? If so you need to include the library (as well as have it installed). If it's a function you wrote, it's code has to be somewhere in the sketch.

Same for mapfloat().

http://arduino.cc/en/Tutorial/Foundations
http://arduino.cc/en/Reference/FunctionDeclaration
http://arduino.cc/en/Reference/Libraries
By Matadormac
#177897
Mee_n_Mac wrote:What is averageAnalogRead() ? It's not part of the standard Arduino commands. Is it part of some other library ? If so you need to include the library (as well as have it installed). If it's a function you wrote, it's code has to be somewhere in the sketch.

Same for mapfloat().

http://arduino.cc/en/Tutorial/Foundations
http://arduino.cc/en/Reference/FunctionDeclaration
http://arduino.cc/en/Reference/Libraries

Thank you Me_n_Mac. Yes, I was stumped too. Your reply made me think of something else though.
Firstly, the code comes from the Sparkfun example sketch. The sketch uses no libraries.

I think I may have a glimmer though. The functions I was calling have not been defined yet (at least by me). They are defined further down in the sketch. I think I threw up my hands too soon, but I was tired and confused.

I had begun checking for errors after every major change in sketch code only this time the answer may lie in completing the function definition!
I will go back and complete the code transfer and see if I have the same issues. Amazing what a bit of sleep will do.

Thank you
By Franciscodr
#179307
Hello!

I searched too for documentation about the "averageAnalogRead" but didn't find anything in the Arduino documentation. But I did find this subrutine inside the sparkfun code for the ML 8511 that maybe is useful:
Code: Select all
//Takes an average of readings on a given pin
//Returns the average
int averageAnalogRead(int pinToRead)
{
  byte numberOfReadings = 8;
  unsigned int runningValue = 0; 

  for(int x = 0 ; x < numberOfReadings ; x++)
    runningValue += analogRead(pinToRead);
  runningValue /= numberOfReadings;

  return(runningValue);  
}
Kind regards,
Francisco
Last edited by Franciscodr on Mon Feb 02, 2015 9:30 am, edited 1 time in total.