Sensor on GPIO pins

2017. 1. 4. 23:09
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Raspberry Pi의 기본문법(=Syntax)을 익히기에 좋다.








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



Posted by ElectricShock
:
BLOG main image
잡동사니들(지극히 개인취향인...) (다른글에도 댓글 부탁해요♥) You May Leave English Messages on GuestBook. by ElectricShock

공지사항

카테고리

분류 전체보기 (782)
Programming(=프로그래밍) (3)
MiDi (2)
Animation (4)
Blender (3D Graphic Program.. (10)
Blendtuts.com (Series) (1)
Blender 기초 팁들 (2)
Processing (디지털미디어과) (2)
Music (1)
Books in the world (0)
Communication(CAN, UART, et.. (12)
MCU Examples (PIC 기반) (7)
Transistor (1)
Mikro C Pro (11)
Mikro Pascal (1)
Proton IDE (0)
Robot (0)
Swift 3D (1)
Dummies Series (1)
All about Hacking (0)
제2 외국어 (1)
PIC 해외서적들 (3)
AVR (25)
PIC (MikroC) (MPLAB) (4)
Assembly (2)
ARM (3)
Arduino (26)
PSpice (1)
Proteus ISIS (14)
CodeVision (2)
FPGA (15)
MPLAB (24)
PCB (the Procedure) (15)
3D Printer (5)
PICKIT3 (6)
Matlab (11)
RaspBerry PI (15)
BeagleBone (1)
Android Studio (17)
졸업작품 (172)
Korea History (0)
Issue(사회) (73)
Multimeter 리뷰 (1)
Oscilloscope (1)
A (34)
B (19)
J (6)
C (32)
P (12)
T (37)
H (12)
I (12)
M (44)
R (5)
E (5)
F (2)
D (9)
O (2)
L (7)
S (9)
W (2)
V (6)
G (14)
Visual C++ or Visual Studio (2)
Android App Development (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백