Skip to content

DaTwo/CanLog2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CanLog2 - Dual CAN Bus Logger for ESP32

Arduino ESP32 License

A simple Arduino sketch for logging data from two separate CAN buses simultaneously and outputting in GVRET format for SavvyCAN compatibility.

πŸš€ Features

  • 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

πŸ“‹ Hardware Requirements

  • 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)

πŸ”§ Installation

Prerequisites

  1. Arduino IDE (version 1.8.x or later)
  2. ESP32 Board Support

Setup Instructions

  1. 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"
  2. Download Project:

    git clone https://github.com/yourusername/CanLog2.git
    cd CanLog2
  3. 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
  4. Upload Sketch:

    • Open CanLog2.ino
    • Click Verify to check for errors
    • Click Upload to flash to your ESP32

πŸ”Œ Wiring Diagram

ESP32 Pin Connections

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

βš™οΈ Configuration

CAN Bus Settings

  • Default Bit Rate: 500 kbps (configurable in config.h)
  • CAN1: MCP2515 controller via SPI
  • CAN2: ESP32 built-in CAN controller

Output Format

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

πŸ“ Project Structure

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

🎯 Usage

  1. Power up the ESP32 with all components connected
  2. Insert SD card (formatted as FAT32)
  3. Open Serial Monitor at 115200 baud
  4. Start logging - data will be written to both serial port and SD card

Serial Output

The serial monitor will show:

  • Initialization status
  • CAN message data in GVRET format
  • Bus identifier for each message

SD Card Output

  • File: /canlog.txt
  • Format: Same GVRET format as serial output
  • Auto-flush: Data is written immediately to prevent loss

πŸ”§ Customization

Changing Pin Assignments

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

Changing Bit Rate

Modify the bit rate settings in config.h:

#define CAN_BITRATE    500000    // Change to desired bit rate

Common CAN Bit Rates

#define CAN_BITRATE    100000    // 100 kbps
#define CAN_BITRATE    250000    // 250 kbps
#define CAN_BITRATE    500000    // 500 kbps
#define CAN_BITRATE    1000000   // 1 Mbps

πŸ› οΈ Troubleshooting

Common Issues

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

Debug Information

The serial monitor provides detailed initialization information:

  • SD card type and size
  • CAN controller status
  • Error codes if initialization fails

πŸ§ͺ Testing

Use the included test sketch to verify your hardware setup:

  1. Open examples/TestSetup.ino
  2. Upload to your ESP32
  3. Check serial monitor for component status
  4. All components should show βœ“ for successful initialization

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ž Support

For issues or questions:

  1. Check the troubleshooting section above
  2. Verify all connections and power supply
  3. Test with known good CAN bus data
  4. Check serial monitor for error messages
  5. Open an issue on GitHub

πŸ™ Acknowledgments

  • ESP32 Arduino community
  • SavvyCAN project for GVRET format specification
  • MCP2515 datasheet and reference implementations

About

ESP32 Dual CAN Logger for SavvyCAN

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages