Catatan ringkas penggunaan Arduino-CLI

Selain menggunakan Arduio IDE, kita juga bisa mempergunakan Arduino-CLI. Ini bisa jadi berguna dan mempermudah di sistem seperti Raspberry Pi. Berikut catatan singkat contoh penggunaannya.

[intense_code type=”block”] sudo arduino-cli compile -b arduino:avr:uno /home/pengguna/Arduino/sunubt/
sudo arduino-cli upload -p /dev/ttyUSB0 –fqbn arduino:avr:uno /home/penggguna/Arduino/sunubt/
[/intense_code]

Di contoh ini file kode program Arduino terdapat di:
[intense_code type=”block”] /home/penggguna/Arduino/sunubt/sunubt.ino
[/intense_code]

Beberapa contoh penggunaan lain:
[intense_code type=”block”] sudo arduino-cli board attach serial:///dev/ttyUSB0 /home/penggguna/Arduino/sunubt/
arduino-cli upload -v -p /dev/rfcomm0 –fqbn arduino:avr:uno /home/penggguna/Arduino/sunubt
[/intense_code]

Rujukan:

 

Catatan avrdude: stk500_recv(): programmer is not responding

Ada beberapa kemungkinan terjadinya pesan kesalahan sebagai berikut ini:

[intense_code type=”block”] avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
[/intense_code]

Salah satunya adalah kemungkinan kesalahan konfigurasi atau perubahan akibat instalasi software baru. Misalnya pustaka yang tadinya telah terinstal menjadi hilang, seperti tampak di Gambar 1 berikut ini.

Gambar 1.

Konfigurasi ini berpotensi mengakibatkan kegagalan upload ke papan yang sebenarnya dalam kondisi baik (demikian juga kondisi PC secara umum). Ini terjadi baik untuk operasi dengan Arduino IDE maupun Arduino-CLI seperti di Gambar 2.

Gambar 2.

Upaya perbaikan dapat dilakukan dengan cara melakukan instalasi ulang/update dari menu board manager seperti di Gambar 3 dan Gambar 4.

Gambar 3.
Gambar 4.

Hasil perbaikan (di GNU/Linux) seharusnya akan tampai seperti di Gambar 5.

Gambar 5.

Setelah pustaka kembali normal, lakukan restart Arduino IDE. Setelah itu bisa dicoba melakukan uploading kembali, misalnya ke Arduino Nano ( old bootloader ) dengan Arduino IDE di Gambar 6.

Gambar 6.
Gambar 7. Hasil uji coba untuk Arduino Uno menggunakan arduino-cli.

Hasil uji coba di Gambar 8 dan Gambar 9 membuktikan bahwa pustaka untuk arsitektur lain tidak terganggu dan tetap berfungsi normal.

Gambar 8. Hasil uji coba untuk ESP8266.
Gambar 9. Uji coba dengan ESP32.

 

Berikut ini ada beberapa rujukan lain yang bisa dibaca untuk gejala yang sama (sekalipun bisa jadi penyebabnya berbeda).

 

Pengaturan HC-05

Pengaturan (setting) operasi modul HC-05 dapat dilakukan dengan beberapa cara. Berikut catatan pengaturan dengan dua cara, dengan FTDI USB to serial adapter  dan dengan memanfaatkan papan Arduino.

Pengaturan Menggunakan Modul FTDI

Gambar 1.

Dari sisi pertimbangan hardware cara ini relatif paling mudah untuk dilakukan. Tidak memerlukan resistor tambahan, cukup mengatur agar modul FTDI bekerja di tegangan 3,3 V (ubah poisisi jumper).

Gambar 2.
Gambar 3.

Gambar 2 dan Gambar 3 diperoleh dari dokumen PDF karya Gyula Molnar berikut ini. Hubungan RX dan TX antar modul perlu diperhatikan.

Untuk memasuki mode AT command, tekan dan tahan tombol yang berada di modul HC-05 sebelum menghubungkannya dengan sumber tegangan ( USB port ).

Gambar 4. [Sumber]
Software yang dapat dipakai untuk pengaturan misalnya CuteCom atau Arduino IDE.

Gambar 5.
Gambar 6.

Yang penting diperhatikan adalah pengaturan baud rate agar sesuai dengan pengaturan yang sudah dilakukan di modul HC-05. Di Gambar 5 dan Gambar 6, pengaturan masih menggunakan pengaturan default untuk HC-05.

Pengaturan Menggunakan Papan Arduino

