Modul dua relay

Sebelumnya saya sudah membuat catatan tentang Arduino shield yang berisi empat relay. Di pasaran lokal, pembeli perlu cermat karena rating relay bisa jadi tidak sesuai dengan aplikasi yang direncanakan.

Gambar 1.

Kali ini adalah catatan tentang papan relay (relai) seperti pada Gambar 1. Rating relai dapat dibaca di bagian atas masing-masing relai, untuk kemudian bisa dibandingkan dengan datasheet yang sesuai. Yang sangat penting diperhatikan adalah mengenai single-line header yang tampak sebagai selection jumper pada bagian kiri dari Gambar 1. Di sana tertulis JD-VCC, VCC dan GND. Lebih detail bisa dilihat pada Gambar 2.

Gambar 2. [sumber]

Posisi jumper secara default dari awal adalah terhubung antara JD-VCC dengan VCC. Konfigurasi ini berarti catu daya untuk optocoupler, transistor BJT dan relai berasal dari catu daya VCC yang sama untuk pemberian sinyal ke optocouler. Perlu berhati-hati VCC pada header ini secara elektris terhubung dengan header VCC untuk masukkan, bisa dilihat langsung pada bagian bawah PCB. Begitu pula GND pada header yang sama.

Gambar 3. [sumber]

Gambar 3 menyampaikan informasi yang sama dengan cara yang berbeda. Di sini bagian GND pada header dihilangkan sehingga jelas bahwa jumper itu bukanlah selector-jumper. Jangan menghubungkan antara VCC dengan GND! Fungsi pin GND pada header itu adalah untuk penyambungan ke sumber catu daya lain. Dua kabel yang perlu disambungkan adalah JD-VCC dan GND, sehingga GND dari catu daya ini akan terhubung dengan GND pada papan pengendali (mikrokontroler seperti ATmega328P atau sistem Arduino).

 

Dari situs http://howtomechatronics.com, bisa juga dilihat gambar yang memberi keterangan tentang sambungan daya.

Gambar 4. Menggunakan catu daya Arduino [sumber]

Gambar 5. Menggunakan catu daya terpisah (sambungkan juga GND) [sumber]

Gambar 6. Papan sistem menggunakan active-low [sumber]

Keterangan yang lebih baik bisa diperoleh langsung dari situs aslinya di link ini: howtomechatronics.com .

Berdasar pengetahuan yang diperoleh dari Gambar 6, kita bisa melakukan pengaturan pada kode progam sehingga penggunaan relai tidak terganggu dengan kode program yang janggal atau tidak natural.

const uint8_t IND_LED_PIN = 1;
#define BLINK_DELAY 500
#define RELAY_ON LOW
#define RELAY_OFF HIGH
#define IN1 3
#define IN2 4


void safeRelayInit(void)
{
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, HIGH);
  delay(100);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
}


void relayTest001(void)
{
  digitalWrite(IN1, LOW);
  delay(2000);
  digitalWrite(IN1, HIGH);
  delay(2000);

  digitalWrite(IN2, LOW);
  delay(2000);
  digitalWrite(IN2, HIGH);
  delay(2000);  
}

void relayTest002(void)
{
  digitalWrite(IN1, RELAY_ON);
  delay(1000);
  digitalWrite(IN1, RELAY_OFF);
  delay(1000);

  digitalWrite(IN2, RELAY_ON);
  delay(1000);
  digitalWrite(IN2, RELAY_OFF);
  delay(1000);  
}

void setup(void)
{
  safeRelayInit();
  delay(10);


  pinMode(IND_LED_PIN, OUTPUT);
  digitalWrite(IND_LED_PIN, LOW);

  

  delay(1000);
  digitalWrite(IND_LED_PIN, HIGH);
  delay(1000);
  
  // relayTest001();

  for (int i = 0; i < 2; ++i)
  {
    /* code */
    relayTest002();
  } 


  digitalWrite(IND_LED_PIN, LOW);

}


void loop(void)
{

}

Gambar 7. Papan SRD-05VDC-SL-C

Gambar 8.

Key button & LED

Untuk belajar maupun untuk pengujian program, secara berurutan yang sering secara sederhana diperlukan adalah LED, push-button/key, dan potensiometer. Selain perangkat lunak simulator dan komunikasi serial (via USB), indikator hardware sering mempermudah proses pembuatan program. Itulah gunanya LED. Berikutnya adalah push button/keys, yang berguna sebagai masukan (input) digital. Tombol-tombol/anak kunci itu sebenarnya bisa diganti dengan kabel, tetapi cara itu bisa jadi tidak praktis dan tidak rapi. Sedangkan yang terakhir, potensiometer, adalah pengganti yang cukup baik untuk banyak sensor dengan output berupa tegangan analog.

Sekarang, modul/papan LED dan push-button sudah banyak dijual dalam bentuk yang lebih praktis untuk dipergunakan. Salah satunya ditampilkan di halaman ini, lihat Gambar 1.

aeProduct.getSubject()Gambar 1. [sumber]

Modul seperti Gambar 1 sudah dijual di toko online lokal, jadi yang berminat tidak harus membelinya langsung Aliexpress.

aeProduct.getSubject()Gambar 2. [sumber]

Penggunaan modul LED tidak berisiko mendatangkan masalah yang fatal. Papan LED sudah dilengkapi dengan resistor pembatas arus sebesar 1 KOhm, seperti yang bisa dilihat pada Gambar 2.

