1

I'm trying to build a clock with an Adafruit 16x2 LCD and my RasPi B+ using Adafruit's tutorial. It works fine at first, but it will start displaying gibberish after a couple seconds. Any ideas as to what might be causing this?

The proper output is the current time and date in UTC (_ = space):

_ _ 10:12:13 _ UTC _ _
_ _ _ 12/25/2017 _ _ _

My code, based on the code in the tutorial:

#!/usr/bin/python

from Adafruit_CharLCD import Adafruit_CharLCD
from time import sleep, strftime
from datetime import datetime

lcd = Adafruit_CharLCD()

lcd.begin(16, 1)

while 1:
    lcd.clear()
    lcd.message(datetime.utcnow().strftime('  %T UTC\n'))
    lcd.message(datetime.utcnow().strftime('   %m/%d/%Y'))
    sleep(1)
  • It could be a wiring error, perhaps a pin floating. Can you show a picture of the setup and a schematic or description of the wiring? Can you try one of Adafruit's example programs to exclude programming errors? Do you supply the display with 5V? – Frepa Jul 30 '15 at 11:11
2

I think that the problem may be that you are not resetting the cursor position inside the loop. Generally, these LCD libraries append the next string that you give it wherever you left off, as you can see in your code, where the '\n' will have the next line start on the bottom row. After the first loop however, you are out of the LCDs range, and I would imagine that it is handling that poorly. Try adding the setCursor command like the following right before you write the strings:

while 1:
    lcd.clear()
    lcd.setCursor(3,0) #rows start at 0
    lcd.message(datetime.utcnow().strftime('%T UTC'))
    lcd.setCursor(4,1)
    lcd.message(datetime.utcnow().strftime('%m/%d/%Y'))
    sleep(1)
| improve this answer | |
  • 1
    This one should be marked as the answer. – 88weighed Oct 6 '17 at 9:45
1

I could never get the Adafruit examples working past a simple "hello world".

I would try tmwilson26's answer - however if all else fails I wrote my own library to display text on an lcd display.

https://github.com/mikestreety/pypi-lcdscreen

Give it a go and see if it helps!

| improve this answer | |
0

I'm a year late and I'm sure you have figured it out, but I had a similar issue.

I'm doing some prototyping. I get the PI going on the TV, then unplug the HDMI and transfer it to the prototype and start plugging things in...this is when my screen starting showing gibberish.

My program had my screen displaying temperature and humidity information, that would be updated every 15 seconds. I simply added a screen initialization everytime it went to update. This meant I'd get a flash as the particular line on the screen went black then refilled with the new information.

This seemed to fix it for me.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.