Hello,
im having a hard time combining code snippets.
i have a arduino uno and a seeed studio can shield (CS= pin 9) and a seeed studio sd shield (CS= pin 4)
ive searched for many many "read csv file from sd card" code examples but they usually just print to the serial line.
for the send to the can shield code, the example that seeed provides is pretty straight forward
// demo: CAN-BUS Shield, send data
#include <mcp_can.h>
#include <SPI.h>
// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
void setup()
{
Serial.begin(115200);
while (CAN_OK != CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("CAN BUS Shield init fail");
Serial.println(" Init CAN BUS Shield again");
delay(100);
}
Serial.println("CAN BUS Shield init ok!");
}
unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
void loop()
{
// send data: id = 0x00, standrad frame, data len = 8, stmp: data buf
CAN.sendMsgBuf(0x00, 0, 8, stmp);
delay(100); // send data per 100ms
}
however, id like to replace the stuff in parentheses:
CAN.sendMsgBuf([b]0x00, 0, 8, stmp[/b])
with a single variable that is the line that is read from the csv file on the SD card.
i know that id have to rework that variable just above the CAN.sendMsgBuf()
i use the can shield to log my vehicles can data straight into a csv file already.
id like to send 7 lines of the saved can data in the csv file on the SD card to the can shield(the 7 variables that ive previously logged into a file and will send later) and then pause for 1 sec, and then send the next 7 lines.
the problem im having is finding a sketch that is close to what im looking to do for the sd text read that is not crazy complicated/under documented so that i dont get overwhelmed trying to work my way down through the code to figure out how to edit it to do what i want.
for clarification, it would flow something like this
read csv line 1 till \n-> save to variable (line) ->CAN.sendMsgBuf(line)
read csv line 2 till \n-> save to variable (line) ->CAN.sendMsgBuf(line)
read csv line 3 till \n-> save to variable (line) ->CAN.sendMsgBuf(line)
read csv line 4 till \n-> save to variable (line) ->CAN.sendMsgBuf(line)
read csv line 5 till \n-> save to variable (line) ->CAN.sendMsgBuf(line)
read csv line 6 till \n-> save to variable (line) ->CAN.sendMsgBuf(line)
read csv line 7 till \n-> save to variable (line) ->CAN.sendMsgBuf(line)
pause(1000)
anyone have any pointers. im muddling through this and reading all the reference material i can read and im still having a hard time.
Thanks
Brian