Sterowanie wyświetlaczem 4x20 I2C
#include<Wire.h>
#include<LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3,POSITIVE);
void setup()
{
lcd.begin(20,4);
lcd.print("Hello World!!!");
}
void loop()
{
}
Data logger
Schemat data loggera:
#include<Wire.h>
#include<LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3,POSITIVE);
#include<SPI.h>
#include<SD.h>
File outputFile;
#include"RTClib.h"
RTC_DS1307 RTC;
void stop()
{
for(;;){}
}
void setup()
{
char filename[13]="TEST.TXT";
lcd.begin(16,2);
if(!SD.begin(10))
{
lcd.print("SD card failed.");
stop();
}
else
lcd.print("SD card ok.");
delay(1000);
outputFile=SD.open(filename,FILE_WRITE);
lcd.clear();
if(!outputFile)
{
lcd.print("Can not open file!");
stop();
}
else
{
lcd.print("Output file:");
lcd.setCursor(0,1);
lcd.print(filename);
delay(1000);
}
outputFile.println("TEST");
outputFile.close();
lcd.clear();
Wire.begin();
RTC.begin();
if(!RTC.isrunning())
{
lcd.print("RTC failed.");
RTC.adjust(DateTime(__DATE__, __TIME__));
}
delay(1000);
lcd.clear();
if(!RTC.isrunning())
{
lcd.print("RTC failed.");
RTC.adjust(DateTime(__DATE__, __TIME__));
}
else
{
lcd.print("RTC set.");
}
delay(1000);
lcd.clear();
}
void loop()
{
lcd.setCursor(0,0);
DateTime now = RTC.now();
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.day(), DEC);
lcd.print(' ');
lcd.setCursor(0,1);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
lcd.print(' ');
delay(500);
}
Mega2560:
Połączyć: A4 - D20(SDA), A5 - D21(SCL)
W plikach /usr/share/arduino/libraries/SD/src/utility/Sd2Card.h i
/usr/share/arduino/libraries/SD/src/utility/Sd2Card.cpp
umieścić definicje:
#define SOFTWARE_SPI
#undef USE_SPI_LIB 1
Problemy z RS232
killall avrdude_bin
Linux: uprawnienia użytkownika
W pliku:
/dev/udev/rules.d/50-udev.rules
umieścić zapis:
KERNEL=="ttyACM[0-9]*", OWNER="username", MODE="0666"
Błędy
"Whenever i have string in my sketch which has threee marksigns in a
string (eg: "!!!"), my sketch will make the Mega2560 timeout when
uploading [...]: stk500v2_ReceiveMessage(): timeout.", deajan,
http://forum.arduino.cc/index.php?topic=83079.15
Arduino DUE LCD
"Edit LiquidCrystal.cpp and add these lines after the inttypes.h
include:
#undef digitalPinToTimer #define digitalPinToTimer(_p) NOT_ON_TIMERArduino DUE SD