Go Down

Topic: sd.h causing output pins to stop working (Read 1 time) previous topic - next topic

agnivohneb

I have been working on a morse code program that will flash an led on pin 13 and also connect to my phone via bluetooth (pin 0/1) to send a new message for the program to decode and flash.
I recently got the Ethernet shield and was excited about the SD card slot. I put it on and tried a few of the examples first to get a feel for it, then all I did was add a few lines to my original program and now any pin that I setup will not flash the LED. I changed the led pin to 2 now and found out that by removing the (#include <SD.h>) from the program the led flashes but it I add it the led stops working. And this will happen for any pin that I select. Now it seems odd just by adding one line to a program will stop all output pin traffic.

All I added to my program was:
Code: [Select]
#include <SD.h>
void setup(){
pinMode(10, OUTPUT);
if (!SD.begin(4)) {
  Serial.println("initialization failed!");
}
}


And if you must know I am using the Arduino Uno R3, Ethernet Shield R3, Developer Software 1.0

Any ideas of why this might be happening please. I wanna take this in and show the guys at work.

PaulS

Quote
I changed the led pin to 2 now and found out that by removing the (#include <SD.h>) from the program the led flashes but it I add it the led stops working.

Where, in that code, are you defining pin 2 to be an output pin?


agnivohneb

I meant to say in that sentence "... flashes but it I add it the led ..." it is suppose to be "when"

I am changing it in my program here
#define LEDPin 2
after I call the include

When I said changed to pin 2 I meant that that is the current pin that it is on as of now.

I know this is hard to understand without me showing you my whole code but I prefer not to display it yet.

PaulS

Quote
I am changing it in my program here
#define LEDPin 2
after I call the include

Saying "I am going to talk to pin 2" and saying "pinMode(2, OUTPUT);" are not quite the same thing, are they?

If you want to turn an LED on, you must connect it to a pin whose mode is OUTPUT. The pins are all INPUT by default.

agnivohneb


Quote
I am changing it in my program here
#define LEDPin 2
after I call the include

Saying "I am going to talk to pin 2" and saying "pinMode(2, OUTPUT);" are not quite the same thing, are they?

If you want to turn an LED on, you must connect it to a pin whose mode is OUTPUT. The pins are all INPUT by default.


you don't know what I am talking about and your starting to get off topic. I am having a problem with #include <SD.h>

In my program I use #define LEDPin 2 as a constant so I am not repeating changes several times in my program. So be more specific:

At the start I have
Code: [Select]
#include <SD.h>
#define LEDPin 2


In setup() I have
Code: [Select]
pinMode(LEDPin, OUTPUT);
pinMode(10, OUTPUT);
if (!SD.begin(4)) {
  Serial.println("initialization failed!");
}


And in loop() I have a bunch of things that make the LED go ON and OFF

Now to get back on topic the problem is that as soon as I add any code related to the SD Library (even the include statement) my led will stop working no matter what pin I have it on.

abrookfield

Sounds crazy, but do you actually have an SD card in the slot?
www.reeftopper.com

CrossRoads

sd.h library may be taking control of the SPI pins D11-12-13, and expecting one other to be an output for Chip Select.
Don't know why that would affect other pins.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

PaulS

Quote
you don't know what I am talking about and your starting to get off topic. I am having a problem with #include <SD.h>

I know what you are talking about, and while what I'm saying might be off topic, it is still relevant.

Quote
In setup() I have

Show me where, in your initial post, you have a pinMode statement that references LEDPin.

You've added one in this code, which is what I was trying to get you to do.

apple32

I have also the same problem =( =( =(  when i'm trying to combine tvout(which uses output pin)with the sd.h or other sd libraries.
When i put the sd library,the tvout demoPAL stop playing.After searching a lot,i found that someone found a solution
to make the output pins working the output pins
but i can't understand what is he saying...Could anyone help???

link:http://code.google.com/p/arduino-tvout/issues/detail?id=40
warumgr.forumgreek.com

fat16lib

Just adding SD.h takes over 500 bytes of additional RAM and this may cause your program to fail if you are already using a lot of RAM.  I think tvout can use lots of RAM.

All SD libraries that write to files need a 512 byte SD block buffer for rewriting SD blocks in file structures.

agnivohneb


Just adding SD.h takes over 500 bytes of additional RAM and this may cause your program to fail if you are already using a lot of RAM.

So if this is the case, how do you free up some ram without affecting my functional program.
I just checked when I compile that my program is saying "Binary sketch size: 9378 bytes (of a 32256 byte maximum)" and when I add the include SD.h the output is "Binary sketch size: 13412 bytes (of a 32256 byte maximum)"


I have also the same problem =( =( =(  when i'm trying to combine tvout(which uses output pin)with the sd.h or other sd libraries.
When i put the sd library,the tvout demoPAL stop playing.After searching a lot,i found that someone found a solution
to make the output pins working the output pins
but i can't understand what is he saying...Could anyone help???

link:http://code.google.com/p/arduino-tvout/issues/detail?id=40

I checked that out and I understand what he is doing but I don't know what parts of the SD library he changed.

Go Up