Cov txheej txheem:

Ua kom muaj hluav taws xob nrog lub tsheb kauj vab Ergometer: 9 Kauj Ruam (nrog Duab)
Ua kom muaj hluav taws xob nrog lub tsheb kauj vab Ergometer: 9 Kauj Ruam (nrog Duab)

Video: Ua kom muaj hluav taws xob nrog lub tsheb kauj vab Ergometer: 9 Kauj Ruam (nrog Duab)

Video: Ua kom muaj hluav taws xob nrog lub tsheb kauj vab Ergometer: 9 Kauj Ruam (nrog Duab)
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Lub Xya hli ntuj
Anonim
Ua kom muaj hluav taws xob nrog lub tsheb kauj vab Ergometer
Ua kom muaj hluav taws xob nrog lub tsheb kauj vab Ergometer
Ua kom muaj hluav taws xob nrog lub tsheb kauj vab Ergometer
Ua kom muaj hluav taws xob nrog lub tsheb kauj vab Ergometer
Ua kom muaj hluav taws xob nrog lub tsheb kauj vab Ergometer
Ua kom muaj hluav taws xob nrog lub tsheb kauj vab Ergometer

Txoj haujlwm kev piav qhia muaj nyob hauv kev sib dhos ntawm "game" nrog lub hom phiaj txhawm rau taug kev hauv lub tsheb kauj vab ergometer txuas nrog lub tshuab hluav taws xob thiab ntau lub teeb ntawm lub teeb uas tau qhib ua haujlwm raws li lub cav nrawm nce - uas tshwm sim raws li lub tsheb kauj vab. Lub kaw lus tau ua raws kev nyeem ntawv-los ntawm qhov chaw nres nkoj sib piv ntawm Arduino Mega-qhov hluav taws xob tau tsim tam sim ntawd, tom qab ntawd xa cov ntaub ntawv no mus rau Raspberry Pi 3 ntawm kev sib txuas lus RX-TX thiab tom qab ua haujlwm ntawm lub teeb ntawm kev xa tawm.

Kauj Ruam 1: Cov Ntaub Ntawv:

  • 1 Raspberry Pi 3;
  • 1 Arduino Mega 2560;
  • 1 Relay Shield nrog 10 Relays 12 V;
  • 10 Teeb Teeb 127 V;
  • 1 Tsheb kauj vab Ergometer;
  • 1 Lub Tshuab Hluav Taws Xob (Lub Tshuab Hluav Taws Xob) 12 V;
  • Resistors (1x1kΩ, 2x10kΩ);
  • 1 Electrolytic Capacitor 10 µF;
  • 1 Zener Diode 5.3 V;
  • 1.5 hli Cable (liab, dub, xim av);
  • 1 MDF ntauwd nrog txhawb nqa 10 lub teeb.

Kauj Ruam 2: Daim Duab Blocks System:

Qhov System Blocks Diagram
Qhov System Blocks Diagram

Kauj Ruam 3: Kev Ua Haujlwm:

Lub kaw lus yog ua raws kev hloov pauv ntawm lub zog hluav taws xob tsim tawm thaum caij tsheb kauj vab hauv lub zog hluav taws xob lub luag haujlwm rau kev ua haujlwm ntawm kev xa tawm uas yuav tig lub teeb rau.

Qhov hluav taws xob uas tsim los ntawm lub tshuab hluav taws xob tau nyeem los ntawm tus lej sib piv ntawm Arduino thiab raug xa los ntawm RX-TX mus rau Raspberry Pi. Kev ua haujlwm ntawm kev xa tawm yog qhov sib npaug rau qhov hluav taws xob tsim tawm - qhov siab dua qhov hluav taws xob, ntau qhov kev xa tawm yuav tshwm sim thiab ntau lub teeb yuav ci.

Kauj Ruam 4: Yam Khoos Phis Tawj

Mechanics Yam
Mechanics Yam

Txhawm rau txhawm rau txhawm rau ob peb lub tshuab hluav taws xob DC rau lub tsheb kauj vab, txoj siv txoj hlua yuav tsum tau hloov los ntawm cov kab ke uas siv los ntawm cov tsheb kauj vab (suav nrog cov yas, saw thiab pinion). Cov phaj hlau tau txuas rau lub thav duab tsheb kauj vab kom lub cav tuaj yeem ruaj ntseg los ntawm cov ntsia hlau. Tom qab ntawd, lub pinion tau txuas rau lub tshuab hluav taws xob kom cov saw tuaj yeem tso tau, sib txuas ua ke lub tshuab hluav taws xob mus rau lub tshuab hluav taws xob.

