Arcade Button with Electron

I would like to use the Adafruit Arcade Button to post a Particle.publish after successful pressing. That’s it. I would like to offer an emergency button, the senior citizen allows a help call.
For this I followed the following instructions in steps 1-3 (also the LED Resistor I have exchanged as described).and have read various contributions to the Debouncing.
My problem is presumably the Wiring: my multimeter can buton pressure imitate, but the example shown in the example does not lead to success (by me). Could you look at this?
It is necessary to use a libary (imo not)?

In addition Adafruit says that this button supports I2C. I am unclear how this would have to be programmed with the photon at D0 / D1 programmtechnically.

Not sure that this means. The button is just that, a simple SPST switch that closes its contacts when pressed. Sharing some pictures of your setup and wiring would be helpful.

I have no idea where you get this. This is a purely electro-mechanical switch, no I2C here!

“This board/chip uses I2C 7-bit address 0x20”, under "Technical Details left from the 6 pictures in the Ada-Shop, peekay123.

My multimeter sounds if the switch closes.

Here my wiring:
left + right = LED; GND to GND, yellow to D3
1 on bottom + 1 on the side = Button; bottom to GND, 1 on the side = 3V3 (red) + D1 (green) with 10k resistor to GND

yeah, it's a switch... I see nowhere in the specs that talk about I2C.

So connecting it is trivial because you can just as easily use the internal pullup/pulldown resistors for the switch side of the equation. Getting the power to the LED correctly:

you have to make sure that the Photon can source enough current for that LED, and you have the right resistor on the LED as well!

I'd test it using the on-board LED (on pin D7) to make sure my button press illuminates the LED. Then get the Big button's led working...

1 Like

I ensure the power supply via USB port or USB PowerBank.
It also functions at the first start immediately - thus without having exerted a pressure on the button.
Then no longer with pressure…

const int BUTTON_PIN = D0;
const int LED_PIN = D3;
const int internalLED = D7;
bool wasPressed = false;

void setup() {
    pinMode(BUTTON_PIN, INPUT);
    pinMode(LED_PIN, OUTPUT);
    pinMode(internalLED, OUTPUT);
}

void loop() {
    
    bool pressed = digitalRead(BUTTON_PIN);
    if (pressed && !wasPressed)
    {
        
        digitalWrite(internalLED, HIGH);
        delay(1000);
        digitalWrite(internalLED, LOW);
        
        Spark.publish("launch");
        digitalWrite(LED_PIN, HIGH);
        delay(250);
        digitalWrite(LED_PIN, LOW);
        delay(250);
        digitalWrite(LED_PIN, HIGH);
        delay(250);
        digitalWrite(LED_PIN, LOW);
        delay(250);        
    }
    
    wasPressed = pressed;
    delay(250);
}

ParticleLog-Snippet:

so you are saying that the event occurs when you load the firmware and then does nothing (i.e. does not respond to a button press)?

right, after restart with this code.
Remark: I changed the 12V resistor soldered on the LED to another one (470 ohms think so).

perhaps your switch’s resistor is too much.

try eliminating the resistor on the switch (wire one side of the switch to ground the other to BUTTON_PIN (D0)) and changing the code here:

void setup() {
    pinMode(BUTTON_PIN, INPUT_PULLUP);  // <<<<<<< this line
    pinMode(LED_PIN, OUTPUT);
    pinMode(internalLED, OUTPUT);
}

@BulldogLowell, there is a 10K resistor as a pulldown and a 470 ohm resistor for the LED which I don’t believe is going through the switch.

Regarding the wiring, I believe it is incorrectly done. The D0 input is configure with a 10K pull-down resistor so the switch need to connect 3.3v to D0 when it is pressed. You also need 3.3v and GND going to the LED contacts of the switch. It is difficult to see all the contacts on the switch/LED from your pictures. So here is what you need:

  1. A connection from D0 (with the 10K pull-down) to one side of the switch.
  2. A connection from 3V3 to the other side of the switch
  3. A connection from GND to the LED cathode (- side)
  4. A connection from 3V3 to the LED anode (+ side), assuming the 470 ohm resistor is inside the assembly.

Revise your wiring and try again :wink:

1 Like

Changed the code to input_pullup and eliminated the switch-10k resistor from my breedboard.
It appears the same as before: after restart its going Blinky-Blinky without any press from the button.

This reply is for peekays-answer: using the 10k resistor on my breedboard to GND, wired as your steps 1-3, number 4 (my yellow) goes to D3. If I to 3V3 on top to the LED anode (+ side) I got “always bright LED”.
It appears the same as before…

No difference if I use INPUT or INPUT_PULLUP in the code.

