Quite new to the Arduino, but have started on a project where I use the Arduino Nano to measure some voltages and displaying them on a 4 digit 7-seg TM 1637 display.
Using the TM1637Display.h library, so far, showing the voltage value is working OK.
However, I have run into a problem. I am using a hall sensor to measure current flow, where the voltage from the sensor is calculated to current. I need to be able to show a negative value. But I have not been able to find a solution for this. Does anyone know how to show negative value with the TM1637? For instance displaying temperatures that are below zero?
Post a link to where you got the library from. Please use the chain links icon on the toolbar to make it clickable. Or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.
At least one library (GitHub - avishorp/TM1637: Arduino library for TM1637 (LED Driver)) doesn't display a sign even though it takes a signed integer for the value. It does, however, allow you to write to the segments directly. The segment values for a minus sign in that library would be 0b01000000 (or 0x40).
Perhaps some other library would handle the sign correctly.
I am using the library in the link above. I have tried to send the minus sign using SetSegment, but then it blanks out the value instead. Seems like it cannot run together with ShowNumberDecEx.
I guess that one way to do it, is to use SetSegment for both value and sign, but I don´t have the programming skills to do that.
From looking at the source code for that library, it appears that if you give it a negative number to display, then what gets displayed will be neither the number you gave it nor its absolute value: rather, it will be garbage.
It's probably not so light weight as some of the alternatives but I really like that it inherits from the Arduino Print class and uses an API similar to the LCD libraries.
GGeorgsson:
I am using the library in the link above. I have tried to send the minus sign using SetSegment, but then it blanks out the value instead. Seems like it cannot run together with ShowNumberDecEx.
I guess that one way to do it, is to use SetSegment for both value and sign, but I don´t have the programming skills to do that.
Do you know how to take a number apart to get at its digits?
odometer:
From looking at the source code for that library, it appears that if you give it a negative number to display, then what gets displayed will be neither the number you gave it nor its absolute value: rather, it will be garbage.
Yes. For instance, when I added a voltage that should give me -3.81A, I got d8 on the display.
I have just downloaded it. Unfortunately, I will not have the possibility to test it until tomorrow.
I guess that I will need to add all 3 libraries, TM1637, Extended & Fun.
GGeorgsson:
I guess that I will need to add all 3 libraries, TM1637, Extended & Fun.
They're all part of one library. To print negative numbers you will only need to add an #include directive for SevenSegmentTM1637.h. The other two headers contain declarations for some extra functions but the really useful stuff is all in SevenSegmentTM1637.h.
Modified the sketch, and had some progress. If I send the command Display_1.print("Vin1");
It shows the text vin1 in the display (due to the " ") But if I send it only as Display_1.print(Vin1);
I don´t get any real value on the display. It starts by showing like 5 then _ 9 then _ _ 1 and finally _ _ _ 7
(or some other digits, see attached picture). However, it seems like the minus sign is working, since I got value like _ - _ 2 on on the displays that are supposed to be able to show negative values.
odometer:
Again: do you know how to take apart a number to get at its digits?
I´m not sure. I have another project, where I measure temperature. There, I take the value apart and send the number (for instance 25 degrees) 2 to first segment and 5 to second segment. Then I send the character C to the 4th segment. However, I have not figured out how to send the decimal, if I have like 25.4 degrees.
GGeorgsson:
I´m not sure. I have another project, where I measure temperature. There, I take the value apart and send the number (for instance 25 degrees) 2 to first segment and 5 to second segment. Then I send the character C to the 4th segment. However, I have not figured out how to send the decimal, if I have like 25.4 degrees.
You multiply the 25.4 by 10 to get 254. Then you display the 254 and turn on the decimal point in the appropriate place.
Got that working now on the temp meter, except for the decimal point. Have not figured out how to send a number AND decimal point to the same segment at the same time.
GGeorgsson:
Got that working now on the temp meter, except for the decimal point. Have not figured out how to send a number AND decimal point to the same segment at the same time.
GGeorgsson:
Using different library for that one.
It would help to know what library you are using, and where to find it.
GGeorgsson:
Can´t find the download link where I found the libraries, so I include them together with my sketch.
That library won't let you manually set the decimal point. You could probably modify it to, but rather than modify a library, probably just better to use the other library (the one from GitHub - avishorp/TM1637: Arduino library for TM1637 (LED Driver)) and feed it the digits manually.
As for that GitHub - avishorp/TM1637: Arduino library for TM1637 (LED Driver) library: its setSegments() function treats each digit's decimal point as just another segment, and it uses bit 7 (the high bit in a byte: it's the 1 in 0b10000000) to represent the on/off status of that "segment". I know, it doesn't actually say this in the docs: I had to suss it out by studying the source code.
I used that library in my main project, that was the reason for this thread.
The project is a battery monitoring system, that continuously measures the voltage on two separate battery banks together with the current flow, in or out from the banks.
Using showNumberDecEx (showNumberDecEx(val*10.0f, 0x20); ) had no problem setting out the dot, however, since I also want to measure current consumption, I have issues showing a negative value.
The question is, how to combine SetSegments together with showNumberDecEx, only setting the negative sign on the first segment, if the value is negative and also convert the negative value to positive to avoind gibberish number.
I guess it would be something like (note this is my thinking of the functionality, not actual programming text)
IF val <0 THEN
setSegment 0 = 0b01000000
invert val
ShowNumberDecEx(val*10.0f, 0x40)
GGeorgsson:
The question is, how to combine SetSegments together with showNumberDecEx,
In an older post, you wrote
GGeorgsson:
I am using the library in the link above. I have tried to send the minus sign using SetSegment, but then it blanks out the value instead. Seems like it cannot run together with ShowNumberDecEx.