I am trying to address particular on the can network i have created but i am unable to talk to a specific device address. i recieve messages from 1-8 but its from all addresses how would i target a particular address???
sorry im a noob to this and im just piecing together peoples existing code im not sure where to go from here
#include <SPI.h> //Library for using SPI Communication
#include <mcp2515.h> //Library for using CAN Communication (https://github.com/autowp/arduino-mcp2515/)
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x3F for a 16 chars and 2 line display
struct can_frame canMsg;
MCP2515 mcp2515(10); // SPI CS Pin 10
void setup()
{
Serial.begin(9600); //Begins Serial Communication at 9600 baudrate
SPI.begin(); //Begins SPI communication
lcd.init();
lcd.clear();
lcd.backlight(); // Make sure backlight is on
lcd.setCursor(0, 0);
lcd.print("CANBUS TUTORIAL");
delay(3000);
lcd.clear();
mcp2515.reset();
mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ); //Sets CAN at speed 500KBPS and Clock 8MHz
mcp2515.setNormalMode();
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
//Serial.print("humi");
}
void loop()
{
if (mcp2515.readMessage(&canMsg) == MCP2515::ERROR_OK) // To receive data (Poll Read)
{
int x = canMsg.data[0];
int y = canMsg.data[1];
int z = canMsg.data[2];
float a = z *(5.0/256);
// lcd.setCursor(0, 0); //Display Temp & Humidity value received at 16x2 LCD
// lcd.print("Humi: ");
//lcd.print(x);
// lcd.setCursor(0, 1);
//lcd.print("Temp: ");
//lcd.print(y);
//delay(1000);
//lcd.clear();
Serial.print(" Humidity ");
Serial.print(x);
Serial.print("% ");
Serial.print(" Temp ");
Serial.print((y * 9/5) + 32);
Serial.print("F ");
//CAN.read(0x700)
//Serial.print("Temp ");
Serial.print(a );
Serial.println(" V");
//delay (100);
if (a>= 2) {
digitalWrite(4, HIGH);
// sets the digital pin 13 on
}else {
digitalWrite(4, LOW);
} // sets the digital pin 13 off
if (a>= 2.5) {
digitalWrite(5, HIGH);
// sets the digital pin 13 on
}else {
digitalWrite(5, LOW);
} // sets the digital pin 13 off
if (a>= 3.5) {
digitalWrite(6, HIGH);
// sets the digital pin 13 on
}else {
digitalWrite(6, LOW);
}
if (x>= 9) {
digitalWrite(7, HIGH);
// sets the digital pin 13 on
}else {
digitalWrite(7, LOW);
} // sets the dig
}
}