Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On ESP32 transceiver stops receiving after first transmission #2

Closed
ob1w4nken0b1 opened this issue Jun 29, 2022 · 25 comments
Closed

On ESP32 transceiver stops receiving after first transmission #2

ob1w4nken0b1 opened this issue Jun 29, 2022 · 25 comments

Comments

@ob1w4nken0b1
Copy link

Hi,

Thanks for the awesome work, I would really love to see this implemented as official component for ESPHome.

The only issue i have is that on ESP32 the transceiver stops receiving after the first transmission...I tested both basic and advanced .yaml configs from your repo so the issue seems to be in CC1101.h code

If you can give any clues about what can cause the issue i can test it

Regards

@dbuezas
Copy link
Owner

dbuezas commented Jun 29, 2022

Hey!
The chip is probably stuck in transmission mode. Did you make sure to call "endTransmission" via a lambda after transmitting?
Btw, I only tested it on esp8266, but it shouldn't make a difference.

May the force be with you obi wan

@ob1w4nken0b1
Copy link
Author

Hi,

Thx for your reply.

The cover actions from my config look like this:

  open_action:
    - lambda: get_cc1101(transciver).beginTransmission();
    - remote_transmitter.transmit_raw:
        code: [-******  ******  -******]
        repeat:
          times: 10
    - lambda: get_cc1101(transciver).endTransmission();

    - delay: 80s
    - cover.template.publish:
        id: gate
        state: CLOSED

So I am calling the "endTransmission" via lambda but somehow it might not be setting the transceiver back to RX

May the force be with you too :)

@ob1w4nken0b1
Copy link
Author

ob1w4nken0b1 commented Jul 2, 2022

Hi!
I finally managed to fix the issue by modifying CC1101.h code adding GDO2 configuration for RX...after some testing i think the issue was in the constant change of pinMode for GDO0 switching from input to output back and forth...setting GDO0 for output and GDO2 for input made it work for me. I also added a block called setRX so you can decide from yaml file if you want to set it back to rx after transmission or leave it idle

this is my version of cc1101.h if you're interested

#ifndef CC1101TRANSCIVER_H
#define CC1101TRANSCIVER_H

#include <ELECHOUSE_CC1101_SRC_DRV.h>

int CC1101_module_count = 0;
#define get_cc1101(id) (*((CC1101 *)id))

class CC1101 : public PollingComponent, public Sensor {
  int _SCK;
  int _MISO;
  int _MOSI;
  int _CSN;
  int _GDO0;
  int _GDO2;
  float _bandwidth;
  
  float _moduleNumber;
  int _last_rssi = 0;

  void setup() {
    ELECHOUSE_cc1101.setGDO(_GDO0, _GDO2);
    ELECHOUSE_cc1101.addSpiPin(_SCK, _MISO, _MOSI, _CSN, _moduleNumber);
    ELECHOUSE_cc1101.setModul(_moduleNumber);
    ELECHOUSE_cc1101.Init();
    ELECHOUSE_cc1101.setRxBW(_bandwidth);
    ELECHOUSE_cc1101.setMHZ(_freq);
    ELECHOUSE_cc1101.SetRx();
  }

 public:
  float _freq;
  CC1101(int SCK, int MISO, int MOSI, int CSN, int GDO0, int GDO2, float bandwidth,
         float freq)
      : PollingComponent(100) {
    _SCK = SCK;
    _MISO = MISO;
    _MOSI = MOSI;
    _CSN = CSN;
    _GDO0 = GDO0;
    _GDO2 = GDO2;
    _bandwidth = bandwidth;
    _freq = freq;
    _moduleNumber = CC1101_module_count++;
  }

