NicoHood / PinChangeInterrupt

A simple & compact PinChangeInterrupt library for Arduino
MIT License
281 stars 68 forks source link

Add ATTinyx61support #39

Open astro59 opened 3 years ago

astro59 commented 3 years ago

Is it possible to use PinChangeInterrupt with ATTiny861 ?

NicoHood commented 3 years ago

Not yet, but I can add support for it, if you like. It seems to support PCINT on all pins: http://ww1.microchip.com/downloads/en/devicedoc/atmel-2588-8-bit-avr-microcontrollers-tinyavr-attiny261-attiny461-attiny861_datasheet.pdf

astro59 commented 3 years ago

Yes, I like it. I will be happy to test this on my project. I need a lot of independent pins, a few of which are interrupts.

NicoHood commented 3 years ago

I accidentally commited the changes directly to master, without a PR. The commit is this one: https://github.com/NicoHood/PinChangeInterrupt/commit/ca4fe2e228b71adc87bec0402c12db720f58396e

Please test and report if it works. Please test all pins (not just a few), if possible.

NicoHood commented 3 years ago

I've just released 1.2.9. Please test if that works for you. I expect that this should be an easy one and just work. If not, I will try to fix it ASAP.

astro59 commented 3 years ago

Hi,

I tested the library but without success.

I just replaced LED_BUILTIN by pinLED to place a led with its resistor on an ATTiny861.

I attach a photo of the assembly and the modified source code.

The led lights up for 1 second but the button does not work

Did I make a mistake?

Thanks


De : NicoHood @.*** Envoyé : mardi 18 mai 2021 19:33 À : NicoHood/PinChangeInterrupt Cc : Alain; Author Objet : Re: [NicoHood/PinChangeInterrupt] Ajout ATTinyx61 (#39)

I've just released 1.2.9. Please test if that works for you. I expect that this should be an easy one and just work. If not, I will try to fix it ASAP.

— You are receiving this because you authored the thread. Reply to this email directly, view https://github.com/NicoHood/PinChangeInterrupt/issues/39#issuecomment-84338 4848 it on GitHub, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI7YQEZBCJH7E7WAPMU4QMLTO KQFRANCNFSM4463HNPA . https://github.com/notifications/beacon/AI7YQE4LPRSOGUCZNJCQ3JDTOKQFRA5CNFS M4463HNPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGJCQQEA .gif

NicoHood commented 3 years ago

I cannot see a photo. Please paste your source, if possible.

This is the example to use for testing: https://github.com/NicoHood/PinChangeInterrupt/blob/master/examples/PinChangeInterrupt_Led/PinChangeInterrupt_Led.ino

astro59 commented 3 years ago
#include <PinChangeInterrupt.h>
#include <PinChangeInterruptBoards.h>
#include <PinChangeInterruptPins.h>
#include <PinChangeInterruptSettings.h>

// ATMEL ATTINY 261/461/861 et 261V/461V/861V  -  BRANCHEMENTS

// Choose a valid PinChangeInterrupt pin of your Arduino board
#define pinBlink 4
#define pinLED   11

void setup() {
  // set pin to input with a pullup, led to output
  pinMode(pinBlink, INPUT_PULLUP);
  pinMode(pinLED, OUTPUT);

  // Manually blink once to test if LED is functional
  blinkLed();
  delay(1000);
  blinkLed();

  // Attach the new PinChangeInterrupt and enable event function below
  attachPCINT(digitalPinToPCINT(pinBlink), blinkLed, CHANGE);
}

void blinkLed() {
  // Switch Led state
  digitalWrite(pinLED, !digitalRead(pinLED));
}

void loop() {
  // Nothing to do here
}

`

astro59 commented 3 years ago

Oups !

for this the button is on physical pin 14 and led on physical pin 4 I have tested other configurations.

astro59 commented 3 years ago

https://www.astrolynx.com/Electronique/IMG_20210518_202605.jpg

NicoHood commented 3 years ago

Can you check what digitalPinToPCINT(pinBlink) returns (it should return 4)? As an alternative you could use for physical pin14/PA4/D4/PCINT4: attachPCINT(PCINT4, blinkLed, CHANGE);

Can you also check if a normal digitalread on the button pin works?

Which attiny core do you use? For example there are two versions for digital pins in this core: https://github.com/SpenceKonde/ATTinyCore/blob/master/avr/variants/tinyX61_New/pins_arduino.h#L173 https://github.com/SpenceKonde/ATTinyCore/blob/master/avr/variants/tinyX61/pins_arduino.h#L189

astro59 commented 3 years ago

I have to go I'm doing this tonight when I get home

astro59 commented 3 years ago

IDE 1.8.13 ATTinyCore Spence Konde 1.5.2 Apparently C:\ ... \Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\variants\tinyX61_New\pins_arduino.h

Tested with 4, PA4 and PCINT4 Start up the led lights up for 1 second Pin 14 (PCINT4) : Button released 5V - Button pressed 0V - No réaction

in digital mode, all is OK

NicoHood commented 3 years ago

What does digitalPinToPCINT(4) return?

astro59 commented 3 years ago

I don't know. how i do that?

NicoHood commented 3 years ago

Something like:

if (digitalPinToPCINT(4) == 4){
led on
}

if it is not true, please check against -1 or try & error all other numbers.

tredpath commented 3 years ago
digitalPinToPCINT(0) == 1
digitalPinToPCINT(1) == 2
digitalPinToPCINT(2) == 4
digitalPinToPCINT(3) == 8
digitalPinToPCINT(4) == 16
digitalPinToPCINT(5) == 32
digitalPinToPCINT(6) == 64
digitalPinToPCINT(7) == 128
digitalPinToPCINT(8) == 9
digitalPinToPCINT(9) == 10
digitalPinToPCINT(10) == 12
digitalPinToPCINT(11) == 16
digitalPinToPCINT(12) == 24
digitalPinToPCINT(13) == 40
digitalPinToPCINT(14) == 72
digitalPinToPCINT(15) == 136

There aren't separate interrupt vectors for each port either. ISR(PCINT_vect) covers everything (see table 9-1 in the datasheet for the list of interrupt vectors).

NicoHood commented 3 years ago

Great progress on your PR so far! I want to note, that we need to also identify the root cause of the invalid digitalPinToPCINT() mappings.

NicoHood commented 3 years ago

Which Core are you using to support this attiny? I need to check if they defined every marco correct. https://github.com/NicoHood/PinChangeInterrupt/blob/d604e1f0bddb0f67fab8d3da753b48d80be02db1/src/PinChangeInterrupt.h#L103

Edit: I've opened an issue (with suggested fix) here: https://github.com/SpenceKonde/ATTinyCore/issues/589

It would be nice if you can test that