Use python on Raspberry Pi 3 to illuminate the LED (Hello World)

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, I will explain "Lighting the LED", which can be said to be the "Hello World" of electronic work!

1. Wiring photo

(Is the photo easier to understand than the wiring diagram?) No. 6 GND No. 16 3.3V LED配線図

2. Source led.py

The description of the program is given in the comments starting with #.

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

Clone with git


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

led.py


#Library to control GPIO
import wiringpi
#Timer library
import time

#GPIO terminal number with LED connected
led_pin = 23 #Terminal 16

#GPIO initialization
wiringpi.wiringPiSetupGpio()
#Set GPIO to output mode (1)
wiringpi.pinMode( led_pin, 1 )

#The while process seems to be in the loop range when indented.
while True:
#GPIO 3.Set to 3V and turn on the LED
	wiringpi.digitalWrite( led_pin, 1 )
	#Wait 1 second
	time.sleep(1)
	#Set GPIO to 0V and turn off the LED
	wiringpi.digitalWrite( led_pin, 0 )
	#Wait 1 second
	time.sleep(1)

3. Run led.py

led.Run py


$ sudo python3 led.py

When run, it glows and turns off every second!

LED video

4. Useful when programming

It doesn't matter to those who operate the Raspberry Pi directly. For those who want to operate Raspberry Pi on Mac. We write the source on Mac, save it as it is on Raspberry Pi, and execute it from Mac. (There is no display ...) For that, we use AFP. The setting method is Install Raspberry Pi 3 → Wireless LAN → Japanese input / output → Operate from Mac of "6. AFP settings" Please refer to! It's convenient because you don't have to upload files by SFTP etc.! Windows users should be able to do something similar with Samba installed!

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

Use python on Raspberry Pi 3 to illuminate the LED (Hello World)
Use python on Raspberry Pi 3 to light the LED with switch control!
How to use the Raspberry Pi relay module Python
Output to "7-segment LED" using python on Raspberry Pi 3!
Use python on Raspberry Pi 3 and turn on the LED when it gets dark!
Use the Grove sensor on the Raspberry Pi
How to use Raspberry Pi pie camera Python
Say hello to the world with Python with IntelliJ
Sound the buzzer using python on Raspberry Pi 3!
Connect to MySQL with Python on Raspberry Pi
About the error I encountered when trying to use Adafruit_DHT from Python on a Raspberry Pi
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Use NeoPixel on Raspberry Pi
Try to use up the Raspberry Pi 2's 4-core CPU with Parallel Python
[Hyperledger Iroha] Notes on how to use the Python SDK
Use vl53l0x with Raspberry Pi (python)
Sakura Use Python on the Internet
[Raspberry Pi] Changed Python default to Python3
Getting Started with Heroku-Viewing Hello World in Python Django with Raspberry PI 3
How to play music (wav / mp3) files on Raspberry Pi python
Detect "brightness" using python on Raspberry Pi 3!
Hello World with Raspberry Pi + Minecraft Pi Edition
How to build Hello, World on #Nix
Memorandum on how to use gremlin python
Run servomotor on Raspberry Pi 3 using python
Install python on xserver to use pip
Detect temperature using python on Raspberry Pi 3!
How to display Hello world in python
How to install NumPy on Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
Use BME280 temperature / humidity / barometric pressure sensor from Python on Raspberry Pi 2
A memo to simply use the illuminance sensor TSL2561 with Raspberry Pi 2
Use Raspberry Pi to solve the problem of insufficient mobile Wi-Fi connection
I connected the thermo sensor to the Raspberry Pi and measured the temperature (Python)
Easy way to use Python 2.7 on Cent OS 6
Detect slide switches using python on Raspberry Pi 3!
Specify the Python executable to use with virtualenv
Detect magnet switches using python on Raspberry Pi 3!
Hello World with nginx + uwsgi + python on EC2
The easiest way to use OpenCV with python
[Algorithm x Python] How to use the list
Use the Python framework "cocotb" to test Verilog.
Introduction to Python with Atom (on the way)
Use Grove-Temperature & Humidity Sensor (DHT11) on Raspberry Pi
Make DHT11 available on Raspberry Pi + python (memo)
Build a Python development environment on Raspberry Pi
I want to use Python in the environment of pyenv + pipenv on Windows 10
Using the 1-Wire Digital Temperature Sensor DS18B20 from Python on a Raspberry Pi
Use Raspberry Pi Python to TMP36 analog temperature sensor and MCP3008 AD converter
From setting up Raspberry Pi to installing Python environment
Think about how to program Python on the iPad
What to do when python3 type venv does not work well on Raspberry Pi
Try to visualize the room with Raspberry Pi, part 1
Steps to install the latest Python on your Mac
pigpio on Raspberry pi
Try debugging Python on Raspberry Pi with Visual Studio.
Study from the beginning of Python Hour1: Hello World
I wanted to use the Python library from MATLAB
[Python] How to use the graph creation library Altair
Use kintone API SDK for Python on Raspberry Pi (easily store data in kintone from Raspberry Pi)
Specify MinGW as the compiler to use with Python