PhilR100742
Posts: 23
Joined: Thu Oct 31, 2019 7:52 pm

Re: MCP4725 DAC with LCD issues

Sun Nov 10, 2019 4:46 pm

Ok, here we go. I ran the install command in Terminal, the install line returned this:-

pi@raspberrypi:~/Adafruit_Python_CharLCD $ sudo python setup.py install
running install
running bdist_egg
running egg_info
creating Adafruit_CharLCD.egg-info
writing requirements to Adafruit_CharLCD.egg-info/requires.txt
writing Adafruit_CharLCD.egg-info/PKG-INFO
writing top-level names to Adafruit_CharLCD.egg-info/top_level.txt
writing dependency_links to Adafruit_CharLCD.egg-info/dependency_links.txt
writing manifest file 'Adafruit_CharLCD.egg-info/SOURCES.txt'
reading manifest file 'Adafruit_CharLCD.egg-info/SOURCES.txt'
writing manifest file 'Adafruit_CharLCD.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-armv7l/egg
running install_lib
running build_py
creating build
creating build/lib.linux-armv7l-2.7
creating build/lib.linux-armv7l-2.7/Adafruit_CharLCD
copying Adafruit_CharLCD/Adafruit_CharLCD.py -> build/lib.linux-armv7l-2.7/Adafruit_CharLCD
copying Adafruit_CharLCD/__init__.py -> build/lib.linux-armv7l-2.7/Adafruit_CharLCD
creating build/bdist.linux-armv7l
creating build/bdist.linux-armv7l/egg
creating build/bdist.linux-armv7l/egg/Adafruit_CharLCD
copying build/lib.linux-armv7l-2.7/Adafruit_CharLCD/Adafruit_CharLCD.py -> build/bdist.linux-armv7l/egg/Adafruit_CharLCD
copying build/lib.linux-armv7l-2.7/Adafruit_CharLCD/__init__.py -> build/bdist.linux-armv7l/egg/Adafruit_CharLCD
byte-compiling build/bdist.linux-armv7l/egg/Adafruit_CharLCD/Adafruit_CharLCD.py to Adafruit_CharLCD.pyc
byte-compiling build/bdist.linux-armv7l/egg/Adafruit_CharLCD/__init__.py to __init__.pyc
creating build/bdist.linux-armv7l/egg/EGG-INFO
copying Adafruit_CharLCD.egg-info/PKG-INFO -> build/bdist.linux-armv7l/egg/EGG-INFO
copying Adafruit_CharLCD.egg-info/SOURCES.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying Adafruit_CharLCD.egg-info/dependency_links.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying Adafruit_CharLCD.egg-info/requires.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying Adafruit_CharLCD.egg-info/top_level.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/Adafruit_CharLCD-1.1.1-py2.7.egg' and adding 'build/bdist.linux-armv7l/egg' to it
removing 'build/bdist.linux-armv7l/egg' (and everything under it)
Processing Adafruit_CharLCD-1.1.1-py2.7.egg
Removing /usr/local/lib/python2.7/dist-packages/Adafruit_CharLCD-1.1.1-py2.7.egg
Copying Adafruit_CharLCD-1.1.1-py2.7.egg to /usr/local/lib/python2.7/dist-packages
Adafruit-CharLCD 1.1.1 is already the active version in easy-install.pth

Installed /usr/local/lib/python2.7/dist-packages/Adafruit_CharLCD-1.1.1-py2.7.egg
Processing dependencies for Adafruit-CharLCD==1.1.1
Searching for Adafruit-GPIO==1.0.4
Best match: Adafruit-GPIO 1.0.4
Processing Adafruit_GPIO-1.0.4-py2.7.egg
Adafruit-GPIO 1.0.4 is already the active version in easy-install.pth

Using /usr/local/lib/python2.7/dist-packages/Adafruit_GPIO-1.0.4-py2.7.egg
Searching for spidev==3.3
Best match: spidev 3.3
Adding spidev 3.3 to easy-install.pth file

Using /usr/lib/python2.7/dist-packages
Searching for Adafruit-PureIO==0.2.3
Best match: Adafruit-PureIO 0.2.3
Processing Adafruit_PureIO-0.2.3-py2.7.egg
Adafruit-PureIO 0.2.3 is already the active version in easy-install.pth

Using /usr/local/lib/python2.7/dist-packages/Adafruit_PureIO-0.2.3-py2.7.egg
Finished processing dependencies for Adafruit-CharLCD==1.1.1
---------------------------------------------------------------------------------------------------------------
I'll move on to the next step now.

