Terminal에서...
sudo raspi-config
Go to "Advanced Options"
and then Go to "SPI" >> Yes >> Ok >> Exit
Terminal에서...
sudo reboot
exit
sudo apt-get install python3-dev
wget
ls (리스트 나열하기 command)
unzip master.zip
ls
rm master.zip (remove master.zip)
ls
cd py-spidev-master
ls
sudo python3 setup.py install
cd..
죄측 상단의
File >> new window
새창을 열고 Save As
/home/pi/Desktop/cookie
여기에 "analog.py" 라는 이름으로 저장
▼이하는 Python3내의 코딩이다.
import spidev
from time import sleep
import OS
#First open up SPI bus
Spi = spidev.Spi.Dev( )
Spi.open(0,0)
#Initialize what sensor is where
lightChannel = 0
tempChannel = 1
sleepTime = 1
def getReading(channel):
#First pull the raw data from the chip
rawData = spi.xfer([1, (8 + channel) << 4,0])
#Process the raw data sth we understand.
processedData = ((rawData [1] & 3) << 8) + rawData[2]
return processedData
while True:
data = getReading(lightChannel)
print(data)
data = getReading(tempChannel)
print(data)
sleep(sleepTime)
def convertVoltage(bitValue, decimalPlaces=2):
voltage = (bitValue*3.3) / float(1023)
voltage = round(voltage, decimalPlaces)
return voltage
def convertTemp(bitValue, decimalPlaces=2):
#Convert to degree celsius
temperature = ((bitValue*330) / float(1023)-50)
temperature = round(voltage, decimalPlaces)
return temperature
while True:
lightData = getReading (lightChannel)
tempData = getReading (tempChannel)
lightVoltage = convertVoltage(lightData)
tempVoltage = convertVoltage(tempData)
temperature = convertTemp(tempData)
#Print All the Things
print("Light bitValue = { } ; Voltage = { } v" .format(lightData, lightVoltage))
print("Temp bitValue = { } ; Voltage = { } v ; Temp = { } C" .format(\tempData, tempVoltage, temperature))
sleep(sleepTime)
LED Blinker Project
Now we start creating projects using the RasPi.
However, I still have some preparatory steps to
discuss and information to provide about the prototype board that will be used in this and other projects.
I will also present a detailed discussion of the GPIO library,
which is critical to making all of the projects work.
우린 또한 보여줄것이다. a 디테일한 논의를 of the GPIO 라이브러리의
which is 중대한 to 만들기에 모든 프로젝트 작업을.
The first project will consist of turning on an LED connected to a GPIO pin
and then causing that LED to blink.
첫 프로젝트는 will 구성한다. of 켜는걸로 an LED를 연결된 to a GPIO핀에
그런다음 유발한다. 그 LED를 to 깜빡이게끔.
>>
Prototype Board
Let’s focus on a piece of hardware that I will use
to demonstrate how to blink an LED
using the RasPi and some Python code.
This section is entitled “Prototype Board” and that is exactly what I will be
using. The board is called the Pi Plate and is available from Adafruit at
https://www.adafruit.com/products/801. It comes as a kit of parts; however, a fully assembled Pi Plate
mounted on a RasPi is shown in Fig. 2–1.
The Pi Plate attaches to the 26-pin GPIO connector, as you can see in the figure. All the active
connections are brought out to the top of the Pi Plate, both to 0.1-inch, on-center, female header strips
as well as to 3.5-mm screw clamp connectors. This makes for a very easy access to the GPIO pins.
Please note that the pins on the Pi Plate are marked with both RasPi and BMC designations, which can
be confusing. Please use Table 1–2, from Chap. 1, to cross-reference all the designations and ensure
that you know what connection you are making.
>>
Soldering
I thought this would be an appropriate time to discuss soldering, since you will need to assemble the
Pi Plate. The assembly operation is very straightforward, and Adafruit provides a step-by-step
illustrated assembly guide at learn.adafruit.com/adafruit-prototyping-pi-plate. I have also included a
photo of my trusty soldering station in Fig. 2–2.
It’s not the prettiest or the snazziest station available, but it has served me well. The key to quality
soldering work is to have good soldering technique, keep the soldering iron tip clean, and use the
highest-quality solder available. Figure 2–3 shows the essence of good soldering technique. It is vital
that the solder joint be hot enough for the solder to flow easily. It takes practice to apply just the right
amount of solder; too little may result in a cold solder joint, and too much could lead to a short
between closely spaced components.
Another issue regarding a good solder joint is the use of lead-free solder. Now, don’t get down on
me; I am all about maintaining a healthful environment, but the elimination of lead from solder often
produces poor solder joints unless some extra precautions are taken. The simplest and probably the
best approach is to apply a high-quality, acid-free, solder flux to the joint prior to heating the joint
with the iron. This will allow the lead-free solder to flow more freely and produce a better-soldered connection.
Again, it takes practice to perfect soldering techniques.
One final thought that relates to solder joints as well as to other types of electrical connections is
worth sharing. There is a long-running anecdotal observation that 90 percent of all
electrical/electronic malfunctions are related to connection malfunctions. This makes a lot of a sense
when you think about it. We live in an oxygen-rich atmosphere and oxygen is a great reduction agent;
it wants to oxidize every element it can possibly chemically combine with. Metal oxides are
reasonably good insulators because some of their free electrons have been “taken” up by oxygen
molecules. This leads to higher and higher resistance being built up in a connection that will
eventually cause a failure.
Of course, current flowing through a resistance produces heat, which in turn can cause a fire if the
current is sufficiently high. So what is the solution? One expensive solution is to gold-plate electrical
contact surfaces. Gold does not oxidize and is not subject to this type of failure. It is, of course, very
expensive and not practical for large-scale connectors. Another solution that the power industry
employs is what is known as gastight connections, which require the use of special components and
specialized training to produce. For the type of projects that I work on, I can only ensure that the
solder joints are sound from both a mechanical and an electrical perspective. I also inspect electrical
connections for oxidation and foreign matter and take appropriate action to replace the compromised
connection or component.
>>
Accessing the GPIO Pins
The GPIO pins have to be made programmable in order to blink the LED.
Being made programmable means that
the pins are set to either sense an input voltage or set an output voltage.
그 GPIO핀들은 만들어져야만한다. 프로그램가능하게 in order to 깜빡이게하기위해 LED를.
그로그램 가능게하기는 의미한다. that
the 핀들이 set되있다는걸 to either 감지하든 an 입력전압을 or 셋하든 an 출력전압을.
The pins are accessed
by using a high-level name such as pin (18)
that you can readily identify—in this case, GPIO pin number 18.
핀들은 접근가능하다.
by 사용함으로써 a 하이-레벨 이름붙은 such as pin (18)이라고
that you can 준비하는 정의하는게 - in 이경우, GPIO 핀 넘버 18.
We must use a software library
that contains the required high-level abstractions and
hardware associations to enable us to control the GPIO pins with a Python program.
This library is named Rpi.GPIO-0.4.1a.tar.gz
and is readily available as a Linux archived file from
https://sourceforge.net/projects/raspberry-gpio-python/.
Figure 2–4 shows this website.
우린 반드시 사용해야한다. a 소프트웨어 라이브러리를
that 포함하는 the 요구된 high-level 추상들을
하드웨어 군집은 to 가능게한다. 우릴 to 제아할수있게 the GPIO핀들을 with a파이선과 함께
이 라이브러리는 이름지어졌다. Rpi.GPIO-0.4.1a.tar.gz 이라고
and is 준비되있다. 사용가능하게 as a 리눅스 achived 파일로써 from
the website.
The archived file must be downloaded, extracted, and stored in an appropriate directory.
I would suggest creating a new directory named Python
located in the pi parent directory.
Open an LXDE terminal window and type the following commands in the terminal window:
그 archived 파일은 반드시 다운로드해야한다, 압축풀고, 저장한다. in an 적합한 디렉토리에.
난 would 제안할것이다. 만드는걸 새 디렉토리를 이름붙은 Python
위치한 in the pi 부모 디렉토리에.
열어라. an LXDE 터미널 윈도우를 and 타이핑해라. the 따라오는 명령어들을 in the 터미널에
pwd
ls
mkdir Python
ls
cd Python
pwd
ls
'RaspBerry PI' 카테고리의 다른 글
SD Card, USB 인식문제 (액세스 할수...., 포맷을 할수....) (1) | 2020.03.20 |
---|---|
AutoRun(=RPi 부팅할때 Run시키기) (0) | 2018.03.27 |
0.라즈베리파이 OS 설치하기 (Window10 IoT Core) (해상도 조절법) (0) | 2016.12.30 |
Use Laptop Screen for using RaspberryPI (노트북 스크린을 라즈베리파이용으로 사용하기) (0) | 2016.12.06 |
리눅스 기초 자료 (0) | 2016.08.10 |