Nucleo - 64 F103RB with Sharp sensor

Have a nice day

I installed stm library arduino IDE.
The microprocessor I am using is Nucleo - 64 F103RB. First I loaded the blink code and it worked fine. However, I wanted to use the sharp sensor that I will use in my project on the nucleo board, but when I uploaded this code, I encountered such a problem. I would appreciate it if you could help me with this. I don't know what to do.



Kind regards
MUHAMMAD ALIZADA

Please copy and paste those error messages and post them as text, not a screen capture image.

Same thing with the code, post it in a new message, using code tags please.

If you have any doubts about this, please read:

In file included from C:\Users\MUHAMMED\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\cores\arduino/wiring.h:34,
from C:\Users\MUHAMMED\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\cores\arduino/Arduino.h:36,
from C:\Program Files (x86)\Arduino\libraries\SharpIR\SharpIR.h:20,
from C:\Program Files (x86)\Arduino\libraries\SharpIR\SharpIR.cpp:45:
C:\Program Files (x86)\Arduino\libraries\SharpIR\SharpIR.cpp: In constructor 'SharpIR::SharpIR(int, long int)':
C:\Users\MUHAMMED\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\cores\arduino/wiring_constants.h:76:17: error: invalid conversion from 'int' to 'eAnalogReference' {aka '_eAnalogReference'} [-fpermissive]
76 | #define DEFAULT 1
| ^
| |
| int
C:\Program Files (x86)\Arduino\libraries\SharpIR\SharpIR.cpp:63:23: note: in expansion of macro 'DEFAULT'
63 | analogReference(DEFAULT);
| ^~~~~~~
In file included from C:\Users\MUHAMMED\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\cores\arduino/wiring.h:33:
C:\Users\MUHAMMED\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\cores\arduino/wiring_analog.h:40:46: note: initializing argument 1 of 'void analogReference(eAnalogReference)'
40 | extern void analogReference(eAnalogReference ulMode) ;
| ~~~~~~~~~~~~~^~
exit status 1
Error compiling for board Nucleo-64.

Thank you. Now please post your code, in code tags.

However, I think that the text of the error message that you posted was truncated. Please use the "copy" button that is provided for that, in the IDE window.

This is my error code:
In file included from C:\Users\MUHAMMED\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\cores\arduino/wiring.h:34,
from C:\Users\MUHAMMED\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\cores\arduino/Arduino.h:36,
from C:\Program Files (x86)\Arduino\libraries\SharpIR\SharpIR.h:20,
from C:\Program Files (x86)\Arduino\libraries\SharpIR\SharpIR.cpp:45:
C:\Program Files (x86)\Arduino\libraries\SharpIR\SharpIR.cpp: In constructor 'SharpIR::SharpIR(int, long int)':
C:\Users\MUHAMMED\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\cores\arduino/wiring_constants.h:76:17: error: invalid conversion from 'int' to 'eAnalogReference' {aka '_eAnalogReference'} [-fpermissive]
76 | #define DEFAULT 1
| ^
| |
| int
C:\Program Files (x86)\Arduino\libraries\SharpIR\SharpIR.cpp:63:23: note: in expansion of macro 'DEFAULT'
63 | analogReference(DEFAULT);
| ^~~~~~~
In file included from C:\Users\MUHAMMED\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\cores\arduino/wiring.h:33:
C:\Users\MUHAMMED\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\cores\arduino/wiring_analog.h:40:46: note: initializing argument 1 of 'void analogReference(eAnalogReference)'
40 | extern void analogReference(eAnalogReference ulMode) ;
| ~~~~~~~~~~~~~^~
exit status 1
Error compiling for board Nucleo-64.

Here is my arduino code:

#include <SharpIR.h>

#define ir A0
#define model 1080
SharpIR SharpIR(ir, model);

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

void loop() {
delay(2000);

unsigned long startTime=millis(); // takes the time before the loop on the library begins

double dis=SharpIR.distance(); // this returns the distance to the object you're measuring

Serial.print("Mean distance: "); // returns it to the serial monitor
Serial.println(dis);

unsigned long calcTime=millis()-startTime; // the following gives you the time taken to get the measurement
Serial.print("Time taken (ms): ");
Serial.println(calcTime);

}

try casting the function parameter

analogReference((eAnalogReference)DEFAULT);

I tried and it worked. Thank you very much.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.