Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Issues with buttons and LCD


Best Answer hanzibal, 16 May 2013 - 12:20 AM

Sorry about the delay, couldn't find the code so I had to write it all over again  :rolleyes:

 

Anyway, attached is some code you can try. It's a small Hd44780 demo app using bit banging to drive the LCD. I wrote the app for the Mini but you should only need to change the pin assignments and using directives according to your board. It works perfectly on the Mini and hopefully it will on your board too.

 

Here's a couple of pictures showing what it should look like when running:

 

 

In the pictures the wiring may look funny because I use PWM to control brightness and contrast. That way I don't need any potentiometers and there's a few lines for this that you can uncomment if you want to use PWM. Should you decide to do so, first measure the currents to make sure you can drive the LCD straight off the PWM outputs. In my case the current is only some 4mA so it's fine.

 

 

Good luck!

 

 

Go to the full post


  • Please log in to reply
28 replies to this topic

#1 cce1911

cce1911

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts
  • LocationGeorgia, USA

Posted 21 April 2013 - 10:57 PM

Where do I start? Well, I'm new to Netduino and C#, but I'm experienced with VB.

 

I'm really struggling with getting my app to run. The app consists of buttons, LED's and a 2x16 LCD. I've worked through examples/tutorials of all three types and can get them to run just fine. However, when I put them all together, I get very strange results when trying to write to the LCD.

 

This app will control 3 relays and I'm starting out by collecting the configuration data. There are three "channels", one for each relay. Each channel will have 6 states (on or off time). The UI will work like this:

 

  • Press the channel button to toggle between the 3 channels
  • Press the state button to toggle between the 6 states

 

The other buttons are for increasing/decreasing the time value for that state and saving that value but I have not gotten that far. I'm using the MicroLiquidCrystal sdk for managing the LCD, but I get different results each time I compile and deploy the code. Sometimes the text will display and other times it won't. Sometimes it will work if I set a breakpoint and step through the code. But then I make a simple change and it won't display anymore.

 

My hardware is N2 running firmware ver 4.2.2. The LCD is: http://www.adafruit.com/products/181

 

The .jpg attached is the wiring diagram and I have it built on a breadboard. The code is attached as well.

 

My gut says the problem is in how I'm scoping the lcdDisplay object and or how the event handler works. I wish I could be more specific on exactly what is misbehaving, but I can't. I don't think I've got bad hardware because all the simple examples work. On the other hand, I'm not sure how I would figure this out without duplicate N2 and LCD hardware.

 

I can say that the hardware is wired correctly because the LED's light when they are supposed to and the buttons trigger events that are caught by their handlers. Unfortunately, I've searched this forum and Googled for hours, but not found anything that can point me in the right direction. 

 

If anyone has an idea, I'm all ears!

-Capel

 

Attached Files



#2 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 22 April 2013 - 11:53 AM

At first glance it looks fine. I have a feeling it's a timing issue with the LCD but not 100% sure. Reading the code on my iPad at the moment so it's not the easiest thing to do. I'll try to setup a repo in the lab when i get there this morning and see what I get.

#3 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 22 April 2013 - 11:57 AM

Hello Capel.

I wonder why many users continue to use the MicroLiquidCrystal library, which is very slow and takes a lot of code/ram.

 

For just an HC595 more, here is a blazing fast way to drive an HD44780-based lcd module.

http://tinyclr.it/th...lcd-module.aspx

I really don't know if that will solve your problem because I should try your code above and check where the problem is.

What I may say, is that the LcdBoost library yields only benefits, with a fraction of the uLiquidCrystal code size.

Cheers


Biggest fault of Netduino? It runs by electricity.

#4 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 22 April 2013 - 02:46 PM

Hello Capel.

I wonder why many users continue to use the MicroLiquidCrystal library, which is very slow and takes a lot of code/ram.

 

For just an HC595 more, here is a blazing fast way to drive an HD44780-based lcd module.

http://tinyclr.it/th...lcd-module.aspx

I really don't know if that will solve your problem because I should try your code above and check where the problem is.

What I may say, is that the LcdBoost library yields only benefits, with a fraction of the uLiquidCrystal code size.

Cheers

 

There's an easy answer to that one Mario... not many people know there are alternatives.  When you search for solutions to connecting and driving hitachi based LCDs to Netduinos the MicroLiquidCrystal Library is the most often found.  I dealt with that early in my projects also.  I still use it but it is highly modified (removed unused files to slim it down).  When I have time I will be creating a new one based on my changes from the ground up.



