sui77 / rc-switch

Arduino lib to operate 433/315Mhz devices like power outlet sockets.
1.94k stars 662 forks source link

Receive and ATiny85 #143

Open danjohn opened 7 years ago

danjohn commented 7 years ago

The implementation disables receive features on ATtiny's due to "missing libm depencies (udivmodhi4)".

I don't know, maybe that requirement has changed in the last few months (new libs? adapted code?), but I can definitely compile and (obviousely successful) run that receive code on a DigiSpark-like target.

Hopefully this could be verified by a more experienced user!? (Also, I can't see where "divmod" would be used in the sources (pls give a noob a hint!:))

All I did for testing, was to comment out "#define RCSwitchDisableReceiving" in RCSwitch.h (line 56). Sketch:

#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
const int LED = 1;

void setup() {                
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
  pinMode(LED,OUTPUT);
}

void loop() {
   if (mySwitch.available()) {
      digitalWrite(LED,HIGH);
      mySwitch.resetAvailable();
      delay(10);
   } else {
      digitalWrite(LED,LOW);
   }
}

Blinks when I press a button on my RC key.

IDE: arduino-1.8.2-linux32 RC-switch: version of Feb 27, 2017 Target: http://www.electrodragon.com/product/attiny85-usb-mini-dev-board-digispark-compatible/

rolandas-valantinas commented 6 years ago

Which pin on Attiny85 you use for receiving? Though code does compile with https://github.com/damellis/attiny LED is not blinking while I'm transmitting from Arduino.

bodtx commented 6 years ago

According to his comment

// Receiver on interrupt 0 => that is pin #2

And to the pin definition

The pin to use is 2, the one under VCC.

I'll check that tonight as I would like to use attiny as receivers also. Will give a feedback

bodtx commented 6 years ago

Ok, I've just did a test like this and led is blinking on attiny85 as receiver:

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
  pinMode(4, OUTPUT);
}

void loop() {
  if (mySwitch.available()) {
    int value = mySwitch.getReceivedValue();
    if (value == 5393) {
      digitalWrite(4, HIGH);
    }
    else if (value == 5396) {
      digitalWrite(4, LOW);
    }
    mySwitch.resetAvailable();
  }
}
lindenaar commented 5 years ago

I can confirm that there seems to be no problem to simply comment out the "#define RCSwitchDisableReceiving" in RCSwitch.h (line 56). Using interrupt 0 (pin 2) is working on Digispark with ATTiny85 just like on an Arduino Nano or Leonardo.

I will continue testing while working on a project that sends and receives (not to itself) over RF433 and so far that is working fine on this platform (I have not encountered any issues yet) so suggest to take out this #define at least for the __AVR_ATtinyX5__ platform.

quanticchaos commented 5 years ago

I confirm that commenting the above said line also works with bare attiny85. But not with every library. Didn't work with Spence Konde "ATTinyCore" Library but did work when using "attiny" Library by David A. Mellis

coldsilk commented 3 years ago

I'm using very old attiny45's and 85's from their release 16 years ago and using David A. Mellis's cores the 45's work, but the 85's do not. Neither work with Spence Konde's cores. These old 45's just work straight out of the tube without burning a bootloader or anything, but these 85's won't work no matter what I try.

bodtx commented 3 years ago

Did yout try to change the speed, 1Mhz, 8Mhz? Do they fail while uploading or when running?

coldsilk commented 3 years ago

Yes, and I was WRONG. Both the old 45's and old 85's work at both 1 and 8 using Mellis's cores. So Mellis's seems choice.

I just received new/latest 85's but I don't know what I changed in the last few days because now when I try to burn a bootloader on the new or old 85's it states: "free(): invalid next size (normal)". Again though, Mellis's works just fine.

vi7 commented 3 years ago

I confirm receiving is working on the ATTiny85 with the following setup:

So as a conclusion Mellis core is definitely not the only one option

@sui77 assuming that multiple people confirm ATTiny85 receive is working pls consider removing RCSwitchDisableReceiving at least for ATTinyX5, I can create PR for that if you'd like or otherwise users of your awesome lib will have to use custom fixed forks all over the place 😢

UPD: tested with non-default CPU frequencies 1, 8 and 16MHz. Default 16.5MHz feels to be the most stable due to being calibrated precisely by the micronucleus, while 1MHz has the most unstable receiving

jilvir commented 1 year ago

Hello, I too late here... I just restarted now hehe... I need same, I use digistump Attiny85. Blue with the micro USB. When I used the Arduino Uno it is fine I have no issue, but my focus is on ATtiny85 because that is more than enough hardware for my project and I love it.

First issue that I encountered is compiling with the RCSwitch Library and saw online regarding the solution same above that I commented the line #define RCSwitchDisableReceiving... I used the Digistump | DigiSpak board in Arduino IDE compiling and uploading Successful but when I pressed the remote key (433 MHZ) there is no response of the built-in LED which I call for the high and low of the LED to know if there is a signal detected. It means its not working. The INT0 in my board is PB2 pin# 7 in the actual IC. PB1 has the built-in LED.

So... I follow here... excitedly...

  1. I install download the ATtiny Library based on the link above and install
  2. Copy and paste the sketch of @bodtx
  3. Select the board under attiny | ATtiny25/45/85
  4. Selecting the clock 16MHz Internal
  5. Processor: ATtiny85
  6. Programmer (??? I don't know what to select, I didn't see the Micronucleus which I always used)
  7. I compile the sketch and successful
  8. but in uploading it gives me an error "A programmer is required to upload"

@vi7 and @bodtx can you help?

jilvir commented 1 year ago

I try to this board https://www.aliexpress.com/item/33062782242.html?src=google&src=google&albch=shopping&acnt=897-548-8760&slnk=&plac=&mtctp=&albbt=Google_7_shopping&gclsrc=aw.ds&albagn=888888&ds_e_adid=&ds_e_matchtype=&ds_e_device=c&ds_e_network=x&ds_e_product_group_id=&ds_e_product_id=ar33062782242&ds_e_product_merchant_id=106258787&ds_e_product_country=SA&ds_e_product_language=ar&ds_e_product_channel=online&ds_e_product_store_id=&ds_url_v=2&albcp=20223361648&albag=&isSmbAutoCall=false&needSmbHouyi=false&gclid=CjwKCAjwu4WoBhBkEiwAojNdXkU_NzKthkJ8eN9H8Fo4KIyIJ6IAUhHpDm8YOu9FyuhbhEE9sC5KDxoCJG0QAvD_BwE&aff_fcid=9e294b7203a443259b3c6e5c32fadf5e-1694627064233-08135-UneMJZVf&aff_fsk=UneMJZVf&aff_platform=aaf&sk=UneMJZVf&aff_trace_key=9e294b7203a443259b3c6e5c32fadf5e-1694627064233-08135-UneMJZVf&terminal_id=41ac2a7ef8714a1a9ae9a126a1a04dac&afSmartRedirect=y

and same as yours @vi7

https://www.aliexpress.com/item/33062782242.html?src=google&src=google&albch=shopping&acnt=897-548-8760&slnk=&plac=&mtctp=&albbt=Google_7_shopping&gclsrc=aw.ds&albagn=888888&ds_e_adid=&ds_e_matchtype=&ds_e_device=c&ds_e_network=x&ds_e_product_group_id=&ds_e_product_id=ar33062782242&ds_e_product_merchant_id=106258787&ds_e_product_country=SA&ds_e_product_language=ar&ds_e_product_channel=online&ds_e_product_store_id=&ds_url_v=2&albcp=20223361648&albag=&isSmbAutoCall=false&needSmbHouyi=false&gclid=CjwKCAjwu4WoBhBkEiwAojNdXkU_NzKthkJ8eN9H8Fo4KIyIJ6IAUhHpDm8YOu9FyuhbhEE9sC5KDxoCJG0QAvD_BwE&aff_fcid=9e294b7203a443259b3c6e5c32fadf5e-1694627064233-08135-UneMJZVf&aff_fsk=UneMJZVf&aff_platform=aaf&sk=UneMJZVf&aff_trace_key=9e294b7203a443259b3c6e5c32fadf5e-1694627064233-08135-UneMJZVf&terminal_id=41ac2a7ef8714a1a9ae9a126a1a04dac&afSmartRedirect=y

bodtx commented 1 year ago

Never use this board but if as I understand you use Arduino IDE and you want to upload with a programmer, you have to choose it here image

jilvir commented 1 year ago

Hello @bodtx, I really appreciated your response... thank you soo much...

Yes... I'm using Arduino... So I will use the ATtiny85 without the board which I attached the link? I will use the ATtiny85 microcontroller IC only not with the board and upload the sketch using other Arduino board and upload it using Arduino as ISP?

because the ATtiny85 with the board as same as I attach the link I don't need Arduino Board it can be directly upload the sketch with the programmer Micronucleus same as mentioned by @vi7.

Thank you very much @bodtx I will try it... If I will use the ATtiny85 microcontroller only, I will burn first the bootloader and upload the sketch.

I just copy and paste your code. You connect the data pin of the RF to the pin 7 (INT0/PB2) right?

I am using this RF below and it's perfectly working with Arduino with the example sketch of the RCSwitch library on receiving sketch... 793813515929526525

