That helped birdmun and
That helped birdmun and Oddbot, thanks.
So now i have it pulling out the first line (I have had to use the letterG to terminate, no idea why but i will sort that once this first issue is sorted. The program doesnt cycle though. it only does one iteration and then stops.
can you see why? Do i need to re open the file each time?
(Updated to include ALL the code)
//LIBRARIES
#include <SD.h>
#include <AFMotor.h>
//CONNECTIONS
File myFile; // instance of a file
const int chipSelect = 15; // adafruit SD breakout, wired 15 - 18. must use modified SD library to allow for reassignment of pins.
AF_Stepper motorL(200, 1); // Left Motor, M1 & M2
AF_Stepper motorR(200, 2); // Right Motor, M3 & M4 // Forward is Up on both motors.
const int button = 13; //button holds the sketch in setup, until pressed. This stops the motors from moving under USB power while uploading.
const int led = 14;
const int relay = 2;
// WORKING VALUES
char inputString [100];
char inputChar;
int stringIndex = 0; // String stringIndexing int;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
// setup
pinMode (led, OUTPUT);
pinMode (button, INPUT);
pinMode (relay, OUTPUT);
motorL.setSpeed(20); // 10 rpm
motorR.setSpeed(20); // 10 rpm
Serial.print(“Motors ready, Initializing SD card…”);
// make sure that the default chip select pin is set to
// output, even if you don’t use it:
pinMode(SS, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(15,16,17,18)) {
Serial.println(“Card failed, or not present”);
// don’t do anything more:
while (1) ;
}
Serial.println(“card initialized.”);
// Open up the file we’re going to log to!
myFile = SD.open(“HELLO.txt”);
if (! myFile) {
Serial.println(“error opening datalog.txt”);
// Wait forever since we cant write data
while (1) ;
}
digitalWrite (led, HIGH);
Serial.println(“Waiting…”);
//hold
while (digitalRead (button) == HIGH){
// stops script. Its waiting for a button press (LOW on “button”)
}
Serial.println("…Running");
}
void loop()
{
inputChar = myFile.read(); // Gets one byte from serial buffer
if (inputChar != ‘G’) // define breaking char here (\n isnt working for some reason, i will follow this up later)
{
inputString[stringIndex] = inputChar; // Store it
stringIndex++; // Increment where to write next
}
else
{
Serial.print("test: "); // shows that the program is cycling, for debugging only
Serial.println(inputString);
delay (1000);
stringIndex = 0; // clear the value for the next cycle
}
}