I2C LCD BUG
#1
Posted 12 April 2012 - 05:03 AM
#2
Posted 12 April 2012 - 05:19 AM
#3
Posted 12 April 2012 - 06:23 AM
#4
Posted 12 April 2012 - 07:02 AM
#5
Posted 12 April 2012 - 07:22 AM
#6
Posted 12 April 2012 - 07:23 AM
For anyone to help you with this you must supply at least some information of what you are trying to do, what parts you're interfacing with, what your code looks like, etc.
...or we could add a special subforum called "thinking out loud"
Sometimes a guy just has to vent you know.
#7
Posted 12 April 2012 - 07:41 AM
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#8
Posted 12 April 2012 - 03:22 PM
#9
Posted 12 April 2012 - 03:30 PM
RUNTIME: 20 minutes.
If anyone would like the additional functions just PM me or post a message on the thread.
Here is my I2CBus class for my microliquid library. I increased the bus speed to 1000. If the number is set to the default 0,0 I get garbled messages. This still happens at 0,300. I am not exactly sure what this does but it does seem to help.
public class I2CBus : IDisposable { /// <summary>Aggregated device for this driver</summary> private I2CDevice Device; /// <summary>Creates a new <see cref="I2CBus"/> instance </summary> /// <remarks> /// At this time the .NET Micro Framework only supports a single I2C bus. /// Therefore, creating more than one I2CBus instance will generate an /// exception. /// </remarks> /// <exception cref="InvalidOperationException">An I2CBus instance already /// exists and it's Dispose() method has not been called</exception> public I2CBus() { this.Device = new I2CDevice(new I2CDevice.Configuration(0, 1000)); }
My function which writes to the LCD
public static void updateLCDDisplay(clFinance Stock, Lcd lcd) //needs LCD in it { /* THIS IS A HELPER FUNCTION WHICH IS CALLED TO UPDATE THE DISPLAY OF THE LCD DISPLAY WITH THE * INPUTTED STOCK. THIS FUNCTION KEEPS THE MAIN FUNCTION CLEAN. * * // LCD Display // * * // LAYOUT // * // STOCK NAME LAST // * // CHANGE PERCENT // * // DAILY - CHANGE // * // MARKET VALUE // * */ //20 x 4 size LCD string formattedStockName = ""; string formattedMarketValue = ""; string formattedDailyChange = ""; string formattedChange = ""; string formattedPercChange = ""; string formattedLast = ""; //Stock Name //if (Stock.GetStockName().Length > 20) formattedStockName = Stock.GetTicker(); //else // formattedStockName = Stock.GetStockName(); //Change if (Stock.GetChange() > 0) formattedChange = "$" + setDecimalPlaceOfString(Stock.GetChange(), 2, true); else formattedChange = "-$" + setDecimalPlaceOfString(Stock.GetChange() * -1,2, true); //Percent formattedPercChange = setDecimalPlaceOfString(Stock.GetPercentChange(), 2, true) +"%"; //Daily Change if (Stock.GetDailyChange() > 0) formattedDailyChange = "$" + setDecimalPlaceOfString(Stock.GetDailyChange(),2, true); else formattedDailyChange = "-$" + setDecimalPlaceOfString(Stock.GetDailyChange() * -1, 2, true); //Market Value if (Stock.GetMarketValue() > 0) formattedMarketValue = "$" + setDecimalPlaceOfString(Stock.GetMarketValue(), 2,true); else formattedMarketValue = "-$" + setDecimalPlaceOfString(Stock.GetMarketValue() * -1, 2,true); //Last formattedLast = "$" + setDecimalPlaceOfString(Stock.GetLastPrice(), 2, true); lcd.Clear(); //lcd.SetCursorPosition(0, 0); Thread.Sleep(1000); //Row 1 lcd.SetCursorPosition(0,0); Thread.Sleep(1000); lcd.Write(removeIllegalCharacters(centerString(formattedStockName, 20))); Thread.Sleep(1000); //Row 2 lcd.SetCursorPosition(0, 1); Thread.Sleep(1000); lcd.Write(removeIllegalCharacters(centerString(formattedChange, formattedPercChange, 20))); Thread.Sleep(1000); //Row 3 lcd.SetCursorPosition(0, 2); Thread.Sleep(1000); lcd.Write(removeIllegalCharacters(centerString(formattedDailyChange, 20))); Thread.Sleep(1000); //Row 4 lcd.SetCursorPosition(0, 3); Thread.Sleep(1000); lcd.Write(removeIllegalCharacters(centerString(formattedMarketValue, 20))); Thread.Sleep(1000); //TESTING CODE //string temp2 = center2String(formattedStockName,formattedLast, 20); //string temp3 = center2String(formattedChange, formattedPercChange, 20); //string temp1 = center1String(formattedDailyChange, 20); //string temp = center1String(formattedMarketValue, 20); }
My function to make sure Illegal characters aren't sent to the LCD
public static string removeIllegalCharacters(string inputString) { int asciiValue; for (int i = 0; i < inputString.Length - 1; i++) { asciiValue = (int) inputString[i]; if (asciiValue == 45 || asciiValue == 36 || asciiValue == 46 || asciiValue == 37 || (asciiValue >= 48 && asciiValue <= 57) || (asciiValue >= 97 && asciiValue <= 122) || (asciiValue >= 65 && asciiValue <= 90) || asciiValue == 32 || asciiValue == 44) { //This character is fine. //Move on to the next } else { return "ILLEGAL CHAR FOUND"; } } return inputString; }
Function to center LCD Text
public static string centerString(string sourceString1, string sourceString2, int formattedStringLength) { /*THIS FUNCTION TAKES IN TWO STRINGS AND CENTERS IT IN THE OUTPUTTED STRING. THIS RETURNED STRING'S * LENGTH IS DETERMINED BY THE INTEGER, FORMATTEDSTRINGLENGTH. * * INPUTS: SOURCESTRING1 ---> STRING CONTAINING A STRING NEEDED TO BE CENTERED * SOURCESTRING2 ---> STRING CONTAINING A STRING NEEDED TO BE CENTERED * FORMATTEDSTRINGLENGTH ---> INTEGER SPECIFING THE LENGTH OF THE RETURNED STRING * * OUTPUT: A STRING THE LENGTH OF FORMATTEDSTRINGLEGTH THAT CENTERS THE SOURCESTRINGS */ string formattedString = ""; if (sourceString1.Length + sourceString2.Length < formattedStringLength) { int diference = (int) (formattedStringLength - sourceString1.Length - sourceString2.Length)/3; //only 2 spaces if (diference == 0 && formattedStringLength - sourceString1.Length - sourceString2.Length >= 2) { diference = 1; } //only 1 space if (diference == 0 && formattedStringLength - sourceString1.Length - sourceString2.Length == 1) return sourceString1 + " " + sourceString2; for (int i = 0; i < formattedStringLength; i++) { if (i < diference) formattedString = formattedString + " "; else if (i < sourceString1.Length + diference) { formattedString = formattedString + sourceString1; i = diference + sourceString1.Length - 1; } else if (i < sourceString1.Length + 2 * diference) { formattedString = formattedString + " "; } else if (i < sourceString1.Length + sourceString2.Length + 2 * diference) { formattedString = formattedString + sourceString2; i = sourceString1.Length + sourceString2.Length + 2 * diference - 1; } else formattedString = formattedString + " "; } return formattedString; } else return sourceString1 + sourceString2; } public static string centerString(string sourceString, int formattedStringLength) { /*THIS FUNCTION TAKES IN ONE STRINGS AND CENTERS IT IN THE OUTPUTTED STRING. THIS RETURNED STRING'S * LENGTH IS DETERMINED BY THE INTEGER, FORMATTEDSTRINGLENGTH. * * INPUTS: SOURCESTRING1 ---> STRING CONTAINING A STRING NEEDED TO BE CENTERED * FORMATTEDSTRINGLENGTH ---> INTEGER SPECIFING THE LENGTH OF THE RETURNED STRING * * OUTPUT: A STRING THE LENGTH OF FORMATTEDSTRINGLEGTH THAT CENTERS THE SOURCESTRING */ string formattedString = ""; if (sourceString.Length < formattedStringLength) { int diference = formattedStringLength - sourceString.Length; for (int i = 0; i < formattedStringLength; i++) { if (i < (int) diference/2) formattedString = formattedString + " "; else if (i < sourceString.Length + (int) diference/2) { formattedString = formattedString + sourceString; i = (int)diference / 2 + sourceString.Length - 1; } else formattedString = formattedString + " "; } return formattedString = formattedString.Substring(0,formattedStringLength); } else //forces it to be the right length return sourceString.Substring(0, formattedStringLength); }
#10
Posted 12 April 2012 - 06:48 PM
#11
Posted 12 April 2012 - 07:11 PM
#12
Posted 12 April 2012 - 08:43 PM
public static void wrtieCharbyCharLCD(Lcd lcd, string inputString, int cursorStartRow) { //Needs a string the width of the LCD. lcd.SetCursorPosition(0, cursorStartRow); //COLUMN ROW for (int i = 0; i < clConstants.LCDWIDTH; i++) { if (inputString[i].ToString() != " ") { Thread.Sleep(clConstants.DELAYBETWEENLCDWRITEMS); lcd.SetCursorPosition(i, cursorStartRow); lcd.Write(inputString[i].ToString()); } } }
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users