Pengaturan HC-05 dengan menggunakan papan Arduino (semisal Arduino Uno) memerlukan lebih banyak komponen. Tetapi di sisi lain, memiliki keuntungan yaitu tidak memerlukan pembelian modul FTDI (jika memang belum dimiliki).

Gambar 7. [Sumber]
Untuk sistem Arduino Uno atau Arduino Nano yang hanya memiliki satu kanal hardware untuk komunikasi serial, pengguna perlu mempergunakan software serial.

Untuk dapat berkomunikasi dengan modul HC-05, papan sistem Arduino Uno perlu diprogram dengan kode berikut.

[sourcecode] /*
* Kode asal dari:
* HC05 – Bluetooth AT-Command mode
* modified on 10 Feb 2019
* by Saeed Hosseini
* https://electropeak.com/learn/guides
*/
#include "SoftwareSerial.h"
SoftwareSerial myHC05a(2, 3); // RX | TX
void setup()
{
delay(100);
Serial.begin(9600);

//myHC05a.begin(9600); //Baud Rate for AT-command Mode.
myHC05a.begin(38400); //Baud Rate for AT-command Mode.
//myHC05a.begin(115200); //Baud Rate for AT-command Mode.

delay(1000); //Delay untuk Arduino IDE.
Serial.println("***AT commands mode***");
}
void loop()
{
//from bluetooth to Terminal.
if (myHC05a.available())
Serial.write(myHC05a.read());
//from termial to bluetooth
if (Serial.available())
myHC05a.write(Serial.read());
}
[/sourcecode]

Gambar 8.

 

Gambar 9.

Gambar 9 menunjukkan akses AT command dengan default baud rate  untuk modul HC-05, yaitu 38400. Sedangkan komunikasi dari PC ( laptop ) ke papan Arduino Uno menggunakan 9600. Ciri adanya ketidaksesuaian pengaturan baud rate adalah tampilnya karakter ASCII  yang berbeda dari pesan yang seharusnya muncul, termasuk respon untuk AT command

AT Command

Ada banyak sumber daftar AT command yang bisa dan biasa dipakai untuk modul HC-05. Beberapa contohnya:

[intense_code type=”block”] AT : Check the connection.
AT+NAME : See default name
AT+ADDR : see default address
AT+VERSION : See version
AT+UART : See baudrate
AT+ROLE: See role of bt module(1=master/0=slave)
AT+RESET : Reset and exit AT mode
AT+ORGL : Restore factory settings
AT+PSWD: see default password
[/intense_code]
Gambar 10. [Sumber]

AT command :

 

Rujukan tambahan AT command:

HC-05 HC-06 Master Slave:

HC-05 :

 

Uji kendali digital pin Arduino dengan HC-05

Uji penggunaan aplikasi Bluetooth Application di smartphone Android untuk melakukan penyakelaran pin digital di Arduino Uno ini dilakukan dengan memanfaatkan modul HC-05.

Gambar 1.

Rangkaian yang dipakai pada prinsipnya sama dengan yang terlihat di Gambar 1.

[sourcecode] /*
Kode hasil modifikasi dari:
https://create.arduino.cc/projecthub/electropeak/getting-started-with-hc-05-bluetooth-module-arduino-e0ca81

HC05 – Bluetooth AT-Command mode
modified on 10 Feb 2019
by Saeed Hosseini https://electropeak.com/learn/
*/

#include <SoftwareSerial.h>
SoftwareSerial MyBlue(2, 3); // RX | TX
int flag = 0;
int LED = 8;
void setup()
{
Serial.begin(9600);
//Sesuaikan baud rate dengan pengaturan di HC-05
//MyBlue.begin(9600);
MyBlue.begin(38400);
//MyBlue.begin(115200);

pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
Serial.println("Ready to connect\nDefualt password is 1234 or 000");
}
void loop()
{
if (MyBlue.available() > 0)
{
flag = MyBlue.read();
}
//if (flag == 1) //Hex
if (flag == ‘1’) //ASCII
{
digitalWrite(LED, HIGH);
Serial.println("LED On");
}
//else if (flag == 0) //Hex
else if (flag == ‘0’) //ASCII
{
digitalWrite(LED, LOW);
Serial.println("LED Off");
}
}
[/sourcecode]

Gambar 2.

Perintah yang dikirim dapat berupa karakter ASCII sebagaimana yang terlihat di Gambar 2 untuk Switch 1. Untuk itu hanya perlu penyesuaian kecil di kode program untuk Arduino (Uno).

Rujukan :

