I have been scouring the internet for an hour trying to find out how to edit Arduino library files.
The results...
You cannot do it
You can do it and it's easy but I have explained it poorly so good luck trying
I am using a rather finicky OLED display and the library for it will not allow me to use a float for the displayed data. I need to use the float to display decimal places, but I don't think any of the functions in this library were designed for that. I would like to open up the header file and add a function with this capacity.
Also, I haven't been coding very long so I would appreciate a rather in depth explanation on the HOW as opposed to the "you need a text editor" that I keep seeing...
Hi @bat_007. First off, you do need a text editor. If you already have one installed, you can use that. If not, I can recommend the excellent free VS Code:
Once you have a text editor, the next step is to figure out where the library is located on your computer. You can follow these instructions to do that:
Open any sketch that uses the library in Arduino IDE.
Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
The "Preferences" dialog will open.
Check the box next to "Show verbose output during: ☐ compile" in the "Preferences" dialog.
Click the "OK" button.
The "Preferences" dialog will close.
Select Sketch > Verify/Compile from the Arduino IDE menus.
Wait for the compilation to finish.
Study the contents of the black "Output" panel at the bottom of the Arduino IDE window. You might need to scroll up to find the part we are looking for. There you will see a list of the libraries that were used to compile the sketch, including the path of the library. For example:
Using library Adafruit GFX Library at version 1.11.9 in folder: C:\Users\per\Documents\Arduino\libraries\Adafruit_GFX_Library
Now start your text editor. Select File > Open... from the menus in the text editor, and then select the file you want to edit from the folder at the path you found from looking at the Arduino IDE compilation output.
You can now edit the library code as you like and then save your changes. The next time you compile or upload a sketch using the library in Arduino IDE, the changes you made to the library will be present in the sketch program.
You are a most probably mistaken in it.
The library certainly has a method to output an integers, so you can easily display a number with decimal places by printing an integer part, than a point "." and a decimal digits after it.
Another way is convert a float to the text string by String(float) or by sprintf() functions and printing the text to the screen.
The both methods above doesn't require an editing the library code.
Hello! Thank you to everyone who responded. Lots of good advice and ways to work around this problem. I found it odd that the float wasn't working, but I have since realized the float is undefined in the cpp file despite being in the header file. That is why this has all be so confusing. Thanks to everyone who reached out and thank you for responding in such a timely fashion!
I just wanted to make an independent post regarding a recent issue I faced in case anyone is having similar struggles. I have found that the file titled "OLED Display 96x96" by Seeed Studio in the Arduino IDE library has an inconsistency in its header file and .cpp file. The header file incorporates a "putFloat" function but it is not defined in the .cpp. This gave me quite the headache so to anyone in a similar boat use the Grove - OLED Display 0.96 by Seeed Studio for the float as it is included in both files. You could also edit the .cpp filed but the Grove 0.96 lib works just fine.
Why?
You should have to add this to your recent thread to which this message is directly connected.
As for the essence of the message - you were given a bunch of different ways to solve the problem of printing float on a display - did they all seem so complicated to you that you still searching for a ready-made library?
Your two or more topics on the same or similar subject have been merged.
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.
Sorry, I thought it might be helpful to someone looking up this particular library if the information was included in a separate post so they could locate it easier since I didn't list the exact info in the title. I tried editing the cpp and header file but was coming up with some issues. The functions people advised me to use weren't in the library (e.g. dtostrf, sprintf() etc.), so rather then writing them in I decided to try to see if there was a better library I could've been using first. I have only been coding for a week, not just with Arduino, but literally coding for the first time as of a week ago, so I am very new to everything. It is easier for me to use libraries as I am still learning quite literally everything, so what might seem like simple solutions are kinda complicated for someone who didn't know what "Serial.begin()" meant a week ago. I will try to do better about how I post and re-read the forum etiquette.
See post #4. If you tell us exactly what library you're having difficulty with, it would be so much easier. There are literally hundreds of similar libraries out there, so you'll have to provide, at minimum, a link to where you downloaded it from. If it came with a beginner kit, you might have to provide the exact file set, such as a .h file, a .cpp file, and any associated documentation. Sorry, but the software world is immense.
They are standard functions, not part of a library.
float pi = PI;
void setup()
{
Serial.begin(115200);
while (!Serial);
Serial.print(F("Normal print, two decimals: "));
Serial.println(pi);
Serial.print(F("Normal print, four decimals: "));
Serial.println(pi, 4);
char buffer[16];
Serial.print(F("dtostrf print, two decimals: "));
dtostrf(pi, 2, 2, buffer);
Serial.println(buffer);
Serial.print(F("dtostrf print, nine decimals: "));
dtostrf(pi, 2, 9, buffer);
Serial.println(buffer);
}
void loop()
{
}
With dtostrf, the buffer will contain the text representation of the float number and you should be able to print that buffer with your library. Note that you must guarantee that the buffer is big enough; also note that floats are only accurate to six or seven digits (the 9 that I used is only for demonstration purposes).
Lastly, on 8 bit Arduinos (Uno, Mega etc), sprintf does not support floating point numbers.
Thank you! I think I just wasn't using dtostrf correctly and sprintf wasn't working since I am using a Mega. I appreciate all of the help from you and I will take note of this in the future.