Partage
  • Partager sur Facebook
  • Partager sur Twitter

capteur infrarouge ATtiny85

    19 avril 2022 à 10:16:54

    Bonjour,

    Je réalise un projet ou j'ai besoin de recevoir une trame infrarouge (protocole NEC) afin d'identifier un conteneur parmi les autres. Chaque conteneur étant indépendant des autres il faut alimenter la carte électronique avec une pile 3V. J'utilise donc un ATtiny85V-10PU et un capteur infrarouge TSOP34438 relié a la broche 5 (PB0). J'utilise la librairie TinyIRReceiver pour décoder la trame. Le problème c'est que j'observe bien la trame reçu sur la broche correspondante a l'oscilloscope mais je n'arrive pas a la capturer via l'ATtiny.

    voici le code utilisé (exemple arduino, minimal receiver de la librairie IRremote)

    /*
     *  MinimalReceiver.cpp
     *
     *  Small memory footprint and no timer usage!
     *
     *  Receives IR protocol data of NEC protocol using pin change interrupts.
     *  On complete received IR command the function handleReceivedIRData(uint16_t aAddress, uint8_t aCommand, bool isRepetition)
     *  is called in Interrupt context but with interrupts being enabled to enable use of delay() etc.
     *  !!!!!!!!!!!!!!!!!!!!!!
     *  Functions called in interrupt context should be running as short as possible,
     *  so if you require longer action, save the data (address + command) and handle it in the main loop.
     *  !!!!!!!!!!!!!!!!!!!!!
     *
     *
     *  Copyright (C) 2020-2022  Armin Joachimsmeyer
     *  armin.joachimsmeyer@gmail.com
     *
     *  This file is part of IRMP https://github.com/ukw100/IRMP.
     *  This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
     *
     *  MinimalReceiver is free software: you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation, either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
     *
     */
    
    #include <Arduino.h>
    
    /*
     * Set sensible receive pin for different CPU's
     */
    #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
    #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut"
    #  if defined(ARDUINO_AVR_DIGISPARKPRO)
    #define IR_INPUT_PIN    9 // PA3 - on Digispark board labeled as pin 9
    #  else
    #define IR_INPUT_PIN    0 // PCINT0
    #  endif
    #elif defined(__AVR_ATtiny1616__)  || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)
    #define IR_INPUT_PIN    10
    #elif defined(ESP8266)
    #define IR_INPUT_PIN    14 // D5
    #elif defined(ESP32)
    #define IR_INPUT_PIN    15
    #elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO)
    #define IR_INPUT_PIN    3   // GPIO15 Use pin 3 since pin 2|GPIO25 is connected to LED on Pi pico
    #elif defined(ARDUINO_ARCH_RP2040) // Pi Pico with arduino-pico core https://github.com/earlephilhower/arduino-pico
    #define IR_INPUT_PIN    15  // to be compatible with the Arduino Nano RP2040 Connect (pin3)
    #else
    #define IR_INPUT_PIN    2
    //#define NO_LED_FEEDBACK_CODE   // Activate this if you want to suppress LED feedback or if you do not have a LED. This saves 14 bytes code and 2 clock cycles per interrupt.
    #endif
    #define IR_INPUT_PIN    5
    //#define DEBUG // to see if attachInterrupt is used
    //#define TRACE // to see the state of the ISR state machine
    
    /*
     * Second: include the code and compile it.
     */
    #include "TinyIRReceiver.hpp"
    
    /*
     * Helper macro for getting a macro definition as string
     */
    #if !defined(STR_HELPER)
    #define STR_HELPER(x) #x
    #define STR(x) STR_HELPER(x)
    #endif
    
    volatile struct TinyIRReceiverCallbackDataStruct sCallbackData;
    
    void setup()
    {
      
      DDRB |= 1<<PB3; //mise en sortie de la broche de la LED
      //verif de bon fonctionnement
      PORTB |= 1 <<(PB3);
      _delay_ms(500);
      PORTB&=~(1<<PB3);
    
      
        Serial.begin(115200);
    #if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217)
        delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor!
    #endif
        // Just to know which program is running on my Arduino
    #if defined(ESP8266)
        Serial.println();
    #endif
        Serial.println(F("START " __FILE__ " from " __DATE__));
        initPCIInterruptForTinyReceiver();
        Serial.println(F("Ready to receive NEC IR signals at pin " STR(IR_INPUT_PIN)));
    }
    
    void loop()
    {
        if (sCallbackData.justWritten)
        {
            sCallbackData.justWritten = false;
            Serial.print(F("Address=0x"));
            Serial.print(sCallbackData.Address, HEX);
            Serial.print(F(" Command=0x"));
            Serial.print(sCallbackData.Command, HEX);
            if (sCallbackData.isRepeat)
            {
                Serial.print(F(" Repeat"));
            }
            else{
              if(sCallbackData.Command !=0){//si on recoit une trame non nulle on fait clignoter la led
                    PORTB |= 1 <<(PB3);
                    _delay_ms(500);
                    PORTB&=~(1<<PB3);
              }  
            }
            Serial.println();
        }
        /*
         * Put your code here
         */
    }
    
    /*
     * This is the function is called if a complete command was received
     * It runs in an ISR context with interrupts enabled, so functions like delay() etc. are working here
     */
    #if defined(ESP8266)
    void ICACHE_RAM_ATTR handleReceivedTinyIRData(uint16_t aAddress, uint8_t aCommand, bool isRepeat)
    #elif defined(ESP32)
    void IRAM_ATTR handleReceivedTinyIRData(uint16_t aAddress, uint8_t aCommand, bool isRepeat)
    #else
    void handleReceivedTinyIRData(uint16_t aAddress, uint8_t aCommand, bool isRepeat)
    #endif
    {
    
    #if defined(ARDUINO_ARCH_MBED) || defined(ESP32)
        // Copy data for main loop, this is the recommended way for handling a callback :-)
        sCallbackData.Address = aAddress;
        sCallbackData.Command = aCommand;
        sCallbackData.isRepeat = isRepeat;
        sCallbackData.justWritten = true;
    #else
        /*
         * This is not allowed in ISR context for any kind of RTOS
         * For Mbed we get a kernel panic and "Error Message: Semaphore: 0x0, Not allowed in ISR context" for Serial.print()
         * for ESP32 we get a "Guru Meditation Error: Core  1 panic'ed" (we also have an RTOS running!)
         */
        // Print only very short output, since we are in an interrupt context and do not want to miss the next interrupts of the repeats coming soon
        Serial.print(F("A=0x"));
        Serial.print(aAddress, HEX);
        Serial.print(F(" C=0x"));
        Serial.print(aCommand, HEX);
        Serial.print(F(" R="));
        Serial.print(isRepeat);
        Serial.println();
    #endif
    }



    • Partager sur Facebook
    • Partager sur Twitter
      19 avril 2022 à 13:05:39

      Bonjour,

      Les broches sont rarement numérotées en fonction de leur position sur la puce. Sur la plupart des bibliothèques de cartes pour ATTiny85 que tu peux ajouter dans l'IDE Arduino, PB0 a pour numéro 0, pas 5.

      La plupart du temps, tu peux trouver un diagramme avec le numéro des broches avec une recherche (ex: "attiny85 pinout") sur google images, mais sinon, il faut essayer de décoder le code source des bibliothèques de cartes et chercher un fichier pin_arduino.h et en fonction des cas, pin_arduino.c.

      • Partager sur Facebook
      • Partager sur Twitter

      capteur infrarouge ATtiny85

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown