Wednesday, May 28, 2008

SD card "working"

I recently read a post on ladyada's blog where she used roland-reigel's code to read an SD card. I used ladyada's adaptation of his code and was able to read my SD card!

The code takes up most of the Arduino memory. Sad, but true.

Hopefully, I will be able to do some data logging and playback.

Monday, October 15, 2007

SD card blues

It has been a long time since I blogged about the SD card project. I have been busy, but every once in a while I was able to do some experimenting.

I was able to build the AVRLIB mmc code and mmctest program, which should work with my SD card, and load it to the Arduino using avrdude. It brings up a command line interface to test mmc functions like read, write, initialize(reset). It seems to interface fine to the SD card, but I keep getting an error back in the status register. The error code is a 0x5. I did some research on the error, but haven't figured out exactly what is happening.

For now, I have put the SD project on hold.

I am now connecting up the TSOP32238 and getting data from my remotes into the PC and hopefully LIRC. The output of the TSOP32238 is a stream of 1's and 0's. I think LIRC expects pulse lengths in hex, so I have some code to write.

I borrowed walter anderson's code to look at what the TSOP32238 is seeing.... I am getting some false pulses probably because I hooked the TSOP directly to the input pin instead of using the recommended cap and resistor.




/*
* File....... IRanalyzer.pde
* Purpose.... Records up to 128 signal changes
* Author..... Walter Anderson
* E-mail..... wandrson@walteranderson.us
* Started.... 18 May 2007
* Updated.... 18 May 2007
*
*
*/
#include <avr/interrupt.h>
#include <avr/io.h>

#define TIMER_RESET TCNT1 = 0
#define SAMPLE_SIZE 64

int IRpin = 2;
unsigned int TimerValue[SAMPLE_SIZE];
char direction[SAMPLE_SIZE];
byte change_count;
long time;

void setup() {
Serial.begin(115200);
Serial.println("Analyze IR Remote");
TCCR1A = 0x00; // COM1A1=0, COM1A0=0 => Disconnect Pin OC1 from Timer/Counter 1 -- PWM11=0,PWM10=0 => PWM Operation disabled
// ICNC1=0 => Capture Noise Canceler disabled -- ICES1=0 => Input Capture Edge Select (not used) -- CTC1=0 => Clear Timer/Counter 1 o
//Compare/Match
// CS12=0 CS11=1 CS10=1 => Set prescaler to clock/64
TCCR1B = 0x03; // 16MHz clock with prescaler means TCNT1 increments every 4uS
// ICIE1=0 => Timer/Counter 1, Input Capture Interrupt Enable -- OCIE1A=0 => Output Compare A Match Interrupt Enable -- OCIE1B=0 => O
//tput Compare B Match Interrupt Enable
// TOIE1=0 => Timer 1 Overflow Interrupt Enable
TIMSK1 = 0x00;
pinMode(IRpin, INPUT);
}

void loop()
{
Serial.println("Waiting...");
change_count = 0;
while(digitalRead(IRpin) == HIGH) {
}
TIMER_RESET;
TimerValue[change_count] = TCNT1;
direction[change_count++] = '0';
while (change_count < SAMPLE_SIZE) {
if (direction[change_count-1] == '0') {
while(digitalRead(IRpin) == LOW) {
}
TimerValue[change_count] = TCNT1;
direction[change_count++] = '1';
}
else {
while(digitalRead(IRpin) == HIGH) {
}
TimerValue[change_count] = TCNT1;
direction[change_count++] = '0';
}
}
Serial.println("Bit stream detected!");
change_count = 0;
time = (long) TimerValue[change_count] * 4;
Serial.print(time);
Serial.print("\t");
Serial.println(direction[change_count++]);
while (change_count < SAMPLE_SIZE) {
time = (long) TimerValue[change_count] * 4;
Serial.print(time);
Serial.print("\t");
Serial.println(direction[change_count-1]);
Serial.print(time);
Serial.print("\t");
Serial.println(direction[change_count++]);
}
Serial.println("Bit stream end!");
delay(2000);
}

Labels: , , , ,

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.

Sunday, April 01, 2007

arduino analog lab

Over the last couple of days, I set up my arduino this way:



The potentiometer controls the speed of the pattern being displayed. The arduino reads the analog value of the potentiometer and adjusts the pattern's delay value based on that.

The program still provides the same 3 patterns: knight rider, wave and binary counter.

Labels: , ,

Friday, March 30, 2007

USB information

I found a really good site today with USB information. They cover everything from an intro (USB in a nutshell) to hardware and development kits and resources.

This is the hardware page.

Another good site is usbdeveloper.

They have a great section about how USB works here.

Labels: ,

Thursday, March 22, 2007

microcontroller


I received my arduino microcontroller several days ago.

The IDE is simple and the arduino is easy to program. I hooked up a 10 LED strip to it and made several programs to display patterns on it.

1. I made a wave program that starts at one end and lights the LEDs sequentially until they are all lit. Then it starts at the same end and turns them off sequentially. The program does that in an endless loop. It looks like a wave of LEDs.

2. I made a binary counter program. It counts up from 0 and displays the binary value on the LEDs. It starts over at zero when it reaches 1023 (all 10 LEDs lit).

3. I made a program that takes serial input from the computer connected to the arduino via the USB cable. The arduino looks like a USB com port to the computer. When you send a '1', the board displays the knight rider pattern. When you send a '2', the board displays the wave pattern. When you send a '3', the board displays the binary counter pattern. You can send a character at any time and the board will reset the LEDs and start the new pattern.

Labels: , ,