I have looked at your suggestion, Peekay again and made a correction in number 1:
instead of the 10k resistor to lead to GND, I have this integrated - as suggested by you - in the jumper of D0 (my green cable) to the switch (see on picture in the corner between green / orange jumper wire).
It appears the same as before: after restart its going Blinky-Blinky without any press from the button.

@Postler, let’s go back to basics. First, forget the button LED so disconnect it entirely. Second, go back to the original code and don’t use INPUT_PULLUP. Next, connect the 10K resistor between D0 and GND and also connect D0 to one side of the button switch. Finally, connect the other side of the button switch to 3V3.

This configuration will hold D0 low (10K pull-down) until you push the button causing it to go HIGH (3V3). If things still don’t work as expected, add some Serial.print() debug statements in your code to see what pressed and wasPressed are doing. :wink:

@Postler, what is your current code?
Have you now removed the stock pull resistor from the switch?
Does this micro switch have a N/O (normally open) and a N/C (normally closed) switch? If so, which one are you using?
Also if you are pulling up and your switch closes to GND then you need to reverse the logic (LOW is closed, HIGH is not closed).

    bool pressed = !digitalRead(BUTTON_PIN); // <-- mark the negation "!"
    if (pressed && !wasPressed)

I follow peekays instruction - double checked inclusive 10k resistor to GND.
At the moment I´m using a Spark Core - hope thats ok.

Its an N/O Switch.

I tested the following if-Statements and documented what happend as remark:

// 10 cm Arcade Button from Adafruit: https://www.adafruit.com/product/1185
// Ingo Lohs, v1.0 v. 05.10.2017
// Projekt, um Senioren die Option zu geben einen Call abzusetzen
// Signalisierung erfolgt via IFTTT an Empfänger bei Trigger des Events
// zum Test sind Kroko-Stecker mit 10k resistor an D0 angeschlossen
// im Einsatz ist ein Spark Core!

// step 1 - Problem aktuell: der Druck des Buttons wird nicht festgestellt. 
// step 2 - LED on top


const int BUTTON_PIN = D0;
//const int LED_PIN = D3;
const int internalLED = D7;
bool wasPressed = false;

void setup() {
    pinMode(BUTTON_PIN, INPUT); // not in use: INPUT_PULLUP
    //pinMode(LED_PIN, OUTPUT);
    pinMode(internalLED, OUTPUT);
}

void loop() {
    
    bool pressed = digitalRead(BUTTON_PIN);
    //if (pressed && !wasPressed)                   // --> always Status "not pressed", only 1 time at start its going Status "pressed" - but without pressing a button manually
    //if (pressed == HIGH && !wasPressed)           // --> always Status "not pressed", only 1 time at start its going Status "pressed" - but without pressing a button manually
    //if (pressed == HIGH && wasPressed == true)    // --> rotates between >>>pressed<<<, not pressed, >>>pressed<<<, not pressed - but without pressing a button mnaually
    if (pressed == HIGH && wasPressed == false)     // --> always Status "not pressed", only 1 time at start its going Status "pressed" - but without pressing a button manually
    
    {
        
        digitalWrite(internalLED, HIGH);
        delay(1000);
        digitalWrite(internalLED, LOW);
        
        Spark.publish("launch");
    
        Serial.println(">>>pressed<<<");
    /*    
        digitalWrite(LED_PIN, HIGH);
        delay(250);
        digitalWrite(LED_PIN, LOW);
        delay(250);
        digitalWrite(LED_PIN, HIGH);
        delay(250);
        digitalWrite(LED_PIN, LOW);
        delay(250);        
    */
    }
    
    wasPressed = pressed;
    delay(250);
    Serial.println("not pressed");
}

@Postler, skip the switch and just use a jumper to simulate it. What happens when you connect D0 to 3V3?

1 Like

…nothing - switched from D0 to D1: work as expected - Spark Core to sell…
now tested with switch: works also. Boah this Core steel our time.

now I go back and integrate the LED…

1 Like

Last question in this context: the LED should only light on if button pressed as an optical signal like D7.
If I connected 3V3 to the LED anode (+), the LED is always on.
But if I connect to D4 (const int LED_PIN = D4;) nothing appears.

Any information about the adafruit information, that the Button supports I2C?
Best regards, thx for support all!

@Postler, did you set D4 as an OUTPUT and set it HIGH?

@Postler, you are playing with the button. It is in front of you. In your opinion, does it look like it supports I2C?

Can you post the exact link and quote about I2C?
As mentioned by others it's more than just unlikely this device will do I2C :wink:

If you only want the LED light up on button press, how about wiring it in series with the button? No µC needed for that.

1 Like