PhilR100742
Posts: 23
Joined: Thu Oct 31, 2019 7:52 pm

Re: MCP4725 DAC with LCD issues

Sun Nov 10, 2019 5:20 pm

2. After installation of LCD library now the Adafruit_python_CharLCD can be used from any python script by using the following line

import Adafruit_CharLCD as LCD​
Note you have to do this at the command line not in python , so assuming you are using a desktop version of raspbian you need to open a terminal window and run the commands in there.
-------------------------------------------------------------------------------------

Yes, I am using the desktop version of Raspian.

I'm not certain whether I properly understood step 2. as above. I ran the import line in Terminal, and got this:-

pi@raspberrypi:~/Adafruit_Python_CharLCD $ import Adafruit_CharLCD as LCD​
bash: import: command not found

I also tried the command when Terminal was in the Home/Pi directory, and had the same result.

Please correct me if I am wrong.

User avatar
DougieLawson
Posts: 36301
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: MCP4725 DAC with LCD issues

Sun Nov 10, 2019 6:33 pm

You need to add

Code: Select all

#!/usr/bin/python3
as the first line of your program so that bash feeds it into python3.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

pcmanbob
Posts: 7060
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: MCP4725 DAC with LCD issues

Sun Nov 10, 2019 6:42 pm

Ok so you did the install bit correctly by the look of it , that's the bit you needed to do at the command line in the terminal window.

The import bit is only ever run in a python program, never at the command line.

So try this to test just your LCD, its based on the code in the tutorial so it should work with your LCD as connected.

Code: Select all

import Adafruit_CharLCD as LCD    
import time

lcd_rs        = 25 
lcd_en        = 24
lcd_d4        = 23
lcd_d5        = 17
lcd_d6        = 18
lcd_d7        = 22
lcd_backlight = 4

# Define LCD column and row size for 16x2 LCD.
lcd_columns = 16
lcd_rows    = 2

lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
                           lcd_columns, lcd_rows, lcd_backlight)

lcd.message("Hello World")
time.sleep(5)
lcd.message(Raspberry Pi)
time.sleep(10)
lcd.clear()
Please ignore Dougie's suggestion the adafruit code was installed only for python 2 in the tutorial.


Dougie.
Having checked the adafruit git hub page for Adafruit Python CharLCD, it only mentions installing for python 2 , python 3 is never mentioned so I don't know if its supported, but its certainly not installed for python 3, please don't confuse the situation by suggesting the OP use python 3 at this stage.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

PhilR100742
Posts: 23
Joined: Thu Oct 31, 2019 7:52 pm

Re: MCP4725 DAC with LCD issues

Sun Nov 10, 2019 8:24 pm

pcmanbob,

I tried to run your code but had this message:-

>>> %Run 'Adafruit LCD test.py'
Traceback (most recent call last):
File "/home/pi/Desktop/Adafruit LCD test.py", line 21
lcd.message(Raspberry Pi)
^
SyntaxError: invalid syntax
>>>

So, no luck with that I'm afraid: Adafruit LCD test.py does exist in the Desktop directory though.

PhilR100742
Posts: 23
Joined: Thu Oct 31, 2019 7:52 pm

Re: MCP4725 DAC with LCD issues

Sun Nov 10, 2019 8:32 pm

Dougie,

I insert: #!/usr/bin/python3 as the first line of code. Running it rreturned this:-

>>> %Run 'MCP4725 code.py'
Traceback (most recent call last):
File "/home/pi/MCP4725 code.py", line 18, in <module>
lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
AttributeError: module 'Adafruit_CharLCD' has no attribute 'Adafruit_CharLCD'
>>>

After reading pcmanbob's post, I changed the first line to: #!/usr/bin/python2


The result:-

>>> %Run 'MCP4725 code.py'
Traceback (most recent call last):
File "/home/pi/MCP4725 code.py", line 18, in <module>
lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
AttributeError: module 'Adafruit_CharLCD' has no attribute 'Adafruit_CharLCD'
>>>

The same problem.

My brain now hurts!

User avatar
joan
Posts: 14348
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: MCP4725 DAC with LCD issues

Sun Nov 10, 2019 8:33 pm

There should be quotes around Raspberry Pi.

PhilR100742
Posts: 23
Joined: Thu Oct 31, 2019 7:52 pm

Re: MCP4725 DAC with LCD issues