Hal yang berbeda dengan push button/key. Bisa diperhatikan pada Gambar 3 dan [ps2id url=’#gambar4′ offset=’300′]Gambar 4[/ps2id], papan ini tidak memiliki bantuan perlindungan apapun, hanya berisi sakelar saja.

aeProduct.getSubject()Gambar 3. [sumber]

aeProduct.getSubject()Gambar 4. [sumber]

Untuk menjaga keselamatan alat (papan sistem Arduino), ada baiknya sebelum menggunakan papan sakelar, pengguna terlebih dahulu mempelajari hal-hal yang berisiko dapat merusak sistem papan Arduino. Beberapa tulisan yang berisi hal-hal yang harus dihindari saya kumpulkan sebagai berikut:

Dari membaca halaman-halaman pada tautan di atas ada beberapa pembahasan mengenai hal yang sama. Justru di situlah salah satu letak keutamaan belajar, melihat berbagai sudut pandang dan pengalaman orang lain mengenai suatu hal/permasalahan. Salah satu yang penting untuk diketahui adalah menghindari arus lebih pada pin, port dan sistem papan Arduino.

Penting untuk mengetahui bagaimana menjadikan suatu pin di papan Arduino sebagai INPUT (bukan OUTPUT) dan bagaimana menggunakan pull-up untuk pin itu.

Dari dua bagian kumpulan tautan di atas, kita bisa belajar tentang bahaya kesalahan penggunaan tombol/sakelar/push button/key pada sistem Arduino. Selanjutnya bagaimana memanfaatkan pin pada papan Arduino sebagai masukan dan bagaimana melakukan konfigurasi yang sesuai dengan pull-up. Juga disinggung bagaimana konsep internel pull-up di sistem mikrokontroler yang lain, sekadar sebagai pembanding.

Berikut, di bawah ini adalah kode dari halaman Aliexpress mengenai penggunaan papan LED dan keys. Dengan pemahaman sebelumnya tentang keamanan dan internel pull-up, kode ini menjadi lebih mudah dipahami.

	
/*
	Format ulang dari kode pada:
	Aliexpress https://goo.gl/wYK6mi

	Ardiuno_4key_6led
	 
	This example code is in the public domain.
*/
 
// Define key pin
int K1 = 13;
int K2 = 12;
int K3 = 11;
int K4 = 10;
// Define led pin
int GND = 6;
int D1 = 5;
int D2 = 4;
int D3 = 3;
int D4 = 2;
int D5 = 1;
int D6 = 0;
 
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
uint8_t btn1, btn2, btn3, btn4; 
 
// the setup routine runs once when you press reset:
void setup() 
{
	// initialize the keys pin as an input.	 
	// pinMode(K1, INPUT);
	// pinMode(K2, INPUT);
	// pinMode(K3, INPUT);
	// pinMode(K4, INPUT);

	for (int i = K1; i >= K4; i--)
	{
		pinMode(i, INPUT);
	}
	 
	// initialize the leds pin as an output.
	// pinMode(GND, OUTPUT);
	// pinMode(D1, OUTPUT);
	// pinMode(D2, OUTPUT);
	// pinMode(D3, OUTPUT);
	// pinMode(D4, OUTPUT);
	// pinMode(D5, OUTPUT);
	// pinMode(D6, OUTPUT);

	pinMode(GND, OUTPUT);
	for (int i = D1; i >= D6; i--)
	{
		pinMode(i, OUTPUT);
	}
	 
	/*
		PERHATIKAN BAGIAN KODE INI
	*/
	//Activate key pin internal pull-up resistors
	digitalWrite(K1, HIGH);
	digitalWrite(K2, HIGH);
	digitalWrite(K3, HIGH);
	digitalWrite(K4, HIGH);

	// for (int i = K1; i >= K4; i--)
	// {
	// 	pinMode(i, HIGH);
	// }	 
	 
	//as LED GND
	digitalWrite(GND, LOW);
}
 
// the loop routine runs over and over again forever:
void loop() 
{
 
	btn1 = digitalRead(K1);
	buttonState = btn1;
	digitalWrite(D1, buttonState); //
	 
	btn2 = digitalRead(K2);
	buttonState = btn2;
	digitalWrite(D2, buttonState); //
	 
	buttonState = btn3 =  digitalRead(K3);
	// buttonState
	digitalWrite(D3, buttonState); //
	 
	btn4 = buttonState = digitalRead(K4);
	// buttonState
	digitalWrite(D4, buttonState); //
	
	// delay(2000); 
	 
	// digitalWrite(D5, HIGH); // turn the LED on (HIGH is the voltage level)
	// digitalWrite(D6, HIGH); // turn the LED on (HIGH is the voltage level)
	digitalWrite(D5, buttonState); // turn the LED on (HIGH is the voltage level)
	digitalWrite(D6, btn2); // turn the LED on (HIGH is the voltage level)
	
	// delay(2000); 
}
 
    
 //******************************************************//

Sebagai bonus dan penutup, berikut adalah tautan ke tulisan-tulisan yang bagus mengenai bouncing, debounce/debouncing. Bisa dibaca jika diperlukan, bahan-bahan sudah diurutkan dari pemahaman dasar umum ke tingkat yang lebih advance.

 

nRF24L01

[ [ images, codes & links ] ]

Ada banyak sumber belajar mengenai nRF24L01 di Internet, dalam berbagai format. Halaman ini hanya merangkum sebagian kecil di antaranya. Lebih lanjut silakan mengikuti link yang sudah disediakan.

Gambar 1. nRF24L01 [sumber]

RF24013.jpgGambar 2. nRF24L01 [sumber]

Gambar 3. nRF24L01 [sumber]

Gambar 4. nRF24L01 [sumber]

Gambar 5. [sumber]

Gambar 6. [sumber]

Gambar 7.

NRF24L01 2.4GHz wireless module with an ArduinoGambar 8. [sumber]

Gambar 9. [sumber]

Gambar 10. [sumber]

NOTE: These units VCC connection must go to 3.3V not 5.0V, although the Arduino itself may run at 5.0V and the signals will be OK. The NRF24L01+ IC is a 3.3V device, but its I/O pins are 5 V tolerant , which makes it easier to interface to Arduino/YourDuino.
Arduino UNO and earlier versions have a 3.3V output that can run the low-power version of these modules (See Power Problems at the top of this page!), but the high-power versions must have a separate 3.3V supply or use a Base Module with a 3.3V regulator. The YourDuino RoboRED has a higher power 3.3V regulator and can be used to run the high-power Power Amplifier type module without a separate 3.3V regulator. ~arduino-info.wikispaces.com

If you scroll through the RF24 library documentation, you will notice that there are many parameters that can be set.  Some key parameters are

  • Channel: the specific frequency channel that communication will occur on (frequencies are mapped to integers between 0 and 125
  • Reading pipe: the reading pipe is a unique 24, 32, or 40-bit address from which the module reads data
  • Writing pipe: the writing pipe is a unique address to which the module writes data
  • Power Amplifier (PA) level: the PA level sets the power draw of the chip and thereby the transmission power.  For the purposes of this tutorial (use with the Arduino) we will use the minimum power setting.  

The RF24 library documentation page provides some great example code for getting started with the library.  The example projects can be found here: http://tmrh20.github.io/RF24/examples.html  ~DevicePlus

Keseluruhan dari keterangan dalam kotak ini dikutip dari
https://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo :

RF24 LIBRARIES: Commonly Used Commands (Methods):

NOTE: If you wish, see ALL the details HERE.
We will try to understand the commands to set up and operate an nRF24L01 radio and build a very simple working example.
First we will look at the minimum needed to set up and transmit or receive data. Later we will write more complete examples and get them working with real radios..

CREATE AND START UP A RADIO (For either transmit or receive):

RF24 (uint8_t _cepin, uint8_t _cspin) Create a radio and set the Arduino pins to be used for CE and CS)

EXAMPLE: (Create an instance of a radio, specifying the CE and CS pins. )
RF24 myRadio (7,8); “myRadio” is the identifier you will use in the following examples

NOTE: The following pins are fixed and unchangeable. AND Vcc (supply voltage MUST be 3.3V)
SCK to Arduino pin 13
MOSI to Arduino pin 11
MISO to Arduino pin 12

NOTE: In all following commands, you must use the same identifying name you used in the RF24 statement that created the radio. (“myRadio” in the example above) You will use that identifier followed by (dot) followed by the method (command), followed by parameters. This is “object oriented programming”. The OBJECT in this case is the Radio, and there are many METHODS that can operate on the Object. A METHOD is much like a Function or a Subroutine.

EXAMPLE: myRadio.begin(); Start up the actual radio module with the “begin” method

NOTE: “PIPES” : This is often confusing. nRF24L01 uses “pipes” that connect from transmitter to receiver. Pipes have an address you need to set. The Transmitter pipe must have the same address as the Receiver pipe. Later it’s possible to use multiple “pipes” at once


EXAMPLE OF RECEIVING DATA:

myRadio.openReadingPipe (1, const uint8_t *address) Pipe number (usually 1), pipe address (which is usually 5 bytes in an array structure).

EXAMPLE:
byte addresses[][6] = {“1Node”}; Create address for 1 pipe.
myRadio.openReadingPipe(1, addresses[0]); Use the first entry in array ‘addresses’ (Only 1 right now)

myRadio.startListening (); Turn on the receiver and listen for received data. You MUST have opened a reading pipe FIRST.

if( myRadio.available()) Check for available incoming data from transmitter
{
while (myRadio.available()) While there is data ready
{
myRadio.read( &myData, sizeof(myData) ) ; Get the data payload (You must have defined that already!)
}
myRadio.stopListening(); stop listening


EXAMPLE OF TRANSMITTING DATA:
byte addresses[][6] = {“1Node”}; Create address for 1 pipe.
myRadio.openWritingPipe(1, addresses[0]); Use the first entry in array ‘addresses’ (Only 1 right now)

myRadio.write( &myData, sizeof(myData) )


We have written working examples of Transmit and Receive sketches using these methods. See them HERE


SET SOME OTHER OPERATING OPTIONS AND PARAMETERS:

NOTE: Many of these methods have default values you can usually use.

radio.printDetails();
Prints out a LOT of debugging information.


radio.setDataRate(RF24_250KBPS);
speed RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps. 250K Bits per second gives longest range.


radio.setPALevel(RF24_PA_MAX);
Set Power Amplifier (PA) level to one of four levels: RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH and RF24_PA_MAX
The power levels correspond to the following output levels respectively: NRF24L01: -18dBm, -12dBm,-6dBM, and 0dBm
0 dBm is equal to 1 milliwatt. Each 3 dB is a 2:1 ratio. 6 dB is 4:1 10 dB is 10:1 So -18 dBm is 0.0000158489 watts !
To calculate all this dBm Stuff (Which us old Radio Engineers love) See THIS..
The “High Power” nRF24L01 modules like THIS have a gain of 100, so their output is +20 dBm (100 milliwatts)


radio.setChannel(108);

Which RF channel to communicate on, 0-124 Can operate on frequencies from 2.400GHz to 2.524GHz.
Programming resolution of channel frequency is 1Mhz
This is the same unlicensed band WiFi operates in (WiFi uses 2.400 to 2.500 gHz). Usually frequencies above channel 100 are best.
NOTE: In most countries the allowed frequencies are from 2.400GHz to 2.483.5GHz which you must not exceed. In USA it’s best to use channels from 70 to 80.

You can scan the channels in your environment to find a channel that is clear… See this Scanner sketch.


radio.enableDynamicPayloads();

Enable custom length payloads on the acknowledge packets. Ack payloads are a handy way to return data back to senders without manually changing the radio modes on both units.


radio.setRetries(15,15);

Set the number and delay of retries upon failed transmit. Parameters:
delay: How long to wait between each retry, in multiples of 250us, max is 15. 0 means 250us, 15 means 4000us.
count: How many retries before giving up, max 15


radio.setCRCLength(RF24_CRC_16);

length: RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit Cyclic Redundancy Check (Error checking)


Gambar 11.

Gambar 12.

Gambar 13.

Gambar 14. [sumber]

http://www.pighixxx.com/test/wp-content/uploads/2014/11/nano.pngGambar 15.

Gambar 16.

Kode uji pengiriman sederhana #01. Sender :

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>



// uint8_t sVal = 0;

RF24 myRadio(9, 10);
byte addresses[][6] = {"1Nodx"}; // Create address for 1 pipe.
// const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup(void) 
{
  delay(2000);
  myRadio.begin();
  myRadio.setChannel(108);  // Above most Wifi Channels
  myRadio.setPALevel(RF24_PA_MIN);
  
  myRadio.openWritingPipe( addresses[0]); // Use the first entry in array 'addresses' (Only 1 right now)
  // radio.openWritingPipe(pipe);
}

void loop(void)
{
  for(int i=0; i<100; i++)
  {
    // myRadio.write(&sVal, sizeof(sVal));
    myRadio.write(&i, sizeof(i));
    delay(400);   
      
  }
}

Kode uji pengiriman sederhana #01. Receiver :

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// Addr, En, Rw, Rs, d4, d5, d6, d7, backlighpin, polarity

RF24 myRadio(9, 10);
byte addresses[][6] = {"1Node"}; // Create address for 1 pipe.
// const uint64_t pipe = 0xE8E8F0F0E1LL;
int nilaiTerkirim;

void setup(void) 
{
  lcd.off();
  Serial.begin(115200);

  myRadio.begin();
  myRadio.setChannel(108);  // Above most Wifi Channels
  myRadio.setPALevel(RF24_PA_MIN);
  myRadio.openReadingPipe(1, addresses[0]); // Use the first entry in array 'addresses' (Only 1 right now)  
  // radio.openReadingPipe(1, pipe);

  myRadio.startListening();

  lcd.on();
  lcd.begin(16, 2);
  lcd.backlight();
  lcd.clear();
  lcd.print("Uji nRF24L01 ...");
  delay(1000);
  lcd.clear();
  lcd.print("Starting ...");
  delay(2000);
  lcd.clear();
}

void loop(void)
{
  if ( myRadio.available() )
  {
    while (myRadio.available())
    {
      myRadio.read(&nilaiTerkirim, sizeof(nilaiTerkirim));
//      lcd.clear();
//      delay(500);
      lcd.setCursor(0, 0);
      lcd.print("Nilai: ");
      lcd.print(nilaiTerkirim);

      delay(400);
    }
  }
  else
  {
    lcd.setCursor(0, 0);
    lcd.print("No radio");
    delay(1000);
  }

//  delay(200);
  lcd.clear();
}

Kode dimodifikasi dari:

Kode uji pengiriman sederhana #02. Sender :

/* 
	M O D I F I E D code

  Beberapa bagian kode di bawah ini telah diubah. 
  Untuk melihat kode aslinya silakan membuka situs asal.

	YourDuinoStarter Example: Simple nRF24L01 Transmit
  - WHAT IT DOES: Transmits simple fixed data with nRF24L01 radio
  - SEE the comments after "//" on each line below
   Start with radios about 4 feet apart.
  - SEE the comments after "//" on each line below
  - CONNECTIONS: nRF24L01 Modules See:
  http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
  Uses the RF24 Library by TMRH2o here:
  https://github.com/TMRh20/RF24
   1 - GND
   2 - VCC 3.3V !!! NOT 5V
   3 - CE to Arduino pin 9 //Telah diubah
   4 - CSN to Arduino pin 10 //Telah diubah
   5 - SCK to Arduino pin 13
   6 - MOSI to Arduino pin 11
   7 - MISO to Arduino pin 12
   8 - UNUSED

   V1.02 02/06/2016
   Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <SPI.h>   // Comes with Arduino IDE
#include "RF24.h"  // Download and Install (See above)



/*-----( Declare Constants and Pin Numbers )-----*/


/*-----( Declare objects )-----*/
// (Create an instance of a radio, specifying the CE and CS pins. )
RF24 myRadio (9, 10); // "myRadio" is the identifier you will use in following methods
/*-----( Declare Variables )-----*/
byte addresses[][6] = {"1Node"}; // Create address for 1 pipe.
int dataTransmitted;  // Data that will be Transmitted from the transmitter

void setup()   /****** SETUP: RUNS ONCE ******/
{
  // Use the serial Monitor (Symbol on far right). Set speed to 115200 (Bottom Right)
  Serial.begin(115200);
  delay(1000);
  Serial.println(F("RF24/Simple Transmit data Test"));
  // Serial.println(F("Questions: terry@yourduino.com"));
  Serial.println(F("Questions: RTFM"));

  dataTransmitted = 10; // Arbitrary known data to transmit. Change it to test...
  myRadio.begin();  // Start up the physical nRF24L01 Radio
  myRadio.setChannel(108);  // Above most Wifi Channels
  // Set the PA Level low to prevent power supply related issues since this is a
  // getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
  myRadio.setPALevel(RF24_PA_MIN);
  //  myRadio.setPALevel(RF24_PA_MAX);  // Uncomment for more power

  myRadio.openWritingPipe( addresses[0]); // Use the first entry in array 'addresses' (Only 1 right now)
  delay(1000);
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  myRadio.write( &dataTransmitted, sizeof(dataTransmitted) ); //  Transmit the data

  Serial.print(F("Data Transmitted = "));
  Serial.print(dataTransmitted);
  Serial.println(F(" No Acknowledge expected"));
  dataTransmitted = dataTransmitted + 1;  // Send different data next time
  delay(500);

}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/



//*********( THE END )***********

Kode uji pengiriman sederhana #02. Receiver :

/* 

  Beberapa bagian kode di bawah ini telah diubah. 
  Untuk melihat kode aslinya silakan membuka situs asal.

  YourDuinoStarter Example: Simple nRF24L01 Receive
  - WHAT IT DOES: Receives simple fixed data with nRF24L01 radio
  - SEE the comments after "//" on each line below
   Start with radios about 4 feet apart.
  - SEE the comments after "//" on each line below
  - CONNECTIONS: nRF24L01 Modules See:
  http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
  Uses the RF24 Library by TMRH2o here:
  https://github.com/TMRh20/RF24
   1 - GND
   2 - VCC 3.3V !!! NOT 5V
   3 - CE to Arduino pin 9 //Telah diubah
   4 - CSN to Arduino pin 10 //Telah diubah
   5 - SCK to Arduino pin 13
   6 - MOSI to Arduino pin 11
   7 - MISO to Arduino pin 12
   8 - UNUSED

   V1.02 02/06/2016
   Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <SPI.h>   // Comes with Arduino IDE
#include "RF24.h"  // Download and Install (See above)
#include <LiquidCrystal_I2C.h>

/*-----( Declare Constants and Pin Numbers )-----*/
//None yet
/*-----( Declare objects )-----*/
// (Create an instance of a radio, specifying the CE and CS pins. )
RF24 myRadio (9, 10); // "myRadio" is the identifier you will use in following methods
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// Addr, En, Rw, Rs, d4, d5, d6, d7, backlighpin, polarity

/*-----( Declare Variables )-----*/
byte addresses[][6] = {"1Node"}; // Create address for 1 pipe.
int dataReceived;  // Data that will be received from the transmitter

void setup()   /****** SETUP: RUNS ONCE ******/
{
  delay(100);
  // Use the serial Monitor (Symbol on far right). Set speed to 115200 (Bottom Right)
  Serial.begin(115200);
  delay(100);
  Serial.println(F("RF24/Simple Receive data Test"));
  Serial.println(F("Q: RTFM dude"));

  myRadio.begin();  // Start up the physical nRF24L01 Radio
  myRadio.setChannel(108);  // Above most Wifi Channels
  // Set the PA Level low to prevent power supply related issues since this is a
  // getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
  myRadio.setPALevel(RF24_PA_MIN);
  //  myRadio.setPALevel(RF24_PA_MAX);  // Uncomment for more power

  myRadio.openReadingPipe(1, addresses[0]); // Use the first entry in array 'addresses' (Only 1 right now)
  myRadio.startListening();

  delay(200);
  lcdInit();

}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
//  lcd.clear();

  if ( myRadio.available()) // Check for incoming data from transmitter
  {
    while (myRadio.available())  // While there is data ready
    {
      myRadio.read( &dataReceived, sizeof(dataReceived) ); // Get the data payload (You must have defined that already!)
    }
    // DO something with the data, like print it
    Serial.print("Data received = ");
    Serial.println(dataReceived);

    lcdDisp(dataReceived);

  } //END Radio available
  else
  {
    lcd.clear();
    // lcd.setCursor(0, 0);
    lcd.print("No radio");
    delay(1000);
    lcd.clear();
  }

}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/
void lcdInit()
{
  lcd.begin(16, 2);

  lcd.backlight();
  lcd.clear();

  lcd.print("Uji nRF24L01 ...");
  delay(1000);
  lcd.clear();
  lcd.print("Mulai ...");
  delay(2000);

  lcd.clear();

}

void lcdDisp(int dataIN)
{

  lcd.setCursor(0, 0);
  lcd.print("Nilai: ");
  lcd.print(dataIN);
  delay(500);
}


//None yet
//*********( THE END )***********

Gambar 17.

Kode dimodifikasi dari:

Sumber belajar:

 

Arduino Uno plus ZIF socket

Tinkering ini bisa jadi tergolong pada proyek “ya karena saya bisa” (just because I can). Sekalipun masih tetap bermanfaat, utak-atik ini lebih merupakan kesenangan dan keisengan.

Gambar 1.

Gambar 2.

 

Arduino (dan sistem yang kompatibel dengannya) sebenarnya terdiri dari dua bagian yang utuh menjadi satu. Di satu bagian adalah hardware, perangkat keras, berupa papan Arduino. Di satu bagian lain adalah software (perangkat lunak), yang juga terdiri dari dua bagian yaitu firmware/bootloader yang terdapat di papan Arduino dan bagian lain adalah Arduino IDE yang dipakai oleh pengguna untuk menyusun program yang akan dimasukkan ke mikrokontroler (papan Arduino). Umumnya Arduino IDE-lah yang lebih dikenal sebagai bagian software.

Karena itu papan Arduino dapat dipakai tanpa mempergunakan bootloader {{1}} dan sistem masih berfungsi dengan baik. Misalnya pada Arduino Mega, Arduino Uno, Arduino Nano, dan Arduino Micro, pengguna bisa langsung menggunakan mikrokontroler AVR dari keluarga ATmega. Pengguna bisa mempergunakan header untuk port ISP/ICSP untuk melakukan pemrograman μC tanpa bantuan bootloader untuk melakukan pemrograman melalui USB port.

Dari Gambar 2, bisa dilihat bahwa kabel pita/kabel pelangi dihubungkan semi permanen ke ICSP port di papan Arduino agar dapat memudahkan proses pemrograman dengan perangkat keras pemrogram seperti USBasp. Dengan demikian papan Arduino Uno bisa juga difungsikan sebagai papan untuk memprogram mikrokontroler Atmel AVR ATmega328P tanpa bootloader Arduino.

Berikutnya adalah mengenai ZIF socket. Pada Gambar 1 dan Gambar 2, bisa dilihat ZIF (Zero Insertion Force) {{2}} adalah benda berwarna hijau tempat IC mikrokontroler dipasang. ZIF memudahkan pengguna untuk memindahkan dan memasang kembali IC. Jadi, untuk mempergunakan papan Arduino Uno sebagai papan mikrokontroler tanpa bootloader Arduino, soket ZIF sebenarnya tidak diperlukan. Itu sebabnya di awal saya sebut utak-atik ini sebagai “just because I can”.  Tetapi, lagi, ZIF memudahkan jika saya hendak mengganti IC yang sedang diprogram. Segala yang mempermudah dan mempercepat proses layak untuk dipertimbangkan untuk dimiliki atau dibuat.

[[1]]Not using a bootloader: If you want to use the full program space (flash) of the chip or avoid the bootloader delay, you can burn your sketches using an external programmer. ~Arduino.cc [[1]] [[2]]Stands for “Zero Insertion Force.” ZIF is a type of CPU socket on a computer motherboard that allows for the simple replacement or upgrade of the processor. Processors that use a ZIF socket can easily be removed by pulling a small release lever next to the processor and lifting it out. The replacement processor is then placed in the socket and secured by pushing the lever in the opposite direction — hence the phrase, “zero insertion force.” I suppose there is some force required to push the lever, but it is significantly less than non-ZIF sockets, which require special tools to force the processor out. ~techterms.com [[2]]

 

ATtiny85 development board

[ [ images & links ] ]

Gambar 1.

Gambar 2.

https://i.stack.imgur.com/gpt63.pngGambar 3.

Gambar 4.

Gambar 5.

Gambar 6.

Gambar 7.

Gambar 8.

Gambar 9.

Gambar 10.

Gambar 11.

Jika tertarik untuk mempergunakan papan yang mikrokontrolernya dapat diisi bootloader yang stabil, bisa membaca di halaman ini.

 

Development Board Learning Kit Multifungsi (Multifuction Shield)

Papan fungsi shield untuk uji komponen dengan empat 7-segment.

Gambar 1.

Gambar 2. [sumber]

Gambar 3. [sumber]

Jumpers:

J1 is used for a 10 k pull up resistor to pin 2 of U5  (to connect a DS1820 temperature sensor [not included with the shield]) (Arduino Pin A4 ?)  {Location C4 in the picture} 

J2 is needed if you want to use the switches S1 S2 and S3 (connected to A1 A2 and A3 of the Arduino. {Location C1 in picture}

A SFH506-38 IR receiver (Pin D2) {Location C3 in picture} is also not included with this shield and can be connected to U4

I expect the 7 pin header {Location B/C1 in picture} with the Chinese characters is the header 7 pin header marked on the shield with “APC220 Bluetooth Voice Recognition Module”. (Pin D0 and D1 ?)

Pin D5 D6 D9 and A5 are accessible by 4 3 pin header connectors next to +5V and GND

D3 is connected to the Buzzer using a transistor! {Location D3 in picture}

 The 4 * 7segement displays are connected using two MC74HC595AD shift registers
D4 7segment Latch
D7 7segment CLK
D8 7segment Data

D10 Led4 {Location A2 in picture}
D11 Led3
D12 Led2
D13 Led1

A0 Pot1 (potentiometer) {Location B/C1 in picture}

A1 Button1 {Location C/D1 in picture}
A2 Button2
A3 Button3

  1. All LEDs blinking
    int led1 = 13;
    int led2 = 12;
    int led3 = 11;
    int led4 = 10;
     
    void setup()
    {
    // initialize the digital pin as an output.
    pinMode(led1, OUTPUT);
    pinMode(led2, OUTPUT);
    pinMode(led3, OUTPUT);
    pinMode(led4, OUTPUT);
    }
     
    void loop()
    {
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);
    delay(1000);
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);
    delay(1000);
    }
  2. Switches example
    const byte LED[] = {13,12,11,10};
     
    #define BUTTON1 A1
    #define BUTTON2 A2
     
    void setup()
    {
    	// initialize the digital pin as an output.
    	/* Set each pin to outputs */
    	pinMode(LED[0], OUTPUT);
    	pinMode(LED[1], OUTPUT);
    	pinMode(LED[2], OUTPUT);
    	pinMode(LED[3], OUTPUT);
    }
     
    void loop()
    {
    	if(!digitalRead(BUTTON1))
    	{
    		digitalWrite(LED[0], HIGH);
    		digitalWrite(LED[1], HIGH);
    		digitalWrite(LED[2], HIGH);
    		digitalWrite(LED[3], HIGH);
    	}
     
    	if(!digitalRead(BUTTON2))
    	{
    		digitalWrite(LED[0], LOW);
    		digitalWrite(LED[1], LOW);
    		digitalWrite(LED[2], LOW);
    		digitalWrite(LED[3], LOW);
    		}
    }
  3. Potentiometer 1
    #define Pot1 0
     
    void setup()
    {
    	Serial.begin(9600);
    }
     
    /* Main Program */
    void loop()
    {
     
    	Serial.print("Potentiometer reading: ");
    	Serial.println(analogRead(Pot1));
    	/* Wait 0.5 seconds before reading again */
    	delay(500);
    }
  4. Pot and led
    const byte LED[] = {13,12,11,10};
    #define Pot1 0
     
    void setup()
    {
    	Serial.begin(9600);
    	// initialize the digital pin as an output.
    	/* Set each pin to outputs */
    	pinMode(LED[0], OUTPUT);
    	pinMode(LED[1], OUTPUT);
    	pinMode(LED[2], OUTPUT);
    	pinMode(LED[3], OUTPUT);
    }
     
    /* Main Program */
    void loop()
    {
    	int PotValue;
    	//Serial.print("Potentiometer reading: ");
    	PotValue = analogRead(Pot1);
    	/* Wait 0.5 seconds before reading again */
    	if(PotValue < 400)
    	{
    		digitalWrite(LED[0], LOW);
    		digitalWrite(LED[1], LOW);
    		digitalWrite(LED[2], LOW);
    		digitalWrite(LED[3], LOW);
    		Serial.print("Potentiometer: ");
    		Serial.println(PotValue);
    	}
    	else
    	{
    		digitalWrite(LED[0], HIGH);
    		digitalWrite(LED[1], HIGH);
    		digitalWrite(LED[2], HIGH);
    		digitalWrite(LED[3], HIGH);
    		Serial.print("Potentiometer: ");
    		Serial.println(PotValue);
    	}
    		delay(500);
    }
    
    
  5. Segment display
    /* Define shift register pins used for seven segment display */
    #define LATCH_DIO 4
    #define CLK_DIO 7
    #define DATA_DIO 8
     
    /* Segment byte maps for numbers 0 to 9 */
    const byte SEGMENT_MAP[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90};
    /* Byte maps to select digit 1 to 4 */
    const byte SEGMENT_SELECT[] = {0xF1,0xF2,0xF4,0xF8};
     
    void setup ()
    {
    	/* Set DIO pins to outputs */
    	pinMode(LATCH_DIO,OUTPUT);
    	pinMode(CLK_DIO,OUTPUT);
    	pinMode(DATA_DIO,OUTPUT);
    }
     
    /* Main program */
    void loop()
    {
     
    	/* Update the display with the current counter value */
    	WriteNumberToSegment(0 , 0);
    	WriteNumberToSegment(1 , 1);
    	WriteNumberToSegment(2 , 2);
    	WriteNumberToSegment(3 , 3);
    }
     
    /* Write a decimal number between 0 and 9 to one of the 4 digits of the display */
    void WriteNumberToSegment(byte Segment, byte Value)
    {
    	digitalWrite(LATCH_DIO,LOW);
    	shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_MAP[Value]);
    	shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_SELECT[Segment] );
    	digitalWrite(LATCH_DIO,HIGH);
    }
  6. Read pot and display value on display
    /* Define shift register pins used for seven segment display */
    #define LATCH_DIO 4
    #define CLK_DIO 7
    #define DATA_DIO 8
     
    #define Pot1 0
     
    /* Segment byte maps for numbers 0 to 9 */
    const byte SEGMENT_MAP[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90};
    /* Byte maps to select digit 1 to 4 */
    const byte SEGMENT_SELECT[] = {0xF1,0xF2,0xF4,0xF8};
     
    void setup ()
    {
    	Serial.begin(9600);
    	/* Set DIO pins to outputs */
    	pinMode(LATCH_DIO,OUTPUT);
    	pinMode(CLK_DIO,OUTPUT);
    	pinMode(DATA_DIO,OUTPUT);
    }
     
    /* Main program */
    void loop()
    {
    	int PotValue;
    	PotValue = analogRead(Pot1);
    	Serial.print("Potentiometer: ");
    	Serial.println(PotValue);
    	/* Update the display with the current counter value */
    	WriteNumberToSegment(0 , PotValue / 1000);
    	WriteNumberToSegment(1 , (PotValue / 100) % 10);
    	WriteNumberToSegment(2 , (PotValue / 10) % 10);
    	WriteNumberToSegment(3 , PotValue % 10);
    }
     
    /* Write a decimal number between 0 and 9 to one of the 4 digits of the display */
    void WriteNumberToSegment(byte Segment, byte Value)
    {
    	digitalWrite(LATCH_DIO,LOW);
    	shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_MAP[Value]);
    	shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_SELECT[Segment] );
    	digitalWrite(LATCH_DIO,HIGH);
    }
  7. Read pot and display value on display (modifikasi untuk meratakan tingkat terang tampilan)
    /* Define shift register pins used for seven segment display */
    #define LATCH_DIO 4
    #define CLK_DIO 7
    #define DATA_DIO 8
     
    #define Pot1 0
     
    /* Segment byte maps for numbers 0 to 9 */
    const byte SEGMENT_MAP[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90};
    /* Byte maps to select digit 1 to 4 */
    const byte SEGMENT_SELECT[] = {0xF1,0xF2,0xF4,0xF8};
     
    void setup ()
    {
      Serial.begin(9600);
      /* Set DIO pins to outputs */
      pinMode(LATCH_DIO,OUTPUT);
      pinMode(CLK_DIO,OUTPUT);
      pinMode(DATA_DIO,OUTPUT);
    }
     
    /* Main program */
    void loop()
    {
      int PotValue;
      PotValue = analogRead(Pot1);
      Serial.print("Potentiometer: ");
      Serial.println(PotValue);
      /* Update the display with the current counter value */
      WriteNumberToSegment(0 , PotValue / 1000);
      delay(5);
      WriteNumberToSegment(1 , (PotValue / 100) % 10);
      delay(5);
      WriteNumberToSegment(2 , (PotValue / 10) % 10);
      delay(5);
      WriteNumberToSegment(3 , PotValue % 10);
    //  delay(4);
    }
     
    /* Write a decimal number between 0 and 9 to one of the 4 digits of the display */
    void WriteNumberToSegment(byte Segment, byte Value)
    {
      digitalWrite(LATCH_DIO,LOW);
      shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_MAP[Value]);
      shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_SELECT[Segment] );
      digitalWrite(LATCH_DIO,HIGH);
    }

Sumber lain:
Hackatronics: Using an Arduino Multi-function Shield

 

 

DFRobot LCD shield

Catatan untuk penggunaan LCD shield.

Ada dua versi dari LCD shield dari DFRobot yaitu versi 1.0 dan versi 1.1. Gambar 1 adalah V1.0 dan Gambar 2 adalah versi V1.1.

 

Gambar 1. [sumber]

File:DFR0009LCD KeyPad Shield mapping.pngGambar 2. [sumber]

 

Pada beberapa bagian kedua versi papan ini memiliki kesaamaan.

Gambar 3. [sumber]

DFR0009-PIN2.pngGambar 4. [sumber]

Contoh kode 01 [sumber]:

/*************************************************************************************

  Mark Bramwell, July 2010

  This program will test the LCD panel and the buttons.When you push the button on the shield,
  the screen will show the corresponding one.
 
  Connection: Plug the LCD Keypad to the UNO(or other controllers)

**************************************************************************************/

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);           // select the pins used on the LCD panel

// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;

#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

int read_LCD_buttons(){               // read the buttons
    adc_key_in = analogRead(0);       // read the value from the sensor 

    // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
    // we add approx 50 to those values and check to see if we are close
    // We make this the 1st option for speed reasons since it will be the most likely result

    if (adc_key_in > 1000) return btnNONE; 

    // For V1.1 us this threshold
    if (adc_key_in < 50)   return btnRIGHT;  
    if (adc_key_in < 250)  return btnUP; 
    if (adc_key_in < 450)  return btnDOWN; 
    if (adc_key_in < 650)  return btnLEFT; 
    if (adc_key_in < 850)  return btnSELECT;  

   // For V1.0 comment the other threshold and use the one below:
   /*
     if (adc_key_in < 50)   return btnRIGHT;  
     if (adc_key_in < 195)  return btnUP; 
     if (adc_key_in < 380)  return btnDOWN; 
     if (adc_key_in < 555)  return btnLEFT; 
     if (adc_key_in < 790)  return btnSELECT;   
   */

    return btnNONE;                // when all others fail, return this.
}

void setup(){
   lcd.begin(16, 2);               // start the library
   lcd.setCursor(0,0);             // set the LCD cursor   position 
   lcd.print("Push the buttons");  // print a simple message on the LCD
}
 
void loop(){
   lcd.setCursor(9,1);             // move cursor to second line "1" and 9 spaces over
   lcd.print(millis()/1000);       // display seconds elapsed since power-up

   lcd.setCursor(0,1);             // move to the begining of the second line
   lcd_key = read_LCD_buttons();   // read the buttons

   switch (lcd_key){               // depending on which button was pushed, we perform an action

       case btnRIGHT:{             //  push button "RIGHT" and show the word on the screen
            lcd.print("RIGHT ");
            break;
       }
       case btnLEFT:{
             lcd.print("LEFT   "); //  push button "LEFT" and show the word on the screen
             break;
       }    
       case btnUP:{
             lcd.print("UP    ");  //  push button "UP" and show the word on the screen
             break;
       }
       case btnDOWN:{
             lcd.print("DOWN  ");  //  push button "DOWN" and show the word on the screen
             break;
       }
       case btnSELECT:{
             lcd.print("SELECT");  //  push button "SELECT" and show the word on the screen
             break;
       }
       case btnNONE:{
             lcd.print("NONE  ");  //  No action  will show "None" on the screen
             break;
       }
   }
}