Uji serial HC-05 Linux Mint dengan CuteCom dan Moserial

Uji coba koneksi dari Moserial ke CuteCom (dan sebaliknya). Hardware serial port Arduino Uno terhubung ke CuteCom (/dev/ttyUSB0) dan software serial Arduino Uno (/dev/rfcomm0) terhubung ke Moserial.

Gambar 1.

Koneksi Perangkat Keras

Gambar 2. [Sumber]
Hanya sebagai pembanding, Gambar 2 yang diperoleh dari howtomechatronics.com menunjukkan penggunaan modul HC-05 dengan Arduino Mega yang memiliki dua kanal komunikasi serial. Sedangkan di artikel ini selanjutnya hanya akan menggunakan sistem papan yang memiliki satu kanal serial hardware comm seperti Arduino Uno (Gambar 3).

Gambar 3.

Jika modul HC-05 dicabut atau tidak berfungsi baik, maka percobaan ini tidak dapat dilakukan. Hanya serial hardware lewat ttyUSB0 saja yang bisa terhubung. LED dalam percobaan ini tidak dipakai tetapi rangkaian yang sama ini akan dipakai untuk beberapa percobaaan yang berbeda (di artikel berikutnya).

Program Arduino

Kode asal program yang akan dipakai diambil dan dimodifikasi dari sumber ini. Kode ini sebenarnya dipakai untuk dapat memberikan AT command dari laptop ke modul HC-05. Tetapi kode yang sama bisa dimanfaatkan untuk demonstrasi komunikasi antar dua aplikasi di laptop yang sama melalui ttyUSB0 dan rfcomm0.

[sourcecode] /*
* Kode asal dari:
* HC05 – Bluetooth AT-Command mode
* modified on 10 Feb 2019
* by Saeed Hosseini
* https://electropeak.com/learn/guides
*/
#include "SoftwareSerial.h"
SoftwareSerial myHC05a(2, 3); // RX | TX
void setup()
{
delay(100);
Serial.begin(9600);
// myHC05a.begin(9600); //Baud Rate for AT-command Mode.
// myHC05a.begin(38400); //Baud Rate for AT-command Mode.
myHC05a.begin(115200); //Baud Rate for AT-command Mode.

delay(1000); //Delay untuk Arduino IDE.
Serial.println("***AT commands mode***");
}
void loop()
{
//from bluetooth to Terminal.
if (myHC05a.available())
Serial.write(myHC05a.read());
//from termial to bluetooth
if (Serial.available())
myHC05a.write(Serial.read());
}
[/sourcecode]

Pengaturan Bluetooth

Untuk HC-05 sudah dalam kondisi berkedip cepat saat uji coba akan dimulai. Ini menandakan modul itu sudah siap untuk dihubungkan.

[intense_code type=”block”]$ sudo service bluetooth restart[/intense_code]

Berikutnya periksa keberadaan rfcomm0. Berikut akan terlihat bahwa rfcomm0 belum ada.

[intense_code type=”block”] $ ls -la /dev/rf*
crw-rw-r–+ 1 root netdev 10, 242 Jul 16 07:05 /dev/rfkill
[/intense_code] [intense_code type=”block”] $ hciconfig
$ sudo hciconfig hci0 up
$ hcitool dev
Devices:
hci0 F0:03:8C:xx:xx:xx
[/intense_code] [intense_code type=”block”] $ hcitool scan
Scanning …
33:03:30:xx:xx:xx sunu-X2
20:14:10:xx:xx:xx Bluino#00
[/intense_code] [intense_code type=”block”] $ hcitool -i hci0 scan
$ sudo rfcomm release 0
$ sudo rfcomm bind 0 20:14:10:xx:xx:xx 1
$ rfcomm
[/intense_code] [intense_code type=”block”] $ sudo rfcomm connect 20:14:10:xx:xx:xx
[/intense_code] [intense_code type=”block”] $ sudo rfcomm bind 0 20:14:10:xx:xx:xx 1
[/intense_code] [intense_code type=”block”] $ sudo rfcomm connect /dev/rfcomm0 20:14:10:xx:xx:xx 1 &
[/intense_code] [intense_code type=”block”] $ bluetoothctl
trust 20:14:10:xx:xx:xx
pair 20:14:10:xx:xx:xx
connect 20:14:10:xx:xx:xx
[/intense_code] [intense_code type=”block”] $ ls -la /dev/rf*
crw-rw—- 1 root dialout 216, 0 Jul 16 16:31 /dev/rfcomm0
crw-rw-r–+ 1 root netdev 10, 242 Jul 16 07:05 /dev/rfkill
[/intense_code]

Perintah berikut hanya diperlukan jika ingin mencoba Minicom.

[intense_code type=”block”] $ sudo minicom -D /dev/rfcomm0
Untuk keluar minicom, tekan ctrl+A lalu tekan X.
[/intense_code]

Perintah berikut hanya sebagai catatan, tidak mutlak diperlukan untuk percobaan ini.

[intense_code type=”block”] $ sudo hcitool cc 20:14:10:xx:xx:xx
$ sudo hcitool auth 20:14:10:xx:xx:xx
$ sdptool browse 20:14:10:xx:xx:xx
[/intense_code]

Pengaturan CuteCom

Pengaturan pertama adalah pengaturan komunikasi untuk CuteCom agar dapat berkomunikasi dengan kanal serial Arduino Uno melalui ttytUSB0. 

Gambar 4.

Pengaturan Moserial

Gambar 5.

Di percobaan ini software Moserial dipakai untuk dapat terhubung ke modul bluetooth HC-05 melalui rfcomm0. Sebelum terhubung, led di modul akan berkedip cepat. Setelah terbung (dengan penundaan beberapa saat), led akan berkedip dengan jauh lebih lambat.

Uji dengan Serial Bluetooth Terminal

Gambar 6.

Sebagai uji coba lanjutan, penggunaan Moserial diganti dengan penggunaan aplikasi SBT yang dijalankan dari smartphone Android. Laptop dan Android dapat terhubung dengan baik dan dapat berkomunikasi sebagaimana di Gambar 6.

 

Rujukan:

 

PCF8591: 8-bit A/D and D/A converter { ADC }