  void beginTransmission() {
    ELECHOUSE_cc1101.setModul(_moduleNumber);
    ELECHOUSE_cc1101.SetTx();
    noInterrupts();
  }
  void endTransmission() {
    interrupts();
    ELECHOUSE_cc1101.setModul(_moduleNumber);
    ELECHOUSE_cc1101.setSidle(); 
  }
  void setRX() {
    ELECHOUSE_cc1101.setModul(_moduleNumber);
    ELECHOUSE_cc1101.SetRx(); 
  }  
  void setBW(float bandwidth) {
    ELECHOUSE_cc1101.setModul(_moduleNumber);
    ELECHOUSE_cc1101.setRxBW(bandwidth);
  }
  void setFreq(float freq) {
    ELECHOUSE_cc1101.setModul(_moduleNumber);
    ELECHOUSE_cc1101.setMHZ(freq);
  }
  bool rssi_on;
  void update() override {
    int rssi = 0;
    if (rssi_on) {
      ELECHOUSE_cc1101.setModul(_moduleNumber);
      rssi = ELECHOUSE_cc1101.getRssi();
    }
    if (rssi != _last_rssi) {
      publish_state(rssi);
      _last_rssi = rssi;
    }
  }
};

#endif

@dbuezas dbuezas mentioned this issue Aug 17, 2022
@ageurtse
Copy link

ageurtse commented Aug 18, 2022

Hi! I finally managed to fix the issue by modifying CC1101.h code adding GDO2 configuration for RX...after some testing i think the issue was in the constant change of pinMode for GDO0 switching from input to output back and forth...setting GDO0 for output and GDO2 for input made it work for me. I also added a block called setRX so you can decide from yaml file if you want to set it back to rx after transmission or leave it idle

this is my version of cc1101.h if you're interested

Do i still need to call the start transmission and stop transmission ?

@ob1w4nken0b1
Copy link
Author

ob1w4nken0b1 commented Aug 18, 2022

Hi! I finally managed to fix the issue by modifying CC1101.h code adding GDO2 configuration for RX...after some testing i think the issue was in the constant change of pinMode for GDO0 switching from input to output back and forth...setting GDO0 for output and GDO2 for input made it work for me. I also added a block called setRX so you can decide from yaml file if you want to set it back to rx after transmission or leave it idle
this is my version of cc1101.h if you're interested

Do i still need to call the start transmission and stop transmission ?

Yes, you absolutely do. You also have to call setRX the same way from yaml file if you want to set it back to RX mode after transmission.

@TheChatty
Copy link

I'm new to HA and ESPHome. I already installed ESPHome to my ESP32 devkit C4. I connected my CC1101 like this because I had success with this config with another firmware.

Could you please post your complete ESP32 yaml file? Where to put the cc1101.h? Where can I follow arbitrary RF signals being received? Once I found the interesting signal (like key presses from a remote) - how to define a "button" in HA to send (repeat) this signal?

@dbuezas
Copy link
Owner

dbuezas commented Mar 24, 2023

The complete yaml is any of the two yaml files in this repo.
The cc1101.h file goes in the same folder as the yaml file.
To pick arbitrary signals take a look at "dump: raw" in the EspHome docs here: https://esphome.io/components/remote_receiver.html

@dbuezas
Copy link
Owner

dbuezas commented Mar 24, 2023

Here's a utility to analyze raw signals btw:
https://github.com/dbuezas/esphome-remote_receiver-oscilloscope

@dbuezas
Copy link
Owner

dbuezas commented Mar 24, 2023

I haven't tried it with the esp32 myself, but somebody did in the issues of this repo, try searching in the issues of this repo :)

Regarding the file, you'll have to copy it to where EspHome stores its yaml files (google HomeAssistant file explorer or ssh), or maybe try including the the GitHub url of the file, it may work

@TheChatty
Copy link

ssh'd into HA, placed @ob1w4nken0b1's cc1101.h in /config/esphome but validation fails with:

INFO Reading configuration /config/esphome/esphome-web-2c7b48.yaml...
Failed config

remote_transmitter: [source /config/esphome/esphome-web-2c7b48.yaml:54]
  - 
    Cannot resolve pin name 'D4' for board esp32dev.
    pin: D4
    carrier_duty_percent: 100%
remote_receiver: [source /config/esphome/esphome-web-2c7b48.yaml:58]
  - 
    Cannot resolve pin name 'D13' for board esp32dev.
    pin: D13
    dump: 
      - raw

@dbuezas
Copy link
Owner

dbuezas commented Mar 25, 2023

@TheChatty
Copy link

Eventually I used GPIOx and bare numbers in new CC1101(...). Now I can see signal noise in the logs. When I push a button of a remote there's a block of numbers. How to go from here?
I could decode the signal using rtl_433 using this flex decoder.

