Author Topic: Digispark with webusb  (Read 242 times)

beckmx

  • Newbie
  • *
  • Posts: 3
Digispark with webusb
« on: June 18, 2019, 04:28:30 pm »
Hello everyone, I am sorry if this has already been asked but I couldn't find a thread about this particular topic. I would like to use my digispark with webusb, I have tried some demos out there and even moving the definition classes, I have gone as far as I could but no luck, I modified the DigiUSB but apparentely it is not able to be understood by the webusb

granzeier

  • Jr. Member
  • **
  • Posts: 53
Re: Digispark with webusb
« Reply #1 on: June 19, 2019, 04:06:14 am »
We will need a bit more information to be able to help you.

How far were you able to get? Did you try any of the examples from GitHub (https://github.com/beigenmann/DigisparkWebUSB/tree/master/examples)? What happened? What error messages (if any) did you receive?

What is your program (code) and did it even compile?

beckmx

  • Newbie
  • *
  • Posts: 3
Re: Digispark with webusb
« Reply #2 on: June 19, 2019, 09:29:17 am »
So far I have tried these libraries:
- DigiCDC
- DigiUSB

Which is the one you suggested.

For the DigiUSB I have modified the library files for the USB device class, vendor, product-id and interfaceClass inside -usbconfig.h-, I have managed to get it only "recognized" but I cant manage to send data from JS into the webusb. Apparently the interface in and out are not properly created and is missing the "in".

The code I use is from the blink example:
Code: [Select]
#define USB_CFG_DEVICE_NAME     'D','i','g','i','B','l','i','n','k'
#define USB_CFG_DEVICE_NAME_LEN 9
#include <DigiUSB.h>
byte in = 0;
int Blue = 0;
int Red = 0;
int Green = 0;

int next = 0;

void setup() {
    DigiUSB.begin();
    pinMode(0,OUTPUT);
    pinMode(1,OUTPUT);
    pinMode(2,OUTPUT);
}


void loop() {
  setBlue();
      DigiUSB.refresh();
      setBlue();
     if (DigiUSB.available() > 0) {
       in = 0;
       
       in = DigiUSB.read();
       if (next == 0){
         if(in == 115){
           next = 1;
           DigiUSB.println("Start");
         }
       }
       else if (next == 1){
            Red = in;
            DigiUSB.print("Red ");
            DigiUSB.println(in,DEC);
            next = 2;
       }
       else if (next == 2){
            Green = in;
            DigiUSB.print("Green ");
            DigiUSB.println(in,DEC);
            next = 3;
       }
       else if (next == 3){
            Blue = in;
            DigiUSB.print("Blue ");
            DigiUSB.println(in,DEC);
            next = 0;
       }


       
       
     }
     

    analogWrite(0,Red);
    analogWrite(1,Green);
     setBlue();

     
   
}

void setBlue(){
    if(Blue == 0){
      digitalWrite(2,LOW);
      return;
    }
    else if(Blue == 255){
      digitalWrite(2,HIGH);
      return;
    }
    // On period 
    for (int x=0;x<Blue;x++){
    digitalWrite(2,HIGH);
    }
   
    // Off period
   
    for(int x=0;x<(255-Blue);x++){
    digitalWrite(2,LOW);
    }
 
}


I have also discovered that some of these libraries were made when the webusb specification came out when aparently chrome was able to freely connect to HID, then they changed into connecting only to "custom devices" and those devices require to set up a propper "interface" for in and out communication. According to the arduino specification for atmega32u4, it generates 3 interfaces, 2 of which have in and out controls. There is where I got stuck, I don't know how exactly migrate the VUSB to support these in out sections.

granzeier

  • Jr. Member
  • **
  • Posts: 53
Re: Digispark with webusb
« Reply #3 on: June 21, 2019, 03:14:25 am »
Ok; I have to admit that I am stumped.

Have you tried with an ATMega32, or another Arduino (Uno or Mega maybe)?

I have also discovered that some of these libraries were made when the webusb specification came out when aparently chrome was able to freely connect to HID, then they changed into connecting only to "custom devices" and those devices require to set up a propper "interface" for in and out communication.
This sounds like the specs have changed. Perhaps they made it so that the WebUSB libraries cannot work without major rewrite?

beckmx

  • Newbie
  • *
  • Posts: 3
Re: Digispark with webusb
« Reply #4 on: June 21, 2019, 09:05:21 am »
Well that's what I don't know, but that's my suspicion, and I didnt want to use a normal arduino, I wanted to prevent spending the double the price