Unsigned Student
Posts: 9
Joined: Tue Feb 12, 2019 4:56 am

Problem with Piscope (pigpio) and spidev

Wed Feb 13, 2019 3:08 am

Hello I hope somebody here can help me with my problem.

Atm. I am trying to write python code to communicate with a BMS Chip via SPI to debug the the Communication I want to use Piscope.
I used this this website as an instruction for installation and use. I also looked into some older forum posts but I was not able to find a solution.

I installed pigpio and piscope as described. The Behavior now is that after starting the pigpio service and then then piscope nothing happens. No error, no window, nothing. Am I doing sth. wrong ?

Code: Select all

sudo pigpiod
gksudo piscope # saw this in a post from the past

I only get an error when I try to command "picsope" without sudo then I get the error response:

Code: Select all

cannot execute binary file: Exec format error...

I am using a Raspberry Pi 3 with Raspbian

Thanks in advance for any help and advice !
Last edited by Unsigned Student on Fri Feb 15, 2019 1:57 am, edited 1 time in total.

User avatar
MrYsLab
Posts: 334
Joined: Mon Dec 15, 2014 7:14 pm
Location: Noo Joysey, USA

Re: Problem with Piscope (pigpio)

Wed Feb 13, 2019 2:36 pm

I am not sure how you installed piscope. Here is what I did, and it comes up.

1:

Code: Select all

wget abyz.me.uk/rpi/pigpio/piscope.tar
tar xvf piscope.tar
cd PISCOPE
make hf
make install

2. Start pigpio:

Code: Select all

sudo pigpiod
3. Start piscope by typing:

Code: Select all

piscope Live

Unsigned Student
Posts: 9
Joined: Tue Feb 12, 2019 4:56 am

Re: Problem with Piscope (pigpio)

Thu Feb 14, 2019 4:27 am

Thank you after reinstalling it with your instructions it is now starting up !

How should the SPI pins look when the Device is not connected atm. ? I expected there to be no activity but GPIO 7, 10 and 11 are showing similar activity.

Image

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

Re: Problem with Piscope (pigpio)

Thu Feb 14, 2019 7:00 am

You need to reduce the length of the time base. Your screen shot currently shows things happening in Piscope for seven seconds. Reduce it to 7 micro seconds and you'll see more detail of what's happening.

If the SPI interface is dormant MISO (master in/slave out) will always be LOW. MOSI (master out/slave in) is data being sent from your RPi. The interface only comes active when the CE0/CS0 or CE1/CS1 (aka "slave select" SS) pin goes low, that only happens when you've got a device connected to the interface.

There's some details of how it works complete with timing diagrams at: https://learn.sparkfun.com/tutorials/se ... ce-spi/all
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Unsigned Student
Posts: 9
Joined: Tue Feb 12, 2019 4:56 am

Re: Problem with Piscope (pigpio)

Thu Feb 14, 2019 8:01 am

DougieLawson wrote: You need to reduce the length of the time base. Your screen shot currently shows things happening in Piscope for seven seconds. Reduce it to 7 micro seconds and you'll see more detail of what's happening.

If the SPI interface is dormant MISO (master in/slave out) will always be LOW. MOSI (master out/slave in) is data being sent from your RPi. The interface only comes active when the CE0/CS0 or CE1/CS1 (aka "slave select" SS) pin goes low, that only happens when you've got a device connected to the interface.

There's some details of how it works complete with timing diagrams at: https://learn.sparkfun.com/tutorials/se ... ce-spi/all
Thank you for the reply! I will test what you suggested.

I already read some articles regarding SPI but it is still pretty new to me. Are you also experienced in using spidev to communicate with a SPI device?

Regarding SPI I think I am able to understand the general Idea and mechanics behind it but I still struggle to properly use python (spidev) to communicate through SPI with my device.
I have read the documentation regarding my device. With the informationen I now have -> page address and register address I want to access it (read it). The general Information regarding the connection is given (MSB First, 122KHz, mode 0). Now from my Understanding I now need to give the chip the information what register I want to access ( it has to transmit). The addresses are for example page "3’b001" and register "6’h0F". I would then transmit the byte 0x1F ( binary 0001 1111) to the chip and expect it to send me the register I asked for.

Is my understanding of the process right? Have I forgotten something or did I make some grave mistake? I would be really grateful for any further help !

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

Re: Problem with Piscope (pigpio) and spidev

Fri Feb 15, 2019 7:26 am

If you have an SPI device there will be a manufacturer's datasheet for the chips that are on the device.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Unsigned Student
Posts: 9
Joined: Tue Feb 12, 2019 4:56 am

Re: Problem with Piscope (pigpio) and spidev

Fri Feb 15, 2019 9:07 am

DougieLawson wrote: If you have an SPI device there will be a manufacturer's datasheet for the chips that are on the device.
Yeah I used the Datasheet but had a dumb mistake in my python code Iam now able to read the voltages just fine :)

The Battery Module I'm working with has 2 stacks of 12 18650 Li-Ion Batteries each has their own BMS Chip. The only issue Iam having is that the Voltage read seems to be faulty when both SPI devices are connected. I though when opening a connection in spidev and choosing 0 or 1 it should be able to work just fine.

Code: Select all

spi = spidev.SpiDev()
spi.open(0, 0) 		# the first one is for port and the other for the device
spi.bits_per_word = 8
spi.max_speed_hz = 122000
spi.mode = 0
spi.lsbfirst = False
Which var do I need to change when I only want to read from 1 device with that connection? It should be the Second var?

EDIT:
After some more testing only reading from the first device seems to be an issue when both are connected, the second on delivers completely plausible and correct data.

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

Re: Problem with Piscope (pigpio) and spidev

Fri Feb 15, 2019 7:33 pm

Simplest option is connect each device with it's own CE/CS/SS pin. Use /dev/spidev0.0 for CE0 and /dev/spidev0.1 for CE1. https://pinout.xyz/pinout/spi
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Unsigned Student
Posts: 9
Joined: Tue Feb 12, 2019 4:56 am

Re: Problem with Piscope (pigpio) and spidev

Mon Feb 18, 2019 12:56 am

DougieLawson wrote: Simplest option is connect each device with it's own CE/CS/SS pin. Use /dev/spidev0.0 for CE0 and /dev/spidev0.1 for CE1. https://pinout.xyz/pinout/spi
Yes each device is connected to their own SPI_CE Pin. The strange outputs for dev0 only happen quite rarely 2/10 or so is it possible that spi just isn't 100% consistent sometimes ? Bitflips, inaccuracy etc. ?

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

Re: Problem with Piscope (pigpio) and spidev

Mon Feb 18, 2019 11:20 am

Please note that pigpio works by sampling the GPIO, by default 200 thousand times per second. With that in mind you need to limit the SPI bit rate to a maximum of 100kbps when debugging with piscope/pigpio.

If other GPIO are showing activity due to noise which is irrelevant but mucking up the display you can disable those GPIO by clicking on their number in piscope or by setting a pull-up or down on them (for instance with pigs pud 12 d to stop noise activity on GPIO 12).

Unsigned Student
Posts: 9
Joined: Tue Feb 12, 2019 4:56 am

Re: Problem with Piscope (pigpio) and spidev

Mon Feb 18, 2019 11:46 am

joan wrote: Please note that pigpio works by sampling the GPIO, by default 200 thousand times per second. With that in mind you need to limit the SPI bit rate to a maximum of 100kbps when debugging with piscope/pigpio.

If other GPIO are showing activity due to noise which is irrelevant but mucking up the display you can disable those GPIO by clicking on their number in piscope or by setting a pull-up or down on them (for instance with pigs pud 12 d to stop noise activity on GPIO 12).
The inconsistent and faulty results are not only occurring visually in piscope but also in the data itself (spidev readbyte function).

Update: The initial problem here is already solved some posts ago so for my current problem I will probably make a new structured post with all important information available, thanks for the help so far :) ! (this can be closed)

Return to “Python”