Coder Social home page Coder Social logo

Comments (12)

Petros144 avatar Petros144 commented on May 29, 2024

What happens when you Software Filter it? like:

if ((CAN.packetId() == 0x18daf110)
{

while (CAN.available()) {
Serial.print((char)CAN.read(), HEX);
}

from arduino-can.

mehrdad987 avatar mehrdad987 commented on May 29, 2024

thank you with your lib
I have a problem with mask and filtering I wanna receive one of the id's in can bus
Sensor_ID_in_DEC = (CAN.packetId());
CAN.filter(Sensor_ID_in_DEC, Sensor_ID_in_DEC);
is it the right thing to do
of course not cuz it's not working
(is there any example to just receive a specific id )
or anyone can help me with this ill appreciate it
thankyou

from arduino-can.

Petros144 avatar Petros144 commented on May 29, 2024

@mehrdad987
You read the bus and save the Vaiable to then filter it? - this not the right way.
"Sensor_ID_in_DEC = (CAN.packetId());"


Filter like this:

CAN.filter(0x7E8);

You will ONLY recive the given ID, in this case 0x7E8.

This is how it works. if you want multiple or a Range you need to make it in software like in my post above

from arduino-can.

mehrdad987 avatar mehrdad987 commented on May 29, 2024

yep
but it's not working I have many ids in can bus and I wanna receive one of them
and if I USE CAN.filter(0xCFF001); it ll receive nothing
and also it's not good cuz its find the id randomly

from arduino-can.

Petros144 avatar Petros144 commented on May 29, 2024

dont use the can.avalable it is too slow.

also do this in the reciver callback. it is mutch faster and filters all ids that you want!

from arduino-can.

Petros144 avatar Petros144 commented on May 29, 2024

also may consider this comit:
#27

for direct access of the Raw Can buffer.

from arduino-can.

mehrdad987 avatar mehrdad987 commented on May 29, 2024

YOU MEAN THIS virtual void onReceive(void(*callback)(int));
actually I'm a beginner and I don't know how to use it
if it's possible to make an example<>ill appreciate it

packetSize = CAN.parsePacket();
if (packetSize) {
  if (CAN.packetExtended()) {
  }
  if (CAN.packetRtr()) {
  }
  if((CAN.packetId())== 218038273){
    while (CAN.available()) {
      byte buff[8];
      CAN.readBytes((char *)buff,8);
      unsigned int byte0 = buff[0];

from arduino-can.

Petros144 avatar Petros144 commented on May 29, 2024

Try this:

But user the Lib for Raw buffer access:

#27

//Globals

#include <CAN.h>
uint8_t CanB[8];

int byte1;
int byte2;
int byte3;
int byte4;
int byte5;
int byte6;
int byte7;
int byte8;

void setup() {

CAN.begin(500E3); //Baud Rate
CAN.onReceive(onReceive); //Calback

}

void loop() {
//Print packet
Serial.println(byte1);
Serial.println(byte2);
Serial.println(byte3);
Serial.println(byte4);
Serial.println(byte5);
Serial.println(byte6);
Serial.println(byte7);
Serial.println(byte8);

}

void onReceive(int packetSize) {

CAN.readBytes(CanB, 8); // CanB is the Name of the Buffer

if (CAN.packetId() == 0x220)
{

byte1 = CanB[0];
byte2 = CanB[1];
byte3 = CanB[2];
byte4 = CanB[3];
byte5 = CanB[4];
byte6 = CanB[5];
byte7 = CanB[6];
byte8 = CanB[7];

}

}

from arduino-can.

zalexzperez avatar zalexzperez commented on May 29, 2024

Hi, I'm a newbie in programming and Arduino, sorry for the dumb questions below! :

Taking a look at the last code, I see that CAN.onReceive(onReceive) is a replacement to CAN.parsePacket() and CAN.available to receive CAN packets in order to get good filtering capabilities. But CAN.onReceive is only executed once because it's in the void setup() function.
Does this mean that only one packet will be captured during program execution? If not, how is it possible that void onReceive(int packetSize) is called multiple times if it's not called out from the void loop () function?

Also, If I'd like to filter the data buffer (ID=0x206, byte1=01 byte2=84 byte3=00 byte4,5,6,7,8=00), would it be fine if I used an IF statement inside the void loop()...or should it be inside the void onReceive(int packetSize) function?
For instance, what I'd do is:

void(loop){

   if(byte1==0x01 && byte2==0x84 && byte3==0x00){
   // actions here (send media commands over bluetooth)

}

Thanks in advance

from arduino-can.

timurrrr avatar timurrrr commented on May 29, 2024

@zalexzperez CAN.onReceive(xyz) sets up xyz as a callback. It should be called for every message received.

If you want to filter packets by data, you probably want to do it in the callback function, not the loop() function.

from arduino-can.

kouuta avatar kouuta commented on May 29, 2024

I encountered a problem where ESP32 would freeze when using extended ID for communication.
The freeze usually happened after 5 to 40 minutes, and it was difficult to identify the cause.
Therefore, I attempted to implement filtering by ID to improve stability, but I got a runtime error.
Thus, I made the modifications according to #117 , which fixed the freezing issue simultaneously.
I believe that the PR of #117 will be the solution to this issue.
Bests,

from arduino-can.

sandeepmistry avatar sandeepmistry commented on May 29, 2024

Fixed by #117.

from arduino-can.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.