Comments (12)
What happens when you Software Filter it? like:
if ((CAN.packetId() == 0x18daf110)
{
while (CAN.available()) {
Serial.print((char)CAN.read(), HEX);
}
from arduino-can.
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.
@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.
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.
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.
also may consider this comit:
#27
for direct access of the Raw Can buffer.
from arduino-can.
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.
Try this:
But user the Lib for Raw buffer access:
//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.
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.
@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.
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.
Fixed by #117.
from arduino-can.
Related Issues (20)
- ESP to Pi not working
- Logic analyser HOT 2
- ESP32 CAN bus errors at 95 kbps HOT 1
- ESP8266 support HOT 3
- ESP32 esp_intr.h header file deprecation warning HOT 1
- SN65HVD230DR ESP32 not communicating HOT 1
- When compiling a file for esp32 s3 dev board, i get the following errors. Is there a new CAN.c file to help? HOT 6
- Is this lib dead? HOT 6
- How can i use this library with a raspberry pi pico?
- Not getting messages
- ESP32 - only 1 extended filter working, is it possible to specify multiple filters? HOT 13
- Esp32 s3 support HOT 2
- Not working with Espressif 3.0
- 怎么知道数据有没有发送成功
- Esp32 multiple ID filter HOT 1
- CPU restart in callback HOT 1
- Working with MCP2515 on Arduino Nano, but fails on ESP32 HOT 2
- ESP32SJA1000Class::filterExtended mask calculation incorrect
- setup() and loop() functions are missing
- can i work with the MCP2515 SPI MODULE instead of the MKR can shield
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino-can.