Go Down

Topic: LCD problem with 1280 mega vs 328 mega- code query (Read 1 time) previous topic - next topic

Onsan

Oct 20, 2010, 01:12 pm Last Edit: Oct 20, 2010, 01:13 pm by Onsan Reason: 1
Hi to the Collective!

My board is a 1280 mega and I'm trying to make use of a code from reef projects http://reefprojects.com/w/phpBB3/viewtopic.php?f=8&t=298, i believe the code is written for the 328 mega and i think the issue i'm having is something to do with which pins are assigned to the LCD screen.
I can get the standard Hello world code to work on the screen when i use th SDA and SCL ports, but not on the code from reefprojects.

I've tried using analog pins 4 & 5 and SDA/SCL pins and don't get any response.

I'm guessing I need to change the code to make use of the SDA/SCL ports but I don't know how, can anyone point out to me where i'm going wrong?

Cheers,
Paul.

i tried posting the code here but it's too large to fit in. sorry.

PaulS

Quote
i tried posting the code here but it's too large to fit in. sorry.

So, cut it down to something that clearly illustrates the problem, and post that.
The art of getting good answers lies in asking good questions.

Onsan

I don't really know what is relevant to cut it down, sorry, i'm kinda in over my head here. The link above takes you directly to the code, this is the first section of code that i can fit in.

Cheers.

Code: [Select]

#include <OneWire.h>
#include <LCDI2C.h>
#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h>
#include <Ethernet.h>

/*
A-normal mode
B-set time
C-feed mode
D-water change mode
#-skimmer cleaning mode
*-sump light on/off

Digital Pin 22 = Relay 1a Actinic lights - sunrise
Digital Pin 23 = Relay 2a Lights Fan
Digital Pin 24 = Relay 3a MH lights
Digital Pin 25 = Relay 4a Actinic lights - sunset
Digital Pin 26 = Relay 5a Automatic Top-off
Digital Pin 27 = Relay 6a Sump pump
Digital Pin 28 = Relay 7a Power Head #1
Digital Pin 29 = Relay 8a Power Head #2

Digital Pin 30 = Relay 1b Skimmer
Digital Pin 31 = Relay 2b UV light
Digital Pin 32 = Relay 3b Moon light
Digital Pin 33 = Relay 4b Chiller
Digital Pin 34 = Relay 5b Doser pump
Digital Pin 35 = Relay 6b Sump light
Digital Pin 36 = Relay 7b
Digital Pin 37 = Realy 8b

Digital Pin 44 = Temp Sensor
Digital Pin 46 = Safety Input
Digital Pin 47 = ATO Input
Digital Pin 48 = Automatic Feeder
Digital Pin 49 = Alarm

MISO - 50
MOSI - 51
SCK - 52
SS - 53
*/

LCDI2C lcd = LCDI2C(4,20,0x4C,1); // [# of lines on LCD],[address of serial LCD controller on I2C]

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 123 };
Server server(80);

int sunrise = 22;
int fan = 23;
int day_light = 24;
int sunset = 25;
int ato = 26;
int sump = 27;
int ph_1 = 28;
int ph_2 = 29;

int skimmer = 30;
int uv_light = 31;
int moon_light = 32;
int chiller = 33;
int doser = 34;
int sump_light = 35;
int available_1 = 36;
int available_2 = 37;

OneWire ds(44);
int safety_input = 46;
int ato_input = 47;
int feeder = 48;
int alarm = 49;

int ph_probe = 1; // pH probe on Analog 1
int orp_probe = 2; // ORP probe on Analog 2
int dosing_control = 3; // Analog commnad for dosing time

int lights_on_time = 1100; // Turn Metal Halide light on at this time (military time)
int lights_off_time = 1800; // Turn Metal Halide light off at this time

int actinic_on_time = 800; // Turn on the actinics at this time
int actinic_off_time = 2100; // Turn off the actinics at this time

int feed_time = 5; // Turn off power heads for this amount of time when feed mode button is pressed.
int water_change = 20; // Turn off power heads for this amount of time when water change mode is present.
int pumps_off = -10; // Placeholder --don't change

int ato_time_day = 10; // Number of seconds the ATO runs each time during day time.
int ato_time_night = 10; // Number of seconds the ATO runs each time during night time.
// Useful for running kalkwasser and account for pH drop during night time.

#define NUMREADINGS_ph 60
int readings_ph[NUMREADINGS_ph]; // The readings from the analog input
#define NUMREADINGS_orp 60
int readings_orp[NUMREADINGS_orp]; // The readings from the analog input

int index_ph = 0; // The index of the current pH reading
int index_orp = 0; // The index of the current ORP reading

int total_orp = 0;
int total_ph = 0;

int average_orp = 0;
int average_ph = 0;

int keypad_delay = 10; // Necessary delay to keep from having scrambled characters on the display
int ato_count = 0; // Counts how many time ATO is active (ato_count X 50 ml = ml/day)
int reset_flag = 0; // flag for reset of displayed values at 6:00 AM / run once flag

// custom character for sump
#define CCHAR_SUMP       1
uint8_t Crom_sump[8] = {
0x0e, 0x1b, 0x0a, 0x04, 0x15, 0x15, 0x11, 0x1f }
;

// custom character for skimmer
#define CCHAR_SKIMMER       2
uint8_t Crom_skimmer[8] = {
0x1f, 0x11, 0x1f, 0x0a, 0x11, 0x11, 0x11, 0x1f }
;

// custom character for chiller
#define CCHAR_CHILLER       3
uint8_t Crom_chiller[8] = {
0x00, 0x04, 0x15, 0x0e, 0x1f, 0x0e, 0x15, 0x04 }
;

// custom character for UV sterilizer
#define CCHAR_UV       4
uint8_t Crom_uv[8] = {
0x1f, 0x00, 0x1b, 0x0a, 0x0a, 0x1b, 0x00, 0x1f }
;

// custom character for Metal Halide
#define CCHAR_MH       5
uint8_t Crom_mh[8] = {
0x0e, 0x1f, 0x0e, 0x04, 0x0e, 0x15, 0x04, 0x04 }
;

// custom character for Actinic #1
#define CCHAR_AC1       6
uint8_t Crom_ac1[8] = {
0x0e, 0x1f, 0x0e, 0x04, 0x06, 0x05, 0x04, 0x04 }
;

// custom character for Actinic #2
#define CCHAR_AC2       7
uint8_t Crom_ac2[8] = {
0x0e, 0x1f, 0x0e, 0x04, 0x0c, 0x14, 0x04, 0x04 }
;

// custom character for lights fan
#define CCHAR_FN       8
uint8_t Crom_fn[8] = {
0x04, 0x0e, 0x15, 0x0e, 0x04, 0x0e, 0x15, 0x04 }
;

// custom character for powerhead #1
#define CCHAR_PH1       9
uint8_t Crom_ph1[8] = {
0x10, 0x18, 0x14, 0x12, 0x18, 0x1c, 0x1e, 0x1f }
;

// custom character for powerhead #2
#define CCHAR_PH2       10
uint8_t Crom_ph2[8] = {
0x01, 0x03, 0x05, 0x09, 0x03, 0x07, 0x0f, 0x1f }
;

// global variables
int minute, hour, second, date, month, year, now, mil_time;
int Tc_100, temp_Low, temp_High, orp_val, orp_Low, orp_High, ph_val, ph_Low, ph_High, dosing_time;

int ato_hour = 0;
int on_minute = 1; // indicates that this is the first time through the program.
int counter_delay =0; // used for countdown during water change and feed mods

