Go Down

Topic: Using a look-up table with Excel and SD card (Read 2889 times) previous topic - next topic

Cowboy303

I'm making a project that receives data from sensors, and the data that it gets will control a stepper motors position.
So I would like to have a look-up table on the SD card where it can see what position it should be at.   The reason for the SD card is so I can change the 'map' whenever I want and don't have to bring my laptop to the project.  Also, there will be around 20 rows, and 60 columns.

So as an example:
Sensor Y=15
Sensor X=42
Value Pos = (SD lookup, X,Y,)//go to look-up table on SD card and look up the value
...

Obviously it's not going to be that simple, but that might give you a better Idea of what I'm trying to do

Thank you all for your help, and if you need any more info please ask.


el_supremo

Which Arduino are you using?
Are the values in the map 8-bit or 16-bit?
If it's 8-bit, the 20x60 table will use up 1200 bytes and you should have room left over for the SD library. If it's 16-bits then you've got a problem because the table will be 2400 bytes, which won't leave room for anything else if you're using a 328-based Arduino such as UNO or Nano.

Pete


Cowboy303

#2
Nov 22, 2013, 02:38 am Last Edit: Nov 22, 2013, 05:19 am by Cowboy303 Reason: 1
Oh yes, I'm going to be using a atmega1284 for this project,  I will program it like with a FTDI cable like this guy>>> (towards the bottom of the page) http://www.gammon.com.au/forum/?id=11637

X is going to be 0-100%
Y is going to be 0-4000 in increments of 50 so with some with some changes I could make it 8 bit
And the Values will all be under 100

Programming it into the arduino itself will be a bit of a pain, because I was hoping on having multiple maps and be able to change them easily.  And the arduino will be doing a bit of other things to so the faster the better.

Thanks

robtillaart


are the values expressable in a formula?

If values can be interpolated, it might be a job for multimap2D

- http://playground.arduino.cc/Main/MultiMap -
- http://forum.arduino.cc/index.php/topic,145632.0.html -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Cowboy303

I saw that when I researched, but couldn't figure out how to make it read the numbers off the SD card.  I'm very new to programming so maybe it's obvious to you. lol

The numbers can't be calculated.  They will all be put in by hand in the excel sheet and are going to be random.

Like I said I'm new to this, but there's got to be a way to go in to SD card file, and go X lines down, and Y characters forward.
  0      50 100 150 200 250 300 350 400 450 500...4000
  5%     0       1      1        1       1        2      2        2      2      2
10%     1        1      1        2       2       2      2        2      3      3
15%      1       2      2       2       3       3      3         3      4     4       
20%     2      2      2       3       4      4      4         5       5    5
25%     3       3     4       4       5      5       6        6       6    6
30%    3       4     4       5       5      6       6        7        7    7 ...50       
...100%

When it comes time to put the Excel sheet on the sd card, I can get rid of the x-y labels.  and the arduino will know how many lines down for 30%, and how many characters across.  does the arduino think every 8bit (0-255) number is a character?  Or does it think every number is a character (0-9)?

Thanks for all the help already

robtillaart

If you want to do it on SD card I would implement it as follows:

create 21 binary files, each representing one row.
0.bin
5.bin
10.bin
etc
every row

So if you want to find value (45%, 600)
the X value indicates you need to open the file 45.bin and
the Y value gives you the position,  600/50 = 12th byte so you can use fseek to go to it.

hope this helps,
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

el_supremo

This is going to be awfully slow if you have to read data from the SD card all the time. How fast are you expecting to be updating the stepper motors? The 1284 should have enough static ram to allow you to read the whole table into ram on startup.

Pete

Cowboy303

#7
Nov 22, 2013, 07:00 pm Last Edit: Nov 22, 2013, 09:39 pm by Cowboy303 Reason: 1

This is going to be awfully slow if you have to read data from the SD card all the time. How fast are you expecting to be updating the stepper motors? The 1284 should have enough static ram to allow you to read the whole table into ram on startup.


I haven't thought of that,  I'm not sure how your planning on doing it, but the faster the better so I'm all for it.  optimally, I would like 4 times a second minimum.

I don't know anything about what your thinking, but I would really like for the user to be able to change the map at any point. so make a function or something to change the map the arduino has.  If it takes up to 10 seconds to actually change that map that would be fine.  Juts to see, I used excel and made a rough map the size I need, and saved it as a text file.  It say "size 3kb, size on disk 4kb" not sure which one we care about.  IIRC, the 1284 has 16kb of ram, so that should leave plenty of ram to do other things.

Really interested in what your thinking!!! Thanks

EDIT:
had a really crazy Idea, what if you had a for loop make all the combinations of variables, ie it makes a byte with the name of 25450 and then sets the value to 6, then when you go to retrieve the value, make a string with the data from sensors Y and X.

So;
X = 25
Y = 450
int Val = String(x+y);//this probably isn't the right way, so if anyone  know how to correctly do it that would be awesome.



el_supremo

How does the data get from Excel to the SD card and how often do you expect to be changing the card?

Pete

Cowboy303


How does the data get from Excel to the SD card and how often do you expect to be changing the card?

Pete

I would stick the SD card in my computer and put it on that way, obviously I would have to save it as a text file.
I don't expect to change the card much, I do plan on useing different maps inside the SD card, and take the SD card out from time to time to revise/improve the map.  I'll only take the SD card out when the project isn't running, but changes will probably be made close to every time until I make a map I like.

Thanks

el_supremo

Write the Excel file as a CSV using commas to separate the values. On the Arduino, read the values into an array and away you go.

Pete

Cowboy303

Thank you all for your help, I was able to use the arrays like Pete said.  should work really good!!!

Code: [Select]
const int rows = 15;
const int cols = 15;
int Map[rows][cols];


Code: [Select]
void downLoadMap(){
  int gettingValue = 0;
  int xPos = -1;
  int yPos = -1;
  byte NR;//Number Read from SD card
  byte isMapDone = 0;
  boolean mapDone = false;
  File dataFile = SD.open("Book1.txt");
  if (dataFile){
    if(dataFile.available()){
      while(mapDone == false){
        NR = (dataFile.read());
        if(NR>='0' && NR<='9')
        {
          NR=NR-'0';
          gettingValue = ((gettingValue*10)+NR);
        }
        else if(NR == 10)
        {
          yPos++;
          xPos= -1; 
        }
        else if(NR == 255)
        {
          isMapDone++;
          if(isMapDone >= 3)
            mapDone = true;
        }
        else
        {
          if(yPos >= 0 && xPos >= 0)
          {
            Map[yPos][xPos] = gettingValue;
          }
          gettingValue = 0;
          xPos++;
        }
      }
    }
  }
  for(int z=0;z<=10;z++){//display it to the Serial Monitor...
    Serial.println();
    for(int v=0;v<=10;v++){
      Serial.print(Map[z][v]);
      Serial.print(',');
    }
  }
}


Here's the code for someone else that stumbles across this thread, my coding skills are pretty bad, but hopefully you can get something from it.

Thanks again!

Go Up