Skip to content

Issues running code #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BongoEADGC6 opened this issue Oct 14, 2016 · 25 comments
Closed

Issues running code #3

BongoEADGC6 opened this issue Oct 14, 2016 · 25 comments

Comments

@BongoEADGC6
Copy link

I'm trying to get responses from my leds on ports 0,1,2. The script runs with "sudo bin/fpulse tlc5947 conf/morse.py" but it just hangs and get no response.

Anything thoughts? Thanks.

@wrobell
Copy link
Owner

wrobell commented Oct 14, 2016

I would double check the connection to the board, see https://github.com/wrobell/fpulse/blob/master/fpulse/driver/tlc5947.py.

Also, can you check if the following command works for you?

sudo bin/fpulse print conf/morse.py

If you are sure the connection is solid and above command works for you, can you send log file generated as root

strace -o logfile bin/fpulse print conf/morse.py

@BongoEADGC6
Copy link
Author

BongoEADGC6 commented Oct 15, 2016

Print shows me the following:

fff0000000000000
0ff0000000000000
f000000000000000
fff0000000000000
0000000000000000
0ff0000000000000
f0f0000000000000
0f00000000000000
f0f0000000000000
f000000000000000
0f00000000000000
0000000000000000

fpulse.txt this log file is the output from strace.

Thank you for getting back to me. Trying to control some LEDs and make them dimmable.

@wrobell
Copy link
Owner

wrobell commented Oct 17, 2016

The strace log is for the command with "print" driver. Sorry my fault. Can I ask you to provide the stacktrace for this command

strace -o logfile bin/fpulse tlc5947 conf/morse.py

Thanks.

@BongoEADGC6
Copy link
Author

I linked it in the comment above

https://github.com/wrobell/fpulse/files/531446/fpulse.txt

@wrobell
Copy link
Owner

wrobell commented Oct 18, 2016

The file you linked above is executed for "print" driver (see the first line of the stack trace). Please provide the stack trace file for tlc5947 driver with command (as root):

strace -o logfile bin/fpulse tlc5947 conf/morse.py

@ravipurigen
Copy link

ravipurigen commented Apr 7, 2017

hey, I am having trouble running the code as well.... below is my stacktrace
I have double checked the LD_LIBRARY_PATH where the path for libbcm2835.so is listed
I also added a print statement right before the ct.CLL on line 52 in tlc5947.py for debug on the terminal but I dont see the path being printed
path ='/home/pi/Documents/bcm2835-1.52/src/libbcm2835.so'
print(path)
self._lib = ct.cdll.LoadLibrary(path)
let me know if more information is necessary..

Thanks for sharing the library !!

logfile.txt

@wrobell
Copy link
Owner

wrobell commented Apr 7, 2017

@ravipurigen, how do you set LD_LIBRARY_PATH?

@ravipurigen
Copy link

ravipurigen commented Apr 7, 2017

I added it to the end of file as
nano $HOME/.bashrc
LD_LIBRARY_PATH = /home/pi/..../bcm2835-1.52/src (src is where the library was built and it has all the files)
export LD_LIBRARY_PATH
when i type the command env on the terminal i don't see the export LD_LIBRARY_PATH variable too
shouldn't it print the path as mentioned in previous path, even before trying to load the library ?

@wrobell
Copy link
Owner

wrobell commented Apr 7, 2017

Can you show output of two commands

echo $LD_LIBRARY_PATH
ls -l /home/pi/Documents/bcm2835-1.52/src

BTW. I can see you use spaces before and after = when setting LD_LIBRARY_PATH. Please ensure you do not have them, for example

$ export LD_LIBRARY_PATH=" /home/wrobell/projects/fpulse/bcm2835-1.52/src"
$ python t.py                                                             
Traceback (most recent call last):
  File "t.py", line 3, in <module>
    print(ct.CDLL('libbcm2835.so'))
  File "/usr/lib/python3.6/ctypes/__init__.py", line 344, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libbcm2835.so: cannot open shared object file: No such file or directory

$ export LD_LIBRARY_PATH="/home/wrobell/projects/fpulse/bcm2835-1.52/src" 
$ python t.py                                                            
<CDLL 'libbcm2835.so', handle 1122590 at 0x7f46e7d6bb00>
$ cat t.py
import ctypes as ct

print(ct.CDLL('libbcm2835.so'))

@wrobell
Copy link
Owner

wrobell commented Apr 7, 2017

BTW. I had a problem compiling latest bcm2835 library on my laptop. The -fPIC parameter is required

    $ cd bcm2835-{VER}
    $ ./configure CFLAGS=-fPIC
    $ make clean
    $ make
    $ cd src
    $ gcc -shared bcm2835.o -o libbcm2835.so -fPIC

@ravipurigen
Copy link

Thanks for pointing out the error I updated the LD_LIBRARY_PATH and it shows up on the env list
env-text.txt
list-text.txt

I also, built the library using the flag you mentioned... it still gives the same error
OSError: libbcm2835.so: cannot open shared object file: No such file or directory

@wrobell
Copy link
Owner

wrobell commented Apr 7, 2017

Can you try this command please (should it be /home/pi/Documents/LEDIndicatorSystem/bcm2835-1.52/src or /home/pi/Documents/bcm2835-1.52/src?):

LD_LIBRARY_PATH=/home/pi/Documents/LEDIndicatorSystem/bcm2835-1.52/src python

Then type:

import ctypes as ct
print(ct.CDLL('libbcm2835.so'))

@ravipurigen
Copy link

