Skip to content

ankushkale1/NEC-IR-Receiver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CH32V003 NEC IR Receiver

CH32V003 Pinout

This project implements a NEC IR decoder for CH32V003 series microcontrollers. It's designed to be a lightweight and efficient library for receiving and decoding infrared signals from common remote controls that use the NEC protocol.

Features

  • Non-blocking: The decoder uses pin change interrupts and a state machine to decode the signal without blocking the main loop.
  • Lightweight: The library has a small footprint, making it suitable for resource-constrained microcontrollers like the CH32V003.
  • Easy to use: A simple available() and read() interface is provided.
  • Debug Mode: Includes an optional debug mode to print detailed state machine transitions and timing information to the serial port.

Pin Configuration

The pin configuration is straightforward.

  • IR Receiver Input: The IR receiver's data pin should be connected to a pin on the CH32V003. In the example main.cpp, this is PD4. You can change this in the NecIrDecoder constructor:

    NecIrDecoder ir_decoder(PD4); // Using PD4 as the IR input pin
  • Status LED (Optional): The example uses a "heartbeat" LED to indicate that the system is running. This is defined on pin PC3.

    #define HEARTBEAT_PIN PC3     // Using PC3 for a status LED

main.cpp Test Program

The src/main.cpp file serves as a test program and an example of how to use the NecIrDecoder library.

How it Works

  1. Initialization:

    • It initializes the serial communication for printing output.
    • It creates an instance of the NecIrDecoder, passing the IR input pin (PD4).
    • It calls ir_decoder.begin() to set up the pin and the interrupt handler.
  2. Main Loop (loop()):

    • The loop is non-blocking.
    • It continuously checks if the decoder has data available using ir_decoder.available().
    • If data is available, it reads the decoded data into a NecDecodedData struct using ir_decoder.read().
    • The decoded data (address, command, raw data, and repeat flag) is then printed to the serial monitor.

Debugging

The main.cpp file includes a compile-time switch NEC_IR_DECODER_DEBUG.

  • If NEC_IR_DECODER_DEBUG is set to 1, the program will print detailed information about the ISR (Interrupt Service Routine) state transitions, timings, and function calls within the decoder. This is useful for debugging the decoder itself or troubleshooting signal reception issues.
  • If NEC_IR_DECODER_DEBUG is set to 0, all debug output is disabled, resulting in a cleaner and faster execution, suitable for a release version.

How to Use

  1. Connect your IR receiver's data pin to PD4 on your CH32V003.
  2. Connect the IR receiver's VCC and GND to the appropriate power pins.
  3. (Optional) Connect an LED to PC3 to act as a status indicator.
  4. Upload the code using PlatformIO.
  5. Open the Serial Monitor at 115200 baud.
  6. Point a NEC-compatible remote at the sensor and press buttons. You should see the decoded address and command codes printed in the monitor.

About

NEC IR Receiver library for CH32V003 family microcontrollers

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages