Cov txheej txheem:

Raspberry PI & Arduino - Blynk Stepper Control: 7 Cov Kauj Ruam (nrog Duab)
Raspberry PI & Arduino - Blynk Stepper Control: 7 Cov Kauj Ruam (nrog Duab)

Video: Raspberry PI & Arduino - Blynk Stepper Control: 7 Cov Kauj Ruam (nrog Duab)

Video: Raspberry PI & Arduino - Blynk Stepper Control: 7 Cov Kauj Ruam (nrog Duab)
Video: How to get 5V from 18650 Lithium Battery Powering Arduino ESP32 ESP8266 or charge your phone 2024, Hlis ntuj nqeg
Anonim
Raspberry PI & Arduino - Blynk Stepper Tswj
Raspberry PI & Arduino - Blynk Stepper Tswj

Qhov kev qhia no yuav qhia koj yuav ua li cas thiaj tswj tau tus tsav tsheb nrog Arduino, Raspberry Pi thiab Blynk Application.

Hauv lub plhaub txiv ntseej, daim ntawv thov xa mus rau Raspberry Pi ntawm Virtual Pins, Pi tom qab ntawd xa HIGH/LOW teeb liab mus rau Arduino thiab Arduino tom qab ntawd cuam tshuam nrog stepper lub cev muaj zog.

Kuv xav tias nws yooj yim dua los siv qhov kev pom zoo vim tias tib neeg feem ntau tau siv los ua haujlwm nrog Arduino thiab tsis ntau nrog node.js ntawm Raspberry Pi.

Cheebtsam xav tau rau qhov no:

- Raspberry PI (Kuv tab tom siv Raspberry Pi 3 qauv b)

- Arduino (Kuv tab tom siv Arduino Nano)

- Servo Motor (Kuv siv 28BYJ-48 5VDC nrog nws tus tswj)

- Qee cov xov hlau jumper

- Lub zog siv hluav taws xob (5VDC 2A.)

Arduino kos duab thiab Node.js code muaj rau rub tawm. Tsuas yog saib cov ntaub ntawv.

Kauj ruam 1: Tsim App ntawm Koj Lub Xov Tooj

Tsim App ntawm Koj Lub Xov Tooj
Tsim App ntawm Koj Lub Xov Tooj
Tsim App ntawm Koj Lub Xov Tooj
Tsim App ntawm Koj Lub Xov Tooj

Rub tawm Blynk los ntawm AppStore lossis GooglePlay

Qhib App thiab tsim ib tus neeg siv lossis nkag mus nrog facebook.

- Tsim txoj haujlwm tshiab

Npe koj qhov project: MyProject

Xaiv Ntaus: Rasapberry Pi 3 B.

Hom Kev Sib Txuas: Wifi (lossis Ethernet yog tias koj tus Pi txuas rau koj lub network)

- Nyem Tsim

Txheeb koj tus email rau koj Token

(zoo li no 3aa19bb8a9e64c90af11e3f6b0595b3c)

Lub Token no tau koom nrog koj li app tam sim no. Yog tias koj ua lwm app, koj yuav tsim lwm tus cim.

Hauv App ntxiv cov cuab yeej hauv qab no (saib daim duab)

- Ntxiv 3 khawm

- Ntxiv 1 LCD

- Kho kom raug lub pob

npe thawj tus Command1, teeb tus Pin li Virtual Pin 1 thiab teeb tsa hom li SWITCH

lub npe thib ob CW, teeb tus Pin li Virtual Pin 2 thiab teeb tsa hom ua PUSH

npe tus thib peb CCW, teeb tus Pin li Virtual Pin 3 thiab teeb tsa hom ua PUSH

- Kho qhov LCD

teeb tus Pins li tus Pin 4 thiab Virtual Pin 5 thiab teeb hom rau PUSH

Kauj Ruam 2: Npaj PI Npaj

Ua ntej, koj yuav tsum teeb tsa Node.js. Before hloov kho Node.js, thov nco ntsoov tshem cov qub version:

Qhib Terminal thiab ntaus ntawv

sudo apt-tau tshem tawm ntawm nodejs

node.js -ysudo apt -get autoremove

Tsis siv neeg Node.js teeb tsa Ntxiv cov chaw cia khoom:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E tsoo -

Nruab Node.js

sudo apt-tau hloov tshiab & sudo apt-tau hloov tshiab

sudo apt-mus nruab tsim-qhov tseem ceeb nodejs -y

Thaum Node.js raug teeb tsa, Nruab Blynk

sudo npm nruab blynk -library -g

sudo npm nruab onoff -g

Kauj Ruam 3: Tsim Koj Txoj Haujlwm

