Raspberry Pi Project Progress— LCD Screen PT 3

To catch you up on parts one and two: setting up the LCD screen I had with a pin adapter (to use only 4 instead of 16) was trickier than anticipated. Most of the code I was using had been with the 16 pins in mind and not my particular setup with the extension board. So, I was stuck for a few days with one “dead end” of an error code.

After a much needed break, I processed all that I had learned, read, and tested during my previous attempts. This morning I didn’t intend to mess around with the Raspberry Pi, but after taking a few classes on Team Treehouse, I felt inspired to give it another go.

With a fresh mind, I decided to go back to the original source I was following for my particular kit and setup. The reason why I hadn’t used this code in the first place was because it was for a more complicated program than what I was trying to setup. But then I went back to the instructions and tried to setup the more complicated program. Although that still didn’t run, it did help me create a must-needed file for my setup.

Then, after trial and error of various forms of code, I noticed that the LCD screen began to blink. The blinking matched up to the code of five seconds. Finally, I had received some sign that the communication between the components was working. But, the screen was too bright and there was no text. Then, I remembered from all of my reading the previous days from various sources and forum responses that the nob on the back of the LCD screen needs to be adjusted sometimes. So, I adjusted it, and black text boxes appeared. One step closer!

Finally, I looked at the code for the more complicated program and started deleting the stuff that I didn’t think I needed. After more trial and error of deleting, altering, and re-entering code, the LCD screen finally lit up with the famous words: Hello World!

But it wasn’t perfect. There were some strings of code running across the screen that shouldn’t have been there. After I finally isolated the code that ended up working and saving a new file, I tested it again to see if the fix was complete. After a couple of more trial and errors, unpinning and re-pinning the wires…it finally worked!

Here were the main issues:

  • This setup required a code specifically for the GPIO extension board and ic2 connection. Out of all the sources I had researched online, none had the exact address specifications that this required except for the example code in the ultimate beginner kit tutorial book.
  • This here was the key factor in getting the code to run:

PCF8574_address = 0x27  # I2C address of the PCF8574 chip.
PCF8574A_address = 0x3F  # I2C address of the PCF8574A chip.
# Create PCF8574 GPIO adapter.
try:
mcp = PCF8574_GPIO(PCF8574_address)
except:
try:
mcp = PCF8574_GPIO(PCF8574A_address)
except:
print (‘I2C Address Error !’)
exit(1)

  • I had also created another file titled PCF8574.py with code from GitHub by Freenove.
  • Another step that was important were these imports:

from PCF8574 import PCF8574_GPIO
from Adafruit_LCD1602 import Adafruit_CharLCD

Admittedly, my best friend was FaceTiming me as I was doing this, and when the code ran the second time across the LCD screen I was so happy to share that moment with someone. I screamed in excitement and showed my friend the words across the screen, and she called over her daughter to see as well.

Small backstory: My best friend’s daughter is incredibly smart, and a Minecraft Master, so I’ve been trying to pass on the coding bug to her through Minecraft. I sent her the whole code of Minecraft and told her to just read it and see if it made any sense. When she came over to the screen to see the Raspberry Pi, I showed her the code and explained what the experiment was and how it worked.

But we all know that seeing is believing. So I told Sammy that I would make the screen say her name. A couple of clicks later, the screen displayed “Hello Sammy!” and I showed it to her. She was elated with a big smile, as if I had performed a magic trick!

What a rewarding moment. I had imagined what the moment would be like when I got this to work, I had even accepted the fact that it may not work, and that I would have to try a different route completely, but I never expected it all to have unfolded in such a beautiful way.

I think what made this time different than the previous was that I wasn’t going by too many forums or outside advice. I just used the one code from the direct source, all I had learned from, and tried to get it to work from there the way I wanted. And it did!

Through this project I realized my pattern for learning will be exactly this: study through online sources like Team Treehouse and Udemy, and then take “breaks” with Raspberry Pi projects. The back and forth of the two helps me not rush through the online programs too fast. I don’t want to just pretend like I’ve learned this, I want to really learn this, and therefore I want to pace it in a way that truly allows my brain to digest all of the new information.

I ended the fun project by sharing the news with my friend and the forum I had gone to help for in the previous attempt. I’ve never really been an active forum member before, but I see now how some online communities can be really comforting and helpful!

Now, onto the next project!

Leave a comment