Arduino

Przebiegi na wyjściu PWM


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()
{
}

Podstawowe polecenia: lcd.on(); lcd.off(); lcd.clear(); lcd.home(); lcd.setCursor(0,1);


Data logger

Schemat data loggera:


Progam testujący zapis na karcie SD i zegar czasu rzeczywistego:


#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_TIMER
Arduino DUE SD
"Use Adafruit SD library."

"On the Uno, the SPI pins are hardwired to both the ICSP header and the 11-12-13 digital pins. The Due has a lot more pins so it isn't wired the same way. The SPI pins are only available on the ICSP header.
Two things to be aware of:
1. The 5v line in the ICSP header is an historical artifact. Don't use that to power your SD card or any other SPI device which talks to the Due. That could put 5v on the Due input pins which will destroy them.
2. You will still need a CS (card-select) line, chosen from any of the other digital outputs on the Due."




http://www.skalgo.5v.pl