Node.js ကျူတိုရီရယ်

Node.js ပင်မစာမျက်နှာ Node.js နိဒါန်း Node.js ကို စတင်လိုက်ပါ။ Node.js မော်ဂျူးများ Node.js HTTP မော်ဂျူး Node.js ဖိုင်စနစ် Node.js URL မော်ဂျူး Node.js NPM Node.js ပွဲများ Node.js ဖိုင်များ အပ်လုဒ်လုပ်ခြင်း။ Node.js အီးမေးလ်

Node.js MySQL

MySQL စတင်လိုက်ပါ။ MySQL ဒေတာဘေ့စ်ဖန်တီးပါ။ MySQL ဇယားဖန်တီးပါ။ MySQL ထဲသို့ ထည့်သွင်းပါ။ MySQL မှ ရွေးချယ်ပါ။ MySQL ဘယ်မှာလဲ။ MySQL Order By MySQL ကိုဖျက်ပါ။ MySQL Drop Table MySQL အပ်ဒိတ် MySQL ကန့်သတ်ချက် MySQL Join

Node.js MongoDB

MongoDB စတင်လိုက်ပါ။ MongoDB ဒေတာဘေ့စ်ဖန်တီးပါ။ MongoDB သည် Collection ကိုဖန်တီးပါ။ MongoDB ထည့်သွင်းပါ။ MongoDB ကိုရှာပါ။ MongoDB မေးခွန်း MongoDB အမျိုးအစား MongoDB ကိုဖျက်ပါ။ MongoDB Drop Collection MongoDB အပ်ဒိတ် MongoDB ကန့်သတ်ချက် MongoDB Join

Raspberry Pi

RasPi စတင်လိုက်ပါ။ RasPi GPIO နိဒါန်း RasPi မှိတ်တုတ်မှိတ်တုတ် LED RasPi LED နှင့် ခလုတ်နှိပ်ပါ။ RasPi စီးဆင်းနေသော LED များ RasPi WebSocket RasPi RGB LED WebSocket RasPi အစိတ်အပိုင်းများ

Node.js အ ကိုး အကား

Built-in Modules များ

Node.js Raspberry Pi GPIO - LED နှင့် Pushbutton


Input နှင့် Output နှစ်မျိုးလုံးကို အသုံးပြုထားသည်။

ယခင်အခန်းတွင် LED မျက်တောင်ခတ်ရန် Raspberry Pi နှင့် ၎င်း၏ GPIO ကို အသုံးပြုနည်းကို လေ့လာခဲ့သည်။

အဲဒါအတွက် GPIO pin ကို "Output" အဖြစ် သုံးပါတယ်။

ဤအခန်းတွင် ကျွန်ုပ်တို့သည် အခြား GPIO ပင်ကို "ထည့်သွင်းခြင်း" အဖြစ် အသုံးပြုပါမည်။

5 စက္ကန့်ကြာ မှိတ်တုတ်မှိတ်တုတ်နေမည့်အစား သင် breadboard နှင့်ချိတ်ဆက်ထားသော ခလုတ်တစ်ခုကို နှိပ်လိုက်သောအခါ LED သည် မီးလင်းစေလိုပါသည်။


ငါတို့ ဘာလိုလဲ?

ဤအခန်းတွင် ကျွန်ုပ်တို့သည် LED မီးအား Push Button ဖြင့် ထိန်းချုပ်သည့် ရိုးရှင်းသော ဥပမာတစ်ခုကို ဖန်တီးပါမည်။

ဤအရာအတွက် သင်လိုအပ်သည်-

မတူညီသောအစိတ်အပိုင်းများ၏ဖော်ပြချက်များအတွက် အထက်ဖော်ပြပါစာရင်းရှိလင့်ခ်များကို နှိပ်ပါ။

မှတ်ချက်- သင်အသုံးပြုသည့် LED အမျိုးအစားပေါ်မူတည်၍ သင်လိုအပ်သော ခုခံအားသည် ကျွန်ုပ်တို့အသုံးပြုသည့်အရာနှင့် ကွဲပြားနိုင်ပါသည်။ သေးငယ်သော LED အများစုသည် 200-500 ohms ဝန်းကျင်ရှိသော သေးငယ်သော resistor တစ်ခုသာ လိုအပ်သည်။ သင်အသုံးပြုသည့်တန်ဖိုးအတိအကျကို ယေဘူယျအားဖြင့် အရေးမယူသော်လည်း resistor ၏တန်ဖိုးသေးငယ်လေ၊ LED သည် ပိုမိုတောက်ပလာမည်ဖြစ်သည်။

ဤအခန်းတွင်ကျွန်ုပ်တို့သည်နောက်ဆုံးအခန်းတွင်ကျွန်ုပ်တို့တည်ဆောက်ထားသော circuit ကိုတည်ဆောက်မည်ဖြစ်သောကြောင့်အထက်စာရင်းပါအစိတ်အပိုင်းအချို့ကိုသင်မှတ်မိလိမ့်မည်။