jilvir commented 1 year ago

Never use this board but if as I understand you use Arduino IDE and you want to upload with a programmer, you have to choose it here image

@bodtx I found out that the error message "A programmer is required to upload." is when I used the Upload button and the uploading successful when I'm using the Sketch | Upload Using Programmer.

so again I uploaded your code and nothing happened. I put the data pin of the RF receiver to the PB2 (pin 7 physical pin of the ATtiny85 next/under the VCC pin where the INT0 pin) and the LED on the PB1 (pin 6 physical pin on the ATtiny85).

Any help please? can you share your's how did you do it?

jilvir commented 1 year ago

Ok, I've just did a test like this and led is blinking on attiny85 as receiver:

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
  pinMode(4, OUTPUT);
}

void loop() {
  if (mySwitch.available()) {
    int value = mySwitch.getReceivedValue();
    if (value == 5393) {
      digitalWrite(4, HIGH);
    }
    else if (value == 5396) {
      digitalWrite(4, LOW);
    }
    mySwitch.resetAvailable();
  }
}

This is the code I uploaded, I want to see only if there is a reaction when pressing any RF remote or detects any signal. just to test if it is working the code and library.


#include <Arduino.h>
#include <RCSwitch.h>
#define RF_PIN PB2
#define LED PB1
RCSwitch mySwitch = RCSwitch();

void setup() 
{                
  mySwitch.enableReceive(RF_PIN);  // Receiver on interrupt 0 => that is pin #2
  pinMode(LED,OUTPUT);
}

void loop() {
   if (mySwitch.available())
  {
    digitalWrite(LED, HIGH);
    mySwitch.resetAvailable();
    delay(100);
   } else 
   {
    digitalWrite(LED, LOW);
   }
} ```
bodtx commented 1 year ago

Did it work on a real Arduino, uno for exemple ?

jilvir commented 1 year ago

IMG_20230915_135228 IMG_20230915_135235 IMG_20230915_135242 IMG_20230915_135250 IMG_20230915_135256 IMG_20230915_135426 IMG_20230915_135442

Did it work on a real Arduino, uno for exemple ?

No... I try in Arduino Uno but still not working.... So... what I did is uncommented the #if defined( AVR_ATtinyX5 ) or defined ( AVR_ATtinyX4 ) and #endif and live the //#define RCSwitchDisableReceiving commented and try again with Arduino Uno and it works...

In my ATtiny85, I change the #define RF_PIN PB2 to RF_PIN 0 and upload the sketch and yehhheyyy it's working...

So... I found out that mySwitch.enableReceive(0) must always be zero parameter but you will connect the RF data pin to where is the INT0 or External Interrupt pin in your board and I uncomment also the #if defined( AVR_ATtinyX5 ) or defined ( AVR_ATtinyX4 ) and #endif and live the //#define RCSwitchDisableReceiving commented.

Now, it's perfectly working... and my project was done!

Thank you soo much @bodtx I can't solve it with out you... I really appreciated your help...

Sharing to you my project is... An RF remote receiver with a relay that will turn-on my air-condition. The remote receiver has a learning capability so that I can use whatever RF remote available. those learn code are saved on the EEPROM so that if the device will turn off and turn back on for what ever the reason, the remote code will still there... now my aircon can be controlled by Alexa and Google Home and I can control it wherever I am in the world.

once again... I really appreciated your help @bodtx and this topic... thank you soo much... cheers...

bodtx commented 1 year ago

Very good, so you were missing some defined parameters. Happy it helped, but as always you did most of the job 🤯🤩😎

jilvir commented 1 year ago

Very good, so you were missing some defined parameters. Happy it helped, but as always you did most of the job 🤯🤩😎

yes... and as always... thank you soo much...

vi7 commented 1 year ago

hey @jilvir , as I see I'm a bit late for the party. JFYI feel free to check my sample project for RX testing on different boards including our subj - Digispark ATTiny85 USB. Couple of notes about the project:

Worth to mention that my ATTiny85 USB clone has INT0 interrupt on PB2 pin, that is the one used by default when you do receiver.enableReceive(0) . On the other hand project above allows you to use any ATTiny85 pin with some additional interrupt messing code (included in the example)

jilvir commented 1 year ago

ing code (included in the example)

Thank you soo much... yes I will... thanks...

nicholasareed commented 2 months ago

For anyone checking, this also works with an ATtiny84 (just make sure to use the ONLY external interrupt pin for your DATA pin. It is physical pin 5, aka "INT0" aka "PB2"), and you need to comment out #define RCSwitchDisableReceiving on line 56 of RCSwitch.h, as mentioned.