Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara mengakses GLCD ST7920 dengan Arduino yang digunakan untuk menampilkan nilai dari nilai frekuensi dan intensitas suaranya, alat ini bertujuan untuk audiometri yaitu alat ukur untuk mendeteksi apakah pasien menderita penyakit pada pendengarannya ataukah tidak, alat ini memiliki fitur bisa merubah frekuensi dari 250 Hz sampai 8000 Hz. penampil yang digunakan adalah GLCD ST7920. sensor intensitas suara yang dipakai bisa FC04 atau sensor suara yang lain yang umum digunakan untuk Arduino. untuk lebih jelasnya berikut adalah program dan skemanya.
a. Arduino Mega
b. GLCD ST7920
c. Sensor Suara
d. Headset
e. Program Arduino TEST GLCD
#include "U8glib.h"
//Utilize a linha abaixo para utilizar a comunicacao serial
//(Enable, RW, RS, RESET)
//U8GLIB_ST7920_128X64_1X u8g(2, 3, 4 ,5);
//Utilize a linha abaixo para utilizar a comunicacao paralela (8 bits)
//(d0, d1, d2, d3, d4, d5, d6, d7, en, di, rw, reset)
U8GLIB_ST7920_128X64_1X u8g(6, 7, 8, 9, 10, 11, 12, 13, 2, 4, 3, 5);
int display = 1;
void u8g_prepare()
{
u8g.setFont(u8g_font_6x10);
u8g.setFontRefHeightExtendedText();
u8g.setDefaultForegroundColor();
u8g.setFontPosTop();
}
void u8g_Tela1() //Tela 1 - Arduino e Cia - Retangulos
{
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 11, 35, "YANUAR M");
u8g.drawStr( 12, 35, "YANUAR M");
u8g.drawFrame(0,0,128,64);
u8g.drawFrame(2,2,124,60);
}
void u8g_Tela2() //Tela 2 - Linhas horizontais e verticais
{
for (int i = 0; i<127 ; i=i+2)
{
u8g.drawLine(i,0,i,64);
}
for (int c = 0; c<64 ; c=c+2)
{
u8g.drawLine(0,c,128,c);
}
}
void u8g_Tela3() //Tela 3 - Arduino e Cia - Retangulo preenchido
{
u8g.setFont(u8g_font_unifont);
u8g.drawBox(0,0,128,64);
u8g.drawBox(2,2,124,60);
u8g.setColorIndex(0);
u8g.drawStr( 11, 35, "YANUAR M");
u8g.drawStr( 12, 35, "YANUAR M");
u8g.drawFrame(2,2,124,60);
}
void draw() //Rotina Desenho
{
u8g_prepare();
switch(display) //Carrega a tela correspondente
{
case 1:
u8g_Tela1();
break;
case 2:
u8g_Tela2();
break;
case 3:
u8g_Tela3();
break;
}
}
void setup()
{
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 )
u8g.setColorIndex(255); // white
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
u8g.setColorIndex(1); // max intensity
else if ( u8g.getMode() == U8G_MODE_BW )
u8g.setColorIndex(1); // pixel on
}
void loop()
{
for (display =1; display < 4; display++)
{
u8g.firstPage();
do
{
draw();
}
while( u8g.nextPage() );
delay(3000);
}
}
//Utilize a linha abaixo para utilizar a comunicacao serial
//(Enable, RW, RS, RESET)
//U8GLIB_ST7920_128X64_1X u8g(2, 3, 4 ,5);
//Utilize a linha abaixo para utilizar a comunicacao paralela (8 bits)
//(d0, d1, d2, d3, d4, d5, d6, d7, en, di, rw, reset)
U8GLIB_ST7920_128X64_1X u8g(6, 7, 8, 9, 10, 11, 12, 13, 2, 4, 3, 5);
int display = 1;
void u8g_prepare()
{
u8g.setFont(u8g_font_6x10);
u8g.setFontRefHeightExtendedText();
u8g.setDefaultForegroundColor();
u8g.setFontPosTop();
}
void u8g_Tela1() //Tela 1 - Arduino e Cia - Retangulos
{
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 11, 35, "YANUAR M");
u8g.drawStr( 12, 35, "YANUAR M");
u8g.drawFrame(0,0,128,64);
u8g.drawFrame(2,2,124,60);
}
void u8g_Tela2() //Tela 2 - Linhas horizontais e verticais
{
for (int i = 0; i<127 ; i=i+2)
{
u8g.drawLine(i,0,i,64);
}
for (int c = 0; c<64 ; c=c+2)
{
u8g.drawLine(0,c,128,c);
}
}
void u8g_Tela3() //Tela 3 - Arduino e Cia - Retangulo preenchido
{
u8g.setFont(u8g_font_unifont);
u8g.drawBox(0,0,128,64);
u8g.drawBox(2,2,124,60);
u8g.setColorIndex(0);
u8g.drawStr( 11, 35, "YANUAR M");
u8g.drawStr( 12, 35, "YANUAR M");
u8g.drawFrame(2,2,124,60);
}
void draw() //Rotina Desenho
{
u8g_prepare();
switch(display) //Carrega a tela correspondente
{
case 1:
u8g_Tela1();
break;
case 2:
u8g_Tela2();
break;
case 3:
u8g_Tela3();
break;
}
}
void setup()
{
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 )
u8g.setColorIndex(255); // white
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
u8g.setColorIndex(1); // max intensity
else if ( u8g.getMode() == U8G_MODE_BW )
u8g.setColorIndex(1); // pixel on
}
void loop()
{
for (display =1; display < 4; display++)
{
u8g.firstPage();
do
{
draw();
}
while( u8g.nextPage() );
delay(3000);
}
}
f. Program Arduino Audiometri
#include "U8glib.h"
#include <PWM.h>
//Utilize a linha abaixo para utilizar a comunicacao serial
//(Enable, RW, RS, RESET)
//U8GLIB_ST7920_128X64_1X u8g(2, 3, 4 ,5);
//Utilize a linha abaixo para utilizar a comunicacao paralela (8 bits)
//(d0, d1, d2, d3, d4, d5, d6, d7, en, di, rw, reset)
U8GLIB_ST7920_128X64_1X u8g(6, 7, 8, 9, 10, 11, 12, 13, 2, 4, 3, 5);
int display = 1;
char tmp_string[8];
char tmp_string2[8];
int dataadc;
int pwmpin = 46;
int duty = 125; // nilai duty cycle
int button;
int frek = 150;
void draw()
{
//konversi ke string
//dtostrf(dataadc, 4, 2, tmp_string);
itoa(dataadc,tmp_string,8);
itoa(frek,tmp_string2,8);
//pilih font
u8g.setFont(u8g_font_u8glib_4);
//u8g.setFont(u8g_font_profont11);
//u8g.setFont(u8g_font_unifont);
//x,y
u8g.drawStr( 0, 4, "FREK= ");
u8g.drawStr( 27, 4, tmp_string2);
u8g.drawStr( 0, 10, "DB= ");
u8g.drawStr( 27, 10, tmp_string);
}
void setup()
{
pinMode(14,INPUT);
digitalWrite(14,HIGH);
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 )
u8g.setColorIndex(255); // white
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
u8g.setColorIndex(1); // max intensity
else if ( u8g.getMode() == U8G_MODE_BW )
u8g.setColorIndex(1); // pixel on
}
void loop()
{
dataadc = analogRead(A0);
int32_t frequency = 0; //frequency (in Hz)
InitTimersSafe();
bool success = SetPinFrequencySafe(pwmpin, 0);
//bool success = SetPinFrequencySafe(pwmpin, frek);
pwmWrite(pwmpin, 0);
button = digitalRead(14);
if(button == 0){
delay(200);
frek = frek + 10;
int32_t frequency = frek; //frequency (in Hz)
InitTimersSafe();
bool success = SetPinFrequencySafe(pwmpin, frequency);
//bool success = SetPinFrequencySafe(pwmpin, frek);
pwmWrite(pwmpin, duty);
delay(20);
}
u8g.firstPage();
do
{
draw();
}
while( u8g.nextPage() );
delay(200);
}
#include <PWM.h>
//Utilize a linha abaixo para utilizar a comunicacao serial
//(Enable, RW, RS, RESET)
//U8GLIB_ST7920_128X64_1X u8g(2, 3, 4 ,5);
//Utilize a linha abaixo para utilizar a comunicacao paralela (8 bits)
//(d0, d1, d2, d3, d4, d5, d6, d7, en, di, rw, reset)
U8GLIB_ST7920_128X64_1X u8g(6, 7, 8, 9, 10, 11, 12, 13, 2, 4, 3, 5);
int display = 1;
char tmp_string[8];
char tmp_string2[8];
int dataadc;
int pwmpin = 46;
int duty = 125; // nilai duty cycle
int button;
int frek = 150;
void draw()
{
//konversi ke string
//dtostrf(dataadc, 4, 2, tmp_string);
itoa(dataadc,tmp_string,8);
itoa(frek,tmp_string2,8);
//pilih font
u8g.setFont(u8g_font_u8glib_4);
//u8g.setFont(u8g_font_profont11);
//u8g.setFont(u8g_font_unifont);
//x,y
u8g.drawStr( 0, 4, "FREK= ");
u8g.drawStr( 27, 4, tmp_string2);
u8g.drawStr( 0, 10, "DB= ");
u8g.drawStr( 27, 10, tmp_string);
}
void setup()
{
pinMode(14,INPUT);
digitalWrite(14,HIGH);
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 )
u8g.setColorIndex(255); // white
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
u8g.setColorIndex(1); // max intensity
else if ( u8g.getMode() == U8G_MODE_BW )
u8g.setColorIndex(1); // pixel on
}
void loop()
{
dataadc = analogRead(A0);
int32_t frequency = 0; //frequency (in Hz)
InitTimersSafe();
bool success = SetPinFrequencySafe(pwmpin, 0);
//bool success = SetPinFrequencySafe(pwmpin, frek);
pwmWrite(pwmpin, 0);
button = digitalRead(14);
if(button == 0){
delay(200);
frek = frek + 10;
int32_t frequency = frek; //frequency (in Hz)
InitTimersSafe();
bool success = SetPinFrequencySafe(pwmpin, frequency);
//bool success = SetPinFrequencySafe(pwmpin, frek);
pwmWrite(pwmpin, duty);
delay(20);
}
u8g.firstPage();
do
{
draw();
}
while( u8g.nextPage() );
delay(200);
}
g. Program Versi baru
// program ini menggunakan tombol sebagai SAVE atau menyimpan data
// jadi saat pasien mendengarkan bunyi maka akan menekan tombol
// jika tidak terdengar maka jangan tekan tombol
// pada tampilan akhir akan muncul frekuensi yang didengar pada GLCD
// dan tidak akan menampilkan frekuensi yang tidak didengar pada GLCD
// frekuensi bisa dirubah sesuai selera
#include "U8glib.h"
#include <PWM.h>
//Utilize a linha abaixo para utilizar a comunicacao serial
//(Enable, RW, RS, RESET)
//U8GLIB_ST7920_128X64_1X u8g(2, 3, 4 ,5);
//Utilize a linha abaixo para utilizar a comunicacao paralela (8 bits)
//(d0, d1, d2, d3, d4, d5, d6, d7, en, di, rw, reset)
U8GLIB_ST7920_128X64_1X u8g(6, 7, 8, 9, 10, 11, 12, 13, 2, 4, 3, 5);
int go = 1;
int display = 1;
char tmp_string[8];
char tmp_string2[8];
int dataadc;
int pwmpin = 46;
int duty = 125; // nilai duty cycle
int button;
int frek = 150;
int i;
int ax = 0;
int bx = 0;
int cx = 0;
int dx = 0;
int ex = 0;
int fx = 0;
int gx = 0;
int hx = 0;
int ix = 0;
int jx = 0;
void draw()
{
//konversi ke string
//dtostrf(dataadc, 4, 2, tmp_string);
itoa(dataadc,tmp_string,8);
itoa(frek,tmp_string2,8);
//pilih font
u8g.setFont(u8g_font_u8glib_4);
//u8g.setFont(u8g_font_profont11);
//u8g.setFont(u8g_font_unifont);
//x,y
// u8g.drawStr( 27, 4, tmp_string2);
// u8g.drawStr( 0, 10, "DB= ");
// u8g.drawStr( 27, 10, tmp_string);
if(ax == 1){
u8g.drawStr( 0, 4, "FREK= 250");
}
if(bx == 1){
u8g.drawStr( 0, 10, "FREK= 500");
}
if(cx == 1){
u8g.drawStr( 0, 16, "FREK= 1000");
}
if(dx == 1){
u8g.drawStr( 0, 22, "FREK= 2000");
}
if(ex == 1){
u8g.drawStr( 0, 28, "FREK= 3000");
}
if(fx == 1){
u8g.drawStr( 0, 34, "FREK= 4000");
}
if(gx == 1){
u8g.drawStr( 0, 40, "FREK= 5000");
}
if(hx == 1){
u8g.drawStr( 0, 46, "FREK= 6000");
}
if(ix == 1){
u8g.drawStr( 0, 52, "FREK= 7000");
}
if(jx == 1){
u8g.drawStr( 0, 58, "FREK= 8000");
}
delay(1000);
if(go == 1){
step1();
step2();
step3();
step4();
step5();
step6();
step7();
step8();
step9();
step10();
}
}
void setup()
{
pinMode(14,INPUT);
digitalWrite(14,HIGH);
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 )
u8g.setColorIndex(255); // white
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
u8g.setColorIndex(1); // max intensity
else if ( u8g.getMode() == U8G_MODE_BW )
u8g.setColorIndex(1); // pixel on
}
void loop()
{
u8g.firstPage();
do
{
draw();
}
while( u8g.nextPage() );
delay(200);
}
void step1(){
int32_t frequency = 250; //frequency (in Hz)
InitTimersSafe();
bool success = SetPinFrequencySafe(pwmpin, frequency);
pwmWrite(pwmpin, duty);
delay(20);
frequency = 0; //frequency (in Hz)
InitTimersSafe();
// bool success = SetPinFrequencySafe(pwmpin, 0);
pwmWrite(pwmpin, 0);
for(i=0;i<100;i++){
button = digitalRead(14);
if(button == 0){
ax = 1;
}
delay(30);
}
return;
}
void step2(){
int32_t frequency = 500; //frequency (in Hz)
InitTimersSafe();
bool success = SetPinFrequencySafe(pwmpin, frequency);
pwmWrite(pwmpin, duty);
delay(20);
frequency = 0; //frequency (in Hz)
InitTimersSafe();
// bool success = SetPinFrequencySafe(pwmpin, 0);
pwmWrite(pwmpin, 0);
for(i=0;i<100;i++){
button = digitalRead(14);
if(button == 0){
bx = 1;
}
delay(30);
}
return;
}
void step3(){
int32_t frequency = 1000; //frequency (in Hz)
InitTimersSafe();
bool success = SetPinFrequencySafe(pwmpin, frequency);
pwmWrite(pwmpin, duty);
delay(20);
frequency = 0; //frequency (in Hz)
InitTimersSafe();
//bool success = SetPinFrequencySafe(pwmpin, 0);
pwmWrite(pwmpin, 0);
for(i=0;i<100;i++){
button = digitalRead(14);
if(button == 0){
cx = 1;
}
delay(30);
}
return;
}
void step4(){
int32_t frequency = 2000; //frequency (in Hz)
InitTimersSafe();
bool success = SetPinFrequencySafe(pwmpin, frequency);
pwmWrite(pwmpin, duty);
delay(20);
frequency = 0; //frequency (in Hz)
InitTimersSafe();
// bool success = SetPinFrequencySafe(pwmpin, 0);
pwmWrite(pwmpin, 0);
for(i=0;i<100;i++){
button = digitalRead(14);
if(button == 0){
dx = 1;
}
delay(30);
}
return;
}
void step5(){
int32_t frequency = 3000; //frequency (in Hz)
InitTimersSafe();
bool success = SetPinFrequencySafe(pwmpin, frequency);
pwmWrite(pwmpin, duty);
delay(20);
frequency = 0; //frequency (in Hz)
InitTimersSafe();
// bool success = SetPinFrequencySafe(pwmpin, 0);
pwmWrite(pwmpin, 0);
for(i=0;i<100;i++){
button = digitalRead(14);
if(button == 0){
ex = 1;
}
delay(30);
}
return;
}
void step6(){
int32_t frequency = 4000; //frequency (in Hz)
InitTimersSafe();
bool success = SetPinFrequencySafe(pwmpin, frequency);
pwmWrite(pwmpin, duty);
delay(20);
frequency = 0; //frequency (in Hz)
InitTimersSafe();
// bool success = SetPinFrequencySafe(pwmpin, 0);
pwmWrite(pwmpin, 0);
for(i=0;i<100;i++){
button = digitalRead(14);
if(button == 0){
fx = 1;
}
delay(30);
}
return;
}
void step7(){
int32_t frequency = 5000; //frequency (in Hz)
InitTimersSafe();
bool success = SetPinFrequencySafe(pwmpin, frequency);
pwmWrite(pwmpin, duty);
delay(20);
frequency = 0; //frequency (in Hz)
InitTimersSafe();
// bool success = SetPinFrequencySafe(pwmpin, 0);
pwmWrite(pwmpin, 0);
for(i=0;i<100;i++){
button = digitalRead(14);
if(button == 0){
gx = 1;
}
delay(30);
}
return;
}
void step8(){
int32_t frequency = 6000; //frequency (in Hz)
InitTimersSafe();
bool success = SetPinFrequencySafe(pwmpin, frequency);
pwmWrite(pwmpin, duty);
delay(20);
frequency = 0; //frequency (in Hz)
InitTimersSafe();
// bool success = SetPinFrequencySafe(pwmpin, 0);
pwmWrite(pwmpin, 0);
for(i=0;i<100;i++){
button = digitalRead(14);
if(button == 0){
hx = 1;
}
delay(30);
}
return;
}
void step9(){
int32_t frequency = 7000; //frequency (in Hz)
InitTimersSafe();
bool success = SetPinFrequencySafe(pwmpin, frequency);
pwmWrite(pwmpin, duty);
delay(20);
frequency = 0; //frequency (in Hz)
InitTimersSafe();
// bool success = SetPinFrequencySafe(pwmpin, 0);
pwmWrite(pwmpin, 0);
for(i=0;i<100;i++){
button = digitalRead(14);
if(button == 0){
ix = 1;
}
delay(30);
}
return;
}
void step10(){
int32_t frequency = 8000; //frequency (in Hz)
InitTimersSafe();
bool success = SetPinFrequencySafe(pwmpin, frequency);
pwmWrite(pwmpin, duty);
delay(20);
frequency = 0; //frequency (in Hz)
InitTimersSafe();
// bool success = SetPinFrequencySafe(pwmpin, 0);
pwmWrite(pwmpin, 0);
for(i=0;i<100;i++){
button = digitalRead(14);
if(button == 0){
jx = 1;
}
delay(30);
}
go = 2;
return;
}
h. VIDEO HASILNYA
No comments:
Post a Comment