I am working on a project where I would like to send CAN data for photosensitive sensor measurements from an Ardunio Nano to Ardunio Uno, and each microcontroller is connected with an MCP 2515 CAN module and the modules are connected to each other with CAN-High and CAN_Low. On each computer connected with the microcontrollers, I am trying to view the data on the serial port using Microsoft Excel Data Streamer. When I connect the device and click Start Data, no data is being shown on either of the computers.
By checking the serial monitor on both ends, it does show the data being sent and received, but nothing is shown on the Excel Dtat Streamer. Is there anything additional I need to add to the Arduino code or change the Streamer's setup?
Below, is the code I am using to read the data from the sensor and send it through CAN:
const int LightSensor = A0;
unsigned char AmbLight[1];
const int spiCSPin = 10;
int ledHIGH = 1;
int ledLOW = 0;
#include <SPI.h>
#include <mcp_can.h>
MCP_CAN CAN(spiCSPin);
void setup() {
Serial.begin(115200);
Serial.println("CLEARDATA"); //clears up any data left from previous projects in Excel
//Serial.println("LABEL,Acolumn,Bcolumn,..."); //always write LABEL, so excel knows the next things will be the names of the columns (instead of Acolumn you could write Time for instance)
while (CAN_OK != CAN.begin(CAN_500KBPS))
{
Serial.println("CAN BUS init Failed");
delay(100);
}
Serial.println("CAN BUS Shield Init OK!");
}
void loop() {
float AmbL = analogRead(LightSensor);
AmbLight[0] = AmbL;
if (AmbLight[0] != NULL){
CAN.sendMsgBuf(0x43, 0, 1, AmbLight[0]);
Serial.println(AmbLight[0]);
}
}
And here is the code I use to receive the data through CAN:
#include <SPI.h>
#include "mcp_can.h"
const int spiCSPin = 10;
const int ledPin = 2;
boolean ledON = 1;
//char state;
MCP_CAN CAN(spiCSPin);
void setup()
{
Serial.begin(115200);
pinMode(ledPin,OUTPUT);
while (CAN_OK != CAN.begin(CAN_500KBPS))
{
Serial.println("CAN BUS Init Failed");
delay(100);
}
Serial.println("CAN BUS Init OK!");
}
void loop()
{
unsigned char len = 0;
char buf[8];
if(CAN_MSGAVAIL == CAN.checkReceive())
{
CAN.readMsgBuf(&len, buf);
unsigned long canId = CAN.getCanId();
Serial.println("-----------------------------");
Serial.print("Data from ID: 0x");
Serial.println(canId, HEX);
for(int i = 0; i<len; i++)
{
//state = buf[i];
Serial.print(buf[i]);
//printf("buf[i]=%c",buf[i]);
Serial.print("\t");
}
delay(500);
Serial.println();
}
}