[ [ images & links ] ]
[su_panel border=”3px solid #482DE3″ radius=”10″]

Gambar 1.

PCF8591Gambar 2. [einhugur.com]

Features

  • Module supports external voltage input of the 4-way acquisition (voltage input range of 0-5v)
  • integrated photoresistor
  • integrated thermistor
  • integrated potentiometer
  • Modules power indicator
  • Modules with DA output indicator, when the module DA output interface voltage reaches a certain value, will be lit panel the DA output indicator, the higher the voltage, the more obvious indicator brightness
  • Remove shunts to bypass on board integrated devices

 The left connector

  • AOUT chip DA output interface
  • AINO chip analog input interface 0
  • AIN1 chip analog input interface 1
  • AIN2 chip analog input interface 2
  • AIN3 chip analog input interface 3

  The right connector

  • SCL
  • SDA
  • GND
  • VCC – connected to  3.3v-5v

Gambar 3. [arduinolearning.com]

 

Gambar 4. [arduinolearning.com]

 

Gambar 5.[forum.arduino.cc]

 

Product Description [electrodragon.com]

[/su_panel] [su_panel border=”3px solid #E1E555″ radius=”10″] [/su_panel] [su_panel border=”3px solid #C0FFC0″ radius=”10″]

Gambar 6.

Gambar 7.

[/su_panel] [su_panel border=”3px solid #8E2DEF” radius=”10″] [/su_panel]

 

Micro SD adapter

[ [ images & links ] ]
[su_panel border=”3px solid #482DE3″ radius=”10″]

Pada mashup sebelumnya, telah diungkapkan mengenai data logging shield. Di papan logger yang ditujukan untuk ukuran papan Arduino Uno itu sudah terdapat RTC. Namun ukuran sistem itu relatif besar dan karenanya pin papan itu tidak mudah diterapkan di sistem lain seperti papan Arduino Nano atau papan Arduino Micro. Alternatif lain adalah MicroSD Card Adapter seperti yang akan ditampilkan di halaman ini.

Gambar 1. [elabpeers.com]

[/su_panel] [su_panel border=”3px solid #30C0F0″ radius=”10″] [/su_panel] [su_panel border=”3px solid #FF6666″ radius=”10″]

Arduino SD Card and Data Logging to Excel Tutorial :

Gambar 3.

 

Arduino Data Logging

Now let’s make another more interesting example of data logging a temperature sensor. For that purpose we will use the DS3231 Real Time Clock module which has a built-in temperature sensor as well. You can find more details about how to connect and use this module in my previous tutorial.

So after connecting the two modules to the Arduino let’s take a look at the code for this example.

[/su_panel] [su_panel border=”3px solid #6C9C29″ radius=”10″]

Arduino LC Studio SD Card Tutorial :

 

Gambar 4. [henrysbench.capnfatz.com]

[/su_panel] [su_panel border=”3px solid #990066″ radius=”10″]

Arduino Nano SD Card Connection :

Arduino Nano SD Card ConnectionGambar 5.

 

[/su_panel] [su_panel border=”3px solid #30C0F0″ radius=”10″]

What is a Data-logger [datalogger.pbworks.com ]

[/su_panel] [su_panel border=”3px solid #30C0F0″ radius=”10″]

Gambar 6.

[/su_panel] [su_panel border=”3px solid #39DECB” radius=”10″] [intense_tabs direction=”right” active_tab_background_color=”#000000″ active_tab_font_color=”#ffff00″ trigger=”click”] [intense_tab title=”Video01″ border=”3px solid #e8e8e8″ link_target=”_self” content_background_color=”#000000″ content_font_color=”#ffffff” icon_size=”1″ icon_position=”left”]

[/intense_tab] [intense_tab title=”Video02″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video03″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video04″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video05″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video06″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [/intense_tabs] [/su_panel] [su_panel border=”3px solid #202DB9″ radius=”10″] [/su_panel]

Data logging shield

[ [ images & links ] ]
[su_panel border=”3px solid #482DE3″ radius=”10″]

https://learn.adafruit.com/adafruit-data-logger-shield?view=all :

Gambar 1. learn.adafruit.com

 

adafruit_products_labeled.jpgGambar 2.

Place the SD library folder your sketchbook libraries folder. You may need to create the libraries subfolder if its your first library.

 

 
[/su_panel] [su_panel border=”3px solid #30C0F0″ radius=”10″]

https://learn.adafruit.com/adafruit-data-logger-shield?view=all :

adafruit_products_Logger_bb.jpgGambar 3.

[/su_panel] [su_panel border=”3px solid #FF6666″ radius=”10″]

Adafruit library examples.

Deek-Robot: Data logging shield V1.0

D10 – Chip Select
D11 – SPI MOSI
D12 – SPI MISO
D13 – SPI SCK

[/su_panel] [su_panel border=”3px solid #6C9C29″ radius=”10″] [/su_panel] [su_panel border=”3px solid #990066″ radius=”10″] [/su_panel] [su_panel border=”3px solid #30C0F0″ radius=”10″]
[code lang=”C”] RTC_DS1307 RTC; // define the Real Time Clock object

// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;

// the logging file
File logfile;

void error(char *str)
{
Serial.print("error: ");
Serial.println(str);

// red LED indicates error
digitalWrite(redLEDpin, HIGH);

while(1);
}
[/code]

“Next is the error() function, which is just a shortcut for us, we use it when something Really Bad happened, like we couldn’t write to the SD card or open it. It prints out the error to the Serial Monitor, turns on the red error LED, and then sits in a while(1); loop forever, also known as a halt

[code lang=”C”] // initialize the SD card
Serial.print("Initializing SD card…");
// make sure that the default chip select pin is set to
// output, even if you don’t use it:
pinMode(10, OUTPUT);

// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don’t do anything more:
return;
}
Serial.println("card initialized.");

// create a new file
char filename[] = "LOGGER00.CSV";
for (uint8_t i = 0; i < 100; i++) {
filename[6] = i/10 + ‘0’;
filename[7] = i%10 + ‘0’;
if (! SD.exists(filename)) {
// only open a new file if it doesn’t exist
logfile = SD.open(filename, FILE_WRITE);
break; // leave the loop!
}
}

if (! logfile) {
error("couldnt create file");
}

Serial.print("Logging to: ");
Serial.println(filename);
[/code]

“Now the code starts to talk to the SD card, it tries to initialize the card and find a FAT16/FAT32 partition. Next it will try to make a logfile. We do a little tricky thing here, we basically want the files to be called something like LOGGERnn.csv where nn is a number. By starting out trying to create LOGGER00.CSV and incrementing every time when the file already exists, until we get to LOGGER99.csv, we basically make a new file every time the Arduino starts up To create a file, we use some Unix style command flags which you can see in the logfile.open() procedure. FILE_WRITE means to create the file and write data to it. Assuming we managed to create a file successfully, we print out the name to the Serial port.”

[code lang=”C”] Wire.begin();
if (!RTC.begin()) {
logfile.println("RTC failed");
#if ECHO_TO_SERIAL
Serial.println("RTC failed");
#endif //ECHO_TO_SERIAL
}

logfile.println("millis,time,light,temp");
#if ECHO_TO_SERIAL
Serial.println("millis,time,light,temp");
#if ECHO_TO_SERIAL// attempt to write out the header to the file
if (logfile.writeError || !logfile.sync()) {
error("write header");
}

pinMode(redLEDpin, OUTPUT);
pinMode(greenLEDpin, OUTPUT);

// If you want to set the aref to something other than 5v
//analogReference(EXTERNAL);
}
[/code]

“OK we’re wrapping up here. Now we kick off the RTC by initializing the Wire library and poking the RTC to see if its alive. Then we print the header. The header is the first line of the file and helps your spreadsheet or math program identify whats coming up next. The data is in CSV (comma separated value) format so the header is too: “millis,time,light,temp” the first item millis is milliseconds since the Arduino started, time is the time and date from the RTC, light is the data from the CdS cell and temp is the temperature read. You’ll notice that right after each call to logfile.print() we have #if ECHO_TO_SERIAL and a matching Serial.print() call followed by a #if ECHO_TO_SERIAL this is that debugging output we mentioned earlier. The logfile.print() call is what writes data to our file on the SD card, it works pretty much the same as the Serial version. If you set ECHO_TO_SERIAL to be 0 up top, you won’t see the written data printed to the Serial terminal. Finally, we set the two LED pins to be outputs so we can use them to communicate with the user. There is a commented-out line where we set the analog reference voltage. This code assumes that you will be using the ‘default’ reference which is the VCC voltage for the chip – on a classic Arduino this is 5.0V. You can get better precision sometimes by lowering the reference. However we’re going to keep this simple for now! Later on, you may want to experiment with it.”

Main loop

Now we’re onto the loop, the loop basically does the following over and over:

  • Wait until its time for the next reading (say once a second – depends on what we defined)
  • Ask for the current time and date froom the RTC
  • Log the time and date to the SD card
  • Read the photocell and temperature sensor
  • Log those readings to the SD card
  • Sync data to the card if its time
[code lang=”C”] void loop(void)
{
DateTime now;

// delay for the amount of time we want between readings
delay((LOG_INTERVAL -1) – (millis() % LOG_INTERVAL));

digitalWrite(greenLEDpin, HIGH);

// log milliseconds since starting
uint32_t m = millis();
logfile.print(m); // milliseconds since start
logfile.print(", ");
#if ECHO_TO_SERIAL
Serial.print(m); // milliseconds since start
Serial.print(", ");
#endif

// fetch the time
now = RTC.now();
// log time
logfile.print(now.get()); // seconds since 2000
logfile.print(", ");
logfile.print(now.year(), DEC);
logfile.print("/");
logfile.print(now.month(), DEC);
logfile.print("/");
logfile.print(now.day(), DEC);
logfile.print(" ");
logfile.print(now.hour(), DEC);
logfile.print(":");
logfile.print(now.minute(), DEC);
logfile.print(":");
logfile.print(now.second(), DEC);
#if ECHO_TO_SERIAL
Serial.print(now.get()); // seconds since 2000
Serial.print(", ");
Serial.print(now.year(), DEC);
Serial.print("/");
Serial.print(now.month(), DEC);
Serial.print("/");
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.print(now.second(), DEC);
#endif //ECHO_TO_SERIAL
[/code]

  “The first important thing is the delay() call, this is what makes the Arduino wait around until its time to take another reading. If you recall we #defined the delay between readings to be 1000 millseconds (1 second). By having more delay between readings we can use less power and not fill the card as fast. Its basically a tradeoff how often you want to read data but for basic long term logging, taking data every second or so will result in plenty of data! Then we turn the green LED on, this is useful to tell us that yes we’re reading/writing data now. Next we call millis() to get the ‘time since arduino turned on’ and log that to the card. It can be handy to have – especially if you end up not using the RTC. Then the familiar RTC.now() call to get a snapshot of the time. Once we have that, we write a timestamp (seconods since 2000) as well as the date in YY/MM/DD HH:MM:SS time format which can easily be recognized by a spreadsheet. We have both because the nice thing about a timestamp is that its going to montonically increase and the nice thing about printed out date is its human readable.”

[/su_panel] [su_panel border=”3px solid #FF6666″ radius=”10″] https://learn.adafruit.com/adafruit-data-logger-shield?view=all :

Plotting with a spreadsheet

 

adafruit_products_dataselect.gifGambar 4.

 

Gambar 5.

[/su_panel] [su_panel border=”3px solid #00C700″ radius=”10″] https://learn.adafruit.com/adafruit-data-logger-shield?view=all :

Using Gnuplot

set xlabel "Time"              # set the lower X-axis label to 'time'

set xtics rotate by -270       # have the time-marks on their side


set ylabel "Light level (qualitative)"    # set the left Y-axis label

set ytics nomirror             # tics only on left side

set y2label "Temperature in Fahrenheit"   # set the right Y-axis label
set y2tics border              # put tics no right side

set key box top left           # legend box
set key box linestyle 0 

set xdata time                 # the x-axis is time
set format x "%H:%M:%S"        # display as time
set timefmt "%s"               # but read in as 'unix timestamp'

plot "LOGTEST.CSV" using 2:4 with lines title "Light levels" 
replot "LOGTEST.CSV" using 2:5 axes x1y2 with lines title "Temperature (F)"

adafruit_products_gnuplotcmd.gifGambar 6.

adafruit_products_gnuplotted.gifGambar 7.

[/su_panel] [su_panel border=”3px solid #990066″ radius=”10″]

https://learn.adafruit.com/adafruit-data-logger-shield?view=all :

adafruit_products_adafruitlogshieldsch.pngGambar 8.

Gambar 9.

Gambar 10.

Gambar 11.

Gambar 12.

[/su_panel]

 

Save

Save

Save

Save

LCD Nokia 5110 + sistem Arduino

[ [ images, codes & links ] ]
[su_panel border=”3px solid #482DE3″ radius=”10″]

The Nokia 5110 display has long been an Arduino Hobbyist favorite and a search of the internet will show that there are tons of different ways to drive this device.

There are a few varieties of this module are out there.   Mine are labeled as you see below.   Others should work just fine with this tutorial if you map your pins correctly.

Remember,  VCC is 3.3 Volts.   The LIGHT Control can use pulse width modulation through a 330 ohm resistor.

https://sunupradana.info/tkr/wp-content/uploads/2017/07/Nokia-5110-Pinouts.png

Gambar 1.

 

~Arduino Nokia 5110 with U8GLIB Tutorial

 

LCD Specifications

  • Controller: PCD8544
  • Supply: 2.7V to 3.3V
  • Interface levels: 2.7V to 5V
  • Backlight Colour: Blue
  • Backlight supply: 3.3V Max
  • Module size: W 43.6mm x H 43.1mm
  • Working current: < 200uA (Backlight off)

Notice that the module only needs 3.3v from the Arduino. More information can be found on the Datasheet located here.

nokiaGambar 2. [sumber]

lcdGambar 3. [sumber]

~hackshed.co.uk

Koneksi pada Gambar 3 hanya contoh, pin pada Arduino dapat diatur sesuai keperluan dan dukungan pustaka.

[/su_panel] [su_panel border=”3px solid #30C0F0″ radius=”10″]

Gambar 4.

 

Untuk penggunaan LCD Nokia 5110, salah satu pustaka yang bisa dipergunakan adalah u8glib (atau versi yang lebih baru u8g2). Sebagai contoh untuk uji coba, dapat diikuti kode program dari: henrysbench.capnfatz.com berikut:

// Henry's Bench
// Arduino Nokia 5110 U8Glib Tutorial


#include "U8glib.h"

 

#define backlight 11
 
//Delcare the display and assign the pins
 
//U8GLIB_PCD8544 u8g(8, 4, 7, 5, 6);  // CLK=8, DIN=4, CE=7, DC=5, RST=6
 
 
U8GLIB_PCD8544 u8g(8, 4, 7, 5, 6);  // CLK=8, DIN=4, CE=7, DC=5, RST=6

 
void draw() {
 
  u8g.setFont(u8g_font_profont11);  // select font
  u8g.drawStr(0, 15, "Nokia 5110..");  // put string of display at position X, Y
  u8g.drawStr(29, 35, "HELLO!!!!");
  
  
}
 
void setup() 
{
  // Set Backlight Intensity
  // 0 is Fully bright
  // 255 is off
  analogWrite(backlight, 20);
  //
  // Enter the U8Glib Picture Loop
  //
  
}
 
void loop() 
{ 
 u8g.firstPage(); 
  do 
  {
    draw();
  } while( u8g.nextPage() ); 
  
}
[/su_panel] [su_panel border=”3px solid #FF6666″ radius=”10″]

Salah satu pustaka/library yang umum dipergunakan untuk LCD Nokia 5110 adalah pustaka  yang dikeluarkan oleh Adafruit. Terdapat dua bagian pustaka untuk lcd ini, satu adalah untuk driver hardware dan satu untuk pustaka grafik.

Urutan pin LCD 5110 pada produk Adafruit bisa jadi tidak sama dengan urutan pin LCD 5110 yang bisa dibeli di pasaran lokal (impor dari China). Meskipun begitu, pustaka dapat dipergunakan dan berfungsi secara normal.

 

Testing

You can find our Nokia Display Arduino library on github. To install it, click this button to download the compressed ZIP file then install it. This guide will help you with the install process if you have never installed an Arduino library.

Then you’ll have to do the same for the Adafruit GFX Graphics core library, available from github. Click the button to download it. Then install Adafruit_GFX just like the library you’ve done except this time name it Adafruit_GFX, etc.

Restart the Arduino software. You should see a new example folder called Adafruit_PCD8544 and inside, an example called pcdtest. Open up that sketch and upload it to your Arduino. You should see the example test sequence.

Graphics Library

We have a ready to go basic graphics library that has primitives for bitmaps, shapes and text. You can probably do everything you want using it. Because of the way the display works we need to buffer the entire display in ram which is 84×48 bits (504 bytes). However, screen updates are very fast.

For more details about the Adafruit GFX library, please visit http://learn.adafruit.com/adafruit-gfx-graphics-library – it supports lines, rectangles, roundrects, circles, text of different sizes etc.

Note that since this display is MONOCHROMATIC it only supports two colors: BLACK or WHITE. BLACK is a displayed dot and WHITE is for erasing pixels

Dont forget, after drawing anything to the screen, call display() to write it out to the LCD!

Downloads

Our PCD8544 (Nokia 5110) LCD display Arduino library is on github which comes with example code. This library uses 1/2 Kbytes of RAM since it needs to buffer the entire display but its very fast! The code is simple to adapt to any other microcontroller.

You’ll also need to get the Adafruit GFX Graphics core library which can print text, bitmaps, pixels, rectangles, circles and lines, also available on github.

The PCD8544 datasheet tells you all about what the display can do.

~learn.adafruit.com

 

[/su_panel] [su_panel border=”3px solid #6C9C29″ radius=”10″]

https://raw.githubusercontent.com/wiki/olikraus/u8g2/img/uc1701_dogs102_uno_board_320.jpgGambar 5. [u8g2/wiki]

[/su_panel] [su_panel border=”3px solid #990066″ radius=”10″]
[/su_panel] [su_panel border=”3px solid #FF6666″ radius=”10″]

Library: LCD5110_Basic

[/su_panel] [su_panel border=”3px solid #D572FF” radius=”10″]

Library: LCD5110_Graph

 

[/su_panel] [su_panel border=”3px solid #30C0F0″ radius=”10″]

Videos >>
[/su_panel] [su_panel border=”3px solid #CE228C” radius=”10″]

[/su_panel]

 

Save

Save

Save

Save

Save

Save

Save

Save

Save

Save

Save

Save

Save

Belajar penggunaan LCD “Nokia 5110” di sistem Arduino [video]

[ [ videos ] ]
[su_panel border=”3px solid #30C0F0″ radius=”10″] [intense_tabs direction=”right” active_tab_background_color=”#000000″ active_tab_font_color=”#ffff00″ trigger=”click”] [intense_tab title=”Video01″ border=”3px solid #e8e8e8″ link_target=”_self” content_background_color=”#000000″ content_font_color=”#ffffff” icon_size=”1″ icon_position=”left”]

[/intense_tab] [intense_tab title=”Video02″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video03″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video04″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video05″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video06″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [/intense_tabs] [/su_panel] [su_panel border=”3px solid #FF6666″ radius=”10″] [intense_tabs direction=”right” active_tab_background_color=”#000000″ active_tab_font_color=”#ffff00″ trigger=”click”] [intense_tab title=”Video07″ border=”3px solid #e8e8e8″ link_target=”_self” content_background_color=”#000000″ content_font_color=”#ffffff” icon_size=”1″ icon_position=”left”]

[/intense_tab] [intense_tab title=”Video08″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video09″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video10″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video11″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video12″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [/intense_tabs] [/su_panel] [su_panel border=”3px solid #00C700″ radius=”10″] [intense_tabs direction=”right” active_tab_background_color=”#000000″ active_tab_font_color=”#ffff00″ trigger=”click”] [intense_tab title=”Video13″ border=”3px solid #e8e8e8″ link_target=”_self” content_background_color=”#000000″ content_font_color=”#ffffff” icon_size=”1″ icon_position=”left”]

[/intense_tab] [intense_tab title=”Video14″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video15″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [/intense_tabs] [/su_panel]