Show Posts
Pages: [1] 2 3
1  Forum 2005-2010 (read only) / Development / Re: Compiling an SD/MMC and fat16 library on: July 23, 2008, 04:59:24 am
I used Rolands code. He uses a slightly different C standard which throws exceptions if you don't enable a flag in the compiler. If you place code into the library directory it automatically gets compiled into a new library. However, it won't compile if the files end with .c, only if they end with .cpp. So I just renamed them to .cpp. Rolands code should compile straight out of the box, however he uses a few pins for sensing a card insertion. These need to be disabled or the card won't read or write properly with the arduino.  
2  Forum 2005-2010 (read only) / Development / Re: Compiling an SD/MMC and fat16 library on: April 22, 2008, 04:24:38 pm
Where did you get your library code from? Did you use rolands code or the one I posted up in the exhibition area. If the card reads fine in your computer then there are two options, either the code isn't correct or the circuit isn't correct. If you claim that the circuit is correct (check your input voltages through the voltage divider with a multimeter) then it should be software based. Post up your arduino board version, software version, the code your using and any other info you have and I'll see if I can find the trouble. It should work no problem   smiley-grin But thats electronics for u!...
3  Forum 2005-2010 (read only) / Development / Re: Compiling an SD/MMC and fat16 library on: April 17, 2008, 03:42:37 pm
Post up the code your using in your arduino sketch., that could help. If the card does nothing, then try making a simple sketch which just initializes the card and then prints out the sd card info. That should tell you if the card was initialized and is working or not.

Also, be aware that once you write to the card from the arduino you cannot read it in the pc again until you reformat it. Because you are writing straight onto the card which overwrites the FAT table.

If the card can be initialized and the disk info printed out then you "should" be able to read/write to it(murphy usually stuffs things up though (smiley-kitty)).
4  Forum 2005-2010 (read only) / Development / Re: Compiling an SD/MMC and fat16 library on: February 16, 2008, 04:24:12 pm
Ok I'll try and expalin but someone else probably can do it better. If you are writing numbers larger than bytes (8bits =  2^8-1 = 255) then you need to split the number up into separate bytes. I'll give a code example. I wanted to store the values of the arduino ADC in the memory card. Values from the ADC are 10bit (10bits = 2^10-1 = 1023). So the 10bit number needs to be split into two values to be able to be stored in 8bits.

Code:
// Store my 10bit value in an int (NOT a byte, which is only 8bits) so 16 bit number. High(1111 1111) Low (1111 1111)
int temp;

byte low;    // Variable to store the low byte in
byte high;   // Variable to store the high byte in

temp=analogRead(0); //Read in the value

// AND the number with 255 which wipes the 8bits at front of number
// The front 8 bits gets wiped->High(1111 1111) Low(1111 1111) = High(0000 0000) Low(1111 1111)
// So you can store half the number in the low byte variable
low=temp&0xFF;    


// Rotate the number 8 bits right to get the high bits.
high=temp>>8;    

So you can then store each byte in an array and then write it to disc. To read back from the disc you read in each byte and then join them together again.
Code:
byte low;
byte high;
byte info[2];
int value;

sd_raw_read(0,info,2); // Read the 2 values from disc
low=info[0];  // store low byte
high=info[1]; //Store high byte
result=high<<8; // rotate left 8 bits the high value and store in result
Serial.print(result+low,DEC); //Add low and high together to get the original number you split up into 2 bytes

The easiest way to see how this all works is to try this code and use Serial.print after each operation and print the numbers in binary. Then you can see how the bit manipulations are working. For larger values long int etc, you have to split the number up into 8bytes and then store each byte individually. So if you wanted to store a 32 bit number you would need to split it into 4 bytes and then write each byte to disc.

Well, hopefully I explained it ok  smiley
5  Forum 2005-2010 (read only) / Development / Re: Compiling an SD/MMC and fat16 library on: February 15, 2008, 07:37:57 pm
That define thing is handy, saves all my hacking in the library, much neater this way!

This code should write 2 bytes to the SD card starting from memory location 0. Then read them back into the tempBytes array. If you were writing your NMEA string, then read it in from serial port into an array of correct length of the string(i.e. 16 bytes or 32 or whatever an NMEA string is) then write that array to a memory location.  It's pretty easy, try this example code.
Code:

// Define an array for storing data.
byte tempBytes[2];
// Store some example numbers
tempBytes[0]=23;
tempBytes[1]=57;

// Write the 2 bytes stored in tempBytes to memory location 0
sd_raw_write(0,tempBytes,2);

// Zero the tempBytes array to make sure read works ok.
tempBytes[0]=0;
tempBytes[1]=0;

// Read 2 bytes starting from memory location 0 into tempBytes print to serial output.
sd_raw_read(0,tempBytes,2)
Serial.print(tempBytes[0],DEC);
Serial.print(tempBytes[1],DEC);
6  Forum 2005-2010 (read only) / Development / Re: Compiling an SD/MMC and fat16 library on: February 15, 2008, 05:26:34 pm
Oh and just for interest,  I got the FAT library compiled and running on the arduino, however I had to do quite a few changes as he uses the C99 standard and I couldn't add that flag in arduino environment. I didn't get it working fully and kept getting a few errors. I gave up in the end because it just fits into the atmega168 memory and leaves little room for anything else. You can only run a few functions before you have no room at all left. It would be good to get it running once the larger size memory atmegas are available for the arduino environment.

Much easier to write to a text file on the memory card, pull it out and chuck it in your computer to read your values!  smiley-wink
7  Forum 2005-2010 (read only) / Development / Re: Compiling an SD/MMC and fat16 library on: February 15, 2008, 03:59:54 pm
Nice, its a good library and makes reading and writing to the SD card easy. There are a few parts  in the sd_raw.cpp and config files that need to be changed to get reliable operation on the arduino.  Something that isnt obvious is that in the library he specifies pins 5 and 6 of analog in(2 wire interface)  as sensor pins for card insertion and read/write tab. You can disable that in the code but the easiest way to check if your code is working is to ground pin 5 and 6 of analog in. I found this out by accident when I was holding the arduino and tilting it and trying to figure out why it wasn't working. Every now and then it would find the card, my hand must have provided a ground.  ;D

I've gone through the code and commented out various bits and changed a few things so that it works well but have to go through and make sure that all the changes work ok and document what I've changed.

Anyway yeah ground analog pin 5 and 6 and it should work.

If you want to remove the code then look in the config.h files and comment out where he defines PortC 5 and PortC 4 pins. Then remove the code that checks for memory card insertion (there's 2 functions and some code in the sd_init function) and it should work fine. If you want to leave it then you'll have to connect your memory card socket to the 2 pins for insertion and read/write checking or ground the pins.

Also if your after an SD card socket this looks nice (i found this after I'd de-soldered a memory card reader to get the SD socket lol)
http://www.futurlec.com/Mini_SC.shtml
8  Forum 2005-2010 (read only) / Development / Re: Compiling an SD/MMC and fat16 library on: January 08, 2008, 03:30:42 pm
Thanks for that. Yeah I finally got it to all compile properly. I put the .c and .h files into a directory, renamed the .c to .cpp and it compiled automatically. I had to change a bit of the code as he uses the C99 standard and I don't know where to add flags when the arduino environment automatically compiles.

I probably will just use the low level read/write routines although the fat16 would be interesting. Just wanted to use robust sd/mmc access routines.
9  Forum 2005-2010 (read only) / Development / Re: Compiling an SD/MMC and fat16 library on: January 07, 2008, 06:43:36 pm
Thanks for the ideas. Yeah I compiled object files. But the object files are quite small (some are the same size as the stepper motor object files or matrix object files) so I'm wondering if I did something wrong when I compiled the code.

If I use #include <stepper.h> (or whatever it is) it uses up only a little code space. If I use #include <my compiled stuff> it immediately blows out over the size limit even though the compiled object files are similar size.

I'm thinking that my object files are compiled somehow wrong and that is what is causing the problem.
10  Forum 2005-2010 (read only) / Development / Compiling an SD/MMC and fat16 library on: January 07, 2008, 03:22:17 pm
Hi, I'm trying to get the software library found here http://www.roland-riegel.de/sd-reader/index.html to work with the arduino. I've successfully got it compiled to object files using the same flags in the makefile that comes with the library and avr-gcc that came with arduino0010 dev environment. I placed the obj files and headers into a directory in the libraries folder so they appear as an included library. However, if I add any of the included files to a project using #include <>, it immediately blows out over the max size of the atmega168.

The code and library I am trying to get work was developed on an atmega168 so it should work. I've checked some of the other libraries and the stepper motor library is compiled to almost the same size as the sd card raw access library. I'm wondering if I've compiled it wrong or done something incorrect. The code is standard C.

Any ideas would be appreciated.  
11  Forum 2005-2010 (read only) / Development / Re: Automobile Cruise Control Project on: January 10, 2008, 03:23:12 am
You need to learn negative feedback and control mechanisms for the software part. There should be some stuff on the web or maybe on this site for negative feedback control algorithms.
12  Forum 2005-2010 (read only) / Development / Re: Library Fails to build on: January 15, 2008, 03:07:51 am
Have you got .h and .cpp files? I've just been building some pretty complex libraries and they build no problem. I put them in a directory under libraries in their own folder and they build automatically using winxp sp2 pro. Here is what I do:

1. make library directory under arduino_dir/hardware/libraries/your_lib_name
2. place the .h and .cpp files
3. start arduino
4. libs are automatically built.

You could try placing an error in the library code and you should get an error message in the console in arduino. If you don't then it can't find the lib for some reason. Other option is to move the whole arduino directory into another folder. I read another thread on here and they had to put it into their program files directory to get it to work.
13  Forum 2005-2010 (read only) / Troubleshooting / Re: Strange digital pin behaviour on: November 22, 2007, 12:41:47 am
Its nowhere near that bright. I've checked the resistors using a multimeter. I've also checked the voltage using an oscilloscope. Some of the pins appear  bright and some don't. For example, one mega168 will have a bright output on pin 13, the next one won't, it will be quite dim. Even with no current limiting resistor the LED's are dim. I ordered the extra 168's direct from atmel as samples so I can't see that 3 samples would all be bad. I don't know if its something to do with the board itself. I'm thinking of buying a new decimelia and seeing how that is.
14  Forum 2005-2010 (read only) / Troubleshooting / Re: Strange digital pin behaviour on: November 21, 2007, 11:30:07 pm
I changed the pins to output pins and use digitalWrite(pinNum,HIGH). It seems like the pins can't supply much current. If I have an LED connected on pin 13 it appears dim on one atmega168 and bright on another. Connecting a digital pin through a LED and then a 220 ohm resistor, some appear bright and others appear dim. It's got me stumped whats causing the problem. I'm using a USB arduino NG modified to work as a decimelia. I have the original atmega168 that came with that and also three new ones I burned with decimelia bootloader. All the code works fine, they just don't supply much current.
15  Forum 2005-2010 (read only) / Troubleshooting / Strange digital pin behaviour on: November 20, 2007, 06:10:01 pm
I am getting some strange behaviour and trying to figure out what is going wrong. If I connect a LED with 220 ohm resistor to any other pin than pin 13 I am getting very low output, like there is very little current for that pin. I have the pins configured as outputs in software. On pin 13 the LED is bright, on any other pin it is very dim.

I've also tried this with 2 different atmega 168 chips, so the chip itself doesn't appear to be the problem.
Pages: [1] 2 3