attiny85 and sleep mode

Go To Last Post
37 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everyone, I need your help, I made a very simple circuit with attiny85, a button and LED, I wanted the circuit to go to sleep when I turn it off and wake up when I press the button again to turn on the LED, I made this code but it doesn't work I can't understand what I'm wrong, you correct me where it is wrong please

 

#include <avr/sleep.h>
#include <avr/interrupt.h>

const int Pulsante = 1;    // 6 sarà il pin dove andrà collegato il pulsante
const int ledPin =  0;      // 5 sarà il pin dove andrà collegato l'anodo del led 

// Variabili
int ledState = LOW;         // Variabile su cui andrà memorizzato lo stato del led (HIGH o LOW)
int buttonState;          // Variabile su cui andrà memorizzato il valore del pulsante
int lastButtonState = HIGH;   // Variabile su cui andrà memorizzato l'ultimo valore del pulsante

long lastDebounceTime = 0;  // Variavile su cui andrà memorizzato il tempo dell'ultima volta che il pulsante è stato premuto
long debounceDelay = 50;    // Tempo di antirimbalzo (Aumentare se si vede uno sfarfallio nel led)

void setup() {
  pinMode(Pulsante, INPUT); // Impostiamo il pin 6 come pin di INPUT (PULSANTE)
  pinMode(ledPin, OUTPUT);   // Impostiamo il pin 5 come pin di OUTPUT (LED)

  digitalWrite(ledPin, ledState); // Impostiamo lo stato iniziale del led, in questo caso è LOW.
}