Contoh kode 02 [sumber]:

/*******************************************************

   Description:
   Reads an analog input on pin 1, prints the result to the LCD.
   This program takes the temperture sensor LM35 for example. 
  
   Connection:
   Plug the LCD Keypad to the UNO(or other controllers)
   Temperture sensor:
   S(blue) -- A1()  
     Note: A0 has been occupied.
   VCC(red) -- VCC
   GND(black) -- GND

********************************************************/

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);        // select the pins used on the LCD panel

unsigned long tepTimer ;    

void setup(){ 
    lcd.begin(16, 2);                       // start the library
}

void loop(){ 
    lcd.setCursor(0, 0);                   // set the LCD cursor   position 
    int val;                               // variable to store the value coming from the analog pin 
    double data;                           // variable to store the temperature value coming from the conversion formula
    val=analogRead(1);                     // read the analog in value:
    data = (double) val * (5/10.24);       // temperature conversion formula
    
    if(millis() - tepTimer > 500){         // output a temperature value per 500ms 
             tepTimer = millis();

             // print the results to the lcd
             lcd.print("T: ");               
             lcd.print(data);             
             lcd.print("C");              
     } 
}

Contoh kode 03 [sumber]:

/*
DFRobot LCD Shield for Arduino
Key Grab v0.2
Written by Glendon Klassen
gjklassen@gmail.com
http://www.sourceforge.net/users/ecefixer
http://ecefixer.tumblr.com

Displays the currently pressed key on the LCD screen.

Key Codes (in left-to-right order):

None   - 0
Select - 1
Left   - 2
Up     - 3
Down   - 4
Right  - 5

*/

