Adafruit Industries, Essential service and business: NYC – Executive Order 202.6 - Read more.
0

Dotstar python library on BBB
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Dotstar python library on BBB

by Tecnoeletbri on Wed Oct 21, 2015 9:23 am

Hi,
I've setup the DotStar Library from https://github.com/adafruit/Adafruit_DotStar_Pi on a raspberry pi and everything is fine.
I'm triyng to do the same on the Beagle Bone Board, but when I use strandtest.py the program run until strip.begin() then it exit without returning any error.

I'm on a BBB rev C with Debian:
Linux test 3.8.13-bone72 #1 SMP Tue Jun 16 21:36:04 UTC 2015 armv7l GNU/Linux

The library isn't compatible with the BBB?
Please let us know, thanks, BR

Tecnoeletbri
 
Posts: 13
Joined: Wed May 27, 2015 4:17 am

Re: Dotstar python library on BBB

by Tecnoeletbri on Mon Oct 26, 2015 3:51 am

Up

Tecnoeletbri
 
Posts: 13
Joined: Wed May 27, 2015 4:17 am

Re: Dotstar python library on BBB

by Tecnoeletbri on Fri Oct 30, 2015 9:14 am

Dear Sirs,
please say something, is the question too silly, is there a tutorial?

Tecnoeletbri
 
Posts: 13
Joined: Wed May 27, 2015 4:17 am

Re: Dotstar python library on BBB

by adafruit_support_mike on Sat Oct 31, 2015 3:51 am

Sorry for taking so long to reply.

I don't know of any compatibility problems between the DotStar Python library and the BBB, but the underlying C code was written for the Raspberry Pi. It's possible that there's some platform-specific code that doesn't carry over.

I'll check with the library developers and see if they have any more specific ideas.

adafruit_support_mike
 
Posts: 60993
Joined: Thu Feb 11, 2010 2:51 pm

Re: Dotstar python library on BBB

by Tecnoeletbri on Mon Nov 09, 2015 3:29 am

Dear Mike,
thanks for your attention, please let us know asap, thanks.
BR

Tecnoeletbri
 
Posts: 13
Joined: Wed May 27, 2015 4:17 am

Re: Dotstar python library on BBB

by pburgess on Wed Nov 11, 2015 1:12 am

The bitbang part of that code is extremely Raspberry Pi-specific.