@dbuezas
Copy link
Owner

dbuezas commented Mar 25, 2023

From there i suggest you read the remote_receiver and remote_transmitter components in the esphome docs abd then take a look at the utility I posted above. Good luck!

@brunopiras
Copy link

brunopiras commented Apr 23, 2023

Hello there, just a little piece of advice, I've the 433Mhz module, same yours, I've 8 pin, but I don't find any information about connection to esp32.

Thanks

ps:

Do you think it's correct this:

  - platform: custom
    lambda: |-
      auto my_sensor = new CC1101(
        GPIO18, // SCK
        GPIO19, // MISO
        GPIO23, // MOSI
        GPIO02, // CSN
        GPIO16, // GDO0
        200, // bandwidth_in_khz
        433.92 // freq_in_mhz
      );
      App.register_component(my_sensor);
      return {my_sensor};
    sensors:
      id: transciver_1
      name: "${name} RF RSSI"
      unit_of_measurement: dBm
      entity_category: diagnostic
remote_transmitter:
  - id: transmitter_1
    pin: GPIO16 
    carrier_duty_percent: 100%   
remote_receiver:
  - id: receiver_1
    pin: GPIO16 
    dump:
      - raw

@deanfourie1
Copy link

class CC1101 : public PollingComponent, public Sensor {
int _SCK;
int _MISO;
int _MOSI;
int _CSN;
int _GDO0;
int _GDO2;
float _bandwidth;

What do we need to add in the YAML with this?

Thanks

@dbuezas
Copy link
Owner

dbuezas commented May 20, 2023

See the yaml file in this repo

@gregb79
Copy link

gregb79 commented Aug 18, 2023

HI , Any chance of getting a copy of your yaml file as well please.

@kgstorm
Copy link

kgstorm commented Sep 13, 2023

The complete yaml is any of the two yaml files in this repo.
The cc1101.h file goes in the same folder as the yaml file.
To pick arbitrary signals take a look at "dump: raw" in the EspHome docs here: https://esphome.io/components/remote_receiver.html

Except you would have to modify the yaml to define the GDO2 pin, correct?

@jbrandek
Copy link

Hello there, just a little piece of advice, I've the 433Mhz module, same yours, I've 8 pin, but I don't find any information about connection to esp32.

Thanks

ps:

Do you think it's correct this:

  - platform: custom
    lambda: |-
      auto my_sensor = new CC1101(
        GPIO18, // SCK
        GPIO19, // MISO
        GPIO23, // MOSI
        GPIO02, // CSN
        GPIO16, // GDO0
        200, // bandwidth_in_khz
        433.92 // freq_in_mhz
      );
      App.register_component(my_sensor);
      return {my_sensor};
    sensors:
      id: transciver_1
      name: "${name} RF RSSI"
      unit_of_measurement: dBm
      entity_category: diagnostic
remote_transmitter:
  - id: transmitter_1
    pin: GPIO16 
    carrier_duty_percent: 100%   
remote_receiver:
  - id: receiver_1
    pin: GPIO16 
    dump:
      - raw

did you make it work for esp32?

@deanfourie1
Copy link

Never got mine working.

@kgstorm
Copy link

kgstorm commented Nov 10, 2023

@brunopiras I believe CSN should be GPIO5 as shown here

That said, I tried for a few days to get an ESP 32S working and gave up and just hooked up another 8266 and it worked right away.

@dbuezas
Copy link
Owner

dbuezas commented Nov 10, 2023

I never tried. You can google if the library I'm using is compatible with the esp32. The library is called ELECHOUSE_CC1101_SRC_DRV

@dbuezas
Copy link
Owner

dbuezas commented Nov 10, 2023

Sorry it is this one: https://github.com/LSatan/SmartRC-CC1101-Driver-Lib which derives from the one I mentioned. It states in the readme that the author made some fixes for the esp32. You may want to dig there

@dbuezas
Copy link
Owner

dbuezas commented Jun 8, 2024

Try the new cc1101 and yaml files. GDO2 not necessary in esp32 anymore.

@dbuezas dbuezas closed this as completed Jun 8, 2024
@TheChatty
Copy link

I can confirm ESP32 to be working with esphome with seperate RX/TX pins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants