Skip to content

Problem in send data to canbus #618

@imohammad74

Description

@imohammad74

Hello.
I have a network include Arduino and RPi 3B+. I Use python-can for receive data from Arduino and it's work well; But i can't send data from RPi to Arduino. I Used a sample code that is readthedocs; python don't me error, but don't receive data to Arduino.
(Although i can send data to Arduino with raspberrian termianal)
python-can: 2.2.0
python: 3.5.2

the python code:
bus = can.Bus(channel='can0', interface='socketcan') msg = can.Message(arbitration_id=123,data=[0, 25, 0, 1, 3, 1, 4, 1]) time.sleep(2) print (msg) bus.send(msg)

the Arduino code:

`
#include <SPI.h>
#include "mcp_can.h"

const int spiCSPin = 10;
const int ledPin = 2;
boolean ledON = 1;

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;
unsigned char buf[8];

if(CAN_MSGAVAIL == CAN.checkReceive())
{
  CAN.readMsgBuf(&len, buf);
    printf("Heloo");

    unsigned long canId = CAN.getCanId();

    Serial.println("-----------------------------");
    Serial.print("Data from ID: 0x");
    Serial.println(canId, HEX);
  }

}
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions