Hi guys.
the point of this project is to create automatic fertilizer dozer.
I use a RTC, because i don't want it to "reset" if the power goes out, and I can check everytime when was the last "deliver".
I'm using the touch screen so i can add features later,
the thing is, when I use everything but the motor shield everything go as planed, if I stack the touch shield on the motor shield the RTC doesn't work anymore. (haven't tested the motors yet)
I'm thinking this as something to the common use of SDA and SCL, but really I don't have a clue.
( I use different tabs just to keep everything organized, because I plan for this code to grow a lot)
I got this motor shield because it says "Only two GPIO pins (SDA & SCL) plus 5v and GND. are required to drive the multiple motors, and since it's I2C you can also connect any other I2C devices or shields to the same pins." and I knew the RTC used SDA & SCL too.
Any advice?
thanks in advance,
datasheets/schematics:
RTC module:
RTC module datasheet
DS3231SN schematics
here's my code:
main tab
//MOTOR CONTROL
//include adafruit motor library
#include <AFMotor.h>
//define motor (pin)
AF_DCMotor motor(1);
//RTC
//include DS3231 (RTC) library
#include <DS3231.h>
// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL);
//rtc power pin
const int vcc_rtc = 53;
//TOUCH Screen
#include <Adafruit_TFTLCD.h>
#include <Adafruit_GFX.h>
#include <TouchScreen.h>
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
//caliration
#define TS_MINX 190
#define TS_MINY 163
#define TS_MAXX 950
#define TS_MAXY 902
#define YP A2 // must be an analog pin, use "An" notation!
#define XM A3 // must be an analog pin, use "An" notation!
#define YM 8 // can be a digital pin
#define XP 9 // can be a digital pin
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
boolean buttonEnabled = true;
void setup() {
//power RTC (because it was easier)
pinMode(vcc_rtc, OUTPUT);
digitalWrite(vcc_rtc, HIGH);
// Setup Serial connection
Serial.begin(9600);
Serial.print("Starting...");
// Initialize the rtc object
rtc.begin();
// The following lines can be uncommented to set the date and time
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(1, 1, 2014); // Set the date to January 1st, 2014
//SCREEN
tft.reset();
tft.begin(0x9325);
tft.setRotation(1);
tft.fillScreen(BLACK);
//Draw white frame
tft.drawRect(0,0,319,240,WHITE);
//Print "Hello" Text
tft.setCursor(100,30);
tft.setTextColor(WHITE);
tft.setTextSize(4);
tft.print("Hello");
//Print "USER!" text
tft.setCursor(80,100);
tft.setTextColor(RED);
tft.setTextSize(4);
tft.print("User!");
//Create Red Button
tft.fillRect(60,180, 200, 40, RED);
tft.drawRect(60,180,200,40,WHITE);
tft.setCursor(80,188);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("Tell me the time!");
}
void loop() {
screen_content();
}
RTC tab
void rtc_show() {
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.print(rtc.getTimeStr());
Serial.print(" -- ");
//send temp
Serial.print(rtc.getTemp());
Serial.println(" C ");
//wait 1 second to show again
delay (1000);
}
Motors tab
void move_motor () {
//this motor only works between 210 and the top speed (255)
motor.setSpeed(255);
motor.run(FORWARD);
// motor.run(BACKWARD);
delay(1000);
motor.run(RELEASE);
delay(1000);
}
Screen tab
void screen_content ()
{
TSPoint p = ts.getPoint(); //Get touch point
if (p.z > ts.pressureThreshhold) {
Serial.print("X = "); Serial.print(p.x);
Serial.print("\tY = "); Serial.print(p.y);
Serial.print("\n");
//convert values to pixels
p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320);
p.y = map(p.y, TS_MAXY, TS_MINY, 0, 240);
if(p.x>60 && p.x<260 && p.y>180 && p.y<220 && buttonEnabled)// The user has pressed inside the red rectangle
{
buttonEnabled = false; //Disable button
//This is important, because the libraries are sharing pins
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
//Erase the screen
tft.fillScreen(BLACK);
//Draw frame
tft.drawRect(0,0,319,240,WHITE);
tft.setCursor(50,50);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print(rtc.getTimeStr());
rtc_show();
}
delay(10);
}
}
main.ino (2.27 KB)
motores.ino (256 Bytes)
RTC.ino (369 Bytes)
screen.ino (917 Bytes)