Skip to content

Instantly share code, notes, and snippets.

@spuder
Last active August 28, 2022 15:39
Show Gist options
  • Select an option

  • Save spuder/e3d233bbe68968bd9c499a8fef12e9d9 to your computer and use it in GitHub Desktop.

Select an option

Save spuder/e3d233bbe68968bd9c499a8fef12e9d9 to your computer and use it in GitHub Desktop.

Revisions

  1. spuder revised this gist Aug 28, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion main.cpp
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ void get_input() {
    if (DigiUSB.available()) {
    // something to read
    lastRead = DigiUSB.read();
    # If you type 1, it will turnon the LED for 100 ms
    //If you type 1, it will turnon the LED for 100 ms
    if (lastRead == '1') {
    digitalWrite(1,HIGH);
    delay(100);
  2. spuder revised this gist Aug 28, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion main.cpp
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ void get_input() {
    if (DigiUSB.available()) {
    // something to read
    lastRead = DigiUSB.read();
    # If you type
    # If you type 1, it will turnon the LED for 100 ms
    if (lastRead == '1') {
    digitalWrite(1,HIGH);
    delay(100);
  3. spuder created this gist Aug 28, 2022.
    21 changes: 21 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    Digispark doesn't allow using the normal `Serial.println()` that an arduino uses becuase it doesn't show up as a com port.

    Instead you need to use `hidapitester` or https://github.com/Bluebie/digiusb.rb ruby app to read from USB data.

    Digispark has `VID/PID` of `16C0/05DF`

    ## bluebie/digiusb

    Start the digterm ruby app and enter `1` in the terminal.
    When 1 is pressed, the blue LED (pin 1) should turn on for 1/10 of a second
    ```bash
    gh repo clone Bluebie/digiusb.rb
    cd digiusb
    gem install colored
    gem intall libusb
    ./bin/digiterm
    >hello world
    >1
    ```


    47 changes: 47 additions & 0 deletions main.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    // To upload this sketch to digispark, you must either use platform.io or a really old version of arduino on a 32 bit mac (64 bit wont work)
    // You more than likely can't plug the digispark into a usb 3.0 port. Use a usb 2.0 port or a usb extenstion cable
    // https://www.youtube.com/watch?v=hVQubqgdoZg
    // To actually upload code with platform.io, click upload, then unplug/replugin in the device within 5 seconds.

    #include <Arduino.h>
    #include <DigiUSB.h>

    void setup() {
    pinMode(1, OUTPUT);
    digitalWrite(1,HIGH);
    delay(500);
    digitalWrite(1,LOW);
    DigiUSB.begin();
    }

    void get_input() {
    int lastRead;
    // when there are no characters to read, or the character isn't a newline
    while (true) { // loop forever
    if (DigiUSB.available()) {
    // something to read
    lastRead = DigiUSB.read();
    # If you type
    if (lastRead == '1') {
    digitalWrite(1,HIGH);
    delay(100);
    digitalWrite(1,LOW);
    }
    DigiUSB.write(lastRead);

    if (lastRead == '\n') {
    break; // when we get a newline, break out of loop
    }
    }

    // refresh the usb port for 10 milliseconds
    DigiUSB.delay(10);
    }
    }

    void loop() {
    // print output
    DigiUSB.println("Waiting for input...");
    // get input
    get_input();
    }