Yes, I manually typed in so missed the LEDIndicatorSystem folder sorry about that....
I did and got an invalid ELF header error :(
snapshot

@wrobell
Copy link
Owner

wrobell commented Apr 8, 2017

Can you please show output of the command

file libbcm2835.so

The error you are getting means that probably, the library you compiled, is not a shared library.

@ravipurigen
Copy link

The output is
libbcm2835.so: current ar archive

@wrobell
Copy link
Owner

wrobell commented Apr 8, 2017

This is static library then. Please use the exact commands from the README file to compile the library.

@ravipurigen
Copy link

I found a problem with the .so file and recompiled it with the flag -fPIC as mentioned in the README
(The invalid elf header problem was because of the file had 0 length of bytes)
the print command works with the following output
fff0000000000000
0ff0000000000000
f000000000000000
fff0000000000000
0000000000000000
0ff0000000000000
f0f0000000000000
0f00000000000000
f0f0000000000000
f000000000000000
0f00000000000000
0000000000000000
But when i run
sudo fpulse tlc5947 /home/pi/...path to/conf/test.conf
or
sudo fpulse tlc5947 /home/pi/...path to../conf/morse.conf
The terminal hangs and there is no output but i am able to terminate it using the ctrl+c
I have double checked the connection to match the pin output (I am using Raspberry Pi compute module lite) from the tlc5947.py file
Do you think I am missing anything while installing the fpulse module ?
$ sudo python setup.py install
It should atleast print the debug print statement just before loading the libbcm2835.so

@wrobell
Copy link
Owner

wrobell commented Apr 9, 2017

Can you debug please and tell me where exactly it hangs?

@ravipurigen
Copy link

I am new both to python and linux so could you please share few links/sources that can help me to debug it ?
I don't see an output when I run the command , does it show any output on the terminal after the command ( sudo fpulse tlc5947 /home/pi/...path to../conf/morse.conf) is run ?

@wrobell
Copy link
Owner

wrobell commented Apr 11, 2017

Please try something like this

$ PYTHONPATH=. python -m pdb ./bin/fpulse tlc5947 conf/morse.conf
> /home/wrobell/projects/fpulse/bin/fpulse(21)<module>()
-> from fpulse.core import start
(Pdb) n
> /home/wrobell/projects/fpulse/bin/fpulse(23)<module>()
-> import argparse
(Pdb) 
> /home/wrobell/projects/fpulse/bin/fpulse(25)<module>()
-> parser = argparse.ArgumentParser(description='fpulse 0.1.0.')
(Pdb) 
> /home/wrobell/projects/fpulse/bin/fpulse(26)<module>()
-> parser.add_argument(
(Pdb) 
> /home/wrobell/projects/fpulse/bin/fpulse(27)<module>()
-> 'driver', choices=['print', 'tlc5947'], help='fpulse LED driver'
(Pdb) 
> /home/wrobell/projects/fpulse/bin/fpulse(29)<module>()
-> parser.add_argument('conf', type=str, help='fpulse LED configuration file')
(Pdb) 
> /home/wrobell/projects/fpulse/bin/fpulse(30)<module>()
-> args = parser.parse_args()
(Pdb) 
> /home/wrobell/projects/fpulse/bin/fpulse(32)<module>()
-> if args.driver == 'print':
(Pdb) 
> /home/wrobell/projects/fpulse/bin/fpulse(35)<module>()
-> elif args.driver == 'tlc5947':
(Pdb) 
> /home/wrobell/projects/fpulse/bin/fpulse(36)<module>()
-> from fpulse.driver.tlc5947 import Driver
(Pdb) 
> /home/wrobell/projects/fpulse/bin/fpulse(37)<module>()
-> drv = Driver()
(Pdb) s
--Call--
> /home/wrobell/projects/fpulse/fpulse/driver/tlc5947.py(50)__init__()
-> def __init__(self):
(Pdb) n
> /home/wrobell/projects/fpulse/fpulse/driver/tlc5947.py(51)__init__()
-> n = self._n_leds = self.N_LEDS # * n_drivers
(Pdb) 
> /home/wrobell/projects/fpulse/fpulse/driver/tlc5947.py(52)__init__()
-> self._values = [0] * n
(Pdb) 
> /home/wrobell/projects/fpulse/fpulse/driver/tlc5947.py(53)__init__()
-> self._lib = ct.CDLL('libbcm2835.so')
(Pdb) 
> /home/wrobell/projects/fpulse/fpulse/driver/tlc5947.py(55)__init__()
-> self._n_bytes = int(n * self.BITS_PER_VALUE / 8)
(Pdb) print(self._lib)
<CDLL 'libbcm2835.so', handle 18695d0 at 0x7f39b3ba0710>

@ravipurigen
Copy link

ravipurigen commented Apr 12, 2017

Thanks for sharing the information. Can you confirm which Raspberry PI OS are you using ? It seems that Jessie (PIXEL) might have problems with SPI communication.
I tried the loopback test from the SPI troubleshooting guide and it fails,
https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md#troubleshooting

@wrobell
Copy link
Owner

wrobell commented Apr 12, 2017

I am using Arch Linux.

@ravipurigen
Copy link

Turned out that my rasp pi compute module was the culprit and it works great with the rasp pi B v3 model.
With respect to setting the LED brightness values, I understood that min/max value are 0/1. So if I am looking to set an RGB color for 100, 50, 200 then I have to normalize them to 0.5 0.25 1
if its 17 237 119 then 0.071723 1 0.5021 so was wondering how many decimal places can be used ?

@wrobell
Copy link
Owner

wrobell commented Apr 17, 2017

I am glad that FPulse works for you at the end. :)

In short, it should be possible to use 15 decimal places.

I am closing this issue as at least one person is able to run the code. Please raise new issues if necessary.

@wrobell wrobell closed this as completed Apr 17, 2017
@ravipurigen
Copy link

Sure thing.. thanks !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants