so I experienced weird stuff today. Yesterday I connected my temperature module and digital light sensor. Everything worked perfectly, but today, when I wanted to connect real time clock, it wasnt showing anything on serial monitor. Was weird for me, so tried yesterday projects and showed same thing. It flashed only like 5 times with data, but when I ran it again, blank monitor.
I discovered, that when I make new project with basic stuff like displaying message "Hello", it works. When I copy old program to that new project, wont work again. I really dont know how to work this problem out. Didnt happened this to you guys? Thanks for every reply.
Didnt post any codes, because didnt think it would be helpful when I changed literally nothing, just opened it day after, but here it is.
Simple code which works fine:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Hello");
}
It can look like the second code is messed up somewhere, or I messed up with the wires on my board, but I didnt touch anything, just opened it again day after. Also tried reinstalling IDE.
Try putting printLn statements in after each line of execuable code. If the first ones work and subsequent ones don't it will give you a clue os to what is stopping things. Is it possible for example a wire has been knocked and no longer makingproper contact - or worse shorting something?
I am really confused right now.. I have two codes, one for real time clock and one for temperature + light sensor. I wanted to try just clock code, so unpluged wires for everything and moved them only to clock, wires for everything I mean just 5V and GND, not sda and scl. Right when I unplugged it, it started to print wrong values, like 54612 lux and -127°C, but hey, thats at least something... How is it possible..? Right after plugging 5V and GND just to clock module and ran the code, It stopped printing anything again.
Ok, so I figured out what was the problem, but I dont know how to fix it. I had light sensor connected to SDA and SCL on pins above AREF on MEGA 2560 and I used SDA and SCL 43 and 44 for clock and that caused the problem, once I unpluged these two, the light sensor and temperature started working, how is it possible? I cannot use both SDA and SCL pins? Also the clock does not work when I plug it to same SDA and SCL as the other module, should it work and is it problem with my clock module or is it problem using 2 modules on one SDA SCL pins?
EDIT: Okay, looks like I have clone of MEGA and original has only SDA and SCL on pins 20,21. So my question stands, how to plug the second module if it needs SDA and SCL too?
lubh:
Ok, so I figured out what was the problem, but I dont know how to fix it. I had light sensor connected to SDA and SCL on pins above AREF on MEGA 2560 and I used SDA and SCL 43 and 44 for clock and that caused the problem, once I unpluged these two, the light sensor and temperature started working, how is it possible? I cannot use both SDA and SCL pins? Also the clock does not work when I plug it to same SDA and SCL as the other module, should it work and is it problem with my clock module or is it problem using 2 modules on one SDA SCL pins?
EDIT: Okay, looks like I have clone of MEGA and original has only SDA and SCL on pins 20,21. So my question stands, how to plug the second module if it needs SDA and SCL too?
You haven't provided enough details to answer this question. Please provide a schematic and identify the modules completely.
I'm not sure you have your pin numbers correct. I am not familiar with the Mega 2560 having never used one, but according to the literature SDA should be Pin20 and SCL Pin21 as far as I can tell. Pins 16 &17 are Serial2. Pins 43 and 44 are digital pins.
Does this agree with what you have or are you using a different numbering scheme?
Your pin numbers are correct. On the 2560 R3, the I2C pins are duplicated on 20,21 and 43,44 (electrically connected, identical). I want to see what you're actually doing, not have to guess...
aarg:
Your pin numbers are correct. On the 2560 R3, the I2C pins are duplicated on 20,21 and 43,44 (electrically connected, identical). I want to see what you're actually doing, not have to guess...
Exactly, I have it now connected 2 modules to 43 and 44 above AREF and clock module to pins 20 and 21.
So the issue now is that I dont know if my clock module can work. Can I plug it to same SDA/SCL pins as the other module?
Well. it looks like you have an Ethernet shield with built in SD reader on that Mega. These are notorious for taking over pins and even the entire SPI bus unless explicit action is taken. If you are having problems of "weird" behaviour, first try to duplicate the problem without the Ethernet card.