Pib los ntawm kev hloov cov npe (cd hais kom ua) mus rau phau ntawv teev npe pi

Qhib Terminal thiab ntaus:

cd/tsev/pi/

Tom qab ntawd, tsim cov npe uas koj qhov haujlwm yuav nyob

mkdir MyProject Cov

Hloov cov npe rau MyProject, ntaus cov hauv qab no hauv Terminal

cd MyProject

Txheeb xyuas cov ntsiab lus ntawm phau ntawv teev npe (nws yuav tsum khoob). Tsuas yog ntaus cov hauv qab no hauv Terminal

ls ua

Tom ntej no, ntaus cov hauv qab no los tsim koj cov lus piav qhia qhov project (pob.json)

npm pib

Tsuas yog ntaus lub npe project, tus sau, version, thiab lwm yam …

Thaum qhov no ua tiav, teeb tsa lub tsev qiv ntawv Blynk, lub tsev qiv ntawv qhib thiab lub tsev qiv ntawv pw tsaug zog hauv koj li ntawv teev npe. Ntaus cov hauv qab no hauv koj lub Terminal

npm nruab blynk-library --save

npm nruab onoff --save

npm nruab system-pw tsaug zog --save

Thaum kawg, tsim koj cov ntaub ntawv.js (Qhov no yuav yog qhov twg koj cov cai yuav nyob). Ntaus cov hauv qab no hauv Terminal

nano MyProject.js

Thaum koj ua tiav cov lus txib ntawd, nano (cov ntawv sau davhlau ya nyob twg) yuav qhib.

Kauj ruam 4: MyProject.js

Hauv nano, sau kab kab hauv qab no

var Blynk = xav tau ('blynk-library');

var AUTH = '******************'; Qhov no yog koj daim duab

var blynk = tshiab Blynk. Blynk (AUTH);

var Gpio = xav tau ('onoff'). Gpio,

command1 = tshiab Gpio (18, 'tawm'), // Yuav txuas nrog Arduino D2

commandCW = tshiab Gpio (23, 'tawm'), // Yuav txuas nrog Arduino D3

commandCCW = tshiab Gpio (24, 'tawm'); // Yuav txuas nrog Arduino D4

var pw tsaug zog = xav tau ('system-sleep');

var v1 = tshiab blynk. VirtualPin (1); // qhov no yog koj li Command1 khawm hauv app

var v2 = tshiab blynk. VirtualPin (2); // qhov no yog koj li CW khawm hauv app

var v3 = tshiab blynk. VirtualPin (3); // qhov no yog koj li CCW khawm hauv app

var v4 = tshiab blynk. VirtualPin (4); // qhov no yog koj li kab LCD 1 hauv app

var v5 = tshiab blynk. VirtualPin (5); // qhov no yog koj li kab LCD 2 hauv app

v1.on ('sau', ua haujlwm (param) // Txheeb rau Command1 khawm hauv app

{

yog (param == 1) // Yog tias lub pob nyem (uas yog 1) ces ua cov hauv qab no

{

v4.write ("Ua tiav"); // Sau "Ua" ntawm thawj kab ntawm LCD

v5.write ("Hais kom ua"); // Sau "Command" ntawm kab thib ob ntawm LCD

command1.writeSync (1); // Teeb tsa GPIO18 (uas yog qhov sib txawv hais kom ua 1) rau 1 (HIGH)

tsaug zog (4000); // Tos 4 vib nas this

command1.writeSync (0); // Teeb tsa GPIO18 (uas yog qhov sib txawv hais kom ua 1) rau 0 (LOW)

v4.write ("Ua tiav"); // Sau "Ua" ntawm thawj kab ntawm LCD

v5.write (""); // Sau "" (tsis muaj dab tsi) ntawm kab thib ob ntawm LCD

v1.write (0); // Sau 0 rau koj lub Command1 khawm, uas yuav rov pib dua rau OFF txoj haujlwm

}

});

v2.on ('sau', ua haujlwm (param) // Txheeb xyuas rau CW khawm hauv app

{

yog (param == 1) // Yog tias lub pob nyem (uas yog 1) ces ua cov hauv qab no

{

commandCW.writeSync (1); // Teeb tsa GPIO23 (uas yog qhov sib txawv hais kom ua CW) rau 1 (HIGH)

}

lwm tus yog (param == 0) // Yog tias lub pob tsis nias (uas yog 0) ces ua cov hauv qab no

{

commadCW.writeSync (0); // Teeb tsa GPIO23 (uas yog qhov sib txawv hais kom ua CW) rau 0 (LOW)

}

});

