Hello Bill,
I really enjoyed many of your youtube videos, especially the one on writing/registering servo positions onto an external EEPROM.
I'm currently somewhat stuck on writing data bigger than a Byte to an external EEPROM.
I found some info on writing to the internal EEPROM, but doing so to an external EEPROM, seems something rare. There is very little information to find. The info I do find is too complex to comprehend.
My Goal, writing a Float to an external EEPROM, and especially knowing step by step what it does, is nowhere to be found.
(To be honest, I thought you did an item about the BPM180, giving back "height" by Float, but I can't find it anywhere.)
I'd like to register that height onto that EEPROM.
Could this be something for a video item?
Kind Regards, FTMZ
I have pretty much the same problem. Did you ever get a reply, or solve your problem?
@ronft @ftmz
Try loading the extEEPROM library and run through the example sketch.
Anything seems possible when you don't know what you're talking about.
Hi,
I never got an actual reply, but I did manage to get things done.
I've put away my project due to other occupations but I might take a look on how I managed it.
I'll get back to you.
Thanks for your quick response. I did load the extEEPROM library, but as I am just a rank noobie, (!) I had some difficulty following the material. I have found a YouTube video on working with EEPROMs, but it only works with single byte data. DroneBots video also is with data that seems to limited to 8 bits, a byte. That is, the value of the variable(usually "var") does not exceed 255. To add to my confusion, the EEPROM has to be addressed with 2 bytes, hence that 2 lines of code.
I'm going to keep plugging at it as time permits. Maybe together we can come up with something.
Ron
@ronft @ftmz
I'm going to assume that you already figured out how you read and write single byes, and that your problem is just how to put and fetch multi-byte values.
OK, I looked up the code for it and there are a couple of relevant methods that should serve your purposes ...
OK, so now you understand how to put more than one byte at a time INTO the file, let's look at how to get it back out. We'll use the method
byte read(unsigned long addr, byte *values, unsigned int nBytes);
and, for an example, we'll read a variable declared "int count" stored at offset 4
byte status = myFile.read(4,&count,2);
I'm sure you'll be able to decode this as move 2 bytes at offset 76 in the file to the memory address of the variable count
Bravo !
Note that we can also do the same thing with longer sequences of bytes, so if we have an array like
int list[10];
We can save it to offset 22 using the command myFile.write(22,list,2*10).
We don't need to use the & here because arrays are passed by address. We do have to set the length to 20 (2*10) because there are 10 entries at 2 bytes each in the array.
After getting rid of the rabbits and hats we've used so far, you can do the same thing with character arrays. So we can extract the string of 32 characters (char surname[32];) in the file at offset 120 using
status = myFile.read(120,surname,32);
Note again that surname is an array and will already be passed by address, so we don't need an & for this case.
So you can see that there's really not much difference reading or writing to an EEPROM whether it's onboard or external.
Hope this helps.
Anything seems possible when you don't know what you're talking about.
Yes it will help. This must have been some effort for you and I really appreciate it. I will start coding very soon and will let you know how it worked out.
Thanks again
@ronft @ftmz
I'm going to assume that you already figured out how you read and write single byes, and that your problem is just how to put and fetch multi-byte values.
OK, I looked up the code for it and there are a couple of relevant methods that should serve your purposes ...
- byte write(unsigned long addr, byte *values, unsigned int nBytes);This method allows you to write a series of contiguous bytes off to the SD card starting at the offset specified by address.So, let's say you have a variable defined as "long whatNot" and now you want to store this value into the SD file myFile.txt (that you've already opened as myFile) 76 bytes into the file, then you'd issue the command:byte isOK = myFile.write(76, &whatNot,4);This call will return a status code (isOK) whose value will indicate if the operation succeeded or to help you figure out why it failed.The important components are:isOK is the byte value of the returned status of the write attempt76 is the offset to where you want to place the value (remember that it's zero-based)&whatNot is the starting address in memory of the variable you want written to the file. The & tells the compiler that you want to enter the ADDRESS of the variable, not its value4 is the count of bytes that need to be copied for the variable whatNot and says how many bytes to write to the file. Note that whatNot is a long and so it uses 4 bytes.So, quite simply this method says write the four bytes starting at memory address for by the variable whatnot into the file at offset 76 and afterwards, tell me whether it worked.Pretty much the same information you'd have to give a human to accomplish the same thing
OK, so now you understand how to put more than one byte at a time INTO the file, let's look at how to get it back out. We'll use the method
byte read(unsigned long addr, byte *values, unsigned int nBytes);
and, for an example, we'll read a variable declared "int count" stored at offset 4
byte status = myFile.read(4,&count,2);
I'm sure you'll be able to decode this as move 2 bytes at offset 76 in the file to the memory address of the variable count
Bravo !
Note that we can also do the same thing with longer sequences of bytes, so if we have an array like
int list[10];
We can save it to offset 22 using the command myFile.write(22,list,2*10).
We don't need to use the & here because arrays are passed by address. We do have to set the length to 20 (2*10) because there are 10 entries at 2 bytes each in the array.
After getting rid of the rabbits and hats we've used so far, you can do the same thing with character arrays. So we can extract the string of 32 characters (char surname[32];) in the file at offset 120 using
status = myFile.read(120,surname,32);
Note again that surname is an array and will already be passed by address, so we don't need an & for this case.
So you can see that there's really not much difference reading or writing to an EEPROM whether it's onboard or external.
Hope this helps.
Is writing to a file the same a writing to an EEPROM?
Cheers.
Think of the EEPROM as a file.
Anything seems possible when you don't know what you're talking about.
Think of the EEPROM as a file.
Sure, I understand that, sorry if I wasn't clear.
I was questioning if there was a difference?
For example... I know I can write POD (a struct) to EPROM as well, but I am not sure if that is possible to an SD card.
Cheers.
Think of the EEPROM as a file.
Sure, I understand that, sorry if I wasn't clear.
I was questioning if there was a difference?
For example... I know I can write POD (a struct) to EPROM as well, but I am not sure if that is possible to an SD card.
Cheers.
Read the library's .H file that you're using for the SD card. It'll tell you whether it's able to read and write arbitrary length byte streams.
Anything seems possible when you don't know what you're talking about.
Think of the EEPROM as a file.
Sure, I understand that, sorry if I wasn't clear.
I was questioning if there was a difference?
For example... I know I can write POD (a struct) to EPROM as well, but I am not sure if that is possible to an SD card.
Cheers.
Read the library's .H file that you're using for the SD card. It'll tell you whether it's able to read and write arbitrary length byte streams.
So are you saying it's library dependent?
Read the library's .H file that you're using for the SD card. It'll tell you whether it's able to read and write arbitrary length byte streams.
So are you saying it's library dependent?
No, what I'm saying is that if you're using a library, you could check to see whether it allows multi-byte I/O.
If you're not using a library then it's up to the programmer to implement it (or not).
Anything seems possible when you don't know what you're talking about.
Read the library's .H file that you're using for the SD card. It'll tell you whether it's able to read and write arbitrary length byte streams.
So are you saying it's library dependent?
No, what I'm saying is that if you're using a library, you could check to see whether it allows multi-byte I/O.
If you're not using a library then it's up to the programmer to implement it (or not).
Fair enough, some libraries *may* offer that, but you can't expect the average joe here to implement such a feature... most people simply plagiarize a piece of code they find on the internet, and tweak it on any advice available they can find, anywhere until it works (seemingly).
Simple Joe, as you call him, would use the built-in SD library.
Anything seems possible when you don't know what you're talking about.