Arduino Polska Forum

Pełna wersja: Pomoc w przerobieniu mojego kodu pod attiny 2313a-pu
Aktualnie przeglądasz uproszczoną wersję forum. Kliknij tutaj, by zobaczyć wersję z pełnym formatowaniem.
Witam,
proszę o pomoc w przerobieniu kodu pod Attiny 2313. Kod działa pod arduino pro mini a na attiny nie chce sie skompilować wyskakują różne błędy. Jak coś to proste programy w stylu miganie diodą się kompilują i działają. Problemem są jak się domyślam inne biblioteki IR ale nie wiem skąd pobrać działające mam nadzieje że są. No chyba że ten mikro kontroler ma jakieś ograniczenia które nie pozwolą wykorzystać go do tego celu co ja chce. Nigdy czegoś takiego nie robiłem nie wiem jak to zrobić. 
Kod:
// Based on Henry's Bench IR Remote Tutorial
// An IR detector/demodulator must be connected to the input RECV_PIN.
// An IR LED must be connected to the output PWM pin 3.

#include <IRremote.h>

int IR_PIN = 7;

IRrecv irDetect(IR_PIN);
IRsend irsend;

decode_results irIn;

unsigned long lastCode;


void setup() {
    irDetect.enableIRIn(); // Start the Receiver

    pinMode(LED_BUILTIN ,OUTPUT);

   


}

void loop() {
    if (irDetect.decode(&irIn)) {
        decodeIR();
        irDetect.resume(); // Receive the next value
        irDetect.enableIRIn(); // Re-enable receiver
    }
}


void decodeIR() {           // Indicate what key is pressed
    static unsigned long lastCode;
    unsigned long code = 0;

    switch(irIn.value) {
        case 0x7EC02B57:    // 0
            code = 0xFF807F;
            break;

        case 0xA669A2AA:    // 1
            code = 0xFF728D ;
            break;

        case 0x407B03BD:    // 2
            code = 0xFFB04F;
            break;

        case 0xBC6836D6:    // 3
            code = 0xFF30CF;
            break;
           
        case 0xC2A56EBC:    // 4
            code = 0xFF52AD;
            break;

            case 0xE7A7E794:    // 5
            code = 0xFF906F;
            break;
            case 0x85BEBE9B:    // 6
            code = 0xFF10EF;
            break;
            case 0x5C917422:    // 7
            code = 0xFF629D;
            break;
            case 0xBFE1AF54:    // 8
            code = 0xFFA05F;
            break;
            case 0xE4E4282C:    // 9
            code = 0xFF20DF;
            break;
            case 0x31603DC:    // menu
            code = 0xFFAA55;
            break;

            case 0xE90B726A:    // power
            code = 0xFF827D;
            break;

             case 0x72A9343B:    // exit
            code = 0xFF2AD5;
            break;

           
case 0xA67001EB:    // usb
            code = 0xFFE21D;
            break;

            case 0xCB052CC8:    // prog up
            code = 0xFF58A7;
            break;

            case 0xDE272CB6:    // ok
            code = 0xFFC837;
            break;


            case 0xEAA5D43C:    // strzalka w prawo
            code = 0xFF0AF5;
            break;


            case 0xA13:    // strzalka w prawo
            code = 0xFFA05F;
            break;


case 0xA12:    // strzalka w prawo
            code = 0xFF30CF;
            break;
           

        default:        // Not a valid key
            code = 0;
            break;
    }

    if (code != 0){
        digitalWrite(LED_BUILTIN, HIGH);
        irsend.sendNEC(code, 32);

    }

    lastCode = code;

    delay(10);
    digitalWrite(LED_BUILTIN, LOW);
}
Pewnie wali błędem że "LED_BUILTIN" nie jest zdefiniowany...
Ta biblioteka jest bardzo rozbudowana i obsługuje bardzo dużo mikrokontrolerów, ale tego Attiny nie ma na liście. Tam są wykorzystywane bezpośrednio timery sprzętowe, więc bez przeróbki biblioteki może nie działać.
https://github.com/Arduino-IRremote/Arduino-IRremote
Kod:
In file included from /home/arek/Arduino/libraries/IRremote-3.4.0/src/IRremote.h:192:0,
                 from /home/arek/Pulpit/pilot_tmobile/pilot_tmobile.ino:5:
/home/arek/Arduino/libraries/IRremote-3.4.0/src/private/IRTimer.hpp:792:2: error: #error Internal code configuration error, no timer functions implemented for this AVR CPU / board
#error Internal code configuration error, no timer functions implemented for this AVR CPU / board
  ^~~~~
exit status 1
Błąd kompilacji dla płytki ATtiny2313(a)/4313 (No bootloader).

No coś tam jest o timerach ogólnie nie mój poziom. A jest gdzieś gotowa działająca biblioteka pod tego attiny?
Jeśliby na magazynie fabryki zalegało parę tysi tego chipa to można by się skusić na takie kombinacje, ale zazwyczaj to się dobiera sprzęt pod projekt, również w sensie posiadanej biblioteki.
Nie wykluczone, że to może być bardzo prosta konwersja, trzeba ściągnąć PDF datasheet tych chipów wymienionych jako obsługiwane i Attiny2313, przejrzeć sekcje timerów i sparować się z tym najbardziej podobnym, potem w pliku IRTimer.hpp zobaczyć jak są definiowane grupy sprzętu, np. cała rodzina attiny 25/45/85:
https://github.com/Arduino-IRremote/Ardu...RTimer.hpp
//ATtiny85, 45, 25
#elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
i wystarczy dopisać na końcu kolejny LUB: || defined(__AVR_ATtiny2313__)
Oczywiście tu to raczej nie zadziała, bo to zupełnie inna generacja. Gdyby wśród obsługiwanych nie było np. Attiny25, to można by tak dopisać na pałę, bo one się różnią tylko wielkością flash.
To bardziej czasy Atmega8, zmiany takich definicji przy przejściu np. z Atmega8 na Atmega88 czy Atmega328 też można zrobić na czuja, w tych uC z 8 na końcu dodano dodatkowe funkcje i rejestry, pojawiły się A i B, więc by z 88 odpalić coś na starej 8 wystarczyło zastąpić te nazwy właściwymi usuwając jedną literkę.
Raczej analizując takie PDF trzeba stworzyć kolejną sekcję:
#elif defined ....
Dodatkowo też dochodzi sam wybór CORE do Attiny, może być tak, że w jednym pin timera jest zdefiniowany jako 9, a w innym jako 8, w kolejnym jako 13. Albo w jednym są dwie definicje do wyboru.
Jak nie chcesz sobie tego ogarniać, to dopłać 5zł do Atmegi 328 i użyj istniejącej biblioteki jak jest.
W sumie to nic nie szkodzi, że nie umiesz dodać tego uC do biblioteki, bo jak przez wszystko przebrniesz to i tak się okaże, że 128 bajtów RAM w Attiny2313 to za mało, a pokazany kod zajmuje na dzień dobry ponad 500 RAM i minimum to Atmega88, podobnie z flash - prawie 6kB (skompilowałem pod Attiny88, z Attiny85 zajmuje mniej, ale i tak daleko do 2313).
Takie coś można zrobić na Attiny13, ale już raczej bez biblioteki, na zwięzłych funkcjach C tylko w zakresie jakim to niezbędne: https://blog.podkalicki.com/attiny13-ir-...nec-proto/
Na digisparku to zadziała? Tam chyba jest Attiny85. Tak się składa że, mam gdzieś taki.
Skompilowałem to dla Attiny85, pisałem wyżej, przecież skompilować też sobie możesz i sprawdzić u siebie nawet jak nie znajdziesz tego digiSparka.
Czy Ci zadziała nie wiem, szanse są, nie analizowałem jak są pomotane piny na tej płytce do USB, zawsze można wylutować co niepotrzebne.
Błąd kompilacji dla płytki Digispark (Default 16 Mhz)
No i taki festiwal błędów:
Kod:
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRProtocol.h:68:7: error: '__FlashStringHelper' does not name a type
const __FlashStringHelper* getProtocolString(decode_type_t aProtocol);
       ^
In file included from /home/arek/Arduino/libraries/IRremote-3.4.0/src/IRremote.h:191:0,
                 from /home/arek/Pulpit/pilot_tmobile/pilot_tmobile.ino:5:
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRremoteInt.h:496:27: error: '__FlashStringHelper' does not name a type
     void sendPronto(const __FlashStringHelper *str, uint_fast8_t aNumberOfRepeats = NO_REPEATS);
                           ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRremoteInt.h:496:48: error: ISO C++ forbids declaration of 'str' with no type [-fpermissive]
     void sendPronto(const __FlashStringHelper *str, uint_fast8_t aNumberOfRepeats = NO_REPEATS);
                                                ^
In file included from /home/arek/Arduino/libraries/IRremote-3.4.0/src/IRremote.h:197:0,
                 from /home/arek/Pulpit/pilot_tmobile/pilot_tmobile.ino:5:
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRReceive.hpp: In function 'void printIRResultShort(Print*, IRData*, uint16_t)':
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRReceive.hpp:874:58: error: 'getProtocolString' was not declared in this scope
     aSerial->print(getProtocolString(aIRDataPtr->protocol));
                                                          ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRReceive.hpp: At global scope:
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRReceive.hpp:1179:7: error: '__FlashStringHelper' does not name a type
const __FlashStringHelper* getProtocolString(decode_type_t aProtocol) {
       ^
In file included from /home/arek/Arduino/libraries/IRremote-3.4.0/src/IRremote.h:198:0,
                 from /home/arek/Pulpit/pilot_tmobile/pilot_tmobile.ino:5:
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp: In member function 'size_t IRsend::write(IRData*, uint_fast8_t)':
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:103:10: error: 'tProtocol' does not name a type
     auto tProtocol = aIRSendData->protocol;
          ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:104:10: error: 'tAddress' does not name a type
     auto tAddress = aIRSendData->address;
          ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:105:10: error: 'tCommand' does not name a type
     auto tCommand = aIRSendData->command;
          ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:142:9: error: 'tProtocol' was not declared in this scope
     if (tProtocol == NEC) {
         ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:143:17: error: 'tAddress' was not declared in this scope
         sendNEC(tAddress, tCommand, aNumberOfRepeats, tSendRepeat);
                 ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:143:27: error: 'tCommand' was not declared in this scope
         sendNEC(tAddress, tCommand, aNumberOfRepeats, tSendRepeat);
                           ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:146:21: error: 'tAddress' was not declared in this scope
         sendSamsung(tAddress, tCommand, aNumberOfRepeats, tSendRepeat);
                     ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:146:31: error: 'tCommand' was not declared in this scope
         sendSamsung(tAddress, tCommand, aNumberOfRepeats, tSendRepeat);
                               ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:149:18: error: 'tAddress' was not declared in this scope
         sendSony(tAddress, tCommand, aNumberOfRepeats, aIRSendData->numberOfBits);
                  ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:149:28: error: 'tCommand' was not declared in this scope
         sendSony(tAddress, tCommand, aNumberOfRepeats, aIRSendData->numberOfBits);
                            ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:152:23: error: 'tAddress' was not declared in this scope
         sendPanasonic(tAddress, tCommand, aNumberOfRepeats);
                       ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:152:33: error: 'tCommand' was not declared in this scope
         sendPanasonic(tAddress, tCommand, aNumberOfRepeats);
                                 ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:155:19: error: 'tAddress' was not declared in this scope
         sendDenon(tAddress, tCommand, aNumberOfRepeats);
                   ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:155:29: error: 'tCommand' was not declared in this scope
         sendDenon(tAddress, tCommand, aNumberOfRepeats);
                             ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:158:19: error: 'tAddress' was not declared in this scope
         sendSharp(tAddress, tCommand, aNumberOfRepeats);
                   ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:158:29: error: 'tCommand' was not declared in this scope
         sendSharp(tAddress, tCommand, aNumberOfRepeats);
                             ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:161:16: error: 'tAddress' was not declared in this scope
         sendLG(tAddress, tCommand, aNumberOfRepeats, tSendRepeat);
                ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:161:26: error: 'tCommand' was not declared in this scope
         sendLG(tAddress, tCommand, aNumberOfRepeats, tSendRepeat);
                          ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:164:27: error: 'tAddress' was not declared in this scope
         sendJVC((uint8_t) tAddress, (uint8_t) tCommand, aNumberOfRepeats); // casts are required to specify the right function
                           ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:164:47: error: 'tCommand' was not declared in this scope
         sendJVC((uint8_t) tAddress, (uint8_t) tCommand, aNumberOfRepeats); // casts are required to specify the right function
                                               ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:167:17: error: 'tAddress' was not declared in this scope
         sendRC5(tAddress, tCommand, aNumberOfRepeats, !tSendRepeat); // No toggle for repeats
                 ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:167:27: error: 'tCommand' was not declared in this scope
         sendRC5(tAddress, tCommand, aNumberOfRepeats, !tSendRepeat); // No toggle for repeats
                           ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:170:17: error: 'tAddress' was not declared in this scope
         sendRC6(tAddress, tCommand, aNumberOfRepeats, !tSendRepeat); // No toggle for repeats
                 ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:170:27: error: 'tCommand' was not declared in this scope
         sendRC6(tAddress, tCommand, aNumberOfRepeats, !tSendRepeat); // No toggle for repeats
                           ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:173:26: error: 'tAddress' was not declared in this scope
         sendKaseikyo_JVC(tAddress, tCommand, aNumberOfRepeats);
                          ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:173:36: error: 'tCommand' was not declared in this scope
         sendKaseikyo_JVC(tAddress, tCommand, aNumberOfRepeats);
                                    ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:176:28: error: 'tAddress' was not declared in this scope
         sendKaseikyo_Denon(tAddress, tCommand, aNumberOfRepeats);
                            ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:176:38: error: 'tCommand' was not declared in this scope
         sendKaseikyo_Denon(tAddress, tCommand, aNumberOfRepeats);
                                      ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:179:28: error: 'tAddress' was not declared in this scope
         sendKaseikyo_Sharp(tAddress, tCommand, aNumberOfRepeats);
                            ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:179:38: error: 'tCommand' was not declared in this scope
         sendKaseikyo_Sharp(tAddress, tCommand, aNumberOfRepeats);
                                      ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:182:33: error: 'tAddress' was not declared in this scope
         sendKaseikyo_Mitsubishi(tAddress, tCommand, aNumberOfRepeats);
                                 ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:182:43: error: 'tCommand' was not declared in this scope
         sendKaseikyo_Mitsubishi(tAddress, tCommand, aNumberOfRepeats);
                                           ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:185:19: error: 'tAddress' was not declared in this scope
         sendOnkyo(tAddress, tCommand, aNumberOfRepeats, tSendRepeat);
                   ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:185:29: error: 'tCommand' was not declared in this scope
         sendOnkyo(tAddress, tCommand, aNumberOfRepeats, tSendRepeat);
                             ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:188:19: error: 'tAddress' was not declared in this scope
         sendApple(tAddress, tCommand, aNumberOfRepeats, tSendRepeat);
                   ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:188:29: error: 'tCommand' was not declared in this scope
         sendApple(tAddress, tCommand, aNumberOfRepeats, tSendRepeat);
                             ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:192:22: error: 'tCommand' was not declared in this scope
         sendBoseWave(tCommand, aNumberOfRepeats);
                      ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:195:32: error: 'tAddress' was not declared in this scope
         sendLegoPowerFunctions(tAddress, tCommand, tCommand >> 4, tSendRepeat); // send 5 autorepeats
                                ^
/home/arek/Arduino/libraries/IRremote-3.4.0/src/IRSend.hpp:195:42: error: 'tCommand' was not declared in this scope
         sendLegoPowerFunctions(tAddress, tCommand, tCommand >> 4, tSendRepeat); // send 5 autorepeats
                                          ^
exit status 1
Błąd kompilacji dla płytki Digispark (Default - 16.5mhz).
Digispark to nieco inna bajka, trzeba mieć zainstalowany core do Attiny, wybrać po prostu Attiny85, wgrać przez programator ISP.
W AttinyCore też jest do wyboru digispark Attiny85 i kompiluje mi się kod nawet z nieistniejącym pinem nr 7.
Natomiast kojarzę, że miałem jakiś dedykowany core od Digisparka, ale go już nie mam by sprawdzić.