Uses the python-can library to listen for pushes of steering wheel buttons, which are visible on the Falcon's mid-speed controller area network with CAN ID 0x2F2. Also listens for ICC button pushes on CAN ID 0x2FC and BEM functions on 0x307. When a button is pushed, the script emulates a keypress on the Raspberry Pi. This is used here with OpenDash's implementation of Android Auto emulator Openauto to control basic media functions. The Car used is an Ford FG mk1 Falcon. The factory display from the vehicle has been replaced with a Raspberry Pi 7 Inch Touchscreen.
SWC are resistance based, all switches run on a single wire, pushing a button causes a specific resistance in the circuit. The Module sees a change in resistance, and accordingly sends data on to CAN-bus where it is recieved by the ACM/FDIM/ICC and acted upon.
-- Relevant ICC Diagrams + Pinouts
Vehicle: FG Falcon mk1
Interface: SocketCAN can0 interface, MCP2515 chipset, Midspeed-CAN@125kbps
Software: Can-Utils, Python-Can, Openauto, Opendash, Raspbian
SBC: Raspberry Pi 4B - 8gb, PiCan2 Hat, i2s audio hat
Other: Modified OBD-DB9 Cable, 7" Official Touchscreen, 2 Metre DSI Ribbon Cable, heatsink case, fans, enclosure, 12vdc-5vdc converter
- edit "/etc/modules" to include
uinput
can
can_dev
can_raw
vcan
-
Add the following to the 'config.txt' file in the /boot partition of the Raspberry Pi sd card.
dtoverlay=mcp2515-can0,oscillator=8000000,interrupt=25
-
If using a PiCan Board set oscillator to 16000000
oscillator=16000000
-
Add the following to '/etc/network/interfaces'
auto can0
iface can0 inet manual
pre-up /sbin/ip link set can0 type can bitrate 125000 triple-sampling on restart-ms 100
up /sbin/ifconfig can0 up txqueuelen 65535
down /sbin/ifconfig can0 down
-
Bring the can0 interface up
sudo ip link set can0 type can bitrate 125000 triple-sampling on restart-ms 100
sudo ifconfig can0 up txqueuelen 65535
sudo apt update -y && sudo apt upgrade -y && sudo apt install -y can-utils libsocketcan2 libsocketcan-dev python-can python3-can && sudo apt install -y python3-uinput python3-evdev && sudo git clone https://github.com/jakka351/can0swc ./can0swc && cd ./can0swc && pip3 install -r requirements.txt && sudo modprobe uinput && sudo cp ./can0swc.service /lib/systemd/system/can0swc.service && sudo systemctl enable can0swc.service && sudo systemctl start can0swc.service && sudo systemctl status can0swc.service && sudo reboot
- Test the script with socketcan virtual can interface, vcan0 and candump log files
sudo modprobe vcan0
sudo ip link add dev vcan0 type vcan
sudo ifconfig vcan0 up txqueuelen 1000
- Use canplayer to run the candump log
canplayer -I ./candump.log -v vcan0=can0
- If running cangen use '-L 8' to keep frames at 11bits or an error will occur
cangen vcan0 -c -L 8 &
- Candump logs available here
`cd ~/can0swc` `sudo python3 ./can0swc.py`
- Test the script with socketcan virtual can interface, vcan0 and candump log files
Address | Data | Function | Byte1 | Byte2 | Byte3 | Byte4 | Byte5 | Byte6 | Byte7 | Byte8 |
---|---|---|---|---|---|---|---|---|---|---|
754 |
8 bytes | Volume Data | 0x00 | x | x | x | x | x | x | x |
754 |
8 bytes | Seek | x | x | x | x | x | x | x | 0x08* |
754 |
8 bytes | Volume Up | x | x | x | x | x | x | x | 0x10* |
754 |
8 bytes | Volume Down | x | x | x | x | x | x | x | 0x18* |
754 |
8 bytes | Phone | x | x | x | x | x | x | 0x61** | x |
748 |
8 bytes | Mode | x | x | x | x | x | x | 0x10 | x |
*+1 depending on audio mode
**65 or 68 depending on audio mode
There is a templated version of the script that can be used to make your own version of can0swc, named as 'template.py'.
-- Python-CAN PiCAN2 Examples
-- Webjocke canbus to keypress