SPI help - SD card and Shift register


hi all, seem have reached impasse code wise.

my desire load code onto micro sd card , have code run multitude of different devices. have been able sd card work , shift register work separately, , have been able run several servos based off of code read off sd card when servos connected arduino directly , not shift register.

when include shift register come problems. guess attempts deselect sd card pulling cs high not working. wise programming sages, willing take @ young fools code , perhaps make suggestions?
code: [select]


#include <sd.h>

file myfile;

char code;
int h = 2;

char buffer[5];
int b = 0;

long data[5];
int d = 0;

int pos = 0;

long duration(long start)
{
  long = millis();
  long interval = - start;
  return interval;
}

void setup()
{
  //serial.begin(9600);
  pinmode(11,output);
  pinmode(13,output);
  pinmode(2,output);
  pinmode(10,output);
  digitalwrite(2,high);

  while(!sd.begin(10))
  {
  }

  myfile = sd.open("test2.txt");

  while(myfile.available())
  {
    while(d < h)
    {
      code = myfile.read();

      if(code != '\r')
      {
        buffer[b] = code;
        b++;
      }
      else
      {
        buffer[b] = '\0';
        data[d] = atol(buffer);
        b = 0;
        d++;
      }
    }
    long servo = data[0];
    long angle = data[1];
   
    //serial.println(servo);
    //serial.println(angle);
   
    pos = myfile.position();
    myfile.close();
    digitalwrite(10,high);

    for(int = 0; < 20; i++)
    {

      digitalwrite(2,low);
      shiftout(11,13,msbfirst,servo);
      digitalwrite(2,high);

      long starttime = millis(); 
      while(duration(starttime) < angle)
      {
      }

      digitalwrite(2,low);
      shiftout(11,13,msbfirst,0);
      digitalwrite(2,high);

      starttime = millis(); 
      while(duration(starttime) < 25 - angle)
      {
      }
    }
    digitalwrite(10,low);
    myfile = sd.open("test2.txt");
    myfile.seek(pos);
    d = 0;
  }
}

void loop()
{
}


the serial communication data testing whether sd card part working right, , "//" out real run.

as additional info - sd transmits code fine, , when sd read part "//" out , 2 variables "servo" , "angle" replaced numbers 128 , .5, servo runs fine. why believe attempts deselect sd faulty.

any appreciated.

as side note - reason, atol weird things numbers read off card such rounding (turning 0.5 0 , 3.5 3, along other odd stuff). isnt big deal, , doesn't impede process, , easy enough around, there way fix without changing data type float??

any advice appreciated!!!

quote
as side note - reason, atol weird things numbers read off card such rounding (turning 0.5 0 , 3.5 3, along other odd stuff).

why think atol() (ascii long) doing weird things when truncates float values long (int)?

quote
the sd transmits code fine

no, doesn't sd card holds data. doesn't transmit anywhere - requires radio. doesn't hold code. code vs. data matter of interpretation of data.

code: [select]
      long starttime = millis(); 
      while(duration(starttime) < angle)
      {
      }

why re-implementing delay()? relationship between time , angle?


Arduino Forum > Using Arduino > Programming Questions > SPI help - SD card and Shift register


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support