#include <LiquidCrystal.h>
#include <DFR_Key.h>

//Pin assignments for DFRobot LCD Keypad Shield
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 
//---------------------------------------------

DFR_Key keypad;

int localKey = 0;
String keyString = "";
                 
void setup() 
{ 
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Key Grab v0.2");
  delay(2500);
  
  /*
  OPTIONAL
  keypad.setRate(x);
  Sets the sample rate at once every x milliseconds.
  Default: 10ms
  */
  keypad.setRate(10);

}

void loop() 
{ 
  /*
  keypad.getKey();
  Grabs the current key.
  Returns a non-zero integer corresponding to the pressed key,
  OR
  Returns 0 for no keys pressed,
  OR
  Returns -1 (sample wait) when no key is available to be sampled.
  */
  localKey = keypad.getKey();
  
  if (localKey != SAMPLE_WAIT)
  {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Current Key:");
    lcd.setCursor(0, 1);
    lcd.print(localKey);
  }
}

Relay shield

Papan relay shield dijual dengan lebih dari satu rating tegangan listrik, berikut dua contoh.

Gambar 1. Arduino Relay Shield v1.0 5V 4-Channel Relay Module [sumber]

 

https://images-na.ssl-images-amazon.com/images/I/71JfWudPY9L._SL1067_.jpgGambar 2. Seeed Arduino Relay Shield V2.0 [sumber]

 

