Output to "7-segment LED" using python on Raspberry Pi 3!

Introduction

My name is Ryosuke Kamei and I am an IT consultant based on the idea of "gentle IT"! Currently, in my work, I am doing upstream processes focusing on requirements analysis and requirements definition, but I also write programs! As part of our friendly IT activities, we will introduce "Raspberry Pi 3" (commonly known as Raspberry Pi), which has the philosophy of "providing inexpensive PCs that can be programmed for education"!

This time, we will output a number (1 digit) to the 7-segment LED! It is a temperature sensor that uses an analog temperature sensor and an A / D converter! [Razpai Magazine-June 2016 Special Feature 1 Akiba's Popular Parts Wiring Diagram Best 17 15 Numbers can be displayed](https://www.amazon.co.jp/ Razpai Magazine-June 2016 Issue-Nikkei BP PC Best Mook -? Nikkei Linux-ebook / dp / B01EH2RX42 / ref = as_li_ss_tl ie = UTF8 & dpID = 61P3o6Agz + L & dpSrc = sims & preST = OU09__BG0,0,0,0_FMpng_AC_UL160_SR120,160 & psc = 1 & refRID = 31SKG5E0DGKBSF9BWNGV & linkCode = ll1 & tag = sr2smail-22 & linkId = 18fd04738627edef8d6fffd6c9b8f9c2) Is referred to.

procedure

  1. Wiring
  2. Program 7segment.py
  3. Run the program

1. Wiring

Wiring diagram is [Razpai Magazine-June 2016 issue Special feature 1 Akiba's popular parts Wiring diagram best 17 15 Numbers can be displayed](https://www.amazon.co.jp/ Razpai Magazine-2016 6 Monthly issue-Nikkei BP PC Best Mook-Nikkei Linux-ebook / dp / B01EH2RX42 / ref = as_li_ss_tl? 22 & linkId = 18fd04738627edef8d6fffd6c9b8f9c2) As it is.

If you get an image like this, referring to the picture of the circuit Raspberry Pi 3でpythonを使い「7セグメントLED」に出力する!回路.jpg

I also made a video Click the video commentary →

Text version From the Raspberry Pi side

--Raspberry Pi 12th pin --7 segment driver 7 D0 --Raspberry Pi 23rd pin --7 segment driver 1 D1 --Raspberry Pi 24th pin --7 segment driver 2 D2 --Raspberry Pi 25th pin --7 segment driver 3 D3 --Raspberry Pi 6th pin (GND) --7 segment driver 5 LE --Raspberry Pi 6th pin (GND) --7 segment driver 8 GND --Raspberry Pi 6th pin (GND) --7 segment LED 3 GND --Raspberry Pi 6th pin (GND) --Battery minus side

7-segment driver side

--7-segment screwdriver 3 LT --Battery (3V) plus side ―― 7-segment screwdriver 4 BL ――Battery (3V) plus side --7-segment screwdriver 16 Vcc --Battery (3V) plus side --7-segment driver 13 a --Resistance (150Ω) --7-segment LED 7 A --7-segment driver 12 b --Resistance (150Ω) --7-segment LED 6 B ―― 7-segment driver 11 c ―― Resistance (150Ω) ―― 7-segment LED 4 C --7-segment driver 10 d --Resistance (150Ω) --7-segment LED 2 D ―― 7-segment driver 9 e --Resistance (150Ω) ―― 7-segment LED 1 E --7-segment driver 15 f --Resistance (150Ω) --7-segment LED 9 F --7-segment driver 14 g --Resistance (150Ω) --7-segment LED 10 G

2. Program 7segment.py

Program is also [Razpai Magazine-June 2016 Issue Special Feature 1 Akiba's Popular Parts Wiring Diagram Best 17 15 Numbers can be displayed](https://www.amazon.co.jp/ Razpai Magazine-June 2016 Issue -Nikkei BP PC Best Mook-Nikkei Linux-ebook / dp / B01EH2RX42 / ref = as_li_ss_tl? Ie = UTF8 & dpID = 61P3o6Agz + L & dpSrc = sims & preST = _OU09__BG0,0,0,0_FMpng_AC_UL160_SR120,0_FMpng_AC_UL160_SR120 It is based on 18fd04738627edef8d6fffd6c9b8f9c2).

The source is uploaded to GitHub, so please use it as you like.

Clone with git


$ git clone https://github.com/RyosukeKamei/raspberrypi3.git

7segment.py


#Library to control GPIO
import wiringpi
#Timer library
import time
#Get arguments
import sys

#Specify the GPIO terminal number connected to 74HC5411 (7-segment driver)
d0_pin = 18
d1_pin = 23
d2_pin = 24
d3_pin = 25

#Put each terminal in output mode
wiringpi.wiringPiSetupGpio()
wiringpi.pinMode( d0_pin, 1 )
wiringpi.pinMode( d1_pin, 1 )
wiringpi.pinMode( d2_pin, 1 )
wiringpi.pinMode( d3_pin, 1 )

#Initialize all to 0
wiringpi.digitalWrite( d0_pin, 0 )
wiringpi.digitalWrite( d1_pin, 0 )
wiringpi.digitalWrite( d2_pin, 0 )
wiringpi.digitalWrite( d3_pin, 0 )

#Get arguments
param = sys.argv
set_number = int(param[1])

if( set_number >= 0 and set_number < 10):
    #Take the AND of the 1st bit
    wiringpi.digitalWrite( d0_pin, set_number & 0x01 )

    #Take the AND of the second bit
    wiringpi.digitalWrite( d1_pin, set_number & 0x02 )

    #Take the AND of the 3rd bit
    wiringpi.digitalWrite( d2_pin, set_number & 0x04 )

    #Take the AND of the 4th bit
    wiringpi.digitalWrite( d3_pin, set_number & 0x08 )
else:
    print("error:The arguments are 0-9.")

3. Run the program

I recorded the video of how it is moving. Click the video commentary →

Activate the temperature sensor


$ sudo python3 temperature_sensor.py

site map

Raspberry Pi 3 setup

Install Raspberry Pi 3 → Wireless LAN → Japanese input / output → Operate from Mac

Build a Python + MySQL environment with Docker on Raspberry Pi 3!

Install Docker on RaspberryPi3 Build a Python + bottle + MySQL environment with Docker on RaspberryPi3![Easy construction] Build a Python + bottle + MySQL environment with Docker on RaspberryPi3![Trial and error]

Make an air conditioner integrated PC "airpi" with Raspberry Pi 3!

Make an air conditioner integrated PC "airpi" with Raspberry Pi 3!

Let's play with Raspberry Pi 3 and python

Programming with Node-RED programming with Raspberry Pi 3 and programming normally Light the LED with python on Raspberry Pi 3 (Hello World) Detect switch status on Raspberry Pi 3 Run a servo motor using python on Raspberry Pi 3 Control the motor with a motor driver using python on Raspberry Pi 3! Detect slide switch using python on Raspberry Pi 3! Detect magnet switch using python on Raspberry Pi 3! Detect temperature using python on Raspberry Pi 3! Sound the buzzer using python on Raspberry Pi 3! Detect analog signals with A / D converter using python on Raspberry Pi 3! Detect "brightness" using python on Raspberry Pi 3! Detect "temperature (using A / D converter)" using python on Raspberry Pi 3! Output to "7-segment LED" using python on Raspberry Pi 3!

Rules focused on test-driven development

Coding rules "Let's write gentle code" (FuelPHP) Naming convention "Friendly to yourself, team-friendly, and unseen members after 3 months"

Web application development with Docker + Python

Install Python3, related libraries pip, virtualenv and frameworks Django, bottle, Flask on CentOS on Docker! With a Dockerfile that summarizes these!

Easy to develop environment construction (Docker + PHP)

PHP environment + Eclipse is linked to Apache using Docker Building FuelPHP development environment using Docker Create CRUD skeleton using initial settings of FuelPHP development environment using Docker and scaffold FuelPHP database migration

Recommended Posts

Output to "7-segment LED" using python on Raspberry Pi 3!
Detect "brightness" using python on Raspberry Pi 3!
Run servomotor on Raspberry Pi 3 using python
Detect temperature using python on Raspberry Pi 3!
Use python on Raspberry Pi 3 to illuminate the LED (Hello World)
Detect slide switches using python on Raspberry Pi 3!
Sound the buzzer using python on Raspberry Pi 3!
Connect to MySQL with Python on Raspberry Pi
Use python on Raspberry Pi 3 to light the LED with switch control!
Output from Raspberry Pi to Line
Try using ArUco on Raspberry Pi
[Raspberry Pi] Changed Python default to Python3
Detect "temperature (using A / D converter)" using python on Raspberry Pi 3!
Access google spreadsheet using python on raspberry pi (for myself)
Control the motor with a motor driver using python on Raspberry Pi 3!
Adafruit Python BluefruitLE works on Raspberry Pi.
How to play music (wav / mp3) files on Raspberry Pi python
How to install NumPy on Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
#Monte Carlo method to find pi using Python
Try using a QR code on a Raspberry Pi
How to use Raspberry Pi pie camera Python
Make DHT11 available on Raspberry Pi + python (memo)
Connect your Raspberry Pi to your smartphone using Blynk
Build a Python development environment on Raspberry Pi
pigpio on Raspberry pi
Cython on Raspberry Pi
[Raspberry Pi] Publish a web application on https using Apache + WSGI + Python Flask
Using the 1-Wire Digital Temperature Sensor DS18B20 from Python on a Raspberry Pi
Use python on Raspberry Pi 3 and turn on the LED when it gets dark!
From setting up Raspberry Pi to installing Python environment
Build an OpenCV4 environment on Raspberry Pi using Poetry
How to use the Raspberry Pi relay module Python
Try debugging Python on Raspberry Pi with Visual Studio.
Try using the temperature sensor (LM75B) on the Raspberry Pi.
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Install pyenv on Raspberry Pi and version control Python
Install PyCall on Raspberry PI and try using GPIO's library for Python from Ruby
Indoor monitoring using Raspberry Pi
I talked to Raspberry Pi
Start to Selenium using python
Introducing PyMySQL to raspberry pi3
Update python on Mac to 3.7-> 3.8
Raspberry Pi + Python + OpenGL memo
raspberry pi 1 model b, python
Broadcast on LINE using python
Introduced pyenv on Raspberry Pi
Use NeoPixel on Raspberry Pi
Install OpenCV4 on Raspberry Pi 3
Install TensorFlow 1.15.0 on Raspberry Pi
Update Python for Raspberry Pi to 3.7 or later with pyenv
Run AWS IoT Device SDK for Python on Raspberry Pi
Cross-compiling for Raspberry Pi Zero on Debian-Try using shared libraries
I want to disable interrupts on Raspberry Pi (≒ DI / EI)
I tried to automate [a certain task] using Raspberry Pi
How to get temperature from switchBot thermo-hygrometer using raspberry Pi
Output product information to csv using Rakuten product search API [Python]
[Raspberry Pi] Minimum device driver creation memo to output GPIO
Translate I2C device driver for Arduino to Python for Raspberry pi
Connect Raspberry Pi to Alibaba Cloud IoT Platform with Python
Input and output display images directly using the frame buffer (/ dev / fb0) on Raspberry Pi