sutekh137 2 Posted May 14, 2013 Share Posted May 14, 2013 Hey all, I recently got a Nokia 5110 LCD working using the LCD_5110 lib from GitHub. Works great, so thanks to giants whose shoulders I stand atop! I moved my chip (G2553) directly to the board as I have done several times before (with a pullup resistor on RST), and I loaded a little demo program on it with my "loader" board (just TEST, RST, GND, and VCC hooked up to the emulation side of an LP). Program loads and runs fine, but when I remove the loader and cycled power (I was just changing battery sources from a 6V pack to a 9V battery -- they are dropped to 3.3V), the LCD does not init properly. Sometimes resetting (disconnecting the RST pullup) would make it come back, sometimes not. The weird thing is that the sketch IS running, because the ISR to toggle the backlight DOES work -- but no text displays on the screen. When it gets this way, I hook up the loader again, flash the same program, and then everything works fine. If I unhook the loader and cycle the power, though, I am back to no text on screen. Am I initializing the screen incorrectly or doing something wrong in terms of power cycling and/or resetting? [incidentally, you'll see in the constructor for LCD_5110 that I use zero for the getButton() pin -- I don't need a button-getter, and would rather use my own button handling code instead of calling the LCD's getButton() method. What is the best way to call the constructor in that case? The zero works (compiles, anyway), and it looks like getButton() just hangs the program if I ever call it (so I won't). But surely I am missing something to use such an inelegant methodology...] Any help would be appreciated! Thanks, sutekh137 Sketch: //System/library includes. #include <LCD_5110.h> // Defines... #define TOGGLE_BACKLIGHT PUSH2 // Instantiate the Nokia 5110 LCD class (non-SPI): // LCD_5110 lcd(Chip Select, Serial Clock, Serial Data, Data/Command, Reset, Backlight, getButton() Trigger) LCD_5110 lcd(12, 13, 14, 15, 18, 19, 0); boolean glBacklight = false; void setup() { // Button will toggle back light using an ISR. pinMode(TOGGLE_BACKLIGHT, INPUT_PULLUP); attachInterrupt(TOGGLE_BACKLIGHT, ISR_ToggleBacklight, FALLING); lcd.begin(); lcd.setBacklight(glBacklight); lcd.text(0, 0, "Hello!"); delay(1000); lcd.clear(); lcd.text(0, 5, "Light off"); } void loop() { lcd.setFont(0); lcd.text(0, 5, glBacklight ? "Light on " : "Light off"); lcd.setFont(1); lcd.text(0, 2, " MSP430"); delay(200); } void ISR_ToggleBacklight() { delayMicroseconds(1000); if (digitalRead(TOGGLE_BACKLIGHT) != LOW) { return; } glBacklight = (glBacklight == 0); lcd.setBacklight(glBacklight); return; } Quote Link to post Share on other sites
semicolo 39 Posted May 14, 2013 Share Posted May 14, 2013 Maybe using a R/C reset circuit on the screen would help. When I read the datasheet of this screen, the part saying you can damage it if not reset correctly freaked me out and I didn't bother trying to do it in software. I used a 4.7K resistor and a 100nF capacitor (I had them on hand), 47K/10nF will work too. Quote Link to post Share on other sites
chibiace 46 Posted May 15, 2013 Share Posted May 15, 2013 maybe put some delays around lcd.begin see if that does anything. Quote Link to post Share on other sites
sutekh137 2 Posted May 15, 2013 Author Share Posted May 15, 2013 Thanks for the responses! Both very good ideas... I was going to try messing with the "begin" code (e.g. delays) last night, but had zero time to project. semicolo, I should definitely go look at the datasheet and work on a circuit...great idea. I had not heard the screen was so finicky about RST, but since the backlight works fine (but no text), it feels like something resett-y is in order. I hope I'm not damaging my screen, cheap as they are (they are down to around 3 bucks these days...pretty sweet! And less soldering than a standard 16x2 LCD, a good thing when you suck at soldering like I do. *smile*). Your circuit is extremely elegant, I'm quite jealous! Basically, this is just acknowledging that the RST on the LCD needs a pull-up, much like the LP itself? Is that right? I didn't run across anyone else mentioning the need to do that, but it makes sense. By the way, I assume I can add that circuit to either "side" of the LCD board, correct? It's nifty that they put pin-holes on both sides. My LCD has the same order of pins as in your picture, but most docs I found early on have a different order... Thanks so much! sutekh137 Quote Link to post Share on other sites
sutekh137 2 Posted May 15, 2013 Author Share Posted May 15, 2013 Hm, in looking more closely at the LCD_5110 lib, I think my use of zero for the button pin is a bad idea. Not sure what happens when you try to set pinMode() on pin zero? I think I will tweak that lib to check for that property being zero (and also make getButton() not hang, probably) throughout the library cpp. I suppose I could even make a new constructor for folks who don't want to use getButton(). In any case, I see all kinds of tweaks I can make to initialization (you are right -- it is very finicky according to the comments over on SparkFun for the unit!) including the init commands that are sent and delays between taking RST low then high. Adding your hardware solution certainly won't hurt, looks kind of fun! Thanks again, sutekh137 Quote Link to post Share on other sites
semicolo 39 Posted May 15, 2013 Share Posted May 15, 2013 It's just an RC low pass filter, it holds Reset to ground when you apply power and after some time the capacitor is charged and the reset pin state becomes 1, no need to connect reset to the MCU at all. I'll try rotating the capacitor to leave more room for the screw hole next time I add this circuit. Quote Link to post Share on other sites
sutekh137 2 Posted May 15, 2013 Author Share Posted May 15, 2013 Ah, I see, a COMPLETE hardware solution. Very cool. I'll definitely remember that if I go all the way to freeing up a pin (which could happen when I hook up a 4x4 matrix keypad = pin eater). As far as the "software" reset (well, using a pin, but driving RST through low/high cycling), the Arduino library I found uses a delay of 500 ms between LOW and HIGH and the LCD_5110 for Energia uses 100 ms (with a correct reference to the datasheet in the comments). So, I'll play around, and hope I don't break anything. *smile* Thanks, sutekh137 Quote Link to post Share on other sites
chibiace 46 Posted May 15, 2013 Share Posted May 15, 2013 this is what im using void init(void){ P1OUT &= ~SCLK+DIN+DC+CE+RST; __delay_cycles(50000); P1OUT |= RST; P1OUT &= ~CE; shift(instruction, 0x21); shift(instruction, 0xC5); shift(instruction, 0x12); shift(instruction, 0x20); shift(instruction, 0x09); shift(instruction, 0x0C); P1OUT |= CE; } i even removed the delay and it works ok. Quote Link to post Share on other sites
sutekh137 2 Posted May 16, 2013 Author Share Posted May 16, 2013 Here is the begin() method in the LCD_5110 library for Energia (current from GitHub): void LCD_5110::begin() { pinMode(_pinChipSelect, OUTPUT); pinMode(_pinReset, OUTPUT); pinMode(_pinDataCommand, OUTPUT); pinMode(_pinSerialData, OUTPUT); pinMode(_pinSerialClock, OUTPUT); pinMode(_pinBacklight, OUTPUT); pinMode(_pinPushButton, INPUT_PULLUP); digitalWrite(_pinDataCommand, LOW); delay(30); digitalWrite(_pinReset, LOW); delay(100); // as per 8.1 Initialisation digitalWrite(_pinReset, HIGH); write(_commandLCD, 0x21); // chip is active, horizontal addressing, use extended instruction set write(_commandLCD, 0xc8); // write VOP to register: 0xC8 for 3V Quote Link to post Share on other sites
semicolo 39 Posted May 16, 2013 Share Posted May 16, 2013 P1OUT |= RST; P1OUT &= ~CE; ... P1OUT |= CE; The first should set the reset pin to 1, the second clears CE, the last sets CE to 1 (should because RST and CE must contain the right values) It should work if you connect the power of the screen to an output pin, expect a voltage drop if you're using the backlight, but the screen is supposed to work correctly. Edit: corrected the line about the backlight. Quote Link to post Share on other sites
Taggsladder 2 Posted September 20, 2016 Share Posted September 20, 2016 Major bump I have the same problem. It works perfect except I need to reset the mcu after every powercycle or else the lcd stays completly blank. I could live with it but its just bugs the h*** out of me. Just basic sketch. In the code below I used a IO pin for powering the LCD but also tried powering from VCC with no luck. // Include LCD library. #include "LCD_5110.h" LCD_5110 myScreen; const int lcdVdd = P1_4; void setup() { pinMode(lcdVdd, OUTPUT); digitalWrite(lcdVdd, HIGH); myScreen.begin(); // Start LCD communication. myScreen.clear(); // Clear LCD. myScreen.setFont(0); // Set "small" font. myScreen.text(4, 2, "TEST"); // Display on LCD. } void loop() { } Tried it with the Maybe using a R/C reset circuit on the screen would help. When I read the datasheet of this screen, the part saying you can damage it if not reset correctly freaked me out and I didn't bother trying to do it in software. I used a 4.7K resistor and a 100nF capacitor (I had them on hand), 47K/10nF will work too. 5110reset.jpg Tried with and with out this. No difference. this is what im using void init(void){ P1OUT &= ~SCLK+DIN+DC+CE+RST; __delay_cycles(50000); P1OUT |= RST; P1OUT &= ~CE; shift(instruction, 0x21); shift(instruction, 0xC5); shift(instruction, 0x12); shift(instruction, 0x20); shift(instruction, 0x09); shift(instruction, 0x0C); P1OUT |= CE; } i even removed the delay and it works ok. Tried the library as is and tried changing the myScreen.begin(); function to something similiar: void LCD_5110::begin() { pinMode(_pinChipSelect, OUTPUT); pinMode(_pinReset, OUTPUT); pinMode(_pinDataCommand, OUTPUT); pinMode(_pinSerialData, OUTPUT); pinMode(_pinSerialClock, OUTPUT); pinMode(_pinBacklight, OUTPUT); pinMode(_pinPushButton, INPUT_PULLUP); delay(500); digitalWrite(_pinReset, HIGH); digitalWrite(_pinDataCommand, LOW); write(_commandLCD, 0x21); // chip is active, horizontal addressing, use extended instruction set write(_commandLCD, 0xc8); // write VOP to register: 0xC8 for 3V Quote Link to post Share on other sites
Taggsladder 2 Posted September 21, 2016 Share Posted September 21, 2016 [sOLVED] > QUICK AND DIRTY I got it working now. Not the best way but it does the job. Just a personal project so no worries. Running the initializing function two times with a delay did the trick for me. // Include LCD library. #include "LCD_5110.h" LCD_5110 myScreen; void setup() { myScreen.begin(); // Start LCD communication. delay(1000); myScreen.begin(); // Start LCD communication. myScreen.clear(); // Clear LCD. myScreen.setFont(0); // Set "small" font. myScreen.text(4, 2, "TEST"); // Display on LCD. } void loop() { } Have a nice day! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.