CAN-BUS shield send data problem!!

Hi all,



I have a seeed canbus shield v2.0 attached on an arduino uno.

My project is to send several data from sensors (analog/digital/i2c) from arduino to an external ECU via can bus protocol.



At the moment I have managed to connect the shield using can L & can H and declare an id10.0.0.0.1 192.168.1.254 hotmail.com

entifier as 0 (zero) running a send example from shield and I can see that there is a communication between the two devices, which is good.

Although, I cannot send the correct data.

To make it easier I have just loaded a temp/hum DHT11 sketch merged with some code lines of the shield’s send example.



Any idea how to declare and send the temperature or humidity via can bus? I have tried several combinations but still nothing.

I don’t have any experience on can bus, so any comment would be helpful.

You can find attached the code.



Thanks
[code]#include “DHT.h”

#define DHTPIN 2 // what pin we’re connected to

// Uncomment whatever type you’re using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

#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);
Serial.println(“DHTxx test!”);

dht.begin();

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 smtp[8] = {0,1,2,3,4,5,6,7};
void loop()
{
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
float h = dht.readHumidity();
float t = dht.readTemperature();

// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) 
{
    Serial.println("Failed to read from DHT");
} 
else 
{
    Serial.print("Humidity: "); 
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: "); 
    Serial.print(t);
    Serial.println(" *C");
}

CAN.sendMsgBuf(0, 0, 8, smtp);
delay (10);

}[/code]

Hi there

you should visit <LINK_TEXT text=“https://www.csselectronics.com/screen/p … anguage/en”>https://www.csselectronics.com/screen/page/simple-intro-to-can-bus/language/en</LINK_TEXT> to grasp what mean CAN BUS.and, our wiki http://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/ will provide code support for the CAN BUS. :smiley:

Thanks for the links, these are gold mines! I did have trouble wrapping my head around CAN-BUS…