Gambar 1 dan Gambar 2 menunjukkan dua sistem relay yang berbeda, tetapi pengoperasiannya sama. Berikut kutipan data untuk relay HJR4102.

Gambar 3. [sumber]

Gambar 4. [sumber]

Relay HJR4102 by Sunu Pradana on Scribd

Arduino ESP8266 WiFi Shield v1.0 WangTongze

[ [ images & links ] ]

Gambar 1. Posisi  switch ON [ Klik gambar untuk memperbesar tampilan ]

Gambar 2. Posisi  switch OFF [ Klik gambar untuk memperbesar tampilan ]

[table id=2 /]

Pengaturan switch untuk tiga mode: flashing/reprogramming ESP8266, komunikasi Arduino ⇔ ESP8266 (system run), Arduino programming

1. flashing/reprogramming ESP8266

Konfigurasi untuk pemrograman modul ESP8266  dengan atau tanpa secara fisik terhubung dengan papan Arduino. Memutus jalur komunikasi serial (hardware), OFF di sw1 dan sw2. Posisi ON pada sw3 (DFU: Device Framework Upgrade) dan posisi ON pada sw4 (lampu LED indikator DFU).

[table id=3 /]

Gambar 3.

2. Arduino programming

Konfigurasi untuk pemrograman papan Arduino dengan shield ESP8266 yang masih terhubung secara fisik.

[table id=4 /]

Gambar 4.

3. komunikasi Arduino ⇔ ESP8266 (system run)

Konfigurasi untuk kondisi saat Arduino bekerja dan berkomunikasi melalui serial hardware dengan modul ESP8266.

[table id=5 /]

Gambar 5.

Gambar 6. [sumber]

 

Gambar 7.

Gambar 8.

Gambar 9. FTDI FT232RL

Gambar 10. Kondisi tegangan kerja 5 V

Gambar 11. Kondisi tegangan kerja 3.3 V

Gambar 12.

Percobaan didahului dengan mengosongkan program pada papan Arduino Uno (Gambar 12). Mengetahui kondisi ESP8266 (Gambar 13), konfigurasi switch mengikuti Gambar 3.

Kondisi peneriksaan semua switch OFF. Kadang-kadang perlu melepas lalu kemudian memasang ulang koneksi kabel USB. Kadang-kadang perlu menekan-tahan tombol reset di shield. Pada beberapa percobaan, penekanan tombol reset saat menunggu jawaban dari papan dapat menggantikan keperluan lepas-pasang koneksi kabel USB. Percobaan berhasil pada tegangan kerja 5 V maupun 3.3 V, dengan penyesuaian pengaturan kabel dari papan FTDI RS232 ke papan WiFi shield  (ESP8266).

Gambar 13.

esptool.py -p /dev/ttyUSB0 flash_id

Perintah penghapusan program di ESP8266, jika diperlukan (Gambar 14), kondisi switch mengikuti Gambar 3.

Gambar 14.

esptool.py -p /dev/ttyUSB0 erase_flash

 

Perintah pengisian firmware program di ESP8266 (Gambar 15), kondisi switch mengikuti Gambar 3.

Gambar 15.

esptool.py write_flash 0x0 ai-thinker-v1.1.1.bin

esptool.py --port /dev/ttyUSB0 write_flash -fm dio 0x00000 ai-thinker-0.9.5.2-115200.bin

Melakukan pemeriksaan kondisi firmware dengan ESPlorer (Gambar 16). Cara yang sama dapat dipakai untuk memberikan perintah AT command.

Kembalikan konfigurasi switch seperti pada Gambar 3 menjadi konfigurasi switch seperti pada Gambar 4.

Gambar 16.

Gambar 17, upload firmware dengan memanfaatkan NodeMCU PyFlasher. Konfigurasi swicth seperti pada Gambar 3.

Gambar 17.

Gambar 18 dan Gambar 19, koneksi ke ESP8266 dengan software moserial, pengaturan switch seperti pada Gambar 4.

Gambar 18.

Gambar 19.

esptool.py write_flash 0x0 ai-thinker-0.9.5.2-9600.bin

esptool.py -p /dev/ttyUSB0 flash_id

Gambar 20, modifikasi Software Serial untuk pengiriman AT command.

Gambar 20.

#include <SoftwareSerial.h>

SoftwareSerial esp8266(10,11); //RX TX

void setup()
{
  Serial.begin(9600);
  
  Serial.println("Hardware serial: aktif");
  Serial.println("");

  esp8266.begin(9600);
}


void loop()
{
  if (Serial.available() > 0)
  {

    byte b = Serial.read();
    esp8266.write(b);
  }

  if (esp8266.available() > 0)
  {
    
    byte b = esp8266.read();
    Serial.write(b);
  }
}

Gambar 21. Koneksi silang untuk SoftwareSerial Rx ⇒ Tx, Tx ⇒ Rx.

 

NodeMCU DEVKIT dan Lua

[ [ images & links ] ]

pinout.pngGambar 1. NodeMCU [sumber]

https://i-esan.com/wp-content/uploads/2013/06/nodemcu_v2_pin_map.pngGambar 2. [sumber]http://c.tutti.ch/images/esp8266-nodemcu-v3-base-board-protoshield-mit-spannungsregle-6355190634.jpgGambar 3. NodeMCU + Base yang tidak memerlukan tambahan adapter [sumber]

Gambar 4. NodeMCU v0.9 pinout [sumber]

Perbedaan antara v0.9 dan v1.0:

If you are going to purchase a NodeMCU board it’s important to know there are two official versions:

  • NodeMCU v0.9 with ESP-12 module
  • NodeMCU v1.0 with ESP-12E module

The main complain about NodeMCU v0.9 is that while it fits on the breadboard, you can’t use as it takes the full width of the board, while NodeMCU v1.0 is really breadboard-friendly as you can see on the right part of the picture above.

wget https://github.com/nodemcu/nodemcu-firmware/releases/download/0.9.6-dev_20150704/nodemcu_integer_0.9.6-dev_20150704.bin
$ /home/sunu/.arduino15/packages/esp8266/tools/esptool/0.4.9/esptool -p /dev/ttyUSB0 erase_flash
$ clear; esptool.py --port /dev/ttyUSB0 flash_id

$ reset; esptool.py --port /dev/ttyUSB0 write_flash -fm dio 0x00000 nodemcu_integer_0.9.6-dev_20150704.bin

$ reset; esptool.py --port /dev/ttyUSB0 write_flash 0x00000 nodemcu_integer_0.9.6-dev_20150704.bin

$ reset; esptool.py --port /dev/ttyUSB1 write_flash -fm dio 0x00000 nodemcu_integer_0.9.6-dev_20150704.bin

$ reset; esptool.py --port /dev/ttyUSB0 write_flash 0x00000 nodemcu-master-7-modules-2017-07-03-14-56-15-integer.bin

Gambar 5.

Gambar 6.

Lakukan hardware reset pada nodeMCU DevKit, setelah menekan Connect pada Moserial.

Gambar 7.

Gambar 8.

Gambar 9.

Lakukan hardware reset pada nodeMCU DevKit, setelah menekan Open pada ESplorer.

Gambar 10.

Gambar 11.

pin = 0
gpio.mode(pin,gpio.OUTPUT)
print("tinker.sunupradna.info")
while 1 do
    gpio.write(pin,gpio.HIGH)
    tmr.delay(100000)
    gpio.write(pin,gpio.LOW)
    tmr.delay(100000)
end

Gambar 12. [ klik gambar untuk memperbesar tampilan ]

~/workspace/LUA/LED_blink $ nodemcu-tool devices
[NodeMCU] Connected Devices | Total: 1
	  |- /dev/ttyUSB0 (Silicon_Labs, usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0)
~/workspace/LUA/LED_blink $ nodemcu-tool --connection-delay 200 -p /dev/ttyUSB0 -b 9600 run blink_led_001.lua 
[NodeMCU-Tool] Connected
[NodeMCU] Version: 0.9.6 | ChipID: 0x74b61 | FlashID: 0x1640e0
~/workspace/LUA/LED_blink $ nodemcu-tool --connection-delay 200 -p /dev/ttyUSB0 -b 9600 upload blink_led_001.lua 
[NodeMCU-Tool] Connected
[NodeMCU] Version: 0.9.6 | ChipID: 0x74b61 | FlashID: 0x1640e0
[NodeMCU-Tool] Uploading "blink_led_001.lua" >> "blink_led_001.lua"...
[NodeMCU-Connector] Transfer-Mode: hex
[NodeMCU-Tool] File Transfer complete!
~/workspace/LUA/LED_blink $ nodemcu-tool init
[NodeMCU-Tool] Creating project based configuration file..
[NodeMCU-Tool] Baudrate in Bit per Seconds, e.g. 9600 (default) (9600) 9600
[NodeMCU-Tool] Serial connection to use, e.g. COM1 or /dev/ttyUSB2 (/dev/ttyUSB0) /dev/ttyUSB0


~/workspace/LUA/LED_blink $ nodemcu-tool run blink.lua
[NodeMCU-Tool] Project based configuration loaded
[NodeMCU-Tool] Connected
[NodeMCU] Version: 0.9.6 | ChipID: 0x74b61 | FlashID: 0x1640e0


~/workspace/LUA/LED_blink $ nodemcu-tool upload init.lua 
[NodeMCU-Tool] Project based configuration loaded
[NodeMCU-Tool] Connected
[NodeMCU] Version: 0.9.6 | ChipID: 0x74b61 | FlashID: 0x1640e0
[NodeMCU-Tool] Uploading "init.lua" >> "init.lua"...
[NodeMCU-Connector] Transfer-Mode: hex
[NodeMCU-Tool] File Transfer complete!

init.lua

--**delay sebelum loop**
--dofile("blink_led_001.lua")

print("tinker.sunupradana.info")

Gambar 13.

Gambar 14. [ klik gambar untuk memperbesar tampilan ]

Gambar 15.

NodeMCU, Lua, Arduino IDE