Install a tact switch on the Raspberry Pi to make daily "Good morning Yosoro !!" tweets comfortable

Introduction

Everyone! Do you use "_Oha Yosoro !! __"? This is the first voice that motivates me to get up every morning. Maybe love live! I think I tweeted every morning before the Sunshine !! anime started. (Saturdays, Sundays, and holidays may not be convenient) You Watanabe is an angel. so cute.

environment

Python 2.7.11 Raspberry Pi2 B Some knowledge of electronic circuits

Wiring on the Raspberry Pi side

The tact switch also has a proper orientation, so let's check it.

Cv8cip-UIAApU3J.jpg

It's messy, Explain after numbering the legs of the tact switch Bottom left: No. 1 Bottom right: No. 2

  1. Connect 3.3V to No. 1
  2. Attach a 1kΩ resistor to No. 2.
  3. Extend from the right end of the resistor to GND
  4. Connect to GPIO 9 from the left foot of the resistor (on the extension of No. 2) (Pin No. 21 on the Raspberry Pi side in the physical arrangement)

Source code

https://bitbucket.org/nnsnodnb/raspi_morning_steady_tweeter/src

I'm pushing to BitBucket for the time being.

app.py


# coding: utf-8

import RPi.GPIO as GPIO
import tweepy
import time, signal, sys, random
from datetime import datetime

def handler(signum, frame):
    print('Signal handler called with signal: ' + str(signum))
    GPIO.cleanup()
    sys.exit(0)

signal.signal(signal.SIGINT, handler)

def tweet():
    CONSUMER_KEY = ''
    CONSUMER_SECRET = ''
    ACCESS_TOKEN = ''
    ACCESS_SECRET = ''

    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)

    api = tweepy.API(auth)

    tweet_text = ''
    if random.randint(1, 7) == 7:
        tweet_text = u'Good morning John! !!'
    else:
        tweet_text = u'Good morning Yosoro! !!'

    api.update_status(tweet_text + '\n{0:%Y/%m/%d %H:%M:%S}'.format(datetime.now()) + u'Niyakashi got up')

GPIO.setmode(GPIO.BCM)
GPIO.setup(9, GPIO.IN)
before = 0

while True:
    now = GPIO.input(9)
    if before == 0 and now == 1:
        tweet()
    time.sleep(0.1)
    before = now

Get CONSUMER_KEY etc. in advance! Also, this time, in response to the request of enthusiastic followers, "_Oha John __" will appear with a probability of 1/6.

Execution result

スクリーンショット 2016-10-30 午前2.31.04.png

スクリーンショット 2016-10-30 午前2.31.16.png

First of all, I don't think that you will press the button continuously, but in consideration of the foolproof of duplicate tweets, I tried to tweet up to seconds.

Finally

I don't know which GPIO the infrared transmission LED was connected to at the time of this jumper code arrangement, I was sacrificed. If the shyness turns, it will be cured.

Recommended Posts

Install a tact switch on the Raspberry Pi to make daily "Good morning Yosoro !!" tweets comfortable
How to make a Raspberry Pi that speaks the tweets of the specified user
How to install NumPy on Raspberry Pi
Use python on Raspberry Pi 3 to light the LED with switch control!
I have a question. Unable to make protocol buffers on raspberry pi 3 modelB.
Make a thermometer with Raspberry Pi and make it visible on the browser Part 3
I tried to create a button for Slack with Raspberry Pi + Tact Switch
Make a note of what you want to do in the future with Raspberry Pi
Create a partition and then install the Raspberry Pi OS
Install OpenCV4 on Raspberry Pi 3
Install TensorFlow 1.15.0 on Raspberry Pi
About the error I encountered when trying to use Adafruit_DHT from Python on a Raspberry Pi
Control the motor with a motor driver using python on Raspberry Pi 3!
Use python on Raspberry Pi 3 to illuminate the LED (Hello World)
Raspberry Pi --1 --First time (Connect a temperature sensor to display the temperature)
raspberry pi 4 centos7 install on docker
Install ghoto2 on Raspberry Pi (memo)
Finally ... Make a radio control using python on Raspberry Pi 3! (The motor moves while the button is pressed)
How to make a deadman's switch
Detect switch status on Raspberry Pi 3
Install OpenMedia Vault 5 on Raspberry Pi 4
A memo to simply use the illuminance sensor TSL2561 with Raspberry Pi 2
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
Finally ... Make a radio control using python on Raspberry Pi 3! (The motor moves while the magnet is brought closer)
Use the Grove sensor on the Raspberry Pi
Install 64-bit OS (bate) on Raspberry Pi
Install docker-compose on 64-bit Raspberry Pi OS
Make a wash-drying timer with a Raspberry Pi
Using the 1-Wire Digital Temperature Sensor DS18B20 from Python on a Raspberry Pi