Ive got a plan for my Polargraph! I was thinking i could extract Lat and Long data from a GPX file, and then make it draw a recorded route onto paper. I suggest GPX, because it seems to be by far the most common format. I would imagine the approach to take would be to have a computer process the data with a program, and then transmit the data as serial communication one way or another. The program could either transmit movements for the plotter, having calculated the movements required on the computer, or it could transmit a stream of longs and lats, and then the arduino could process the information.
Another way i guess would be to load a GPX file, wholesale onto an SD card, and then have the Arduino sketch process the file directly. It would have to chop out the required bits of data though!
i have a little experience of processing and getting it to communicate with an arduino, but i reckon it is based a bit to heavily on graphical rendering, and wouldnt be the best program to try and use?
any suggestions as to the best approach here?
I have an Adafruit SD shield, but whether it would stack onto the existing motordriver is another quesion. Might be better to connect them via a breadboard if i went with that option...
I think i am going to go down the SD card route. I have the datalogging shield (dont see why i shouldnt be able to read data from the card, as well as write to it). Hows this for a code process? :
1) Setup (including read first position)
2) Read next Lat/Long position
3) work out the difference between the two value-sets
4) calculate how to move the steppers to achieve this on the plotter
So i was hoping that SD files could be used on a line by line basis. ie: read a line, do something with it, and upon looping around increase an int which would tell it which line was on!?
I cant seem to find how to do that. As far as i can tell the Arduino uses text files etc as a continuous stream of data and cannot differentiate between lines? It can however differentiate between values and “punctuation”?
therefore i have cobbled together this sketch (below), along with a comment indicating where the bulk of the code will go.
It parses out two numbers, actions something, and then goes on to the next two. This approach requires that all the numbers are in pairs and dont get mixed up or swapped around! (which should be fine to be fair)
does this seem about right? it certainly prints out the lats and longs to the serial monitor as i wanted, so it should just be a case of putting “what we do with this data” in the correct position.
#include <SD.h>
File myFile; const int chipSelect = 10; // adafruit SD protoboard pin 10 int Lat; int Lon;
void setup() {
// Open serial communications and wait for port to open: Serial.begin(9600); Serial.print(“Initializing SD card…”); pinMode(SS, OUTPUT); if (!SD.begin(chipSelect)) { Serial.println(“initialization failed!”); return; }
Serial.println(“initialization done.”);
}
void loop() {
File myFile = SD.open(“CoOrd.txt”); if (myFile) { Serial.println(“CoOrd.txt”); while (myFile.available()) {
int Lat = myFile.parseInt(); int Lon = myFile.parseInt();
one thing that hasn’t been mentioned is EOF. If you are pulling data from an SD card, the file should have an EOF. That said you set up a while loop that looks for the read statement = EOF, or, while (read != EOF) {…} If you want, you can add a counter inside your loop, but, it won’t affect the flow of the loop. EOF is a special /null character. I believe it is /0 or /null.