{"id":23831904,"url":"https://github.com/onitake/canhat","last_synced_at":"2025-06-20T03:04:53.613Z","repository":{"id":146469474,"uuid":"178968171","full_name":"onitake/canhat","owner":"onitake","description":"Raspberry Pi CAN extension board","archived":false,"fork":false,"pushed_at":"2023-09-24T19:31:28.000Z","size":1328,"stargazers_count":13,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-20T03:04:07.986Z","etag":null,"topics":["can-bus","electronics","kicad","raspberry-pi"],"latest_commit_sha":null,"homepage":null,"language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onitake.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-02T00:27:40.000Z","updated_at":"2025-04-27T01:55:06.000Z","dependencies_parsed_at":"2025-01-02T17:01:04.555Z","dependency_job_id":null,"html_url":"https://github.com/onitake/canhat","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/onitake/canhat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onitake%2Fcanhat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onitake%2Fcanhat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onitake%2Fcanhat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onitake%2Fcanhat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onitake","download_url":"https://codeload.github.com/onitake/canhat/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onitake%2Fcanhat/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260868849,"owners_count":23074959,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["can-bus","electronics","kicad","raspberry-pi"],"created_at":"2025-01-02T14:10:33.280Z","updated_at":"2025-06-20T03:04:48.598Z","avatar_url":"https://github.com/onitake.png","language":"Makefile","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CAN HAT for Raspberry Pi Zero\n\nLook! A hat! :tophat:\n\nThis little board extends the Raspberry Pi with a CAN interface, a 5V regulator\nto supply the Pi with power and a pin header to access some GPIO lines.\n\n![canhat](https://github.com/onitake/canhat/assets/371687/27ac0d41-902f-49d6-9be3-aae559b2bb56)\n\n\n## Specifications\n\n### Mechanical\n\nThe board outline and component placement conform to the [Micro HAT specification]\nand the [Add-On Boards and HATs] specification. It is designed to fit the\nRaspberry Pi Zero, but can also be mounted to other models. (Pi 2, 3, 4, ...)\n\nInstead of the usual DB9 connector found on many CAN interface boards, the\nCAN HAT has terminal blocks for easier wiring and a smaller footprint.\n\nFor added stability, 11mm spacers should be mounted between the Pi and the HAT.\n\n### Electronics\n\nThe circuit is built around the Microchip MCP2515 CAN Interface Controller,\nconnected to SPI port 0 on the Raspberry Pi, and a CAN transceiver IC.\n\nIt is highly recommended to use a 5V CAN transceiver with a separate 3.3V\ninput for the RX/TX pins, such as Texas Instruments SN65HVD541.\nWhen using a different transceiver without split voltage, the voltage inputs\nmust be reconfigured through solder bridges JP3 and JP4.\n\nThe SN65HVD541 also supports disabling the transceiver through pin 8.\nThis pin is connected to ground via JP2 and 0Ω resistor R5 by default,\nwhich enables the transceiver at full speed. With JP2, it can be connected\nto Raspberry Pi pin GPIO22, which makes it controllable. Not that this is not\nsupported by the MCP2515 device drivers and must be implemented manually.\nR5 is useful for transceivers that support slope control, but this is not\navailable in the SN65HVD541.\n\nSee the section \"Transceiver Configuration\" below.\n\nTo reduce interference on the CAN bus, tuned microstrips were used to\nconnect the CAN transceiver to the terminals on the PCB. The differential\nimpedance is matched to 60Ω. For added fun, the pair length is also matched\nwith meanders.\n\nAside from the CAN interface part, an additional ID EEPROM ensures conformance\nwith the HAT specification. JP1 is only needed to program the EEPROM. The part\ncan be left out if desired, and the connection be made by other means, such as\na screwdriver or a temporary solder bridge.\n\nThe left side of the board is populated with a 6-24V to 5V step-down converter.\nIf the Raspberry Pi is powered via USB, the components for this converter\nshould not be soldered, or at least not be connected to a power source.\nIt's also possible to power the Rasberry Pi from a 5V source via this\nconnector directly. See the section \"Power Options\" below.\n\nNote that the AP63205 regulator is rated for a maximum current of 2A.\nThe [Add-On Boards and HATs] specification recommends at least 2.5A, but 2A\nis normally sufficient unless a lot of peripherals and USB devices are used.\nThe Raspberry Pi 3 and the CAN HAT will only draw a few hundred mA when using\nEthernet and the CAN bus and no other external peripherals.\n\nOvervoltage protection is done through the TVS diode D1, but note it cannot\nhandle overcurrent. The fuse may not react quickly enough if a large amount\nof energy is sent through D1, and it may still fail to protect the circuit.\n\n### Transceiver Configuration\n\nThe recommended transceiver SN65HVDA541 has separate voltage inputs for\nthe logic and the CAN transceiver. In the default configuration, the logic\nis connected to 3.3V and the transceiver to 5V.\n\nIf transceiver power control should be possible from the Raspberry Pi,\ncut the solder bridge from JP2 (IOCTL) pins 1-2 and connect 2-3 instead.\nNote that this is not supported by the driver and must be implemented\nseparately.\n\nFor over transceivers, the 3.3V power supply should be disconnected by\ncutting JP3 (3VIO) and choosing an appropriate voltage on JP4 (VBUS).\n1-2 is 5V and 2-3 is 3.3V. Note that there is no input voltage protection\non the MCP2515, which is powered from 3.3V. Choosing a 5V part may result\nin damage to the MCP2515.\n\nIf the chosen transceiver supports slope control on pin 8, JP2 should be\nleft in position 1-2 and the 0Ω resistor R5 should be replaced with an\nappropriate value. Refer to the transceiver's data sheet for more information.\n\n### Power Options\n\n:warning: **Do not supply power to the Raspberry Pi and J5 at the same time!**\n\nThe CAN hat can backpower the Raspberry Pi, but it can also be powered by it.\n\nThe following configurations are supported:\n\n#### All power on Raspberry Pi\n\nIf you're already powering the Raspberry Pi from a 5V source (such as USB),\nyou don't need the regulator circuit on the CAN hat.\n\nLeave out the parts J5, F2, D1, D2, C9, U4, C10, L1, C12 and C13.\n\n#### 5V power on CAN hat\n\nIn this configuration, 5V is delivered directly from the hat to the RPi.\n\nLeave out the parts F2, D1, D2, C9, U4, C10, L1, C12 and C13, but connect\nthe solder bridge JP5.\n\n#### 12V power on CAN hat\n\nIf you only have a 12V power source available, you can populate the step-down\nvoltage regulator on the CAN hat, which will convert the input to 5V and feed\nit to the Raspberry Pi.\n\nKeep the solder bridge JP5 disconnected, or you may damage your Raspberry Pi!\n\nInput polarity reversal and overvoltage is protected by D2 and D1, but you\nshould still make sure not to swap the polarity on the 12V input.\nFailure to do so could lead to a short-circuit via other bus components.\n\n## Cabling and Termination\n\nIt is recommended to use twisted pair or star quad cabling to connect other\nCAN nodes. With star quad cables, connect opposite wires together to the\nsame terminal for better noise resistance.\n\nUse shielded cable if possible and make sure all CAN bus componentes share\na common ground. To facilitate connecting the bus ground, there is a ground\nterminal for each CAN connection, marked with an earth sign (⏚).\n\nIf the Raspberry Pi is the last node in a chain, attach a 120Ω termination\nresistor to the terminals marked with a downwards arrow (↓).\n\n:warning: **Note the polarity on the terminals! CAN does not support swapping\nthe H/L pins.**\n\n## GPIO Pins\n\nFor added convenience, 4 Raspberry Pi GPIO pins are available via an optional\nconnector on the board. If you would like to use them, solder the J3 header.\n\nR11, R12, R13, R14 are optional pull-up resistors. When using the GPIO lines\nas external inputs, you can solder 1k-10k resistors into them. A ground pin\nfor toggling the logic level is available on the pin header.\n\nThe 4 GPIO lines are: GPIO19, GPIO20, GPIO21, GPIO26. GPIO19-21 are also\navailable for SPI, but this requires custom configuration and is outside\nthe scope of the CAN HAT.\n\nNote: To actually use the GPIO pins, you must edit eeprom_settings.txt to\nsuit your custom configuration, or enable the GPIO pins from user space\nafter booting the Raspberry Pi.\n\n## Integration\n\nThe built-in ID EEPROM contains device information according to the\n[HAT ID EEPROM Specification], as well as a Device Tree blob. This allows for\nautomatic configuration when Linux boots.\n\nThe EEPROM can be programmed in the field by shorting the jumper JP1 and\nflashing with the help of [eepromutils].\n\nThe provided Makefile will compile a DeviceTree overlay and the device descriptor\ninto an EEPROM image. To build the image, type:\n\n    make\n\nTo flash the image to the attached EEPROM, you first need to allow access to\nthe first I²C bus. On the Raspberry Pi, this bus is used for several system\ncomponents, and hidden by default to avoid accidental access. Put the following\nline into `/boot/config.txt`:\n\n    dtparam=i2c_vc=on\n\nShort the write protection jumper, reboot, and flash the EEPROM:\n\n    sudo make flash\n\nRemove the line from `/boot/config.txt` and the jumper, then reboot.\n\nThe preconfigured I²C bus and and device address correspond with the AT24C32E\nchip on the HAT. Change them in the Makefile if you use a different device.\n\nThe CAN bus should then appear automatically as network device `can0`.\n\n## Compatibility\n\nThe HAT is fully compatible with the Linux drivers for the MCP2551.\nRefer to the [CAN bus on raspberry pi quick guide] for more information\non how to configure the device manually.\n\nThis may be necessary on older Raspberry Pi boards that don't support the\nID EEPROM feature.\n\nDuring testing, you can use the following command to quickly load the driver\nwithout the ID EEPROM:\n\n    sudo dtoverlay mcp2515-can0 oscillator=16000000 interrupt=12\n\nNote that the interface still needs to be brought up like a network device:\n\n    sudo ip link set can0 up type can bitrate 125000 loopback off sample-point 0.75\n\nThis configures a line speed of 1MHz. Commonly supported rates are 125kHz or\n1MHz. Choose according to your other CAN components and wiring quality.\n\n## Links\n\n[Add-On Boards and HATs]: https://github.com/raspberrypi/hats\n[Micro HAT Specification]: https://github.com/raspberrypi/hats/blob/master/uhat-board-mechanical.pdf\n[HAT ID EEPROM Specification]: https://github.com/raspberrypi/hats/blob/master/eeprom-format.md\n[CAN bus on raspberry pi quick guide]: https://www.raspberrypi.org/forums/viewtopic.php?t=141052\n[eepromutils]: https://github.com/raspberrypi/hats/tree/master/eepromutils\n[Overview of 3.3V CAN Transceivers]: http://www.ti.com/lit/an/slla337/slla337.pdf\n\n### Data Sheets\n\n* [Microchip MCP2515 CAN Interface Controller](https://www.microchip.com/wwwproducts/en/en010406)\n* [Microchip MCP2551](http://ww1.microchip.com/downloads/en/devicedoc/21667e.pdf)\n* [Texas Instruments SN65HVD234 3.3 V CAN Transceiver](http://www.ti.com/product/SN65HVD234)\n* [Microchip AT24C32E 32Kbit Serial EEPROM](https://www.microchip.com/wwwproducts/en/AT24C32E)\n* [Diodes Inc AP63205 Buck Regulator](https://www.diodes.com/assets/Datasheets/AP63200-AP63201-AP63203-AP63205.pdf)\n\n## Legal\n\nThis circuit, schematics, board layouts and accompanying documentation is\nCopyright © 2019-2022 by Gregor Riepl\n\nYou may use it under the terms of the CERN Open Hardware Licence, version v1.2.\n\nRaspberry Pi is a trademark of the Raspberry Pi Foundation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonitake%2Fcanhat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonitake%2Fcanhat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonitake%2Fcanhat/lists"}