Sun Nov 10, 2019 8:41 pm

Dougie,

your line: #!/usr/bin/python3 is commented out with the #

I tried deleting the # but got this returned:-

>>> %Run 'Adafruit LCD test.py'
Traceback (most recent call last):
File "/home/pi/Desktop/Adafruit LCD test.py", line 1
!/usr/bin/python3
^
SyntaxError: invalid syntax
>>>
I get the same when changing to python2.

User avatar
rpdom
Posts: 15353
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: MCP4725 DAC with LCD issues

Sun Nov 10, 2019 8:45 pm

PhilR100742 wrote:
Sun Nov 10, 2019 8:41 pm
Dougie,

your line: #!/usr/bin/python3 is commented out with the #
No, it isn't. The #! syntax on the first line of a script has a special meaning to the Linux command line (not the Python interpreter shell where you appear to be running it from.)

But as previously mentioned, that code doesn't appear to be support under Python3 yet, just Pythin2 which is the default in Buster.

PhilR100742
Posts: 23
Joined: Thu Oct 31, 2019 7:52 pm

Re: MCP4725 DAC with LCD issues

Sun Nov 10, 2019 8:47 pm

Joan,

Line 22 is this:-

lcd.message(Raspberry Pi)

PhilR100742
Posts: 23
Joined: Thu Oct 31, 2019 7:52 pm

Re: MCP4725 DAC with LCD issues

Sun Nov 10, 2019 8:49 pm

Dougie,

#!/usr/bin/python3

Ok, I didn't know that. However, the line is wholly greyed out in the IDE.

PhilR100742
Posts: 23
Joined: Thu Oct 31, 2019 7:52 pm

Re: MCP4725 DAC with LCD issues

Sun Nov 10, 2019 8:52 pm

Guys, I'm going to have to leave this for now. I'll get back to it tomorrow.

Thank you everyone for your input. :?

User avatar
DougieLawson
Posts: 36301
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: MCP4725 DAC with LCD issues

Sun Nov 10, 2019 8:58 pm

You may need to use

Code: Select all

#!/usr/bin/python
since it appears Adafruit aren't living in the same decade as the rest of us. It's a special comment known as a shebang line. https://en.wikipedia.org/wiki/Shebang_(Unix)
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

pcmanbob
Posts: 7060
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: MCP4725 DAC with LCD issues

Sun Nov 10, 2019 10:56 pm

PhilR100742 wrote:
Sun Nov 10, 2019 8:32 pm


>>> %Run 'MCP4725 code.py'
Traceback (most recent call last):
File "/home/pi/MCP4725 code.py", line 18, in <module>
lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
AttributeError: module 'Adafruit_CharLCD' has no attribute 'Adafruit_CharLCD'
>>>

The same problem.

My brain now hurts!
Not the same problem at least its finding the module now , but there appears to be a problem with the module.

Well the line at which the error is occurring is correct I looked in the example program on the git hub page.

So I have no idea why it should not work , but the program was last updated in sept 2017 and the git hub page has been locked to read only which suggests its been abandoned.

You could ask the writer of the tutorial for help , but I doubt help will be forth coming.

I would suggest you look at an LCD drive module that is still maintained like RPLCD : https://pypi.org/project/RPLCD/
and use that instead to drive you LCD.

Out of interest which version of raspbian are you using ?

Edit...

I tried running the install for the LCD on a fully updated raspbian stretch , it fails with an error which suggests the OS has moved on from the point at which the adafruit LCD module will work.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

PhilR100742
Posts: 23
Joined: Thu Oct 31, 2019 7:52 pm

Re: MCP4725 DAC with LCD issues

Mon Nov 11, 2019 4:45 pm

pcmanbob,

Ok, you appear to correct with this. I'll take a look at your suggested alternative. Yes, the video in the tutorial is hopeless; nothing useful in it!

Phil

pcmanbob
Posts: 7060
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: MCP4725 DAC with LCD issues

Mon Nov 11, 2019 4:49 pm

PhilR100742 wrote:
Mon Nov 11, 2019 4:45 pm
pcmanbob,

Ok, you appear to correct with this. I'll take a look at your suggested alternative. Yes, the video in the tutorial is hopeless; nothing useful in it!

Phil
If you need help setting up RPLCD to work with your existing connections , just ask and I will do a write up on installing and setting up .

I would suggest you start over with a fresh install of raspbian stretch or preferably buster, RPLCD will work with python 2 & 3.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “General discussion”