PlatformIO Community

M5Stack library missing mcp_can.h

Hi, complete noob here. I am having problems using the M5Stack library in VSCode. In the Arduino IDE I can complile the code no problem but with pio I am getting this error.

src\commu_can_receiver.cpp:9:21: fatal error: mcp_can.h: No such file or directory

Both the library in pio and github.com are version 0.3.0 and the library I need is below.

https://github.com/m5stack/M5Stack/blob/master/examples/Modules/COMMU/MCP_CAN_lib.rar

Why doesn’t pio find this header file and what is the best solution so I can compile the code?

Thanks in advance, Greg

If it needs that specific library version to compile the easiest way would be best to download the file, unpack it and put it in the lib/ directory, so that the file structure is lib/MCP_CAN_lib/<source files>. Usually for library management (see docs) we would use a lib_deps statement in the platformio.ini to point to an external needed library, but I’m not sure if PIO can unpack a .rar file instead of the usual .zip file.

Though in this case (judging from the name of the header files) it may also be sufficient to use the registered CAN_BUS_Shield, as it can be searched for in the library searcher. Following the general documentation on the library page it will tell you that you can add it to the project by e.g. putting

lib_deps = 
    CAN_BUS_Shield

in the platformio.ini.

That library is for Atmel AVR platform and I’m on Espressif32 so I don’t think it will be suitable for the M5Stack COMMU module that I am using.

Thanks, this solution worked.

Now my question is why doesn’t pio find the mcp_can.h in the M5Stack library when the file is here, MCP_CAN_lib.rar? Is the solution to simply have a MCP_CAN_lib.zip file with the same contents as the MCP_CAN_lib.rar file in the same location in the repo?

Thanks in advanced helping a noob understand how this all works.

PlatformIO will not attempt to blindly unpack any archive file in the project to see if there’s a library file it can use. Does it work in the Arduino IDE without previously installing this lib manually? I’d be suprised if the Arduino IDE did such a thing.

If it were at least a ZIP file it could be referenced with a statement like lib_deps = https://github.com/m5stack/M5Stack/raw/master/examples/Modules/COMMU/MCP_CAN_lib.zip directly, but the clean way for this author would be to put the modified library in its own proper repository under a new library name and proper library.json which defines this library. That way it can be registered in PlatformIO and referenced with a library name in lib_deps (and also picked up automatically by the LDF).

1 Like