A simple Arduino sketch for logging data from two separate CAN buses simultaneously and outputting in GVRET format for SavvyCAN compatibility.
- Dual CAN Bus Support: MCP2515 (CAN1) and ESP32 built-in CAN (CAN2)
- SD Card Logging: High-speed logging using SD_MMC interface
- Serial Output: Real-time data output to serial monitor
- GVRET Format: Native format compatible with SavvyCAN
- Configurable: Easy pin assignment and bit rate changes
- Error Handling: Comprehensive error checking and status reporting
- ESP32 Dev Board (any ESP32 development board)
- MCP2515 TJA1050 CAN Bus Module (for CAN1)
- Waveshare SN65HVD230 CAN Board (for CAN2)
- Generic SD Card Module (using SD_MMC interface)
- Micro SD Card (formatted as FAT32)
- Arduino IDE (version 1.8.x or later)
- ESP32 Board Support
-
Install ESP32 Board Support:
- Open Arduino IDE
- Go to File β Preferences
- Add this URL to "Additional Board Manager URLs":
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
- Go to Tools β Board β Board Manager
- Search for "ESP32" and install "ESP32 by Espressif Systems"
-
Download Project:
git clone https://github.com/yourusername/CanLog2.git cd CanLog2
-
Open Project:
- Open the entire CanLog2 folder in Arduino IDE
- Select Board: Tools β Board β ESP32 Arduino β ESP32 Dev Module
- Set Upload Speed: Tools β Upload Speed β 115200
-
Upload Sketch:
- Open
CanLog2.ino
- Click Verify to check for errors
- Click Upload to flash to your ESP32
- Open
Component | Pin | ESP32 GPIO | Description |
---|---|---|---|
CAN1 (MCP2515) | SCK | 18 | SPI Clock |
MOSI | 23 | SPI MOSI | |
MISO | 19 | SPI MISO | |
CS | 5 | Chip Select | |
INT | 2 | Interrupt | |
VCC | 3.3V | Power | |
GND | GND | Ground | |
CAN2 (SN65HVD230) | RX | 16 | CAN2 RX |
TX | 17 | CAN2 TX | |
VCC | 3.3V | Power | |
GND | GND | Ground | |
SD Card (SD_MMC) | CLK | 14 | SD_MMC_CLK |
CMD | 15 | SD_MMC_CMD | |
DATA0 | 2 | SD_MMC_DATA0 | |
DATA1 | 4 | SD_MMC_DATA1 | |
DATA2 | 12 | SD_MMC_DATA2 | |
DATA3 | 13 | SD_MMC_DATA3 | |
VCC | 3.3V | Power | |
GND | GND | Ground |
- Default Bit Rate: 500 kbps (configurable in
config.h
) - CAN1: MCP2515 controller via SPI
- CAN2: ESP32 built-in CAN controller
The logger outputs data in GVRET native format for SavvyCAN compatibility:
- Standard ID:
T
+ 3-char ID + 1-char length + data +\r
- Extended ID:
R
+ 8-char ID + 1-char length + data +\r
Example outputs:
T1238AABBCCDDEEFF\r
R1234567881122334455667788\r
CanLog2/
βββ CanLog2.ino # Main Arduino sketch
βββ config.h # Configuration file
βββ lib/
β βββ ACAN2515.h # MCP2515 CAN controller library (header-only)
β βββ ACAN2515Settings.h # Settings class
βββ examples/
β βββ TestSetup.ino # Hardware test sketch
βββ README.md # This file
βββ WIRING.md # Wiring diagram
βββ INSTALLATION.md # Installation guide
βββ .gitignore # Git ignore file
βββ library.properties # Library metadata
- Power up the ESP32 with all components connected
- Insert SD card (formatted as FAT32)
- Open Serial Monitor at 115200 baud
- Start logging - data will be written to both serial port and SD card
The serial monitor will show:
- Initialization status
- CAN message data in GVRET format
- Bus identifier for each message
- File:
/canlog.txt
- Format: Same GVRET format as serial output
- Auto-flush: Data is written immediately to prevent loss
Edit the pin definitions in config.h
:
// CAN1 - MCP2515 Configuration
#define MCP2515_SCK 18 // Change as needed
#define MCP2515_MOSI 23 // Change as needed
// ... etc
Modify the bit rate settings in config.h
:
#define CAN_BITRATE 500000 // Change to desired bit rate
#define CAN_BITRATE 100000 // 100 kbps
#define CAN_BITRATE 250000 // 250 kbps
#define CAN_BITRATE 500000 // 500 kbps
#define CAN_BITRATE 1000000 // 1 Mbps
Issue | Solution |
---|---|
SD Card Not Detected | Ensure SD card is formatted as FAT32, check wiring |
CAN1 (MCP2515) Not Working | Verify SPI connections, check CS and INT pins |
CAN2 (ESP32 CAN) Not Working | Check RX/TX connections, verify transceiver power |
No Data Received | Verify CAN bus is active, check bit rate settings |
The serial monitor provides detailed initialization information:
- SD card type and size
- CAN controller status
- Error codes if initialization fails
Use the included test sketch to verify your hardware setup:
- Open
examples/TestSetup.ino
- Upload to your ESP32
- Check serial monitor for component status
- All components should show β for successful initialization
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
For issues or questions:
- Check the troubleshooting section above
- Verify all connections and power supply
- Test with known good CAN bus data
- Check serial monitor for error messages
- Open an issue on GitHub
- ESP32 Arduino community
- SavvyCAN project for GVRET format specification
- MCP2515 datasheet and reference implementations