digistump / DigisparkArduinoIntegration

DEPRECATED - REPLACED BY: https://github.com/digistump/DigistumpArduino
280 stars 330 forks source link

Cannot compile USB Keyboard based program #1

Closed Bluebie closed 11 years ago

Bluebie commented 11 years ago

I try to compile this:

#include "DigiKeyboard.h"

#define PIN_RADIO_IN 2
#define PIN_RADIO_GND 1
#define MIN_DURATION_LEADIN 4000
#define MAX_DURATION_LEADIN 5000

void setup() {
  pinMode(2, INPUT);
  pinMode(1, OUTPUT);
  digitalWrite(1, LOW);
  digitalWrite(2, LOW);
}

// type something in to the computer using the keyboard input
void type_string(char* string) {
  byte idx = 0;
  while (string[idx] != 0) {
    byte chr = string[idx];
    byte key = KEY_SPACE;
    byte mod = 0;

    if (chr == '0') {
      key = KEY_0;
    } else if (chr >= '1' && chr <= '9') {
      key = KEY_1 + (chr - '1');
    } else if (chr >= 'a' && chr <= 'z') {
      key = KEY_A + (chr - 'a');
    } else if (chr >= 'A' && chr <= 'Z') {
      key = KEY_A + (chr - 'A');
      mod = MOD_SHIFT_LEFT;
    } else if (chr == ' ') {
      key = KEY_SPACE;
    } else if (chr == '\n') {
      key = KEY_ENTER;
    }

    DigiKeyboard.sendKeyStroke(key, mod);

    idx++;
  }
}

void loop() {
  unsigned int pulse = pulseIn(PIN_RADIO_IN, LOW);

  if (pulse >= MIN_DURATION_LEADIN && pulse <= MAX_DURATION_LEADIN) {
    unsigned int pulses[30];
    byte idx = 0;
    byte toggle = HIGH;
    pulse = 0;

    while (pulse < 1000) {
      pulse = pulseIn(PIN_RADIO_IN, toggle);
      pulses[idx] = pulse;
      toggle = !toggle;
      idx++;
    }

    byte length = idx;
    idx = 0;
    type_string("code ");
    while (idx < length) {
      char message[15] = "";
      sprintf(message, " %d", pulses[idx]);
      type_string(message);
      idx++;
    }
    type_string("\n");
  }

  usbPoll();
}

with tinycore and it has this error:

unknown MCU 'digispark' specified
Known MCU names:
   avr2
   at90s2313
   at90s2323
   at90s2333
   at90s2343
   attiny22
   attiny26
   at90s4414
   at90s4433
   at90s4434
   at90s8515
   at90c8534
   at90s8535
   avr25
   attiny13
   attiny13a
   attiny2313
   attiny24
   attiny44
   attiny84
   attiny25
   attiny45
   attiny85
   attiny261
   attiny461
   attiny861
   attiny43u
   attiny48
   attiny88
   at86rf401
   avr3
   at43usb320
   at43usb355
   at76c711
   avr31
   atmega103
   avr35
   at90usb82
   at90usb162
   attiny167
   avr4
   atmega8
   atmega48
   atmega48p
   atmega88
   atmega88p
   atmega8515
   atmega8535
   atmega8hva
   at90pwm1
   at90pwm2
   at90pwm2b
   at90pwm3
   at90pwm3b
   avr5
   atmega16
   atmega161
   atmega162
   atmega163
   atmega164p
   atmega165
   atmega165p
   atmega168
   atmega168p
   atmega169
   atmega169p
   atmega32
   atmega323
   atmega324p
   atmega325
   atmega325p
   atmega3250
   atmega3250p
   atmega328p
   atmega329
   atmega329p
   atmega3290
   atmega3290p
   atmega406
   atmega64
   atmega640
   atmega644
   atmega644p
   atmega645
   atmega6450
   atmega649
   atmega6490
   atmega16hva
   at90can32
   at90can64
   at90pwm216
   at90pwm316
   atmega32m1
   atmega32c1
   atmega32u4
   atmega32u6
   at90usb646
   at90usb647
   at94k
   avr51
   atmega128
   atmega1280
   atmega1281
   atmega1284p
   at90can128
   at90usb1286
   at90usb1287
   avr6
   atmega2560
   atmega2561
   avrxmega4
   atxmega64a3
   avrxmega5
   atxmega64a1
   avrxmega6
   atxmega128a3
   atxmega256a3
   atxmega256a3b
   avrxmega7
   atxmega128a1
   avr1
   at90s1200
   attiny11
   attiny12
   attiny15
   attiny28
DigisparkOOK.cpp:1: error: MCU 'digispark' supported for assembler only
In file included from DigisparkOOK.ino:2:
/Users/bluebie/Documents/Arduino/libraries/DigisparkKeyboard/DigiKeyboard.h: In constructor 'DigiKeyboardDevice::DigiKeyboardDevice()':
/Users/bluebie/Documents/Arduino/libraries/DigisparkKeyboard/DigiKeyboard.h:133: error: 'TIMSK' was not declared in this scope
/Users/bluebie/Documents/Arduino/libraries/DigisparkKeyboard/DigiKeyboard.h:133: error: 'TOIE0' was not declared in this scope
/Users/bluebie/Documents/Arduino/libraries/DigisparkKeyboard/DigiKeyboard.h:135: error: 'DDRB' was not declared in this scope

or with MIT High-Low:

/Applications/Digispark Ready - Arduino 1.03.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o: In function `__vector_default':
(.vectors+0xa): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_5' defined in .text.__vector_5 section in core.a(wiring.c.o)
/Applications/Digispark Ready - Arduino 1.03.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o:(.init9+0x2): relocation truncated to fit: R_AVR_13_PCREL against symbol `exit' defined in .fini9 section in /Applications/Digispark Ready - Arduino 1.03.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25/libgcc.a(_exit.o)
core.a(main.cpp.o): In function `main':
/Applications/Digispark Ready - Arduino 1.03.app/Contents/Resources/Java/hardware/arduino/cores/arduino/main.cpp:15: relocation truncated to fit: R_AVR_13_PCREL against undefined symbol `serialEventRun()'

The R_AVR_13_PCREL problem seems to be solvable by updating the version of avr-gcc in the IDE to a newer release, says some googling. Don't have any clue what's going on with the tinycore board.

digistump commented 11 years ago

The tinycore should be fixed with the latest commit - the boards.txt was outdated and some there are some fixes for tinycore to work with 16.5mhz - I've found the MIT High-Low doesn't work so well with most libraries, so I recommend the tiny core.

Bluebie commented 11 years ago

Yep! Sorted! <3