ပတ်လမ်းတည်ဆောက်ခြင်း။

ယခု ကျွန်ုပ်တို့၏ Breadboard တွင် ဆားကစ်ကို တည်ဆောက်ရန် အချိန်ကျရောက်ပြီဖြစ်သည်။ ကျွန်ုပ်တို့သည် နောက်ဆုံးအခန်းတွင် ကျွန်ုပ်တို့ဖန်တီးထားသော ပတ်လမ်းကို အစမှတ်အဖြစ် အသုံးပြုပါမည်

အကယ်၍ သင်သည် အီလက်ထရွန်နစ်ပစ္စည်းကို တတ်ကျွမ်းသူဖြစ်ပါက Raspberry Pi အတွက် ပါဝါပိတ်ရန် အကြံပြုအပ်ပါသည်။ ပြီးလျှင် မပျက်စီးစေရန် ဆန့်ကျင်ဘက် ဖျာ သို့မဟုတ် မြေစိုက်သိုင်းကြိုးကို အသုံးပြုပါ။

အမိန့်ဖြင့် Raspberry Pi ကို ကောင်းစွာပိတ်ပါ။

pi@w3demopi:~ $ sudo shutdown -h now

Raspberry Pi တွင် LED မီးများ မှိတ်တုတ်မှိတ်တုတ် ရပ်တန့်ပြီးနောက် Raspberry Pi မှ ပါဝါပလပ်ကို ဆွဲထုတ်ပါ (သို့မဟုတ် ၎င်းနှင့် ချိတ်ဆက်ထားသည့် ပါဝါကြိုးကို လှည့်ပါ)။

ကောင်းစွာမပိတ်ဘဲ ပလပ်ကိုဆွဲလိုက်ရုံဖြင့် မန်မိုရီကတ်ကို ပျက်စီးစေနိုင်သည်။

Breadboard နှင့်အတူ Raspberry Pi 3  LED နှင့် ခလုတ်ပတ်လမ်း

ပတ်လမ်း၏အထက်ပုံဥပမာကိုကြည့်ပါ။

  1. Starting with the circuit we created in the last chapter:
    On the Raspberry Pi, connect the female leg of a jumper wire to a 5V power pin. In our example we used Physical Pin 2 (5V, row 1, right column)
  2. On the Breadboard, connect the male leg of the jumper wire connected to the 5V power, to the Power Bus on the right side. That entire column of your breadboard is connected, so it doesn't matter which row. In our example we attached it to row 1
  3. On the Breadboard, connect the push button so that it fits across the Trench. In our example it connects to rows 13 and 15, columns E and F
  4. On the Breadboard, connect one leg of the 1k ohm resistor to the Ground Bus column on the right side, and the other leg to the right side Tie-Point row where it connects to one of the right side legs of the push button. In our example we attached one side to Tie-Point row 13, column J, and the other side to the closest Ground Bus hole
  5. On the Breadboard, connect a male-to-male jumper wire from the right Power Bus, to the right Tie-Point row that connects to the other leg of the push button. In our example we attached one side to Tie-Point row 15, column J, and the other side to the closest Power Bus hole
  6. On the Raspberry Pi, connect the female leg of a jumper wire to a GPIO pin. In our example we used Physical Pin 11 (GPIO 17, row 6, left column)
  7. On the Breadboard, connect the male leg of the jumper wire to left Tie-Point row the Push Button leg that is directly across the Ground connection leg.  In our example we attached it to row 13, column A

Your circuit should now be complete, and your connections should look pretty similar to the illustration above.

Now it is time to boot up the Raspberry Pi, and write the Node.js script to interact with it.



Raspberry Pi and Node.js LED and Button Script

Go to the "nodetest" directory, and create a new file called "buttonled.js":

pi@w3demopi:~ $ nano buttonled.js

The file is now open and can be edited with the built in Nano Editor.

Write, or paste the following:

buttonled.js

var Gpio = require('onoff').Gpio; //include onoff to interact with the GPIO
var LED = new Gpio(4, 'out'); //use GPIO pin 4 as output
var pushButton = new Gpio(17, 'in', 'both'); //use GPIO pin 17 as input, and 'both' button presses, and releases should be handled

pushButton.watch(function (err, value) { //Watch for hardware interrupts on pushButton GPIO, specify callback function
  if (err) { //if an error
    console.error('There was an error', err); //output error message to console
  return;
  }
  LED.writeSync(value); //turn LED on or off depending on the button state (0 or 1)
});

function unexportOnClose() { //function to run when exiting program
  LED.writeSync(0); // Turn LED off
  LED.unexport(); // Unexport LED GPIO to free resources
  pushButton.unexport(); // Unexport Button GPIO to free resources
};

process.on('SIGINT', unexportOnClose); //function to run when user closes using ctrl+c

Press "Ctrl+x" to save the code. Confirm with "y", and confirm the name with "Enter".

Run the code:

pi@w3demopi:~ $ node buttonled.js

Now the LED should turn on when you press the button, and turn off when you release it.

End the program with Ctrl+c.