v3.on ('sau', ua haujlwm (param) // Txheeb xyuas rau CCW khawm hauv app

{

yog (param == 1) // Yog tias lub pob nyem (uas yog 1) ces ua cov hauv qab no

{

commandCCW.writeSync (1); // Teeb tsa GPIO24 (uas yog qhov sib txawv hais kom ua CCW) rau 1 (HIGH)

}

lwm tus yog (param == 0) // Yog tias lub pob tsis nias (uas yog 0) ces ua cov hauv qab no

{

commandCCW.writeSync (0); // Teeb tsa GPIO24 (uas yog qhov sib txawv hais kom ua CCW) rau 1 (HIGH)

}

});

Txuag nws thiab tawm nano

- kom txuag CTRL+O

- txiav tawm CTRL+X

Koj tau ua tiav nrog Raspberry Pi.

Tam sim no sim nws kom pom tias muaj qee yam yuam kev (feem ntau yog Typo yuam kev)

Txhawm rau sim nws, tsuas yog ntaus cov hauv qab no hauv koj Terminal

ntawm MyProject.js

Koj yuav tsum tau txais cov zis uas zoo li qhov no

OnOff hom

Txuas mus rau: blynk-cloud.com 8441

Kev tso cai SSL…

Tso cai

Kauj Ruam 5: MyProject hauv Arduino

Ok tam sim no peb muaj 2/3 yam ua tiav!

Tam sim no peb tsuas yog yuav tsum sau qee cov cai rau Arduino.

- Tsim tus qauv Arduino tshiab thiab ntaus cov cai hauv qab no.

#suav nrog

#define STEPS_PER_MOTOR_REVOLUTION 32

#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64 // 2048

// Tus pin txuas yuav tsum yog tus pin 8, 9, 10, 11 txuas

// rau Tsav Tsav Tsheb In1, In2, In3, In4

// Tom qab ntawd cov pins tau nkag ntawm no hauv ntu 1-3-2-4 rau kev ua kom raug

Stepper small_stepper (STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);

int Kauj Ruam 2 Nqa;

hais kom ua 1;

int CommandCW;

int CommandCCW;

void teeb tsa ()

{

pinMode (2, INPUT);

pinMode (3, INPUT);

pinMode (4, INPUT);

// (Stepper Library teeb tsa tus pin raws li cov txiaj ntsig)

}

void lub voj ()

{

Hais kom ua 1 = digitalRead (2);

CommandCW = digitalRead (3);

CommandCCW = digitalRead (4);

yog (Command1 == 0)

{

// tsis ua dab tsi

}

lwm tus

{

Kev ua haujlwm tiav ();

}

yog (CommandCW == 1)

{

small_stepper.setSpeed (700);

small_stepper.step (-1);

ncua (1);

}

yog (CommandCCW == 1)

{

small_stepper.setSpeed (700);

small_stepper.step (1);

ncua (1);

}

}

void ExecutionFunction ()

{

Steps2Take = STEPS_PER_OUTPUT_REVOLUTION / 4; // Tig CCW 1/4 tig

small_stepper.setSpeed (700);

small_stepper.step (Steps2Take); // Koj tuaj yeem hloov Steps2Take nrog tus nqi nruab nrab ntawm 0 thiab 2048

ncua (500);

Steps2Take = - STEPS_PER_OUTPUT_REVOLUTION / 4; // Tig CW 1/4 tig

small_stepper.setSpeed (700);

small_stepper.step (Steps2Take); // Koj tuaj yeem hloov Steps2Take nrog tus nqi nruab nrab ntawm 0 thiab 2048

ncua (2000);

}

Sau thiab xa mus rau koj Arduino.

Tam sim no nco ntsoov tias koj txuas txhua yam kom raug! Saib cov kauj ruam tom ntej rau kev thaiv.

Kauj Ruam 6: Txuas kab

Thaiv
Thaiv
Thaiv
Thaiv
Thaiv
Thaiv
Thaiv
Thaiv

Txuas Arduino D3 rau RaspberryPi GPIO18 (uas yog tus pin tiag 12)

Txuas Arduino D4 rau RaspberryPi GPIO23 (uas yog tus pin tiag 16)

Txuas Arduino D4 rau RaspberryPi GPIO24 (uas yog tus pin tiag 18)

Txuas Arduino GND rau RaspberryPi GND (tus pin 6)

Txuas Arduino D8 rau Stepper Controller In1

Txuas Arduino D9 rau Stepper Controller In2

Txuas Arduino D10 rau Stepper Controller In3

Txuas Arduino D11 rau Stepper Controller In4

Txuas 5VDC rau Arduino, Raspberry Pi thiab Stepper Controller

Kauj ruam 7: Nws yog

Txheeb cov vis dis aus, thiab koj yuav tsum ua tiav!

Ua tsaug thiab txaus siab!

Pom zoo: