มีปัญหาเรื่องการใช้งาน ปรึกษาได้ที่เว็บบอร์ดนี้เลยครับ
ArduinoAll มีสินค้าหลายชนิด ผมอาจจะยังเล่นไม่หมด ต้องขออภัยมาไว้ล่วงหน้าครับผมจะพยายามช่วยแนะนำเท่าที่มีความรู้ ถ้ายังทำไม่เป็นก็จะพยายามหามาให้ ช่วย ๆ กันน่าจะทำออกได้ไว
แบบนี้แสดงว่าติดต่อบอร์ดไม่ได้ เกิดจากต่อวงจรผิด หรือตั้งค่าผิด
เช็คว่า arduino uno ทำเป็นเครื่องโปรแกรมแล้ว โดยอัพโหลดโปรแกรม arduinoISP ลงบอร์ด arduino ก่อน
แล้วเลือกเครื่องโปรแกรม Programmer เป็น arduinoISP หรือ arduino as ISP ครับ
ดูไม่ได้ โคดในโปรแกรม Arduino จะถูกคอมไพล์แปลงเป็นภาษาเครื่อง
ไฟล์ที่อยู่ใน Arduino Uno เป็นไฟล์ .HEX มีค่าเป็นเลข 0 หรือ 1 เท่านั้นครับ
พี่ค่ะช่วยดูโค้ดให้ทีค่ะพี่ แสดงเวลาเเล้ว สามารถตั้งเวลาได้ เเต่เมื่อ#อีกครั้งมัน มันบันทึกเวลา เเต่กลับเลือนCursorไปอีกบรรทัด ช่วยเเนะนำทีค่ะพี่
#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
int Buzzer = 11;
int LOAD = A0;
//------------ Key Pad ----------------------
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {8, 7, 6 , 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
//------------ LCD ----------------------------------
LiquidCrystal_I2C lcd(0x27,20,4);// PCF8574A = 0x3F
// ----------- DS3231 -------------------------------
RTC_DS3231 RTC;
DateTime Time;
char Year,Mon,Day,Hour,Min,Sec;
long TimerON,TimerOFF;
/*-------------------------------------------------------------*
* Setup Program *
*-------------------------------------------------------------*/
void setup ()
{
lcd.begin();
lcd.setCursor(0,0);lcd.print("TimeON = ");
lcd.setCursor(0,1);lcd.print("TimeOFF = ");
lcd.setCursor(0,2);lcd.print("Date = ");
lcd.setCursor(0,3);lcd.print("Time = ");
RTC.begin();
pinMode(Buzzer,OUTPUT); digitalWrite(Buzzer,HIGH);
pinMode(LOAD,OUTPUT); digitalWrite(LOAD,HIGH);
}
/*-------------------------------------------------------------*
* Main Loop *
*-------------------------------------------------------------*/
void loop ()
{char Key;
while(Key == NO_KEY)
{
Time = RTC.now();
ShowDate(13,3);
ShowTime(13,4);
CheckTime();
Key = keypad.getKey();
}
Beep();
if(Key == '1')
{ GetDate(13,3);
GetTime(13,4);
RTC.adjust(DateTime(Year,Mon,Day,Hour,Min,Sec));
}
if(Key == '2')
{
GetTime(13,1);
TimerON = Hour;
TimerON = (TimerON << 8) + Min;
TimerON = (TimerON << 8) + Sec;
GetTime(13,2);
TimerOFF = Hour;
TimerOFF = (TimerOFF << 8) + Min;
TimerOFF = (TimerOFF << 8) + Sec;
}
}
/*-------------------------------------------------------------*
* Show Time *
*-------------------------------------------------------------*/
void CheckTime()
{ long Timer;
Timer = 0;
Timer = (Timer << 8)+Time.hour();
Timer = (Timer << 8)+Time.minute();
Timer = (Timer << 8)+Time.second();
if(Timer == TimerON){digitalWrite(LOAD,LOW);}
if(Timer == TimerOFF){digitalWrite(LOAD,HIGH);}
}
/*-------------------------------------------------------------*
* Show Time *
*-------------------------------------------------------------*/
void ShowTime(char X,char Y)
{ lcd.setCursor(X-1,Y-1);
if(Time.hour() < 10){lcd.print(0);}
lcd.print(Time.hour());
lcd.print(':');
if(Time.minute() < 10){lcd.print(0);}
lcd.print(Time.minute());
lcd.print(':');
if(Time.second() < 10){lcd.print(0);}
lcd.print(Time.second());
}
/*-------------------------------------------------------------*
* Show Date *
*-------------------------------------------------------------*/
void ShowDate(char X,char Y)
{ lcd.setCursor(X-1,Y-1);
if(Time.day() < 10){lcd.print(0);}
lcd.print(Time.day());
lcd.print('/');
if(Time.month() < 10){lcd.print(0);}
lcd.print(Time.month());
lcd.print('/');
if(Time.year()%100 < 10){lcd.print(0);}
lcd.print(Time.year()%100);
}
/*-------------------------------------------------------------*
* Get Date From Key *
*-------------------------------------------------------------*/
void GetDate(char X,char Y)
{
ShowDate(X,Y);
Day = GetNum(2,X,Y);
Mon = GetNum(2,X+3,Y);
Year = GetNum(2,X+6,Y);
}
/*-------------------------------------------------------------*
* Get Time From Key *
*-------------------------------------------------------------*/
void GetTime(char X,char Y)
{
ShowTime(X,Y);
Hour = GetNum(2,X,Y);
Min = GetNum(2,X+3,Y);
Sec = GetNum(2,X+6,Y);
}
/*-------------------------------------------------------------*
* Slide Number *
*-------------------------------------------------------------*/
char BufNum[8];
void SlideNum(void)
{
BufNum[6] = BufNum[5];
BufNum[5] = BufNum[4];
BufNum[4] = BufNum[3];
BufNum[3] = BufNum[2];
BufNum[2] = BufNum[1];
BufNum[1] = BufNum[0];
}
/*-------------------------------------------------------------*
* Get Number From Keypad *
*-------------------------------------------------------------*/
unsigned long GetNum(int Count,int X,int Y)
{ char Key,i,N;
int Sum;
lcd.blink();
lcd.setCursor(X+(Count-2),Y-1);
N = 0;
for(i=0;i<Count;i++){BufNum[i] = ' ';}
i = 0;
while(Key != '#')
{ Key = NO_KEY;
while(Key == NO_KEY){Key = keypad.getKey();}
Beep(); delay(300);
if(Key == '*'){for(i=0;i<Count;i++){BufNum[i] = ' ';}N = 0;}
if((N < Count)&&(Key >= '0')&&(Key <= '9'))
{ SlideNum();
BufNum[0] = Key;
N++;
}
lcd.setCursor(X-1,Y-1);
for(i=0;i<Count;i++){lcd.print(BufNum[Count-(i+1)]);}
lcd.setCursor(X+(Count-2),Y-1);
}
Sum = 0;
for(i=0;i<Count;i++)
{
if(BufNum[Count-(i+1)]==0x20){BufNum[Count-(i+1)] = '0';}
Sum = (Sum*10) + (BufNum[Count-(i+1)]-'0');
}
lcd.noCursor();
lcd.noBlink();
return(Sum);
}
/*-------------------------------------------------------------*
* Beep Sound *
*-------------------------------------------------------------*/
void Beep()
{
digitalWrite(Buzzer,LOW);delay(50);
digitalWrite(Buzzer,HIGH);
}
ต้องลองดีบั๊กทีละจุด เพื่อหาจุดที่ผิด ตามที่ออกแบบไว้ ฝึกอ่านโคดจะได้ทำเข้าใจมากขึ้นครับ
สั่งน่าจอ lcd16x4 แบบเเยก i2c เเต่พอเบรินโปรเเกรมเเล้ว บรรทัดที่3กับ4
5ตัวเเรกตัวอักษรไม่ขึ้นตัวหนังสือ ตัวถัดไปขึ้นปกติ เเต่จ่ายไฟเข้าก่อนเบรินโปรเเกรมมีเเทบขาวขึ้นปกติ แบบนี้หน้าจอเสียรึเปล่าค่ะ สั่งมานานเเล้ว เเต่พึ่งเริ่มทำโปรเจค
ที่ร้านไม่มีจอ lcd 16x4 จำหน่าย มีแต่ขนาด 20x4
ได้ซื้อกับที่ร้าน ArduinoAll หรือเปล่าขอเลขที่สั่งซื้อด้วยครับ
ถ้าซ์้อกับที่ร้าน ArduinoAll จอ LCD ทดสอบให้แบบละเอียดระดับ pixel ทุกจุดก่อนส่ง ต้องใช้ได้ทุกชิ้นครับ
ซื้อจากทางร้านค่ะ lcd1604 module16x4 สั่งมาสักพักเเต่พึ่งใช้งานค่ะ
เลขสั่งซื้อ109802
หนูสั่งของเเค่เวป Arduinoall เวปเดียวค่ะ
ทุกครั้งสั่งของไปก็ไม่มีปัญหาอะไร
หนูเลยเเค่สงสัยว่ามันเกิดจากที่หนูบัดกรีใส่I2Cรึเปล่า
ถ้าซ์้อกับที่ร้าน ต้องใช้งานได้ทุกชิ้นครับ
จอทางร้านตรวจสอบให้แล้วก่อนส่ง การบัดกรีก็ไม่น่าจะมีปัญหา
สาเหตุที่พบบ่อย คืออ้างอิง address i2c ไม่ถูกต้อง ลองใช้โปรแกรม scand i2c https://playground.arduino.cc/Main/I2cScanner เช็คตำแหน่ง address แล้วอ้างอิงในโคดให้ถูกต้องครับ
แต่ในนี้แจ้งว่าขึ้นตัวอักษร แสดงว่าอ้างอิง Address ถูกต้อง และจอทำงานแสดงผลได้แล้ว แสดงว่าสาเหตุมาจากโคดโปรแกรม
จากโคดนี้ LiquidCrystal_I2C lcd(0x27,20,4);// PCF8574A = 0x3F
กำหนดจอเป็นขนาด 20x4 ซึ่งที่ใช้คือ 16x4 เช็คที่โคดนี้ครับ