Kauj Ruam 5: Kev Nyeem Ntawv:

Txhawm rau nyeem lub tshuab hluav taws xob qhov hluav taws xob siv Arduino yog qhov tsim nyog los txuas tus ncej zoo ntawm lub tshuab hluav taws xob mus rau A0 tus pin ntawm tus tswj thiab tus ncej tsis zoo rau GND - kom zam qhov siab tshaj plaws ntawm lub tshuab hluav taws xob ntau dua 5 V ntawm Arduino pins, qhov ntsuas hluav taws xob siv lub capacitor ntawm 10 µF, tus tiv thaiv ntawm 1 kΩ thiab Zener diode ntawm 5.3 V tau tsim thiab txuas nrog ntawm tus tswj thiab lub tshuab hluav taws xob. Lub khoos phis tawj thauj khoom hauv Arduino yog qhov yooj yim heev thiab tsuas yog nyeem qhov chaw nres nkoj sib piv, muab tus nqi nyeem los ntawm qhov tas li 0.0048828125 (5/1024, uas yog Arduino's GPIO qhov hluav taws xob faib los ntawm tus lej ntawm nws qhov chaw nres nkoj analog) thiab xa sib txawv rau Serial - cov cai yuav muaj nyob hauv kab lus.

Cov txheej txheem txhawm rau ua kom RX-TX kev sib txuas lus hauv Raspberry Pi yog qhov nyuaj me ntsis, thiab koj yuav tsum ua raws cov txheej txheem tau piav qhia hauv kab ntawv txuas. Luv luv, koj yuav tsum kho cov ntaub ntawv hu ua "inittab" -nyob hauv "/etc/inittab" -, tawm kab "T0: 23: respawn:/sbin/getty -L ttyAMA0 115200 vt100" (yog tias cov ntawv tsis yog nrhiav tau hauv Raspberry's OS, koj yuav tsum sau cov lus txib: "sudo leafpad /boot/config.txt" thiab txuas kab "enable_uart = 1" mus rau qhov kawg ntawm cov ntawv). Thaum qhov no ua tiav, koj yuav tsum rov qhib LX Terminal thiab kaw qhov Serial nrog cov lus txib "sudo systemctl nres [email protected]" thiab "sudo systemctl lov tes taw [email protected]". Tom qab ntawd koj yuav tsum ua raws cov lus txib "sudo leafpad /boot/cmdline.txt", rho tawm kab "console = serial0, 115200", khaws cov ntawv thiab rov pib dua lub cuab yeej. Txhawm rau kom RX-TX kev sib txuas lus tuaj yeem ua tau, Lub Tsev Qiv Ntawv Serial yuav tsum tau teeb tsa ntawm Raspberry Pi nrog cov lus txib "sudo apt-get install -f python-serial" thiab ntshuam lub tsev qiv ntawv rau hauv tus lej los ntawm kev nkag mus "kab ntawv txuas" kab, pib ua ntu zus los ntawm kev nkag kab "ser = serial. Serial (" / dev / ttyS0 ", 9600)" thiab nyeem qhov hluav taws xob xa los ntawm Arduino siv cov lus txib "ser.readline ()" - tag nrho cov cai siv hauv Raspberry yuav tsum muaj nyob rau ntawm qhov kawg ntawm tsab xov xwm.

Ua raws li cov txheej txheem piav qhia saum toj no, nyeem thiab xa cov kauj ruam hluav taws xob tau ua tiav.

Kauj Ruam 6: Arduino Programming:

Raws li tau hais yav tas los, txoj cai lav ris rau kev nyeem qhov hluav taws xob tau tsim thaum caij tsheb kauj vab yooj yim heev.

Ua ntej tshaj, nws yog qhov tsim nyog xaiv A0 tus pin raws li lub luag haujlwm nyeem qhov hluav taws xob.

Hauv qhov "tsis muaj teeb tsa ()" ua haujlwm, koj yuav tsum teeb tus pin A0 rau INPUT nrog "pinMode (sensor, INPUT)" hais kom ua thiab xaiv qhov chaw nres nkoj xa xov xwm ceev siv "Serial.begin (9600)" hais kom ua.

Hauv "void loop ()", "Serial.flush ()" muaj nuj nqi tau siv los tshem qhov tsis nyob txhua lub sijhawm nws xaus qhov xa cov ntaub ntawv ntawm cov lej; kev nyeem qhov hluav taws xob tau ua los ntawm kev ua haujlwm "analogRead (sensor)" - nco ntsoov tias nws yog qhov tsim nyog los hloov tus nqi nyeem los ntawm qhov chaw nres nkoj analog rau Volts - txheej txheem hais hauv ntu "nyeem voltage" ntawm kab lus.

Tsis tas li, hauv qhov "void loop ()" muaj nuj nqi, nws yog qhov tsim nyog los hloov qhov sib txawv x los ntawm ntab mus rau txoj hlua, vim qhov no yog tib txoj kev xa qhov sib txawv ntawm RX-TX. Kauj ruam kawg hauv lub voj kev ua haujlwm yog luam cov hlua hauv kab ntawv txuas kom nws tuaj yeem xa mus rau Raspberry - rau qhov no koj yuav tsum siv "Serial.println (y)" ua haujlwm. Kab "ncua (100)" tau ntxiv rau cov cai nkaus xwb kom qhov sib txawv raug xa hauv ib ntus ntawm 100 ms - yog lub sijhawm no tsis hwm, Serial overload yuav tshwm sim, ua rau muaj kev sib tsoo hauv txoj haujlwm.

voltage_read.ino

ntab sensor = A0;
voidsetup () {
pinMode (sensor, INPUT);
Serial.begin (9600);
}
voidloop () {
Serial.flush ();
ntab x = analogRead (sensor)*0.0048828125*16.67;
Txoj hlua y = "";
y+= x;
Serial.println (y);
ncua (100);
}

saib rawvoltage_read.ino tuav nrog ❤ los ntawm GitHub

Kauj Ruam 7: Raspberry Pi 3 Programming:

lamps_bike.py

ntshuam os #import lub tsev qiv ntawv os (siv los tshem qhov screen thaum tsim nyog)
ntshuam RPi. GPIOas gpio #import lub tsev qiv ntawv siv los tswj Raspnerry's GPIO
ntshuam ntshuam #import lub tsev qiv ntawv lub luag haujlwm rau kev sib txuas lus
ntshuam sijhawm #import lub tsev qiv ntawv uas ua rau nws muaj peev xwm siv lub sijhawm qeeb
ntshuam cov txheej txheem #import lub tsev qiv ntawv lub luag haujlwm rau ua cov nkauj
#pib serial
ser = serial. Serial ("/dev/ttyS0", 9600) #txhais lub npe ntaus ntawv thiab tus nqi baud
#ntshiab screen
clear = lambda: os.system ('meej')
#teeb pins rau kev tswj hwm kev xa tawm
gpio.setmode (gpio. BOARD)
gpio.setup (11, gpio. OUT) #lamp 10
gpio.setup (12, gpio. OUT) #lamp 9
gpio.setup (13, gpio. OUT) #lamp 8
gpio.setup (15, gpio. OUT) #teeb 7
gpio.setup (16, gpio. OUT) #lamp 6
gpio.setup (18, gpio. OUT) #teeb 5
gpio.setup (19, gpio. OUT) #lamp 4
gpio.setup (21, gpio. OUT) #lamp 3
gpio.setup (22, gpio. OUT) #lamp 2
gpio.setup (23, gpio. OUT) #lamp 1
#pib cov ntaub ntawv
npe = ["Tsis muaj"]*10
qhov hluav taws xob = [0.00]*10
#nyeem cov ntaub ntawv
f = qhib ('cov ntaub ntawv', 'r')
rau kuv inrange (10): #10 qhov qhab nia zoo tshaj plaws tshwm hauv daim ntawv teev npe
npe = f.readline ()
npe [kuv] = npe [kuv] [: len (npe [kuv])-1]
voltage [kuv] = f.readline ()
voltage = ntab (voltage [: len (voltage )-1])
f.close ()
meej ()
#teeb tsa qhov siab tshaj plaws
max = 50.00 Nws
#tau lub teeb tawm
rau kuv inrange (11, 24, 1):
yog kuv! = 14 thiab kuv! = 17 thiab kuv! = 20:
gpio.output (i, gpio. HIGH) #set rau HIGH, cov xa tawm raug kaw
#pib
thaum tseeb
#pib qhov screen
print "Cov ntaub ntawv: / n"
rau kuv inrange (10):
sau lub npe , ":", voltage , "V"
current_name = raw_input ("Sau koj lub npe kom pib:")
meej ()
#Hloov pauv tus nqi siab
yog current_name == "max":
max = input ("Sau qhov siab tshaj qhov hluav taws xob: (2 qhov chaw zauv)")
meej ()
lwm tus:
#pib ceeb toom
rau kuv inrange (11, 24, 1): #lub voj pib hauv tus PIN 11 thiab nres hauv PIN 24
if i! = 14and i! = 17and i! = 20: #PIN 14 thiab 20 yog GND pins thiab 20 yog tus pin 3.3 V
gpio.output (i, gpio. LOW) #tig lub teeb rau
sijhawm.s pw (0.5)
k = 10 hli
rau kuv inrange (23, 10, -1):
meej ()
yog kuv! = 14 thiab kuv! = 17 thiab kuv! = 20:
subprocess. Popen (['aplay', 'Audios/'+str (k)+'. wav'])
sijhawm.s pw (0.03)
meej ()
print "Npaj! / n", k
sijhawm.sleep (1)
k-1 = np
gpio.output (i, gpio. HIGH) #tau lub teeb tawm (ib ntawm ib qho)
subprocess. Popen (['aplay', 'Audios/go.wav']) #plays lub suab paj nruag pib
sijhawm.s pw (0.03)
meej ()
print "YOG!"
sijhawm.sleep (1)
meej ()
#voltage nyeem
tam sim no_voltage = 0.00
voltage1 = 0.00
rau kuv inrange (200):
ser.flushInput ()
yav dhau los = voltage1
voltage1 = ntab (ser.readline ()) #sau Arduino cov ntaub ntawv xa los ntawm RX-TX
meej ()
luam tawm voltage 1, "V"
yog voltage1> tam sim no_voltage:
tam sim no_voltage = voltage1
# nyob ntawm qhov tsim hluav taws xob, ntau lub teeb pom kev.
yog voltage1 <max/10:
rau kuv inrange (11, 24, 1):
yog kuv! = 14 thiab kuv! = 17 thiab kuv! = 20:
gpio.output (kuv, gpio. HIGH)
yog voltage1> = max/10:
gpio.output (11, gpio. LOW)
rau kuv inrange (12, 24, 1):
yog kuv! = 14 thiab kuv! = 17 thiab kuv! = 20:
gpio.output (kuv, gpio. HIGH)
yog voltage1> = 2*max/10:
rau kuv inrange (11, 13, 1):
gpio.output (kuv, gpio. LOW)
rau kuv inrange (13, 24, 1):
yog kuv! = 14 thiab kuv! = 17 thiab kuv! = 20:
gpio.output (kuv, gpio. HIGH)
yog voltage1> = 3*max/10:
rau kuv inrange (11, 14, 1):
gpio.output (kuv, gpio. LOW)
rau kuv inrange (15, 24, 1):
yog kuv! = 17 thiab kuv! = 20:
gpio.output (kuv, gpio. HIGH)
yog voltage1> = 4*max/10:
rau kuv inrange (11, 16, 1):
yog kuv! = 14:
gpio.output (kuv, gpio. LOW)
rau kuv inrange (16, 24, 1):
yog kuv! = 17 thiab kuv! = 20:
gpio.output (kuv, gpio. HIGH)
yog voltage1> = 5*max/10:
rau kuv inrange (11, 17, 1):
yog kuv! = 14:
gpio.output (kuv, gpio. LOW)
rau kuv inrange (18, 24, 1):
yog kuv! = 20:
gpio.output (kuv, gpio. HIGH)
yog voltage1> = 6*max/10:
rau kuv inrange (11, 19, 1):
yog kuv! = 14 thiab kuv! = 17:
gpio.output (kuv, gpio. LOW)
rau kuv inrange (19, 24, 1):
yog kuv! = 20:
gpio.output (kuv, gpio. HIGH)
yog voltage1> = 7*max/10:
rau kuv inrange (11, 20, 1):
yog kuv! = 14 thiab kuv! = 17:
gpio.output (kuv, gpio. LOW)
rau kuv inrange (21, 24, 1):
gpio.output (kuv, gpio. HIGH)
yog voltage1> = 8*max/10:
rau kuv inrange (11, 22, 1):
yog kuv! = 14 thiab kuv! = 17 thiab kuv! = 20:
gpio.output (kuv, gpio. LOW)
rau kuv inrange (22, 24, 1):
gpio.output (kuv, gpio. HIGH)
yog voltage1> = 9*max/10:
rau kuv inrange (11, 23, 1):
yog kuv! = 14 thiab kuv! = 17 thiab kuv! = 20:
gpio.output (kuv, gpio. LOW)
gpio.output (23, gpio. HIGH)
yog voltage1> = max:
rau kuv inrange (11, 24, 1):
yog kuv! = 14 thiab kuv! = 17 thiab kuv! = 20:
gpio.output (kuv, gpio. LOW)

yog voltage 1

so
#tau lub teeb tawm
rau kuv inrange (11, 24, 1):
yog kuv! = 14 thiab kuv! = 17 thiab kuv! = 20:
gpio.output (kuv, gpio. HIGH)
#victory suab paj nruag
yog current_voltage> = max:
subprocess. Popen (['aplay', 'Audios/rocky.wav'])
sijhawm.s pw (0.03)
meej ()
luam tawm "Zoo heev, Koj Yeej Tau!"% (u '\u00c9', u '\u00ca', u '\u00c2')
rau kuv inrange (10):
rau j inrange (11, 24, 1):
yog j! = 14 thiab j! = 17 thiab j! = 20:
gpio.output (j, gpio. LOW)
sijhawm.s pw (0.05)
rau j inrange (11, 24, 1):
yog j! = 14 thiab j! = 17 thiab j! = 20:
gpio.output (j, gpio. HIGH)
sijhawm.s pw (0.05)
sijhawm.s pw (0.5)
subprocess. Popen (['aplay', 'Audios/end.wav'])
sijhawm.s pw (0.03)
meej ()
luam tawm "Xaus game … / n", current_voltage, "V"
#cov ntaub ntawv
sijhawm.sleep (1.2)
mus txog = 0
rau kuv inrange (10):
yog current_voltage> voltage :
mus txog+= 1
temp_voltage = voltage [kuv]
voltage = tam sim no_voltage
tam sim no_voltage = temp_voltage
temp_name = npe [kuv]
name [kuv] = current_name
tam sim no_name = temp_name
yog mus txog> 0:
subprocess. Popen (['aplay', 'Audios/record.wav'])
sijhawm.s pw (0.03)
meej ()
f = qhib ('cov ntaub ntawv', 'w')
rau kuv inrange (10):
f.write (lub npe [kuv])
f.write ("\ n")
f.write (str (voltage [kuv])))
f.write ("\ n")
f.close ()
meej ()

saib rawlamps_bike.py tuav nrog ❤ los ntawm GitHub

Kauj Ruam 8: Cov Qauv Hluav Taws Xob:

Cov Qauv Hluav Taws Xob
Cov Qauv Hluav Taws Xob
Cov Qauv Hluav Taws Xob
Cov Qauv Hluav Taws Xob
Cov Qauv Hluav Taws Xob
Cov Qauv Hluav Taws Xob

Arduino thiab Raspberry Pi 3 tau siv los ntawm 5V qhov chaw nrog 3A tam sim no.

Cov hluav taws xob hluav taws xob pib nrog kev sib txuas ntawm DC lub tshuab hluav taws xob (txuas nrog lub tsheb kauj vab) mus rau Arduino los ntawm lub ntsuas hluav taws xob tsim los ntawm Zener diode ntawm 5.3V, lub capacitor ntawm 10μF thiab tus tiv thaiv ntawm 1kΩ - lub lim dej nkag tau txuas nrog rau cov tshuab hluav taws xob thiab cov zis tau txuas nrog A0 chaw nres nkoj thiab GND ntawm tus tswj.

Arduino txuas nrog Raspberry ntawm RX-TX kev sib txuas lus-ua los ntawm kev sib cais tiv thaiv siv 10kΩ resistors (xav tau los ntawm cov tswj 'cov chaw nres nkoj ua haujlwm ntawm cov hluav taws xob sib txawv).

Raspberry Pi's GPIOs txuas nrog rau lub luag haujlwm xa mus rau tig lub teeb. "COM" ntawm txhua qhov kev sib txuas tau sib txuas thiab txuas nrog rau theem (AC daim phiaj) thiab "N. O" (ib txwm qhib) ntawm txhua qhov txuas tau txuas nrog txhua lub teeb thiab qhov nruab nrab ntawm AC daim phiaj tau txuas nrog txhua lub teeb. Yog li, thaum GPIO lub luag haujlwm rau txhua qhov xa tawm tau qhib, kev xa rov qab tau hloov mus rau theem ntawm AC network thiab qhib lub teeb sib xws.

Kauj Ruam 9: Cov txiaj ntsig:

Image
Image

Tom qab qhov kev sib dhos zaum kawg ntawm txoj haujlwm, nws tau txheeb xyuas tias nws ua haujlwm raws li qhov xav tau - raws li qhov nrawm uas tus neeg siv pedals ntawm lub tsheb kauj vab, ntau qhov hluav taws xob tau tsim thiab ntau lub teeb pom kev.

Pom zoo: