PDA

View Full Version : Add a python library (SPI-pi) to picoreplayer



cubii
2017-03-18, 01:59
H there,

i want to use an RFID Reader combined with picoreplayer.
For that rfid reader, i need to use a library (MRFC522 library) and the library needs SPI-py https://github.com/lthiery/SPI-Py.
i have installed python-dev, compile?? and RPI-Gpio?? extensions (via the webpage)

So now i just downloaded the SPI-py library on my Windows pc and then copied the folder to home/tc/SPI-Py.

Now i need to install it, and thats my problem:

When i use:

sudo python setup.py install

it installs fine, but i can only use it until the next reboot, because the internal backup function of picoreplayer does not backup the installation folder of SPI-py (not that one under /home/tc, but the one where it gets installed)

If i use

sudo python setup.py install --user

i can start my python script which uses it also after restarting picoreplayer (and using its backup function) but i cannot autostart my script, it only works if i start the script inside its installation folder (i mean it starts only if i do: Cd /home/tc/Myscript/ and then sudo python Myscript.py
.

Autostarting is done by using:

sudo nano /opt/bootlocal.sh
sudo python /home/tc/Myscript/Myscript.py

Any idea how to solve this?

Like Backup the Library differently? or installing it differently?

Greetings

cubii

paul-
2017-03-18, 03:34
H there,

i want to use an RFID Reader combined with picoreplayer.
For that rfid reader, i need to use a library (MRFC522 library) and the library needs SPI-py https://github.com/lthiery/SPI-Py.
i have installed python-dev, compile?? and RPI-Gpio?? extensions (via the webpage)

So now i just downloaded the SPI-py library on my Windows pc and then copied the folder to home/tc/SPI-Py.

Now i need to install it, and thats my problem:

When i use:

sudo python setup.py install

it installs fine, but i can only use it until the next reboot, because the internal backup function of picoreplayer does not backup the installation folder of SPI-py (not that one under /home/tc, but the one where it gets installed)

If i use

sudo python setup.py install --user

i can start my python script which uses it also after restarting picoreplayer (and using its backup function) but i cannot autostart my script, it only works if i start the script inside its installation folder (i mean it starts only if i do: Cd /home/tc/Myscript/ and then sudo python Myscript.py
.

Autostarting is done by using:

sudo nano /opt/bootlocal.sh
sudo python /home/tc/Myscript/Myscript.py

Any idea how to solve this?

Like Backup the Library differently? or installing it differently?

Greetings

cubii

That's starting to get involved, have you read all of the information over at www.tinycorelinux.net? There is a lot of information about persistence and creating extensions for the Core based OS.

Files are Backed up based on /opt/.filetool.lst

cubii
2017-03-18, 12:50
Files are Backed up based on /opt/.filetool.lst

Thanks for the answer, i have added the folder usr/local/lib/python2.7/site-packages to /opt/.filetool.list

so that the compiled SPI-py module gets backed up.

Now the startup of myscript.py works.

Is this good way to do it? or at least ok?


Greetings

cubii

paul-
2017-03-18, 12:59
Thanks for the answer, i have added the folder usr/local/lib/python2.7/site-packages to /opt/.filetool.list

so that the compiled SPI-py module gets backed up.

Now the startup of myscript.py works.

Is this good way to do it? or at least ok?


Greetings

cubii

Backups work fine, we do it more than we should with pCP. If files never change, they are better off in extensions.

cubii
2017-03-18, 13:34
Thanks,

If i have the time, i will read into the extension thing of tinycorelinux.

cubii
2017-11-14, 15:36
Hi there,

I cant get picoreplayer 3.22 and a MFRC522 NFC Reader via spi-py work together.

I have installed:


tce-load -wi compiletc.tcz
tce-load -wi python-dev.tcz
tce-load -wi python-RPi.GPIO.tcz
tce-load -wi nano.tcz


via ssh

and then i want to install the following apps via git:


_ _____ ___ __
___ (_) ___/__ _______ / _ \/ /__ ___ _____ ____
/ _ \/ / /__/ _ \/ __/ -_) ___/ / _ `/ // / -_) __/
/ .__/_/\___/\___/_/ \__/_/ /_/\_,_/\_, /\__/_/
/_/ /___/

piCorePlayer = piCore + Squeezelite + Raspberry Pi

The software is provided "as is" without warranty of any kind,
either express or implied, including without limitation any implied
warranties of condition, uninterrupted use, merchantability,
fitness for a particular purpose, or non-infringement.
tc@piCorePlayer:~$ cd SPI-Py/
tc@piCorePlayer:~/SPI-Py$ sudo python setup.py install
running install
running build
running build_ext
building 'spi' extension
creating build
creating build/temp.linux-armv6l-2.7
gcc -pthread -fno-strict-aliasing -O3 -pipe -march=armv6zk -mtune=arm1176jzf-s - mfpu=vfp -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/in clude/python2.7 -c spi.c -o build/temp.linux-armv6l-2.7/spi.o
creating build/lib.linux-armv6l-2.7
gcc -pthread -shared build/temp.linux-armv6l-2.7/spi.o -L/usr/local/lib -lpython 2.7 -o build/lib.linux-armv6l-2.7/spi.so
running install_lib
copying build/lib.linux-armv6l-2.7/spi.so -> /usr/local/lib/python2.7/site-packa ges
running install_egg_info
Writing /usr/local/lib/python2.7/site-packages/SPI_Py-1.0-py2.7.egg-info
tc@piCorePlayer:~/SPI-Py$ git clone https://github.com/mxgxw/MFRC522-python
Cloning into 'MFRC522-python'...
remote: Counting objects: 60, done.
remote: Total 60 (delta 0), reused 0 (delta 0), pack-reused 60
Unpacking objects: 100% (60/60), done.
Checking connectivity... done.
tc@piCorePlayer:~/SPI-Py$ cd MFRC522-python/
tc@piCorePlayer:~/SPI-Py/MFRC522-python$ sudo python Read.py
can't open device: No such file or directory
Aborted
tc@piCorePlayer:~/SPI-Py/MFRC522-python$
tc@piCorePlayer:~/SPI-Py/MFRC522-python$


But the MRFCReader is not found.

This is working with picoreplayer 3.18 and the same hardware.

Does someone know what is the problem there?

There was a problem with the Reader and raspbian, see here:
https://github.com/lthiery/SPI-Py/commit/2c6cf5c8caa6157f84617de5e31af8e48ddbd8e7

and here:
https://github.com/raspberrypi/linux/issues/1547

perhaps these links can give a hint?

It seems the change from spi-bcm2708 to the bcm2835 broke something.

config.txt is untouched.

Thanks
cubii

cubii
2017-11-15, 15:27
to make a long story short,

Why do i get with picore 3.11 on a wifi zero the following answer:


tc@piCorePlayer:~$ ls /dev/spi*
/dev/spidev0.0 /dev/spidev0.1
tc@piCorePlayer:~$



and with picore 3.22 on the same wifi zero:


tc@piCorePlayer:~$ ls /dev/spi*
ls: /dev/spi*: No such file or directory


both untouched images, with activated
dtparam=i2c=on,spi=on,i2s=on
, only ssh activates and wifi added.


:confused:
cubii

paul-
2017-11-15, 17:51
I don't have or use any SPI devices, so I'm not much help. SPI drivers included in pCP.

Did you read that entire github issue?

Did you add dtoverlay=spi0-hw-cs as the thread said?

cubii
2017-11-16, 12:13
Did you read that entire github issue?

Did you add dtoverlay=spi0-hw-cs as the thread said?


Yes and Yes.

Thanks for taking a look.

Perhaps this is a general problem with spi devices, not only with the NFC Reader...(or i am using them wrong...)
What is your output of ls /dev/spi* ?
Perhaps the driver is loaded (lsmod shows a spi... device/driver) but the module is missing? (i dont know exactly what i am saying here, but this is what i understood after searching the net.)

paul-
2017-11-16, 18:04
if lsmod shows the module loaded, then that is not the issue. spi-bcm2835.ko is supplied in the base image.

I guess what I would do is start with the latest Raspbian image and see what happens.

cubii
2017-11-20, 11:40
I guess what I would do is start with the latest Raspbian image and see what happens.

Thanks, i did that with picore 9.03 (latest) and Raspbian stretch lite (7.9.17):

Hardware: 4gb micros sd card Raspberry Zero (without w), power supply. Nothing connected to the gpios, only keyboard attached.


Results:
the text in red was added by myself

Picore 9.03:



Lsmod
Spi_bcm2835

Ls /dev
Spidev0.0 und spidev 0.1

Uname ľa
Linux Box 4.9.22-piCore #1 ... (somenumber)

Raspbian stretch lite (7.9.17)


Lsmod
Spi_bcm2835

Ls /dev
Spidev0.0 und spidev 0.1

Uname -a
Linux Raspberry 4.9.41+ #1023 ... (somenumber)

PicorePlayer 3.22


Lsmod
Spi_bcm2835

Ls /dev
(Nothing)

Uname ľa
Linux piCoreplayer 4.9.50-pcpCore #1 ... (somenumber)


So there is something different... but what?

paul-
2017-11-20, 14:04
I thought I posted a response, but I guess I forgot to hit post.

We are missing spidev.ko I can fix this in future releases, but for now.. You can download all modules here.....

https://sourceforge.net/projects/picoreplayer/files/repo/8.x/armv6/releases/RPi/src/kernel/4.9.50-pcpCore_modules.tar.xz/download



tc@piTouch:~$ cd /tmp
tc@piTouch:/tmp$ wget https://sourceforge.net/projects/picoreplayer/files/repo/8.x/armv6/releases/RPi/src/kern
el/4.9.50-pcpCore_modules.tar.xz
Connecting to sourceforge.net (216.34.181.60:443)
Connecting to sourceforge.net (216.34.181.60:443)
Connecting to downloads.sourceforge.net (216.34.181.59:443)
Connecting to newcontinuum.dl.sourceforge.net (64.79.96.4:443)
4.9.50-pcpCore_modul 100% |************************************************* ************| 11158k 0:00:00 ETA
tc@piTouch:/tmp$ sudo tar xvf 4.9.50-pcpCore_modules.tar.xz -C / lib/modules/4.9.50-pcpCore/kernel/drivers/spi
/spidev.ko
lib/modules/4.9.50-pcpCore/kernel/drivers/spi/spidev.ko
tc@piTouch:/tmp$ echo lib/modules/4.9.50-pcpCore/kernel/drivers/spi/spidev.ko >> /opt/.filetool.lst
tc@piTouch:/tmp$ pcp bu
[ INFO ] Backing up files to /mnt/mmcblk0p2/tce/mydata.tgz\
Done.
[ OK ] Backup successful.
tc@piTouch:/tmp$


That will add the module to your system and restore it at boot time, but likely you will still need to

run
sudo depmod -a

and possibly
sudo modprobe spidev.ko

At the beginning of your scripts.

cubii
2017-11-20, 16:15
I thought I posted a response, but I guess I forgot to hit post.

We are missing spidev.ko I can fix this in future releases, but for now.. You can download all modules here.....

Thank You! That is great to hear!, will test it asap!

cubii:D