Hey there future frustrated forum searcher,
I spent half a day cursing the Arduino MKR CAN Shield and the annoying lack of good documentation on docs.arduino.cc. Don't let the pretty layout fool you, there's not much meat on the bone over there.
If you are like I was, excited to take your CAN gadget out into the wild with your trusty LiPo pack, only to find it mysteriously falling flat when the USB cable gets unplugged, then I think I have the solution for you!
What the docs and the examples fail to mention is that the CAN transceiver requires at least 4.75 volts on the VCC pin in order to power on. This pin is supplied by the +5V bus on the schematics, and this is connected to the 5V coming from USB when you're plugged in.
However, when you're on battery, this bus only gets about 3.2V. But, you can enable the boost converter on the built-in PMIC and get this powered up to 5V while on battery power!
Just install the Arduino_BQ24195 library, add #include <Arduino_PMIC.h> to your sketch, then call PMIC.begin() and PMIC.enableBoostMode() in your setup() function. See the example included with the library for better error handling you can copy paste.
#include <Arduino_PMIC.h>
void setup() {
Serial.begin(9600);
// while (!Serial); // Wait for serial connection to continue
// PMIC is the Power Management IC on the ARduino
if (!PMIC.begin()) {
Serial.println("Failed to initialize PMIC!");
while (1) {blink_led(50);}
}
// Enable boost mode, this mode allows the board
// to provide power to the CAN tranceiver while on battery
if (!PMIC.enableBoostMode()) {
Serial.println("Error enabling Boost Mode");
}
Serial.println("PMIC Initialization Done!");
// ... Rest of your setup()
}
Hope that helps. Its a shame that they so prominently advertise that the CAN Shield works on battery, but then never mention this arcane detail to get it working.