#5 cce1911

cce1911

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts
  • LocationGeorgia, USA

Posted 22 April 2013 - 03:48 PM

At first glance it looks fine. I have a feeling it's a timing issue with the LCD but not 100% sure. Reading the code on my iPad at the moment so it's not the easiest thing to do. I'll try to setup a repo in the lab when i get there this morning and see what I get.

 

Dave,

I would certainly appreciate you taking a look at my code to see if anything jumps out at you.

 

Mario, Dave hit the nail on the head. I looked high and low and found MicroLiquidCrystal. I just looked at the URL you posted, but it's a little over my head at the moment. First, I'm not using a shift register. If you could point me at some other examples of using a 2x16 LCD, I'm willing to try it.

-Capel



#6 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 22 April 2013 - 03:53 PM

Hey Capel,

 

I created a repro of your project on the bench using the exact same parts right down to the 181 LCD.  Code compiled and installed without an issue.  So far I've had no glitches with the LCD.

 

What I did notice is inconsistent use of the Set Position within all of your methods.  I am not seeing your htstate write to the LCD and I believe this is because you are not setting the position before each write.

 

I've made some more enhancements to the LCD classes that may benefit you.  I'll try to post them later.  They will help you with clearing the lines instead of using "   " to clear them.



#7 cce1911

cce1911

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts
  • LocationGeorgia, USA

Posted 23 April 2013 - 01:41 AM

Dave,

Is it a requirement that you must set the position before every write? Somehow I assumed that once you set it, that's where it would start writing every time.

 

BTW, did the LCD show "Ready!" on the 2nd line before you pressed any button?

-Capel



#8 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 23 April 2013 - 01:47 AM

Dave,

Is it a requirement that you must set the position before every write? Somehow I assumed that once you set it, that's where it would start writing every time.

 

BTW, did the LCD show "Ready!" on the 2nd line before you pressed any button?

-Capel

I believe the way that class is written you need to set it each time.  I changed my classes so I pass a row, column parameter in the write each time.  I'll post some of that code tomorrow.

 

Yes I saw the Ready.  The Channel also showed using the channel button.  All else didn't show.



#9 cce1911

cce1911

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts
  • LocationGeorgia, USA

Posted 23 April 2013 - 02:41 AM

I believe the way that class is written you need to set it each time.  I changed my classes so I pass a row, column parameter in the write each time.  I'll post some of that code tomorrow.

 

Yes I saw the Ready.  The Channel also showed using the channel button.  All else didn't show.

 

First, I'm not seeing the "Ready" every time, but I do see the "Channel #n" every time. When I press the 2nd button, I'm not seeing anything displayed, So this is similar to what you are seeing.

 

Does this behavior sound like a s/w problem or a h/w problem?



#10 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 23 April 2013 - 03:02 AM

Sounds more like a hardware issue (wiring or loose wiring).  I made a few mods to the program and it works fine here.  All the writes show up all the time.



#11 cce1911

cce1911

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts
  • LocationGeorgia, USA

Posted 28 April 2013 - 01:22 AM

I believe the way that class is written you need to set it each time.  I changed my classes so I pass a row, column parameter in the write each time.  I'll post some of that code tomorrow.

Dave,

Would you mind posting your version of MicroLiquidCrystal?

-Capel



#12 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 28 April 2013 - 02:19 AM

Mario, Dave hit the nail on the head. I looked high and low and found MicroLiquidCrystal. I just looked at the URL you posted, but it's a little over my head at the moment. First, I'm not using a shift register. If you could point me at some other examples of using a 2x16 LCD, I'm willing to try it.
-Capel

Guys, Mario's library is generic and works with any character Hd44708 based LCD. It's as fast as ever possible, it's a simple schematic and all you need is shiftregister.

I made my own design with an i2c controlled 8 bit paralellport which is fast too but I'm switching to Mario's now that I know it exists :-) It uses SPI to boost performance by clocking in the bits into the shiftregister with great speed. Plus, the library is top knotch.

Everything you need is in the article, including samples:
http://tinyclr.it/th...lcd-module.aspx

#13 cce1911

cce1911

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts
  • LocationGeorgia, USA

Posted 28 April 2013 - 03:02 AM