void setup(void) {
Wire.begin(); // Initialize the I2C bus
lcd.init(); // Initialize LCD

//****** initialize inputs/outputs ************************************/
pinMode(sunrise, OUTPUT); // digital pin for sunrise as output
pinMode(fan, OUTPUT); // digital pin for moon light as output
pinMode(day_light, OUTPUT); // digital pin for day light as output
pinMode(sunset, OUTPUT); // digital pin for sunset as output
pinMode(ato, OUTPUT); // digital pin for auto top off as output
pinMode(ph_1, OUTPUT); // digital pin for power head 1 as output
pinMode(ph_2, OUTPUT); // digital pin for power head 2 as output
pinMode(sump, OUTPUT); // digital pin for skimmer as output

pinMode(skimmer, OUTPUT); // digital pin for Skimmer
pinMode(uv_light, OUTPUT); // digital pin for UV Sterilizer
pinMode(moon_light, OUTPUT); // digital pin for Moon light LEDs
pinMode(chiller, OUTPUT); // digital pin for Chiller
pinMode(doser, OUTPUT); // digital pin for doser pump
pinMode(sump_light, OUTPUT); // digital pin for sump light
pinMode(available_1, OUTPUT);
pinMode(available_2, OUTPUT);

pinMode(safety_input, INPUT); // digital pin for water level in the sump
pinMode(ato_input, INPUT); // digital pin for ATO float switch as input
pinMode(alarm, OUTPUT); // digital pin for Alarm
pinMode(feeder, OUTPUT); // digital pin for Automatic feeder

digitalWrite(day_light, LOW); // set the light off for beginning
digitalWrite(feeder, LOW); // set feeder off to start with
digitalWrite(sump_light, LOW); // set sump light low
digitalWrite(doser, LOW); // set doser pump low
digitalWrite(alarm, LOW); // set Alarm low
digitalWrite(available_1, LOW); // for future use
digitalWrite(available_2, LOW); // for future use

lcd.load_custom_character(CCHAR_SUMP, Crom_sump);
delay(10);
lcd.load_custom_character(CCHAR_SKIMMER, Crom_skimmer);
delay(10);
lcd.load_custom_character(CCHAR_CHILLER, Crom_chiller);
delay(10);
lcd.load_custom_character(CCHAR_UV, Crom_uv);
delay(10);
lcd.load_custom_character(CCHAR_MH, Crom_mh);
delay(10);
lcd.load_custom_character(CCHAR_AC1, Crom_ac1);
delay(10);
lcd.load_custom_character(CCHAR_AC2, Crom_ac2);
delay(10);
lcd.load_custom_character(CCHAR_FN, Crom_fn);
delay(10);


for (int i = 0; i < NUMREADINGS_ph; i++) /* reset vector values */
readings_ph[i] = 0;
for (int i = 0; i < NUMREADINGS_orp; i++) /* reset vector values */
readings_orp[i] = 0;

delay(100);
Ethernet.begin(mac, ip);
server.begin();
}

void loop(void){
int mode = 100;
if(lcd.keypad() != -1) {
mode = lcd.keypad();
}

switch (mode) {
case 101:
{
int minute, hour, second, date, month, year, tens, ones, key;
int set_time = 0;
while(set_time == 0){
lcd.clear();
hour = RTC.get(DS1307_HR,true); // This is in military time [0,23]
minute = RTC.get(DS1307_MIN,false);
second = RTC.get(DS1307_SEC,false);
date = RTC.get(DS1307_DATE,false);
month = RTC.get(DS1307_MTH,false);
year = RTC.get(DS1307_YR,false);

lcd.setCursor(0,0);
lcd.print("Set time:");
lcd.setCursor(1,10);
if(hour < 10){
lcd.print(" ");
delay(keypad_delay);
}
lcd.print(hour);
delay(keypad_delay);
lcd.print(":");
delay(keypad_delay);
if(minute < 10){
lcd.print("0");
delay(keypad_delay);
}
lcd.print(minute);
delay(keypad_delay);

lcd.setCursor(2,0);
lcd.print("Set date:");
lcd.setCursor(3,10);
if(month < 10){
lcd.print(" ");
delay(keypad_delay);
}
lcd.print(month);
delay(keypad_delay);
lcd.print("/");
delay(keypad_delay);
if(date < 10){
lcd.print(" ");
delay(keypad_delay);
}
lcd.print(date);
delay(keypad_delay);
lcd.print("/");
delay(keypad_delay);
if(year < 10){
lcd.print("0");
delay(keypad_delay);
}
lcd.print(year);
delay(keypad_delay);
lcd.setCursor(1,10);
lcd.cursor_on();
//**************Set Hour*********************************************************************************************
for (;;){
key = lcd.keypad();
if(key >= 0 && key <= 2){
tens = key;
break;
}
}
for (;;){
key = lcd.keypad();
if(key == -1){
break;
}
}
lcd.print(tens);
delay(keypad_delay);
for (;;){
key = lcd.keypad();
if(key >= 0 && key <= 9){
ones = key;
break;
}
}
for (;;){
key = lcd.keypad();
if(key == -1){
break;
}
}
lcd.right();
RTC.stop();
RTC.set(DS1307_HR,tens * 10 + ones);
RTC.start();
lcd.setCursor(1,10);
hour = RTC.get(DS1307_HR,true);
if(hour < 10){
lcd.print(" ");
delay(keypad_delay);
}
lcd.print(hour);
delay(keypad_delay);
lcd.right();
................

Go Up