Cov txheej txheem:

Nyeem thiab Teeb Duab Lub Teeb thiab Kub Sensor Cov Ntaub Ntawv Nrog Raspberry Pi: 5 Cov Kauj Ruam
Nyeem thiab Teeb Duab Lub Teeb thiab Kub Sensor Cov Ntaub Ntawv Nrog Raspberry Pi: 5 Cov Kauj Ruam

Video: Nyeem thiab Teeb Duab Lub Teeb thiab Kub Sensor Cov Ntaub Ntawv Nrog Raspberry Pi: 5 Cov Kauj Ruam

Video: Nyeem thiab Teeb Duab Lub Teeb thiab Kub Sensor Cov Ntaub Ntawv Nrog Raspberry Pi: 5 Cov Kauj Ruam
Video: Часы G-Shock до 250 долларов-15 лучших часов Casio G до 250 доллар... 2024, Kaum ib hlis
Anonim
Nyeem thiab Teeb Duab Lub Teeb thiab Kub Sensor Cov Ntaub Ntawv Nrog Raspberry Pi
Nyeem thiab Teeb Duab Lub Teeb thiab Kub Sensor Cov Ntaub Ntawv Nrog Raspberry Pi

Hauv Cov Lus Qhia no koj yuav kawm paub nyeem lub teeb thiab ntsuas kub li cas nrog raspberry pi thiab ADS1115 analog rau cov hloov pauv thiab teeb duab nws siv matplotlib. Cia pib nrog cov ntaub ntawv xav tau.

Khoom siv

  1. Raspberry pi (ib tus twg yuav ua, txawm hais tias kuv tab tom siv 4)
  2. MicroSD daim npav nrog Raspbian teeb tsa (nyeem tau zoo:
  3. HDMI saib thiab lub zog siv
  4. Micro USB kab
  5. Adafruit ADS 1115 analog to digital converter:
  6. Jumper xov hlau
  7. lub teeb pom kev zoo (LDR)
  8. kub sensor
  9. potentiometer x2 (tus nqi yuav yog qhov nruab nrab ntawm qhov ntau ntawm qhov tsis kam ntawm koj lub ntsuas cua thiab lub teeb, uas peb yuav ntsuas tom qab)
  10. Cov qhob cij

Kauj Ruam 1: Teeb Koj Raspberry Pi

1. Ua raws cov ntawv qhia no kom teeb tsa koj li raspberry pi: https://www.raspberrypi.org/help/noobs-setup/2/2. Pab kom I2C: nyem lub cim raspberry pi nyob rau sab saud. Mus rau qhov nyiam> raspberry pi teeb tsa> cuam tshuam> thiab khij lub npov "pab" ntawm I2C. Tom qab ntawv nyem OK. 3. Tam sim no qhib lub davhlau ya nyob twg qhov rai. Ntawm kab hais kom ua hom:

sudo apt-tau hloov tshiab

sudo pip3 nruab adafruit-circuitpython-ads1x15

sudo apt-tau nruab python-matplotlib

Kauj Ruam 2: Ntsuas Koj Lub Teeb thiab Qhov Kub Kub

Tam sim no peb yuav tsum tau ntsuas lub teeb thiab qhov ntsuas kub tsis kam. Siv lub ntsuas hluav taws xob ntsuas ntawm qhov ntsuas qhov ntsuas tsis zoo thiab ntsuas hla txoj hauv kev ntawm koj lub teeb pom kev hauv qhov pom kev thiab tsaus ntuj. Sau cov txiaj ntsig. Tam sim no coj koj lub ntsuas hluav taws xob ntawm qhov ntsuas ntawm koj qhov ntsuas kub hauv qhov kub thiab txias (Kuv tau siv dej). Sau cov txiaj ntsig. Peb yuav siv lawv tom qab hauv peb qhov kev sib tham.

Kauj Ruam 3: Txhim Kho Koj Li Circuit Court

Txhim Kho Koj Txoj Cai
Txhim Kho Koj Txoj Cai

1. Sau cov ntaub ntawv teev tseg hauv cov npe khoom siv. Rau lub zog ntsuas, siv tus nqi uas yog qhov nruab nrab ntawm qhov siab thiab qis (lub teeb thiab tsaus, kub thiab txias).

(siab-qis) / 2

2. Ua raws daim duab qhia chaw saum toj no:

  1. Txuas SDA ntawm qhov sib piv rau digital hloov mus rau SDA ntawm tus pi
  2. Txuas SCL ntawm qhov sib piv rau digital hloov mus rau SCL ntawm tus pi
  3. Txuas VDD ntawm qhov sib piv rau digital hloov mus rau 3.3v ntawm tus pi
  4. Txuas GND ntawm qhov sib piv rau digital hloov pauv mus rau hauv av ntawm pi
  5. Txuas cov khoom seem raws li daim duab qhia chaw.

Kauj ruam 4: Code

1. Ntaus hauv lub davhlau ya nyob twg:

nano cov digital.py

2. Muab tshuaj txhuam tus lej kuv muaj hauv qab no lossis ntawm Github rau hauv cov ntawv sau uas yuav tsum tshwm sim.

ntshuam matplotlib.pyplot li plt

import numpy as np import board import busio import time import adafruit_ads1x15.ads1115 as ADS from adafruit_ads1x15.analog_in import AnalogIn i2c = busio. I2C (board. SCL, board. SDA) tawm = ADS. ADS1115 (i2c) x = 0 teeb = AnalogIn (tawm, ADS. P0) temp = AnalogIn (tawm, ADS. P1) X1 = X2 = Y1 = Y2 = plt.ylim (-50, 1000) plt.plot (X1, Y1, label = "light", color = '#0069af') plt.plot (X2, Y2, label = "Temp", color = '#ff8000') plt.xlabel ('Sijhawm (feeb)') plt.ylabel (' Theem ') plt.title (' Lub teeb thiab kub dhau sijhawm ') plt.legend () thaum Tseeb: x += 5 Y1.append (lub teeb.value/30) X1.append (x) Y2.append (temp.value /3) X2.append (x) plt.plot (X1, Y1, label = "light", color = '#0069af') plt.plot (X2, Y2, label = "Temp", color = '#ff8000') plt.pause (300)

3. Tam sim no nias CTRL+X kom tawm, nias y kom txuag, tom qab ntawd nias nkag mus.

Khiav koj qhov program los ntawm kev ntaus hauv lub davhlau ya nyob twg:

sudo python3 digital.py

4. Kho cov potentiometers kom cov duab qhia ntau yam ntawm cov txiaj ntsig. Sim ua lub teeb ci ntawm lub ntsuas hluav taws xob thiab tua lub teeb hauv chav kom ntseeg tau tias kab teeb qhia ntau yam txiaj ntsig.

Yog tias ib qho ntawm cov txiaj ntsig poob qis hauv qab, sim txo qhov sib faib sib xws (kab 29 thiab 31).

Yog tias ib qho ntawm cov txiaj ntsig mus saum toj saud, sim ua kom sib npaug sib npaug (kab 29 thiab 31).

Kauj ruam 5: Troubleshooting

1. Muab ob npaug rau xyuas txhua qhov kev sib txuas tiv thaiv kab kos duab

2. I2C kuaj pom - Yuav qhia koj txhua lub cuab yeej txuas nrog los ntawm i2c:

Hom hauv davhlau ya nyob twg:

sudo apt-tau nruab i2c-cuab yeej

sudo i2cdetect - y 1

Pom zoo: