Digital Input

fabltd
Posts: 2
Joined: Wed Oct 16, 2019 7:59 pm

Digital Input

Postby fabltd » Wed Oct 16, 2019 8:11 pm

Hello All

I have a 868Mhz Radio connected to GPIO 14.

The transmitter ( handheld remote) sends a Logic 1 as a 0.88 MS Pulse and logic 0 as 0.44 Pulse.

I have tried every thing I can think of but I cannot seem to read the port quickly enough. I fail to detect the Logic pulses.

The transmitter uses a Sync bit ( Logic 1) of 2.6 MS this can be detected.

I have attached a change Interrupt and with in the ISR I have the following code:

Code: Select all

  void IRAM_ATTR ISR(){
  unsigned long timestamp = micros();
  unsigned long pulse_width = timestamp - last_timestamp;
  int pin = digitalRead(14);
  
  last_timestamp = timestamp;
  last_pulse_width = pulse_width;
  update = true;
  }
  
  void loop(){
  
  if (change){
  Serial.println(last_pulse_width);
  change = false;
  }
  
 
Is there a better way to read the pin so that I can detect the fast pulses. Help :D

JT

rodmcm
Posts: 37
Joined: Sat Sep 02, 2017 3:31 am

Re: Digital Input

Postby rodmcm » Thu Oct 17, 2019 7:35 am

Have you tried something simple like a print statement in the interrupt routine to see if it's working?

Serial.println(micros());

rodmcm
Posts: 37
Joined: Sat Sep 02, 2017 3:31 am

Re: Digital Input

Postby rodmcm » Thu Oct 17, 2019 7:38 am

I should have read your code better

You have to attach the interrupt to Pin 14 in the setup, not call it in the Interrupt routine
See
attachInterrupt( , ,)
Google
ESP32 with PIR Motion Sensor using Interrupts and Timers

Who is online

Users browsing this forum: No registered users and 14 guests