Hello,
This is my first post on the Adafruit forum so please bear with me.
I recently acquired an Adafruit 0.54" 14-Segment LED with I2C Bacykpack. I am using it to display a humidity reading provided by a Honeywell Humidicon sensor. I am able to extract a binary reading from the sensor and convert it into a float.
I tried several approaches to converting the float reading into an LED output with two decimal points:
1. I used dtostrf from the stdio.h library to convert my reading into a string. I then accessed each element of the string that I needed and used writeDigitAscii. This works for reproducing the digit but excludes the period to indicate decimals.
2. I tried to fix the dtostrf approach by enabling the period with a writeDigitRaw but it does not show up and the output is unchanged from Approach #1.
3. I tried inputting all fields for the writeDigitAscii function: writeDigitAscii(position, ASCII value, true) to enable the boolean dot as per the .h file but this caused no change in the original output.
4. I tried a different function, printFloat, from the 7segment object. This time I did not use dtostrf but passed the float directly. I get a different number in that the display shows two whole numbers, a space and a decimal value but no dot (53 4) even though I specified that I wanted two decimal resolution. The numbers are also missing some LED lights although are still recognizable.
5. Since the printFloat function requires a double as an input I tried declaring a random double and passing it in to see if it was displayed properly. I ran into the same issue as with Approach #4.
At this point I am out of ideas on how to approach this problem. I need the dot enabled to clearly show that this is a decimal number. I've searched the forums, read up the library and tried various fixes but cannot get the display I need. The long fix is manually redefining each digit by individual LEDs but would really prefer to avoid this fix. Could really use some advice from the community.
Hope to hear from you,
Yusif Nurizade
Can't display decimal point for 14-segment LED w/I2C Backpac
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 5
- Joined: Wed Jul 30, 2014 11:33 am
- Franklin97355
- Posts: 23911
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Can't display decimal point for 14-segment LED w/I2C Bac
What are you using to talk to the display (micro, computer, what) and what does the float look like when you print it out before sending it and what displays when you send it?
-
- Posts: 5
- Joined: Wed Jul 30, 2014 11:33 am
Re: Can't display decimal point for 14-segment LED w/I2C Bac
Franklin,
Thank you for the response. To answer your questions:
1. I am using an Arduino Uno R3 microcontroller.
2. When I do a serial.print(), I get the humidity displayed as a percentage (i.e. 53.41).
3. Depending on which approach I am using, I either get the number with no decimal point (5341) or the number with no decimal point separated by a space (53 4) with some of the numbers missing LEDs but still recognizable.
Hope to hear from you,
Yusif Nurizade
Thank you for the response. To answer your questions:
1. I am using an Arduino Uno R3 microcontroller.
2. When I do a serial.print(), I get the humidity displayed as a percentage (i.e. 53.41).
3. Depending on which approach I am using, I either get the number with no decimal point (5341) or the number with no decimal point separated by a space (53 4) with some of the numbers missing LEDs but still recognizable.
Hope to hear from you,
Yusif Nurizade
- Franklin97355
- Posts: 23911
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Can't display decimal point for 14-segment LED w/I2C Bac
So you are getting the numbers correct just not formatting them for the display. One way is to assign the number to an integer called main then multiply the number by 100 and do a mod 100 to get the digits below 100 (the decimal) then send main+"."+the number from the mod.
-
- Posts: 5
- Joined: Wed Jul 30, 2014 11:33 am
Re: Can't display decimal point for 14-segment LED w/I2C Bac
Franklin,
What command should be used for trying this approach? When I was pulling these numbers out of a string and adding a ".", I got no change.
Is your suggestion to use writeDigitRaw? Also, if you are multiplying by 100, how do you specify where the decimal point goes? I am still confused as to why the writeDigitAscii with boolean dot enabled isn't working.
Best,
Yusif Nurizade
Update: I played around with the code based on your suggestion. The 14 segment display has only two commands - writeDigitRaw and writeDigitAscii.
writeDigitRaw inputs a hexadecimal number with each bit corresponding to an individual LED (2 of 16 bits are not used since there are only 14 LEDs). Using this command, adding the bit mask for the dot (0x4000) to whatever I was going to send allows me to control the decimal. The problem with this approach, however, is that the hexadecimal number does not correspond to any number I get from my sensor but a bitmask for the LEDs so I would have to write an extensive translator to get this to work that would most likely be its own library for memory considerations.
writeDigitAscii translates a char to a number on the LED. This works well for my purposes because it allows me to translate a sensor reading (float) to a string and pass individual string values to be displayed. The problem is that it does not allow me to control the decimal. If I were to add the decimal point to the character being passed in, say 'A' + '.', I would get another character further down the line (I think I got 'o'). The function, as defined in the library, has a third input boolean dot which is set to false. Neither inputting a true, nor changing the library setting enables the decimal point, however. I think this third input is the key but can't figure out why it isn't enabling the dot. Do you have any thoughts on why this could be?
What command should be used for trying this approach? When I was pulling these numbers out of a string and adding a ".", I got no change.
Is your suggestion to use writeDigitRaw? Also, if you are multiplying by 100, how do you specify where the decimal point goes? I am still confused as to why the writeDigitAscii with boolean dot enabled isn't working.
Best,
Yusif Nurizade
Update: I played around with the code based on your suggestion. The 14 segment display has only two commands - writeDigitRaw and writeDigitAscii.
writeDigitRaw inputs a hexadecimal number with each bit corresponding to an individual LED (2 of 16 bits are not used since there are only 14 LEDs). Using this command, adding the bit mask for the dot (0x4000) to whatever I was going to send allows me to control the decimal. The problem with this approach, however, is that the hexadecimal number does not correspond to any number I get from my sensor but a bitmask for the LEDs so I would have to write an extensive translator to get this to work that would most likely be its own library for memory considerations.
writeDigitAscii translates a char to a number on the LED. This works well for my purposes because it allows me to translate a sensor reading (float) to a string and pass individual string values to be displayed. The problem is that it does not allow me to control the decimal. If I were to add the decimal point to the character being passed in, say 'A' + '.', I would get another character further down the line (I think I got 'o'). The function, as defined in the library, has a third input boolean dot which is set to false. Neither inputting a true, nor changing the library setting enables the decimal point, however. I think this third input is the key but can't figure out why it isn't enabling the dot. Do you have any thoughts on why this could be?
- Franklin97355
- Posts: 23911
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Can't display decimal point for 14-segment LED w/I2C Bac
Have you tried writeDigitAscii(digit, value, 1)? the 1 should set the decimal point if I read the library correctly.
Code: Select all
void Adafruit_AlphaNum4::writeDigitAscii(uint8_t n, uint8_t a, boolean d) {
uint16_t font = pgm_read_word(alphafonttable+a);
displaybuffer[n] = font;
/*
Serial.print(a, DEC);
Serial.print(" / '"); Serial.write(a);
Serial.print("' = 0x"); Serial.println(font, HEX);
*/
if (d) displaybuffer[n] |= (1<<15);
}
-
- Posts: 5
- Joined: Wed Jul 30, 2014 11:33 am
Re: Can't display decimal point for 14-segment LED w/I2C Bac
Franklin,
I did try this option. The default setting in the .h file is boolean dot = false so I first changed it in my Arduino program then, when that didn't work, changing the .h file to read true and finally to read nothing (boolean dot). Neither of these has worked and I am confused as to why this is considering how it is defined in the library.
Please advise.
Best,
Yusif Nurizade
I did try this option. The default setting in the .h file is boolean dot = false so I first changed it in my Arduino program then, when that didn't work, changing the .h file to read true and finally to read nothing (boolean dot). Neither of these has worked and I am confused as to why this is considering how it is defined in the library.
Please advise.
Best,
Yusif Nurizade
- tdicola
- Posts: 1074
- Joined: Thu Oct 17, 2013 9:11 pm
Re: Can't display decimal point for 14-segment LED w/I2C Bac
Looks like there was a small bug in the library and the third parameter to writeDigitAscii was flipping bit 15 on when it really should have been flipping bit 14 on for the decimal point. I just reproed the issue and fix with a 14 segment display, and updated the library on github. Can you grab the latest version of the library and give it a test to see if calling writeDigitAscii(0, '1', true) for example will display a 1 with a decimal point in the first position? Thanks for all the detailed repro steps and info!
-
- Posts: 5
- Joined: Wed Jul 30, 2014 11:33 am
Re: Can't display decimal point for 14-segment LED w/I2C Bac
tidicola,
Sorry for the late reply, I was away from the office a few days.
I tried your fix and it did the trick; I am now able to properly control the decimal and display my data.
I'm glad I could help you flush this out and grateful for you following it up. I was seriously considering writing my own library for the sensor in order to get the dot right!
Any chance we can call the latest version on GitHub the Yusif Nurizade Patch? =)
Thanks again,
Yusif Nurizade
Sorry for the late reply, I was away from the office a few days.
I tried your fix and it did the trick; I am now able to properly control the decimal and display my data.
I'm glad I could help you flush this out and grateful for you following it up. I was seriously considering writing my own library for the sensor in order to get the dot right!
Any chance we can call the latest version on GitHub the Yusif Nurizade Patch? =)
Thanks again,
Yusif Nurizade
Please be positive and constructive with your questions and comments.