Author Topic: Incompatibility between DigiUSB and Adafruit_NeoPixel libraries  (Read 5871 times)

pirlouwi

  • Newbie
  • *
  • Posts: 19
Hi,
i want to program my Digispark to drive an Adafruit led strip, and receive commands by USB, but everytime I use the DigiUSB.h and the Adafruit_NeoPixel.h libraries at the same time, USB hid device is not discovered by udev (under Linux).

What I would expect is the following scenario (captured by "sudo udevadm monitor" command):

Quote
KERNEL[83202.943306] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3 (usb)
KERNEL[83202.943766] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0 (usb)
UDEV  [83202.963379] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3 (usb)
UDEV  [83202.966542] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0 (usb)
KERNEL[83205.239671] remove   /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0 (usb)
KERNEL[83205.239826] remove   /devices/pci0000:00/0000:00:14.0/usb3/3-3 (usb)
UDEV  [83205.240161] remove   /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0 (usb)
UDEV  [83205.245813] remove   /devices/pci0000:00/0000:00:14.0/usb3/3-3 (usb)
KERNEL[83208.047810] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3 (usb)
KERNEL[83208.048291] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0 (usb)
KERNEL[83208.049850] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0/0003:16C0:05DF.000C (hid)
KERNEL[83208.050914] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0/usb/hiddev1 (usb)
KERNEL[83208.050955] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0/0003:16C0:05DF.000C/hidraw/hidraw2 (hidraw)
UDEV  [83208.065935] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3 (usb)
UDEV  [83208.067048] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0 (usb)
UDEV  [83208.068754] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0/usb/hiddev1 (usb)
UDEV  [83208.069308] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0/0003:16C0:05DF.000C (hid)
UDEV  [83208.070139] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0/0003:16C0:05DF.000C/hidraw/hidraw2 (hidraw)

When using both libraries at the same time, I only see the following in udevadm:
Quote
KERNEL[83242.220817] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3 (usb)
KERNEL[83242.221208] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0 (usb)
UDEV  [83242.240584] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3 (usb)
UDEV  [83242.245341] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0 (usb)
KERNEL[83257.595970] remove   /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0 (usb)
KERNEL[83257.596181] remove   /devices/pci0000:00/0000:00:14.0/usb3/3-3 (usb)
UDEV  [83257.596696] remove   /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0 (usb)
UDEV  [83257.603581] remove   /devices/pci0000:00/0000:00:14.0/usb3/3-3 (usb)

This is not a compilation issue. The problem only occurs when I actually use the Neopixel functionnality: I mean: try to modify the color of one led pixel.

Any help would be appreciated.
Thank you

defragster

  • Sr. Member
  • ****
  • Posts: 467
Re: Incompatibility between DigiUSB and Adafruit_NeoPixel libraries
« Reply #1 on: May 19, 2014, 12:33:13 am »
Can you programmatically control the Neopixel using resident code on the DigiSpark with no active USB library usage?  With and without having it linked?

Can you use USB library and your code to control a simple LED output with no active Neopixel library usage?  With and without having it linked?

If you tried that and it only fails when the two are combined and used - I'd guess there is a conflicting pin overlap.

pirlouwi

  • Newbie
  • *
  • Posts: 19
Re: Incompatibility between DigiUSB and Adafruit_NeoPixel libraries
« Reply #2 on: May 19, 2014, 01:06:37 am »
I can control the Neopixel, while not using USB library, yes.
But when I program the USB "echo" example, the device "/devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0/0003:16C0:05DF.000E/hidraw/hidraw2 (hidraw)" appears in udev monitor, but the digiusb program don't seems to work. The Digispark is detected by the "digiusb" program, but nothing that I type in my terminal is printed back by the Digispark.

I also tried to add DigiUSB with an RGB shield, by modifying the DigisparkRGB sketch. I see the RBG shield working, but the hidraw USB device is not appearing in udev monitor.
There seems to be incompatibilities in that case as well.

pirlouwi

  • Newbie
  • *
  • Posts: 19
Re: Incompatibility between DigiUSB and Adafruit_NeoPixel libraries
« Reply #3 on: May 19, 2014, 01:11:03 am »
I tried this simple code:
Code: [Select]
#include <DigiUSB.h>

// the setup routine runs once when you press reset:
void setup() {
  DigiUSB.begin(); 
  // initialize the digital pin as an output.
  pinMode(0, OUTPUT); //LED on Model B
  pinMode(1, OUTPUT); //LED on Model A   
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(0, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(1, HIGH);
  delay(1000);               // wait for a second
  digitalWrite(0, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(1, LOW);
  delay(1000);               // wait for a second
}

The led 0 and 1 are drived well, but the hid USB device does not appear in udev monitor.

gogol

  • Sr. Member
  • ****
  • Posts: 398
Re: Incompatibility between DigiUSB and Adafruit_NeoPixel libraries
« Reply #4 on: May 19, 2014, 01:38:38 am »
How big is your Neo-Pixel-Strip?
Try first with only 2 LEDs and increase the number form there on.
Both, the Neopixel-Library and the USB-library are using good amounts of RAM and you might run into some overruns.

pirlouwi

  • Newbie
  • *
  • Posts: 19
Re: Incompatibility between DigiUSB and Adafruit_NeoPixel libraries
« Reply #5 on: May 19, 2014, 02:07:51 am »
Yes there is apparently a memory issue, i can now initialize DigiUSB with DigiUSB.begin(), and I can drive 12 pixels of the Neopixel.
But I still don't see the hid USB device appearing in udevadm monitor.
I suppose that I will not be able to talk to my Digispark if the hid USB device is not appearing on my system.

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Incompatibility between DigiUSB and Adafruit_NeoPixel libraries
« Reply #6 on: May 31, 2014, 05:49:29 pm »
You should consider just using LittleWire. It can drive > 100 neopixels per pin, requires no arduino coding or dealing with timing stuff, and has libraries for ruby, c, and processing (tho I'm not sure if processing one supports ws2812 protocol). Check it out at http://littlewire.cc/ if you like - it's digispark compatible :)

dougal

  • Sr. Member
  • ****
  • Posts: 289
Re: Incompatibility between DigiUSB and Adafruit_NeoPixel libraries
« Reply #7 on: June 02, 2014, 02:13:00 pm »
The NeoPixel library eats a lot of RAM. With the standard example sketch loaded, I found that I couldn't drive more than about 30 lights without problems. When I went above about 33, it would seem to be running fine at first, but after looping through a few of the patterns, it would freeze up.

I haven't tried to debug it to get any real details about the nature of the failure, but it sure smells like a RAM issue.

pirlouwi

  • Newbie
  • *
  • Posts: 19
Re: Incompatibility between DigiUSB and Adafruit_NeoPixel libraries
« Reply #8 on: June 02, 2014, 10:29:33 pm »
With my Digispark, i am able to drive 120 leds using Neopixel library, as well as with light_ws8211 library.
Both are working well, so, only driving leds, does not lead to a RAM problem.
My problems come when I want to use DigiUSB library along with one of those two libraries.
But, anyway, even when the digiusb device comes up in dmesg under Linux, I never succeded in exchanging characters between Linux and the Digispark.
It should be a problem, but I don't know what