Thursday, August 23, 2007

Adding an SD/MMC card - step 2

I wrote some code to test my wiring and voltage dividing resistor setup. It allows me to toggle each of the pins (10 - 13) using the serial port of the PC. All of the wiring and voltage dividers seem to be working.

Now for the real work. The question is: do I write my own code or try to reuse other code. AVRLib has MMC code which can be adapted to SD very easily, but AVRLib may not integrate with the Arduino development environment. There are other AVR examples out there. I even found one that does FAT format and IDE, which would be useful if I were connecting up a compact flash card interface because compact flash behaves like an IDE drive.



Test Code




int incomingByte = '1';
int prevByte = 0;

int pinArray[] = {
10, 11, 12, 13
};
int pinCount = 4;
int LastPinVals[] = {
LOW, LOW, LOW, LOW };
int count = 0;

void setup()
{
for (count=0;count<pinCount;count++) {
pinMode(pinArray[count], OUTPUT);
}

reset_pins();

Serial.begin(9600);
Serial.println("Start");
}

void reset_pins()
{
for (count=0;count<pinCount;count++) {
digitalWrite(pinArray[count], LOW);
}
}

int pinToIdx(int pin)
{
int i;
for (i = 0; i < pinCount; i++)
{
if (pinArray[i] == pin)
{
return i;
}
}
return 0;
}

void toggle(int pin)
{
digitalWrite(pin, ! LastPinVals[pinToIdx(pin)]);
LastPinVals[pinToIdx(pin)] = ! LastPinVals[pinToIdx(pin)];
}

int byteToPin(int byteVal)
{
return pinArray[byteVal - '1'];
}

void loop()
{
if (Serial.available() > 0)
{
incomingByte = Serial.read();
if (incomingByte >= '1' && incomingByte <= '4')
{
if (prevByte != incomingByte)
{
Serial.print("Got ");
Serial.println(incomingByte);
toggle(byteToPin(incomingByte));
prevByte = incomingByte;
}
}
}
}


Labels: ,

Wednesday, August 08, 2007

Adding an SD/MMC card - step 1

I set up the arduino this way to connect a micro SD card to it for extra memory.



Step one is to get regulated 3.3V to the SD card. I used an LM317T and some resistors to take the 5V from the arduino and turn it into 3.3V.

I purchased the micro SD card breakout board from SparkFun electronics.

Step two will be to write the firmware. This will be discussed in my next installment.