SPI might work on BBB if the system has a /dev/spidev0.0
(Or if there's a different spidev available, tweak the C code, line 240, to point to it.)

pburgess
 
Posts: 4049
Joined: Sun Oct 26, 2008 2:29 am

Re: Dotstar python library on BBB

by Tecnoeletbri on Wed Nov 11, 2015 6:43 am

Dear pburgess,
Thanks for the attention, this is what I've done:

I've enabled spi, following:

http://elinux.org/BeagleBone_Black_Enable_SPIDEV

now I see:

$ ls -al /dev/spidev1.*
crw-rw---T 1 root spi 153, 0 Mar 1 2015 /dev/spidev1.0

I've edited the dotstar.c, replacing spidev0 with spidev1.

Then run: sudo python setup.py install

Then if I start strandtest.py as sudo it continue to exit the script without any message when it came to strip.begin()



ipdb>
> /home/debian/Adafruit_DotStar_Pi/strandtest.py(17)<module>()
16 datapin = 23
---> 17 clockpin = 24
18 strip = Adafruit_DotStar(numpixels, datapin, clockpin)

ipdb>
> /home/debian/Adafruit_DotStar_Pi/strandtest.py(18)<module>()
17 clockpin = 24
---> 18 strip = Adafruit_DotStar(numpixels, datapin, clockpin)
19

ipdb>
> /home/debian/Adafruit_DotStar_Pi/strandtest.py(27)<module>()
26
---> 27 strip.begin() # Initialize pins for output


Am I missing something?

Tecnoeletbri
 
Posts: 13
Joined: Wed May 27, 2015 4:17 am

Re: Dotstar python library on BBB

by pburgess on Wed Nov 11, 2015 1:39 pm

The example uses bitbang output by default. Comment that out, and there should be a second strip declaration in the code (enable that one) showing how to do it with hardware SPI (i.e. don't pass the data & clock pin numbers, since they're dictated by the SPI hardware in this case).

pburgess
 
Posts: 4049
Joined: Sun Oct 26, 2008 2:29 am

Re: Dotstar python library on BBB

by Tecnoeletbri on Mon Nov 16, 2015 3:51 am

Thanks for the reply.

I've edited the example, commented out:

#datapin = 23
#clockpin = 24

and enabled:

strip = Adafruit_DotStar() # SPI, No pixel buffer

but when I run it, the beagle bone crash, loose ssh connection and no way to get it back without a forced reboot.

Tecnoeletbri
 
Posts: 13
Joined: Wed May 27, 2015 4:17 am

Re: Dotstar python library on BBB

by Tecnoeletbri on Mon Nov 16, 2015 3:51 am

Thanks for the reply.

I've edited the example, commented out:

#datapin = 23
#clockpin = 24

and enabled:

strip = Adafruit_DotStar() # SPI, No pixel buffer

but when I run it, the beagle bone crash, loose ssh connection and no way to get it back without a forced reboot.

Tecnoeletbri
 
Posts: 13
Joined: Wed May 27, 2015 4:17 am

Re: Dotstar python library on BBB

by mrburns42 on Fri Sep 30, 2016 10:02 pm

FYI,
I am seeing the same thing. The python library is crashing at "(void)ioctl(self->fd, SPI_IOC_MESSAGE(3), xfer);" in the function static void raw_write(DotStarObject *self, uint8_t *ptr, uint32_t len)

If I run the test python script from SSH and then monitor the debug serial port with another terminal window, then the debug console connection prints out:
root@beaglebone:~# [ 117.427808] spi_master spi1: failed to transfer one message from queue

After the debug console prints out that message, it continues to run for about 60 seconds, then when the ioctl call does not return, it will throw a kernel panic and the Beaglebone will need a power cycle. Before the 60 seconds, I tried to kill the process for my python script, however it still threw a kernel panic. However, if you type reboot in the debug console before the 60 seconds has expired, then at least it will not hang. That at least allows me to work on it remotely without having access to the power switch.

Googling the message above, there is some references to the spi driver only being able to handle 31 bytes in some implementations. No clue yet whether that applies to the Beaglebone. I tried dmesg and I tried to enable extra printk messages, but nothing additional was displayed. I also tried to only send the header structure and not all three. That too gave the same error message as above.

A couple of other items to note, in static PyObject *begin(DotStarObject *self), the
uint8_t mode = SPI_MODE_0 | SPI_NO_CS;
Will cause the line:
ioctl(self->fd, SPI_IOC_WR_MODE, &mode);
to return an error code. Apparently the TI processor does not support the SPI_NO_CS portion.
Also, I was getting an error code on:
ioctl(self->fd, SPI_IOC_WR_MAX_SPEED_HZ, self->bitrate);
The speed is too high for the Beaglebone and it throws a return code. (The original dotstar.c does not check the return codes.) As a test, I changed my version to:
ioctl(self->fd, SPI_IOC_WR_MAX_SPEED_HZ, 500000);

From a fresh boot on my Beaglebone, there are no spi entries the the /dev tree. So, the very first attempt to open "/dev/spidev1.0" would fail. I get around that by running a small demo python script that calls an SPI read. That import of the SPI portion of the library when running that demo script does some magic and configures the devicetree overlays to enable SPI. I mention that to show that I am not using a funky homebrew, and untested devicetree overlay.

If anyone has a clue about the "failed to transfer one message" or hints about how to troubleshoot this, please let us know.

Thanks.

---- Steve

P.S. I would have never gotten this far in the testing without the terrific tutorials and the Beaglebone IO python libraries provided by Adafruit. A big thank you for providing that great information in an very thorough and easy to understand format.
mrburns42
 
Posts: 20
Joined: Tue Jan 01, 2013 11:31 pm

Re: Dotstar python library on BBB

by drewfustini on Mon Oct 03, 2016 11:15 am

There a new release (v1.0.0) of Adafruit_BBIO published to PyPI last week. Could you please make sure you have the latest installed?

PyPi package:
https://pypi.python.org/pypi/Adafruit_BBIO

This is the release on GitHub for reference:
https://github.com/adafruit/adafruit-be ... /tag/1.0.0

Also, it would be helpful to know more about the system software on your BeagleBone.

Could you please paste the output of these commands?

uname -a

cat /etc/debian_version

cat /etc/dogtag

drewfustini
 
Posts: 920
Joined: Sat Dec 26, 2015 1:19 pm

Re: Dotstar python library on BBB

by mrburns42 on Mon Oct 03, 2016 4:50 pm

Hi Drew,

Thank you for the reply. Today has been most difficult. In attempting to hook a logic analyzer to the SPI pins of P9, I inadvertently pushed in the SDCard while it is running. This trashed the card and I did not have a current backup. That is my bad! Recreating the SDCard, I then found that /sys/devices/bone_capemgr.9 did not exist. It was there on Friday and earlier this morning. Now gone. After trying several SDCards and reloading the flash on the BBB, I finally discovered that my kernel version must be newer than I had on Friday. I rebuilt everything again and reloaded the Adafruit BBIO library. Below are the details of the system.
Code: Select all | TOGGLE FULL SIZE
root@beaglebone:~# uname -a
Linux beaglebone 4.4.9-ti-r25 #1 SMP Thu May 5 23:08:13 UTC 2016 armv7l GNU/Linux
root@beaglebone:~# cat /etc/debian_version
8.6
root@beaglebone:~# cat /etc/dogtag
BeagleBoard.org Debian Image 2016-05-13
root@beaglebone:~#

root@beaglebone:/home/steve# sudo pip install Adafruit_BBIO
Collecting Adafruit_BBIO
  Downloading Adafruit_BBIO-1.0.0.tar.gz (43kB)
    100% |################################| 51kB 912kB/s
Building wheels for collected packages: Adafruit-BBIO
  Running setup.py bdist_wheel for Adafruit-BBIO ... done
  Stored in directory: /root/.cache/pip/wheels/4b/de/99/025af4b72c4411a4a3ceeb27eea0907959c0b516daa3617a5a
Successfully built Adafruit-BBIO
Installing collected packages: Adafruit-BBIO
Successfully installed Adafruit-BBIO-1.0.0


Now, if I attempt to run a simple SPI read that worked on earlier today, I get
Code: Select all | TOGGLE FULL SIZE
Traceback (most recent call last):
  File "./SPI_Test.py", line 13, in <module>
    result = spi.xfer2([0x9F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
IOError: [Errno 22] Invalid argument


In the debug serial port, I get
Code: Select all | TOGGLE FULL SIZE
[ 1114.576762] bone_capemgr bone_capemgr: slot #5: BB-SPIDEV0 conflict P9.17 (#4:cape-universaln)
[ 1114.585713] bone_capemgr bone_capemgr: slot #5: Failed verification


The issue blocking me is this universaln cape. I don't believe I installed it and I cannot figure out how to uninstall it. This cape is at slot 4. If I echo a -4 to slots, then it reboots. After reboot this universaln is still there! So that is where I am. If I can figure out how to get rid of universaln, then I can continue attempting to debug.

Thanks.

---- Steve
mrburns42
 
Posts: 20
Joined: Tue Jan 01, 2013 11:31 pm

Re: Dotstar python library on BBB

by mrburns42 on Mon Oct 03, 2016 5:28 pm

OK, The question on removing the universal cape was answered by Drew is this post.

viewtopic.php?f=49&t=103442&p=518326&hilit=universaln#p518326

I did that and my example script still throws and error. However, it does setup spi devices in dev. So I will leave that error for a future time.

In the DotStar code, the line "(void)ioctl(self->fd, SPI_IOC_MESSAGE(3), xfer);" in raw_write(), no longer causes the system to hang. Instead, that line returns with an error code of 0x2D. According to my lookup, that is "Level 2 not synchronized" I don't really have a clue as to what the Level 2 is. Could be Level 2 Ninjas for all I know! However, I will keep digging.

The good news for anyone else attempting this, is that the version 4 kernel must have some fix in it for that system hang. So going to that version should make it easier to debug.

----- Steve
mrburns42
 
Posts: 20
Joined: Tue Jan 01, 2013 11:31 pm

Re: Dotstar python library on BBB

by mrburns42 on Tue Oct 04, 2016 10:39 am

The serial console which prints the kernel messages has a different error. Its error is :
spidev spi1.0: Bufferless transfer has length 4

Below is a very simple Python script that I was using to test the SPI bus. This worked with or without the SPI eeprom attached on the previous kernel. With no EEPROM attached, it would print out that all the 0xFF as expected. Now when I run the code, it throws an Invalid Argument [Errno 22] at the xfer2 call.
Code: Select all | TOGGLE FULL SIZE
#!/usr/bin/python
from Adafruit_BBIO.SPI import SPI
import time

spi = SPI(0,0)   #/dev/spidev1.0

#Set the maximum clock frequency to 500kHz so it is easy to view on the CRO
spi.msh=500000


# Transfer 0x9F,  and a bunch of 0x00.  The 0x9F commands the SPI EEPROM to read
# its  ID Registers the 0x00 are dummy bytes that pads out the length to the
# number of read bytes requested.
result = spi.xfer2([0x9F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
# The result of the transfer will be an array of 7 bytes where the first byte is what
# was read while the command byte was written and the rest are the devices
# contents of the ID registers.

for i in range(1, 7):
  val = result[i]
  print "Read Byte[%d] was 0x%x." %(i, val)


Searching the web, I see some discussion on the Raspberry PI forums that centers around the spidev install being stale or old. The gurus there asked for a print out of pip search spidev. Below is what I get on the BBB
Code: Select all | TOGGLE FULL SIZE
root@beaglebone:/home/steve# pip search spidev
max7219 (0.2.2)          - A library to drive a MAX7219 LED serializer using hardware spidev
SPIlib (0.1.0)           - A small library to use the SPIdev linux interface
spidev (3.2)             - Python bindings for Linux SPI access through spidev
Adafruit-PureIO (0.2.0)  - Pure python (i.e. no native extensions) access to Linux IO including I2C and SPI.
                           Drop in replacement for smbus and spidev modules.
spi (0.2.0)              - Pure Python SPI Interface using spidev
RPimax7219 (0.2)         - A small library to drive a MAX7219 LED serializer using hardware spidev


I don't really know if those revision levels play nice together. The fact that my BBB seems to have a Raspberry Pi driver for Max7219 does not give me a warm fuzzy.
Since this used to work, I guess my next step is to archive this SD Card and then take a blank card and recreate the system. My concern is that the card has some stale junk that may be causing some of the issues.
mrburns42
 
Posts: 20
Joined: Tue Jan 01, 2013 11:31 pm

Please be positive and constructive with your questions and comments.