I can't get the second line of my LCD to display even when setting the contrast to full brightness. Since this is my first LCD, does this sound like a bad board or that I have something wired wrong?



#14 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 28 April 2013 - 08:50 AM

I had the exact same problem at some point. In my case, the clocking was wrong, that is, the E pin (chip enable / clock enable) was not being toggled as it should. Make sure your data bits are all set when raising the E pin, then lower it again. ...or, you could just use Mario's library ;-) Just kidding, doing the stuff your self is twice the fun and ten times more educational.

#15 cce1911

cce1911

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts
  • LocationGeorgia, USA

Posted 29 April 2013 - 02:10 PM

I had the exact same problem at some point. In my case, the clocking was wrong, that is, the E pin (chip enable / clock enable) was not being toggled as it should. Make sure your data bits are all set when raising the E pin, then lower it again. ...or, you could just use Mario's library ;-) Just kidding, doing the stuff your self is twice the fun and ten times more educational.

So I take it you were not using the MicroLiquidCrystal library?



#16 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 29 April 2013 - 03:00 PM

No, that was actually from an old test where I was bit banging the LCD using the hd44708 driver from Stefan's Toolbox. The LCD only displayed 16 fully filled rectangular characters on the first row. I think is what the LCD looks like when not configured correctly. You could try putting a 10 second delay between the pin writes and debug using 5 x LEDs, each connected from the respective pin to ground via a 1k resistor. You could do this for the EN, d4, d5, d6 and d7 pins while printing out the values using Debug.Print. The delay will give you time to see what is going on. EDIT: Before trying the above, you could see if it helps pulling the unused pins (d0, d1, d3 and d4) of the LCD to ground via a 100k resistor. Floating pins can sometimes result in erratic behavior.

#17 cce1911

cce1911

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts
  • LocationGeorgia, USA

Posted 15 May 2013 - 03:22 AM

Hanz,

Well I'm still getting intermittent behavior with the second line of the display. I grounded D0-D4 with a 100k resistor as you suggested and that did not resolve the problem. I purchased another 16x2 LCD from Adafruit and that did not solve the problem. I've even ported my code to a N+2 and I'm still seeing the issue of sometimes being able to see line 2 but most of the time I can't. If I unplug the USB cable to reboot, hold my jaw just right and I'm not wearing any socks, the 2nd line will sometimes work. All joking aside, I'm convinced its not a hardware problem.

 

You mentioned that it could be an issue with clocking. I assume this would be in the MicroLiquidCrystal library correct? Would a shift register and Mario's library solve the problem?



#18 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 15 May 2013 - 05:20 AM

I agree, it's hardly a h/w error "anymore". Using a shiftregister would probably help but you need to change your wiring to use SPI with the shift register and probably have to use a different library (e.g. Mario's) too. Before trying that, I could post you some code to try when I'm home after work today. That code would be more or less a drop in replacement.

#19 cce1911

cce1911

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts
  • LocationGeorgia, USA

Posted 15 May 2013 - 01:17 PM

I agree, it's hardly a h/w error "anymore". Using a shiftregister would probably help but you need to change your wiring to use SPI with the shift register and probably have to use a different library (e.g. Mario's) too. Before trying that, I could post you some code to try when I'm home after work today. That code would be more or less a drop in replacement.

 

Any suggestions you have would be appreciated.



#20 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 16 May 2013 - 12:20 AM   Best Answer

Sorry about the delay, couldn't find the code so I had to write it all over again  :rolleyes:

 

Anyway, attached is some code you can try. It's a small Hd44780 demo app using bit banging to drive the LCD. I wrote the app for the Mini but you should only need to change the pin assignments and using directives according to your board. It works perfectly on the Mini and hopefully it will on your board too.

 

Here's a couple of pictures showing what it should look like when running:

 

Attached File  LCD-1.JPG   81.1KB   20 downloads

Attached File  LCD-2.JPG   78.75KB   21 downloads

 

In the pictures the wiring may look funny because I use PWM to control brightness and contrast. That way I don't need any potentiometers and there's a few lines for this that you can uncomment if you want to use PWM. Should you decide to do so, first measure the currents to make sure you can drive the LCD straight off the PWM outputs. In my case the current is only some 4mA so it's fine.

 

 

Good luck!

 

 

Attached File  Hd44780Test.zip   4.55KB   4 downloads






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.