Cov txheej txheem:
- Kauj Ruam 1: Cov Ntaub Ntawv thiab Cov Cuab Yeej
- Kauj Ruam 2: Txuas Cov Softpots rau ESP32
- Kauj Ruam 3: Txuas ESP32 thiab RPI Wirelessly
- Kauj Ruam 4: Txuas Koj Lub Vev Xaib thiab Database
- Kauj Ruam 5: Txuas Txhua Yam Ua Ke
- Kauj Ruam 6: Ntxiv: Txuas LCD Screen
Video: Ntsuas Txoj Haujlwm Ntiv Tes ntawm Tus Violin Nrog ESP32: 6 Cov Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:29
Raws li tus ntaus nkauj ntaus nkauj Kuv ib txwm xav tau lub app lossis cov cuab yeej uas tuaj yeem qhia kuv txoj haujlwm ntawm kuv tus ntiv tes ntawm tus nkauj laus ncas kom raug. Nrog txoj haujlwm no kuv tau sim tsim qhov no. Txawm hais tias qhov no yog tus qauv thiab koj tseem tuaj yeem ntxiv ntau yam ntxiv.
Kuv kuj tau sim cais ESP32 thiab rPI thiab yog li kuv ua ESP32 xa cov ntaub ntawv wireless mus rau rPi. Uas yog tej zaum qhov nyuaj tshaj plaws ntawm txoj haujlwm no.
Nws kuj tseem ceeb heev uas thaum kawg ntawm txoj haujlwm no tsis muaj dab tsi khaws cia hauv koj lub computer tab sis nws yog nyob ntawm rPI lossis ESP32.
Kauj Ruam 1: Cov Ntaub Ntawv thiab Cov Cuab Yeej
Ua ntej nkag mus rau qhov tshwj xeeb ntawm kev tsim txoj haujlwm no peb xav tau ob peb yam.
- 4 x Tawm Softpot: Kab Tawm Potentiometers los ntsuas txoj haujlwm ntawm tus ntiv tes (tus nkauj laus ncas muaj 4 txoj hlua)
- ESP32: ESP32 tus qauv los nyeem cov ntaub ntawv los ntawm cov kab muag muag muag.
- a 4/4 nkauj laus ncas: nkauj laus laus tso qhov muag muag muag muag rau saum.
- Raspberry Pi nrog daim npav SD: raspberry pi uas yuav khaws peb cov ntaub ntawv thiab lub vev xaib.
- 10k potentiometer: potentiometer rau qhov ci ntawm LCD
- LCD-screen: lub vijtsam LCD los qhia rau tus ip ntxiv ntawm rPi
- Cov Khoom Siv Hluav Taws Xob: Rau qhov muag tag nrho cov khoom togheter
- Txiv neej-rau-txiv neej xaim thiab txiv neej-rau-poj niam xaim: Cables rau txuas txhua yam
- Micro USB cable: Rau lub zog ESP32
Kauj Ruam 2: Txuas Cov Softpots rau ESP32
Ua ntej tshaj plaws peb yuav tsum txuas peb lub softpots rau esp32. Peb txuas cov laug thiab sab xis rau 5V thiab GND feem. Peb txuas tus pin nruab nrab mus rau tus pin analog ntawm ESP32. Peb kuj yuav tsum txuas tus pin nruab nrab nrog qhov ua haujlwm ntawm 10k ohm thiab txuas qhov no rau GND. Qhov no yog li ntawd peb cov txiaj ntsig ntawm softpots tsis rov qab tus nqi random.
Tom qab ntawd peb txuas ESP32 nrog lub micro usb cable rau peb lub pc kom peb tuaj yeem xa cov cai rau nws. Peb yuav siv Arduino IDE rau kev ua haujlwm ESP32. Tab sis ua ntej peb yuav tsum tau teeb tsa Arduino core rau ESP32 kom peb tuaj yeem tso rau nws. Qhov no tuaj yeem ua tiav ntawm no.
Tom qab ntawd peb tuaj yeem pib sau cov cai.
Ua ntej peb yuav tsum tau muab peb tus pin uas peb txuas nrog peb tus pin nruab nrab ntawm cov softpots.
const int SOFT_POT_PIN1 = 34;
const int SOFT_POT_PIN2 = 35;
const SOFT_POT_PIN3 = 32;
const int SOFT_POT_PIN4 = 33;
tsis tau kos npe rau sijhawm ntev;
unsigned ntev softPotTime;
Tom qab ntawd peb tuaj yeem teeb tsa peb tus pin. Thiab peb yuav tsum tau pib peb cov saib xyuas thiab peb lub sijhawm.
void teeb tsa () {
onTime = millis ();
Serial.begin (115200);
Serial.println ("Pib qhov program");
pinMode (SOFT_POT_PIN1, INPUT);
pinMode (SOFT_POT_PIN2, INPUT);
pinMode (SOFT_POT_PIN3, INPUT);
pinMode (SOFT_POT_PIN4, INPUT); }
tsis muaj dab tsi getdata (byte pdata ) {
// Nyeem hauv lub lauj kaub mos tus nqi ADC
Tom qab ntawd peb yuav tsum nyeem peb tus pin kom peb tuaj yeem tau txais peb cov ntaub ntawv.
int softPotADC1 = analogRead (SOFT_POT_PIN1);
nt softPotADC2 = analogRead (SOFT_POT_PIN2);
int softPotADC3 = analogRead (SOFT_POT_PIN3);
int softPotADC4 = analogRead (SOFT_POT_PIN4);
Tom qab ntawd peb muab cov txiaj ntsig tso rau hauv ib daim ntawv kom peb tuaj yeem tso tawm nws tom qab.
rau (int i = 0; i <4; i ++) {
int Cov npe = {softPotADC1, softPotADC2, softPotADC3, softPotADC4};
int softpot = Npe [kuv];
yog (softpot> 10) {
pdata [0] = kuv;
pdata [1] = softpot;
pdata [2] = millis ();
} } }
}
Kauj Ruam 3: Txuas ESP32 thiab RPI Wirelessly
Txog kev txuas ESP32 thiab RPI wirelessly, peb yuav siv lub tsev qiv ntawv hu ua websocket. Txhawm rau teeb tsa lub tsev qiv ntawv no, peb tuaj yeem tau txais cov ntaub ntawv ntawm no. Peb yuav xav hloov qee cov cai hauv cov ntaub ntawv nws tus kheej txhawm rau siv lub tsev qiv ntawv no rau ESP32.
Peb yuav tau hloov MD5.c thiab MD5.h.
- MD5Init rau MD5InitXXX
- MD5Update rau MD5UpdateXXX
- MD5Final to MD5FinalXXX
Peb tseem yuav xav rho tawm cov kab avr/io.h hauv cov ntaub ntawv sha1.
Tom qab ntawd peb tuaj yeem ntxiv lub tsev qiv ntawv rau peb Arduino IDE los ntawm kos duab> suav nrog tsev qiv ntawv> ntxiv. ZIP lub tsev qiv ntawv thiab tom qab ntawd peb tuaj yeem xaiv koj lub tsev qiv ntawv hauv zip file.
Tom qab ntawd peb tuaj yeem pib sau peb cov cai.
Ua ntej rau ESP32:
Nrog rau peb lub tsev qiv ntawv
#ncig #ncig
Muab peb tus pin dua.
const int SOFT_POT_PIN1 = 34;
const int SOFT_POT_PIN2 = 35;
const int SOFT_POT_PIN3 = 32;
const int SOFT_POT_PIN4 = 33;
Muab peb cov neeg rau zaub mov wifi
WiFiServer server (80);
Pib peb lub websocket server
WebSocketServer webSocketServer;
Muab peb SSID thiab tus password rau koj lub wifi
const char* ssid = "koj li wifi SSID";
const char* password = "koj tus password wifi";
void teeb tsa () {
Teeb tsa koj lub xov tooj saib
Serial.begin (115200);
Teeb koj lub softpots
pinMode (SOFT_POT_PIN1, INPUT);
pinMode (SOFT_POT_PIN2, INPUT);
pinMode (SOFT_POT_PIN3, INPUT);
pinMode (SOFT_POT_PIN4, INPUT);
Pib peb wifi thiab txuas rau nws
WiFi.begin (ssid, password);
thaum (WiFi.status ()! = WL_CONNECTED) {
ncua (1000);
Serial.println ("Txuas rau WiFi.."); }
Serial.println ("Txuas nrog WiFi network");
Serial.println (WiFi.localIP ());
server.begin (); ncua (100); }
tsis muaj dab tsi getdata (char *pdata) {
Nyeem koj cov ntaub ntawv
// Nyeem hauv lub lauj kaub mos tus nqi ADC
int softPotADC1 = analogRead (SOFT_POT_PIN1);
int softPotADC2 = analogRead (SOFT_POT_PIN2);
int softPotADC3 = analogRead (SOFT_POT_PIN3);
int softPotADC4 = analogRead (SOFT_POT_PIN4);
Muab cov ntaub ntawv tso rau hauv ib daim ntawv thiab hloov mus rau hexadecimal.
sprintf (pdata, " %x, %x, %x, %x, %x", softPotADC1, softPotADC2, softPotADC3, softPotADC4, millis ());
}
void voj () {
Txuas koj cov neeg siv khoom (rPI)
WiFiClient tus thov = server.available ();
yog (client.connected ()) {
ncua (10);
yog (webSocketServer.handshake (tus thov)) {
Serial.println ("Client txuas nrog");
Xa thiab txais cov ntaub ntawv.
thaum (client.connected ()) {
cov ntaub ntawv [30];
getdata (cov ntaub ntawv);
Serial.println (cov ntaub ntawv);
webSocketServer.sendData (cov ntaub ntawv);
ncua (10); // Ncua sij hawm xav tau kom tau txais cov ntaub ntawv raug}
Serial.println ("Cov neeg siv txuas nrog");
ncua (100); }
lwm tus {
Serial.println ("shitsfuckedyo");
} } }
Tom qab ntawd rau rPI hauv sej:
Ntshuam peb cov tsev qiv ntawv
ntshuam websocketimport lub sijhawm
Assasigning lub ntiaj teb hloov pauv i
kuv = 0
Teeb qhov siab kawg ntawm 200 cov lus uas peb tuaj yeem tau txais
nrOfMessages = 200
chav Websocket ():
def _init _ (tus kheej):
Pib peb lub websocket thiab txuas nws rau peb ESP32
self.ws = websocket. WebSocket ()
self.ws.connect ("ws: //172.30.248.48/")
Tau txais peb cov ntaub ntawv
def ua haujlwm (tus kheej):
self.ws.send ("message nr: 0")
result = self.ws.recv () time.sleep (0.5) xa rov qab
Kaw qhov websocket tom qab tau txais txhua yam
def kaw (tus kheej):
nws.ws.close ()
Kauj Ruam 4: Txuas Koj Lub Vev Xaib thiab Database
Raws li txuas rau peb Cov Ntaub Ntawv thiab lub vev xaib, koj yuav tsum xub tsim koj cov ntaub ntawv ntawm tus pi los ntawm kev txhim kho mariadb: sudo apt install mariadb.
Tom qab ntawd koj tuaj yeem nkag nws los ntawm kev ua: sudo mariadb.
Tom qab ntawd koj tseem yuav xav tsim koj lub vev xaib. Koj tuaj yeem ua qhov no txawm li cas los xij koj nyiam, tab sis koj yuav tsum siv Flask thiab koj yuav tsum muaj daim ntawv hauv koj li HTML txhawm rau siv thiab pib koj cov ntaub ntawv.
Tom qab ntawd koj tuaj yeem ntxig cov cai no txhawm rau txuas koj cov ntaub ntawv thiab koj lub vev xaib (ob qho tib si koj lub vev xaib thiab chaw khaws ntaub ntawv yuav tsum ob leeg nyob ntawm koj tus pi, qhov no tuaj yeem ua tiav los ntawm kev siv lub tab xa khoom hauv chaw ntawm pycharm)
los ntawm flaskext.mysql ntshuam MySQL
app.config ["MYSQL_DATABASE_HOST"] = "localhost"
app.config ["MYSQL_DATABASE_DB"] = "koj lub npe database"
app.config ["MYSQL_DATABASE_USER"] = "koj tus neeg siv database"
app.config ["MYSQL_DATABASE_PASSWORD"] = "koj lo lus zais database"
Muaj nuj nqi kom tau txais cov ntaub ntawv tawm ntawm peb cov database.
def get_data (sql, params = Tsis muaj):
conn = mysql.connect ()
tus cursor = conn.cursor ()
print ("tau txais cov ntaub ntawv")
sim:
luam tawm (sql)
cursor.execute (sql, params)
tsuas yog Kev zam raws li e:
luam tawm (e)
rov dag
tshwm sim = cursor.fetchall ()
cov ntaub ntawv =
rau kab hauv qhov tshwm sim:
data.append (daim ntawv (kab)))
cursor.close ()
conn.close ()
xa cov ntaub ntawv
Muaj nuj nqi rau ntxig cov ntaub ntawv rau hauv peb lub database
def set_data (sql, params = Tsis muaj):
conn = mysql.connect ()
tus cursor = conn.cursor ()
sim:
log.debug (sql)
cursor.execute (sql, params) conn.commit ()
log.debug ("SQL uitgevoerd")
tsuas yog Kev zam raws li e:
log.exception ("Fout bij uitvoeren van sql: {0})". format (e))
rov dag
cursor.close ()
conn.close ()
rov Tseeb
Peb tseem yuav xav tau xov peb daim ntawv thov kom koj tuaj yeem ua lwm yam thaum koj kaw.
chav kawm ThreadedTask (threading. Thread):
def _init _ (tus kheej,):
Teeb tsa xov
threading. Thread._ init _ (tus kheej)
Tsim cov npe rau tuav tag nrho koj cov ntaub ntawv tau txais
self.data_all =
def khiav (tus kheej):
sijhawm.sleep (5)
Ntshuam koj tus kheej sej chaws qhov twg koj tau txais cov ntaub ntawv
ntshuam txais_websocket
Tau txais koj cov ntaub ntawv
w = tau txais_websocket. Websocket ()
Ntxiv koj cov ntaub ntawv hauv koj daim ntawv thiab luam tawm.
rau kuv hauv ntau (0, 200):
self.data_all.append (w.work (). phua (","))
print (tus kheej.data_all)
haujlwm = ThreadedTask ()
Tom qab ntawd koj tuaj yeem ua haujlwm.run () pib koj Xov thiab pib txais cov ntaub ntawv.
Kauj Ruam 5: Txuas Txhua Yam Ua Ke
Txhawm rau khiav koj lub vev xaib los ntawm koj Pi koj yuav tsum siv kev pabcuam:
[Chav] Nqe lus piav qhia = piv txwv uWSGI los ua haujlwm qhov project1 web interface
Tom qab = network.target
BindsTo = mysqld.service
Tom qab = mysqld.service
[Kev pabcuam]
Hloov mus rau koj tus neeg siv
User = pib
Pawg = www-data
Ntawm no koj yuav tsum nkag mus rau koj phau ntawv teev npe ntawm koj cov ntaub ntawv Flask
WorkingDirectory =/tsev/pi/project1/web
Cov npe ntawm koj cov ntaub ntawv ini uas tuaj yeem pom tom qab.
ExecStart =/usr/bin/uwsgi --ini /home/pi/project1/conf/uwsgi-flask.ini
[Nruab]
WantedBy = ntau-user.target
uwsgi-flask.ini uas koj yuav tsum tau muab tso rau hauv cov npe uas koj tau teev tseg hauv ExecStart saum toj no
[uwsgi] module = web: app virtualenv =/tsev/pi/project1/env
tswv = txheej txheem tseeb = 5
plugins = python3
socket = project1.sock chmod-socket = 660 nqus = muaj tseeb
tuag-rau-lub sij hawm = muaj tseeb
Tam sim no koj tuaj yeem nyeem koj cov ntaub ntawv thiab tso tawm ntawm koj lub vev xaib.
Kauj Ruam 6: Ntxiv: Txuas LCD Screen
Peb tuaj yeem txuas lub vijtsam LCD kom peb tuaj yeem qhia tus ip-adress ntawm peb Pi rau peb lub vev xaib.
ntshuam RPi. GPIO ua GPIOimport lub sijhawm
ntshuam lus txib
GPIO.cleanup ()
Txd0 = 22
D1 = 5
D2 = 6
Txd3 = 13
D4 = 19
Txd5 = 26
Txd6 = 20
Txd7 = 21
npe = [22, 5, 6, 13, 19, 26, 20, 21]
E = 24 hli
RS = 23 hli
Chav Kawm Screen:
def _init _ (tus kheej):
GPIO.setmode (GPIO. BCM)
self.setup ()
#Function set self.stuur_instructie (0x3f) #Display self.stuur_instructie (0x0c) #On + cursor self.stuur_instructie (0x01) @staticmethod def setup (): GPIO.setup (daim ntawv, GPIO. OUT) GPIO.setup ([E, RS], GPIO. OUT)
def stuur_instructie (tus kheej, byte):
GPIO.output (E, GPIO. HIGH)
GPIO.output (RS, GPIO. LOW)
self.set_GPIO_bits (byte)
sijhawm.s pw (0.005)
GPIO.output (E, GPIO. LOW)
def stuur_teken (tus kheej, char):
temp = ord (char)
GPIO.output (E, GPIO. HIGH)
GPIO.output (RS, GPIO. HIGH)
self.set_GPIO_bits (qhov kub)
sijhawm.s pw (0.005)
GPIO.output (E, GPIO. LOW)
def set_GPIO_bits (tus kheej, byte):
rau kuv hauv ntau (0, 8):
yog (byte & (2 ** i)) == 0:
GPIO.output (npe , GPIO. LOW)
lwm tus:
GPIO.output (npe , GPIO. HIGH)
def lub ntsiab ():
s = Screen ()
teken = "IP chaw nyob:"
rau tsab ntawv hauv teken:
s.stuur_teken (tsab ntawv)
teken2 = commands.getoutput ("ip addr qhia wlan0 | grep -Po 'inet / K [d.]+'")
luam tawm (teken2)
s.stuur_instructie (0xc0)
rau tsab ntawv 2 hauv teken2:
s.stuur_teken (tsab ntawv 2)
yog _name_ == '_main_': #Program pib ntawm no
sim:
lub ntsiab ()
tshwj tsis yog KeyboardInterrupt:
dhau
Tom qab ntawd peb tuaj yeem tsim kev pabcuam los pib lub LCD ntawm kev pib ua haujlwm.
Pom zoo:
ARUPI - Tus Nqi Tus Nqi Tus Nqi Uas Tau Txais Tus Nqi Uas Tau Txais Tus Nqi/Tus Kheej Tus Kheej (ARU) rau Soundscape Ecologists: 8 Kauj Ruam (nrog Duab)
ARUPI - Tus Nqi Tus Nqi Uas Tau Txais Tus Nqi Tus Nqi Uas Tau Txais Tus Nqi/Tus Kheej Tus Kheej (ARU) rau Soundscape Ecologists: Cov lus qhia no tau sau los ntawm Anthony Turner. Txoj haujlwm tau tsim los nrog ntau qhov kev pab los ntawm Shed hauv Tsev Kawm Ntawv ntawm Kev Suav, University of Kent (Mr Daniel Knox tau pab zoo!)
Casting Yam Kom Paub Ntxiv: Cov Ntiv Tes Ntiv Tes (Uas Glow, Hloov Xim Nrog Tshav Kub, thiab Ntau Ntxiv ): 10 Cov Kauj Ruam (nrog Duab)
Casting Cov Lus Qhia Kom Paub: Cov Ntiv Tes Ntiv Tes (Uas Glow, Hloov Xim Nrog Tshav Kub, thiab Ntau Ntxiv …): Nov yog cov lus qhia hais txog kev nrum cov khoom me me, qhov nyuaj - pheej yig. Nws yuav tsum tau hais tias kuv tsis yog tus kws tshaj lij, tab sis raws li qhov xav tau feem ntau yog leej niam ntawm kev tsim khoom - qee cov txheej txheem ntawm no tau ua haujlwm zoo. Kuv tau ntsib Nigel Ackland ntawm Fest Yav Tom Ntej hauv London, thiab
Ntse Tsheb Ua Haujlwm los ntawm Kev Siv Lub Ntiv Tes: 7 Kauj Ruam (nrog Duab)
Lub Tsheb Ntse Ua Haujlwm los ntawm Kev Siv Cov Ntiv Tes: Qhov ntawd yog kuv txoj haujlwm ntse tsheb nws tsis ua haujlwm los ntawm lub xov tooj ntawm tes lossis ib txwm tswj hwm Nws ua haujlwm los ntawm hnab looj tes yog li cov chaw taws teeb tswj yog txav ntawm kuv tus ntiv tes
Ntiv ntiv tes: 4 Kauj Ruam (nrog Duab)
Ntiv ntiv tes: Oliwier yog tus tub zoo siab, muaj zog thiab xav paub ntxiv. Hmoov tsis zoo, nws kuj tseem mob hnyav - nws yug los tsis muaj ob txhais ceg thiab tsuas yog siv tes thiab ntiv tes me ntsis. Tsis ntev los no peb tau muaj sijhawm los muab nws me ntsis ntawm kev xyiv fab los ntawm kev ua kev cai d
Ntiaj Teb Txoj Kev Tawv Tawv Tawv Tes Tawv Tes Tawv Tes Tawv Tes!: 6 Cov Kauj Ruam (nrog Duab)
Ntiaj Teb Txoj Kev Tawv Tawv Tawv Tes Tawv Tes Tawv Tes Tawv!: Khawm-tus kws tsim, los ntawm Aniomagic, yog qhov zoo kawg nkaus me me. Nws yog tus nyeem ntawv ib puag ncig qhov loj me ntawm npib tsib xee uas tuaj yeem ua haujlwm tau nrog tshwj xeeb lub sijhawm ua haujlwm ntawm lub teeb. Nrog nws, peb yuav ua rau lub ntiaj teb nyias nyias, tuaj yeem tsim cov hlua tes. Kuv tau