void loop() {

  int reading = digitalRead(Pulsante); // Con questa istruzione leggiamo il valore del pulsante
                                       // e lo salviamo nella variabile reading

  if (reading != lastButtonState) {    // Se reading è diverso di lastButtonState

    lastDebounceTime = millis();       // lastDebounceTime sarà uguale a mills()
  } 

  if ((millis() - lastDebounceTime) > debounceDelay) {

    if (reading != buttonState) {
      buttonState = reading;

      if (buttonState == LOW) {
        ledState = !ledState;
      }
    }
  }

  digitalWrite(ledPin, ledState);

  lastButtonState = reading;

  if (buttonState == HIGH) {
    enterSleep();
  }
}
void enterSleep() {
  GIMSK |= _BV(PCIE);                     // Enable Pin Change Interrupts
  PCMSK |= _BV(PCINT1);                   // Use PB6 as interrupt pin
  ADCSRA &= ~_BV(ADEN);                              // ADC off
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);    // replaces above statement
  sleep_enable();                         // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
  sei();                              // Enable interrupts
  sleep_cpu();                            // sleep
  sleep_disable();
}
ISR(PCINT_vect) {
}
ISR(BADISR_vect) {
  cli();                                // Disable interrupts
  GIMSK &= ~(1<<PCIE);                    // Disable Pin Change Interrupts
  PCMSK &= ~_BV(PCINT1);                  // Turn off PB6 as interrupt pin
  sleep_disable();
  ADCSRA |= _BV(ADEN);                    // ADC on
  sei();    // Enable interrupt
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm not sure how the Arduino system inits ports, but it may help to init all unused port pins as inputs with pull ups enabled so they are not left floating, as a floating pin will trigger random PCInt's.

You should also have a 100nf cap connected across pin's 4 & 8 (VCC/GND).

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

Last Edited: Wed. Jan 8, 2020 - 08:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lidas wrote:

 // Use PB6 as interrupt pin

May not be the issue, but it is PB1, which is on physical pin 6 of the dip chip, who knows what pin number the Arduino platform assigns it.

 

Jim

Edit: found pin out for attinyX5

// ATMEL ATTINY45 / ARDUINO
//
//                  +-\/-+
// Ain0 (D 5) PB5  1|    |8  Vcc
// Ain3 (D 3) PB3  2|    |7  PB2 (D 2)  Ain1
// Ain2 (D 4) PB4  3|    |6  PB1 (D 1) pwm1
//            GND  4|    |5  PB0 (D 0) pwm0
//                  +----+

So button is on D1 or PB1

 

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

Last Edited: Wed. Jan 8, 2020 - 08:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found this example that is similar to yours, compare to find why yours is not working.

// ATtiny85 sleep mode, wake on pin change interrupt demo
// Author: Nick Gammon
// Date: 12 October 2013

// ATMEL ATTINY 25/45/85 / ARDUINO
//
//                  +-\/-+
// Ain0 (D 5) PB5  1|    |8  Vcc
// Ain3 (D 3) PB3  2|    |7  PB2 (D 2) Ain1
// Ain2 (D 4) PB4  3|    |6  PB1 (D 1) pwm1
//            GND  4|    |5  PB0 (D 0) pwm0
//                  +----+

#include <avr/sleep.h>    // Sleep Modes
#include <avr/power.h>

const byte LED = 3;  // pin 2
const byte SWITCH = 4; // pin 3 / PCINT4

ISR (PCINT0_vect)
{
// do something interesting here
}

void setup ()
  {
  pinMode (LED, OUTPUT);
  pinMode (SWITCH, INPUT);
  digitalWrite (SWITCH, HIGH);  // internal pull-up
 
  // pin change interrupt (example for D4)
  PCMSK  |= bit (PCINT4);  // want pin D4 / pin 3
  GIFR   |= bit (PCIF);    // clear any outstanding interrupts
  GIMSK  |= bit (PCIE);    // enable pin change interrupts
 
  }  // end of setup

void loop ()
  {
  digitalWrite (LED, HIGH);
  delay (500);
  digitalWrite (LED, LOW);
  delay (500);
  goToSleep ();
  }  // end of loop
 
 
void goToSleep ()
  {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  ADCSRA = 0;            // turn off ADC
  power_all_disable ();  // power off ADC, Timer 0 and 1, serial interface
  sleep_enable();
  sleep_cpu();                             
  sleep_disable();   
  power_all_enable();    // power everything back on
  }  // end of goToSleep 

BTW: Welcome to AVRFreaks!

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the welcome,

but my circuit uses other pins and also has debounce, I need more help, I don't know how to do it

i already have the pcb done

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
ISR(BADISR_vect) {
  cli();                                // Disable interrupts
  GIMSK &= ~(1<<PCIE);                    // Disable Pin Change Interrupts
  PCMSK &= ~_BV(PCINT1);                  // Turn off PB6 as interrupt pin
  sleep_disable();
  ADCSRA |= _BV(ADEN);                    // ADC on
  sei();    // Enable interrupt
}

This looks like a truly terrible approach. Why would you use a mechanism that, in correctly designed code, should never execute ?

 

BADISR is only there to catch an interrupt for which you forgot to provide a true ISR (there's a clue in the name!)

 

Also never use sei() in an ISR. It's fairly benign to use cli() (that state is guaranteed anyway so it does nothing) but doing sei() means you are re-enabling interrupts before the handling of the current one is finished. If the interrupting source is frequent you then face the prospect of the ISR being interrupted (and then that ISR being interrupted and so on). Each time it occurs the registers will be resaved, eating some RAM each time. Eventually all the RAM runs out.

 

PS and if you ever find yourself doing:

ISR(PCINT_vect) {
}

(as you often do in sleeping code when you want an interrupt to wake up but don't actually want to do anything when it occurs) then use:

EMPTY_INTERRUPT(PCINT_vect);

Documented in the manual here:

 

https://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html#ga751c22101f7e8f2fbe792c64a81f8dba

Last Edited: Thu. Jan 9, 2020 - 09:20 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

then we reset everything, this is the code that I use and it works on the circuit that I put at the beginning, since it must be powered by a battery I have to add sleep, some of you are able to add sleep to me I don't know how to do it

 

const int led = 0;
const int button = 1;
int led_state = LOW;

// Button states and debounce
int buttonState = 0;
int lastButtonState = HIGH;
unsigned long lastDebounceTime = 0;

void setup() {
  pinMode(led, OUTPUT);
  pinMode(button, INPUT_PULLUP);
}

void loop() {
  int reading = digitalRead(button);
  if (reading != lastButtonState)
    lastDebounceTime = millis();

  if ((millis() - lastDebounceTime) > 50) {
    if (reading != buttonState) {
      buttonState = reading;
      if (buttonState == LOW) {
        led_state = !led_state;
      }
    }
  }

  lastButtonState = reading;

  digitalWrite(led, led_state);
}

Many thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lidas wrote:
, some of you are able to add sleep to me I don't know how to do it
You aren't doing yourself any favours by trying to do this inside Arduino code. It already runs some interrupts anyway. In fact:

    lastDebounceTime = millis();

only works because millis() is relying on a timer interrupt.

 

If I were you I'd switch to plain C/C++ in AS7 where nothing is switched on by default and you will have more direct control over everything that is going on.

 

You can still use the Arduino board and its bootloader to program it - but the .hex you send to it with avrdude is something you will build independently as a main() C/C++ project in AS7

 

Do note however that low power/battery/sleeping is something that should be in the design right from the start and that includes things like the power supply design, the clocking circuitry, the use of the IO lines, the surrounding peripherals and everything that forms part of the design. An Arduino (USB/line powered) i s not necessarily the best candidate circuit for working on low power design.

Last Edited: Thu. Jan 9, 2020 - 12:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lidas wrote:
but my circuit uses other pins and also has debounce, I need more help, I don't know how to do it

But the program shows how to do sleep properly, look how it is structured, how is it different from your program, make adjustments as needed.

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

But the program shows how to do sleep properly, look how it is structured, how is it different from your program, make adjustments as needed.

Jim

 

 

I meant what I posted on post # 7
on that there is no sleel mode

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
switch to plain C/C++ in AS7 ... You can still use the Arduino board and its bootloader to program it

Indeed. And you also have the option to use an Atmel-ICE (or similar) to do the programming - and real debugging!

 

(although things can get interesting when trying to debug things that sleep)

 

 

Do note however that low power/battery/sleeping is something that should be in the design right from the start

Absolutely!

 

An Arduino (USB/line powered) i s not necessarily the best candidate circuit for working on low power design.

+1

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Lidas,

 

I remember well that the sleep modus was confusing me as well for quite a while.

I do not work with Arduino but directly with writing a c-code and use Atmel Studio.

So maybe my solution will not perfectly help you but you might read something from the code which helps you.

 

If the ATTiny is in deep sleep (power down mode) you can only wake it up by grounding INT0 (i.e. PB2). As you have a PCB ready with a connection on PB1 you can help yourself like this:

Use the internal pull-ups (you use an external one) on PB2 and PB1. Then you solder a bridge between PB2 and PB1. Looks a bit like a prototype but you could use your available PCB.

I just tested and it worked.

Here is the code:

#include <stdlib.h>
#include <avr/io.h>
#include <util/delay.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>

volatile uint8_t LED = 0;

int main (void)
{
	GIMSK = 0b01000000; //interupt as INT0 defined
	DDRB  = 0b00000001; //set PB0 as output
	PORTB = 0b00000110; //set Pull-Up-Resistor at PB1 and PB2

	while (1)
	{
		MCUCR = 0b00110000; //sleep enabled (SE=1), Power Down mode (SM1=1, SM0=0)
		sei(); //enable interrupts
		sleep_mode(); //start sleeping and wait for INT0
		cli(); //disable interrupts
		MCUCR &= ~(1<<SE); //sleep disable
		PORTB = PORTB | (1<<PB0); //light on
		LED = 1; //marker that LED is on now
		sei();
		while (LED == 1); //waiting until next button-press (ISR) will change to LED=0
		cli();
		PORTB = PORTB & ~(1<<PB0); //light off and restart the loop
	}
}

ISR(INT0_vect)
{
	_delay_ms(50); //debouncing time
	if ((PINB & (1<<PB2)) == 0) //check if PB2 still grounded
	{
		LED = 0; //escape from while-loop by changing status to zero
	}
}

For sure you need to read into the datasheet of the ATTINY85 to understand everything.

And yes, it is not Arduino-code.

Maybe it helps anyhow.

 

Keep on testing ;-))

 

Ole

Last Edited: Thu. Jan 9, 2020 - 08:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Laubfrosch wrote:
For sure you need to read into the datasheet of the ATTINY85 to understand everything.

Indeed.

 

Also look at the Application Notes - available on the device's Product Page:

 

https://www.microchip.com/wwwproducts/en/ATtiny85 - see the 'Documents' tab.

 

eg,  AN_8469 - AVR1201: Using External Interrupts for tinyAVR Devices - has a section on Interrupts for Wakeup ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Laubfrosch wrote:

Hi Lidas,

 

I remember well that the sleep modus was confusing me as well for quite a while.

I do not work with Arduino but directly with writing a c-code and use Atmel Studio.

So maybe my solution………………….

 

Ole

 

 

Dear Laubfrosch, 

I wanted to thank you infinitely, now I managed to load your program on attiny and now it works, I have to ask you something, how can I improve the debounce function, because it is too sensitive I want it both on and off, you put me on affixed this, thank you

Last Edited: Sat. Jan 11, 2020 - 04:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey,

 

Good to hear that it works now. Congratulations.

 

Debouncing is a story for itself. I always use the "software"-debouncing which is simply implementing a delay and then doing another check if the button is still pressed (or not).

This means if the interrupt is reacting on the first rising or falling edge then you inject a pause to not see the ups and downs of the following bouncing of the signal. After a while the signal is stable as the switch is now fully closed or open.

This waiting time is defined by the "_delay_ms(xxx)"-command in the Interrupt-Service Routine (ISR). You can play now with the value. In my code it was 50 Milliseconds. Play around with value and see what fits best.

You may also want to test a different type of button which is maybe more accurate.

 

By the way: you can also use other interrupts then INT0. But using INT0 gives you the only chance to wake-up the ATTINY85 when send into the most energy-saving sleep-mode.

 

If you have fun to further understand the coding I would take the datasheet of ATTINY85 and go though the code line by line. What is MCUCR? What is GIMSK?

Super important is to understand "bitmanipulation". Without that several commands are not understandable at all.

Once you understand the logic new ideas for new projects come up and each time the coding becomes more fluent.

 

Ole

 

Last Edited: Sat. Jan 11, 2020 - 05:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello and thank you very much,

 

but I ask you a last effort because for me everything is still incomprehensible, maybe with time and studying I will be able to understand but now I need to solve my problem, I actually use a piezo button, and I need that there are absolutely no accidental switching on or off because it is an underwater light, it must work almost like the tach button on the iphone to understand, if you beat it it must not work if you press yes, if there is something to add in the code add it to me please,

practically now if I keep my finger on the button, sometimes it turns me on and off, I have already raised the _delay_ms to 90

thanks again

Last Edited: Sat. Jan 11, 2020 - 06:15 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am sorry but I never worked with a piezo-buttoon so far.

I understand that the on-state is really short. Then consequently the above mentioned debouncing-method is not the right one.

By searching the forum a bit I see as well that the delay-time in the ISR is anyway not really a prefered solution.

 

You need to check the forum or internet for different methods.

Or can any other reader maybe help here?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If there is someone who knows how to improve the code made by

@ Laubfrosch, I am grateful to you, I always have the problem that if I hold the (piezo) button it turns on and off immediately

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe using a piezo-button is not the best starter-Project ;-)

A piezo-button is obviously creating everything but not a precise on/off-signal without further processing.

I am a moderate beginner as well and need to raise my personal white flag.

Check this link and you will understand why it is so difficult to bring the signal of a piezo-button into something like on/off.

https://learn.sparkfun.com/tutor...

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No the piezo button I use is this, do a search with "elewind piezo switch"

 

https://www.alliedelec.com

 

https://it.aliexpress.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can you confirm the following behaviour of the switch (by measurement with adequate Equipment)?

If yes, I believe that your finger on the sensor is not giving a constant pressure and consequently lots of Output pulses are generated.

Let's assume the user wants to press once but keeps the finger for two seconds on the button (generating several unwanted pulses).

Then try this Code:

#include <stdlib.h>
#include <avr/io.h>
#include <util/delay.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>

int main (void)
{
	GIMSK = 0b01000000; //interupt as INT0 defined
	DDRB  = 0b00000001; //set PB0 as output
	PORTB = 0b00000110; //set Pull-Up-Resistor at PB1 and PB2

	while (1)
	{
		MCUCR = 0b00110000; //sleep enabled (SE=1), Power Down mode (SM1=1, SM0=0)
		sei(); //enable interrupts
		sleep_mode(); //start sleeping and wait for INT0
		cli(); //disable interrupts
		MCUCR &= ~(1<<SE); //sleep disable
		PORTB = PORTB ^ (1<<PB0); //toggle light status
		_delay_ms(2000); //ignore button-pulses for 2 seconds and start with sleep again
	}
}

ISR(INT0_vect)
{
// function is empty but is needed to be there
// interupt will jump here, execute nothing and then jump back where it was before the interrupt
}

Ole

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Laubfrosch wrote:

// function is empty but is needed to be there

If so then explore EMPTY_INTERRUPT:

 

https://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html#ga751c22101f7e8f2fbe792c64a81f8dba

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi clawson,

Cool, thanks a lot. Didn't know that and will use it from now on.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Clawson and Laubfrosch, many thanks

 

Later when I can test them, many thanks in the meantime

For Laubfrosch, if I redo the pcb, I could move the button and the resistance on the right PB2, do I have to change anything on the program?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lidas,

if (!) it will work and if you Change to PB2 then you could leave the Code like it is. But it would be cleaner to switch off the unused internal pull-up-resistor at PB1.

Code would Change from <PORTB = 0b00000110;> to <PORTB = 0b00000100;>.

But you should (now already) not use your external pull-up and the internal pull-up at the same time. Either you take the internal one (less parts, PCB is smaller) or your external one.

If you use external one, then you can delete the full <PORTB = 0b00000110;> line of Code.

Please let us know if it works once it is tested.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So I tested the new software and I must say that it is much better, but one needs to perfect it, is the button that I modify parameters too sensitive?
I would like if it works after a light pressure of 1 sec and not if it takes a hit, maybe I modify these parameters I just need to explain what I have to change

I am testing the circuit on breadboard, so I would say that we remove the external resistance and connect the directing button PB2 (pin 7), right? make changes to the software I'm afraid of making mistakes

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I would take out the resistor and work with the internal pull-up at PB2 by using

PORTB = 0b00000100; //maybe 0b00000110; if still PB1 and PB2 are connected

Your wish for the light to become active after pressing one second is maybe not in line with the way the button works.

If the above mentioned piezo button behavior (see graphic in post #21) is true, then it doesn't matter how long you press the button. It will send on short signal at the beginning of the press. The button doesn't care how long you press. And this makes sense as there is a good chance that your pressure on the button varies and then generates several impulses instead of one (see initial problem).

Can't you measure somehow what kind of signal is coming out of the button when you press it? Without knowing that all this is best guess.

And you may want to implement the comment from clawson.

Exchange the complete ISR(INT0-vect) function by one line only

 EMPTY_INTERRUPT(INT0_vect);

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Give me an idea of how I should measure the button

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe building a simple circuit of a battery, resistor, LED and button.

If you press the button for 1 second, I would expect that the LED just lightens up for a short impuls at the beginning (if you press with constant pressure).

In case of varying pressure I would expect several impulses on the LED.

I would not expect that the LED is on as long as you press the button.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried to put the button in series between a power supply and a simple oscilloscope this is the result by holding the button down

I don't know if it helps you and if I did it right

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah, you have a QUIMAT with DSO Shell. Good enough for measurements like this.

Try again and again to push the button for more or less exactly two second with constant pressure (and then immediately take away your finger). One measurement is not representative.

Once you have the feeling you get repetitive results come back again with a screenshot.

is there A) one peak only at the beginning or B) a peak as long as you press or maybe C) a peak at the beginning and a peak at the end? I still would expect A).

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 I made a video for you I hope you need it

 

video

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmm. And I assume you pressed all the time constantly?

Looks like a repetitive pulse with a bit varying frequency. Maybe depending on Speed, pressure and length of button–press.

Can you download the datasheet from the supplier?

Honestly, I am learning here at same pace as you as I never worked with piezo elements. 
I could imagine putting a check in the code that the pulse need to be counted twice before switching on/off the light.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have tried to keep the rhythm of the button presses always the same, it is not easy to be precise

the only information can be found at the link I have attached where I buy the buttons

 

 

 

Link piezo switch

Last Edited: Mon. Jan 13, 2020 - 10:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please Always say what you do and then link the result. Otherwise it is difficult to understand what is going on.

Assuming that each press creates a short impuls, you have some Options:

1) you accept that and light will go on/off each time you touch the button (solution in post #21 without delay)

2) you put in a delay after first touch before the next light Change can happen (solution in post #21)

3) you install a logic that you have to press double like <tap, tap> or even three times before the program recognizes the pulses as trigger to switch the light

Have a good day.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

good day to you too and many thanks

I would say if you want to make two more efforts, you also make me the software with the ignition with your impulses

then I have to use this circuit by replacing the LED with a mosfet that closes the contact, I have to turn a LED driver on and off, these also have the PWM pin can you also do the part to turn the driver on and off in PWM can the driver be done?

are more things with the same circuit

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Laubfrosch

hello you abandoned me, I hope not