Arduino Ethernet Shield and SD Reader

Hi Everyone,

My project is coming a long nicely and I received the much anticipated Ethernet shield in the mail last week. I’ve never used an Ethernet shield before and seek your guidance.

My Uno is controlling 4 servos and I intend to use the Ethernet shield to provide information from the SD card to tell each servo to cycle. Now, I have no idea what format to store information on the SD card nor, do I know how to get the Uno to look for it.

The information I intend to store is number sequences of 0001, 0010, 0100, 1000, 0011, etc. There will be thousands of these 4 digit number sequences, many of which will repeat. What format would I used to store this information on the SD card?

In controlling the servo’s, I intend to have the number sequence 0001 to cycle Servo1, sequence 0010 to cycle Servo2 and so on. When there are more than one number 1s in the sequence, I intend to have the Uno operate both Servos at the same time. For example, 0110 would cause Servo2 and Servo3 to cycle, and so on. Again, I have never used the Ethernet shield or an SD card to provide instruction for the Uno and not sure how to add this to my code.

I will include the code I am using so you can get a feel of what I am trying to do.

Thank you

// Four Servo
// Modified by Daniel O'Connor 
// Original code found at <http://barraganstudio.com> written by BARRAGAN



#include <Servo.h> 
 
Servo myservo2;  
Servo myservo3;  
Servo myservo4;  
Servo myservo5;  // create servo object to control a servo 
                 
 
int pos = 0;    // variable to store the servo position 
 
void setup() 
{ 
  myservo2.attach(2);  // attaches the servo on pin # to the servo object 
  myservo3.attach(3);
  myservo4.attach(4);
  myservo5.attach(5);
} 
 
 
void loop() 
{ 
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo2.write(pos);              // tell servo to go to position in variable 'pos' 
    myservo3.write(pos);
    myservo4.write(pos);
    myservo5.write(pos);
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo2.write(pos);              // tell servo to go to position in variable 'pos' 
    myservo3.write(pos);
    myservo4.write(pos);
    myservo5.write(pos);
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
}

Now, I have no idea what format to store information on the SD card nor, do I know how to get the Uno to look for it.

The format (ASCII or binary) will be defined by the application that is used to write the data to the card.

There are examples provided with the IDE that show how to read data from the SD card.

The information I intend to store is number sequences of 0001, 0010, 0100, 1000, 0011, etc. There will be thousands of these 4 digit number sequences, many of which will repeat. What format would I used to store this information on the SD card?

What do the ones and zeros mean? How important is speed? What application is generating the data?

In controlling the servo's, I intend to have the number sequence 0001 to cycle Servo1, sequence 0010 to cycle Servo2 and so on.

It seems to me that 1, 2, 3, and 4 would make more sense.

When there are more than one number 1s in the sequence, I intend to have the Uno operate both Servos at the same time. For example, 0110 would cause Servo2 and Servo3 to cycle, and so on.

OK, never mind that last comment. But, what does "cycle" mean? Using a for loop, any number of servos can be commanded at one time. The actual value to write to the servo does not need to the same for each servo.

The format (ASCII or binary) will be defined by the application that is used to write the data to the card.

There are examples provided with the IDE that show how to read data from the SD card.

Great, thank you.

What do the ones and zeros mean?

I am converting text to 8-bit binary and I will manually "break up" the string of 1s and 0s into 4 digit segments. Each 1 is to represent the loop of its corresponding servo motor from 0 -180-0 degrees.

How important is speed?

The retrieval processes does not need to be very fast, I would need it to be consistent though. A 1000ms interval used to retrieve each new string of numbers (the 1s and 0s) would be sufficient.

What application is generating the data?

I have not designated a specific application to generate the data. I plan on using Text Edit and manually typing out the 1s and 0s, then saving the file in the required format, storing the data on the SD card manually, and hope that the Adruino will be able to locate and read the data.

But, what does "cycle" mean? Using a for loop, any number of servos can be commanded at one time.

"Cycle" is a term I have used to describe the "loop" of each servo from 0-180-0 deg. Do you think it is possible in the code to allow each servo to move from 0-180 deg. and wait till the next string of data has another 1 in its corresponding location in the sequence to return from 180-0 deg.? For example, a retrieved set of numbers, such as 0001, would cause Servo1 to move from 0-180 deg. and stop. Then a recalled number of 0000 (or what ever the next set of number is recalled), would cause Servo1 to remain stationary, and a third recalled number of 0001 (for the second time) would cause Servo1 to return from 180-0 deg. And, would it be possible to have all 4 servos operate the same way?

Do you think it is possible in the code to allow each servo to move from 0-180 deg. and wait till the next string of data has another 1 in its corresponding location in the sequence to return from 180-0 deg.?

Yes, though it might be easier to understand the code if you use 0 (do nothing), 1 (move from 0 to 180) and 2 (move from 180 to 0) in each position, rather than keeping track of which way to move.

Yes, though it might be easier to understand the code if you use 0 (do nothing), 1 (move from 0 to 180) and 2 (move from 180 to 0) in each position, rather than keeping track of which way to move.

I agree.

I find the Arduino Learning section to be very helpful.