Hi,
I have two of these I2C displays: https://www.sparkfun.com/products/16917.
I have them working pretty well, but I cannot figure out how to get them to show negative numbers.
I am using Arduino and two rotary encoders as devices for creating numerical counts.
If I print to the Serial monitor, I see positive numbers when I go above 0 and negative numbers when I go below 0.
If I print to the display, I can only get positive (no “-” in front of a number less than 0). Is there something I can do with the display code that would show negative numbers? Do I have to convert integers to a string?
Thank you.
I have an idea of how to fix this; looking at the section around line ~655 here https://github.com/sparkfun/SparkFun_Al … isplay.cpp I think we just need to add another if statement for character 13 (line 59) to add in the negative symbol and put it in front of the displayed value
If you’re better than me at coding you can probably knock it out on your own; otherwise I’m going to try and fix it over the weekend and put in a push request…wish me luck!
Wow, that would be great!
If you have any luck with it, and the push request, please let me know. My simple change of data type (to string) did not work. I was next thinking about an if statement to print a “-” and shift the numbers right (if number < 0 …, “-” sign first…shift digits right) but your idea sounds much better. Thank you!
Hi, I was wondering if you had figured out on how to get the displays to show negative numbers? Thanks!
Hello, I just wanted to follow-up on this with some testing I did. I believe my issue might have to do with the encoder library I am using and/or the frequency I am updating the display.
I tested a stand-alone print of a negative number on the display, and it worked. I also noticed that, once in a while, using my setup, the display does show a “–” sign or a partial “-” sign after the numbers.
I am wondering if what might be happening is a partial reading on the display. My guess is the update part of the code I am using (if encoder value changes, update display) ends faster than the “-” character populates the display. This is just my best guess.
I am using this type of update because I am using stepper motors. I found that a constant update of the display caused hiccups with the steppers. If I update only on a change in the value, there are still some hiccups while changing the encoder values (display updates), but once I stop turning the dial (static display), the steppers run ok.
As a workaround for a “-” indicator, I added a led to light-up when the encoder values go below 0. I get the numbers from the encoder on the display, and the led lets me know if it is + or -.
I just wanted to follow-up with this info in case the testing info is helpful, and to let you know I found something that works for my project.