-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathcluster_rpm.py
More file actions
60 lines (51 loc) · 1.31 KB
/
Copy pathcluster_rpm.py
File metadata and controls
60 lines (51 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python3
#
## cluster_rpm.py
#
# This python3 program sends out CAN data from the PiCAN2 board to a Mazda RX8 instrument cluster.
# For use with PiCAN boards on the Raspberry Pi
# http://skpang.co.uk/catalog/pican2-canbus-board-for-raspberry-pi-2-p-1475.html
#
# Make sure Python-CAN is installed first http://skpang.co.uk/blog/archives/1220
#
# 27-08-16 SK Pang
#
#
import RPi.GPIO as GPIO
import can
import time
import os
from threading import Thread
led = 22
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(led,GPIO.OUT)
GPIO.output(led,True)
RPM_PID = 0x201
#oil temp 0x420
print('Bring up CAN0....')
os.system("sudo /sbin/ip link set can0 up type can bitrate 500000")
time.sleep(0.1)
print('Ready')
try:
bus = can.interface.Bus(channel='can0', bustype='socketcan_native')
except OSError:
print('Cannot find PiCAN board.')
GPIO.output(led,False)
exit()
# Main loop
try:
while True:
for rpm in range(0,130):
GPIO.output(led,True)
msg = can.Message(arbitration_id=RPM_PID,data=[rpm,0x00,0,0,0,0,0,0],extended_id=False)
bus.send(msg)
print(' {0:d}'.format(rpm))
time.sleep(0.01)
GPIO.output(led,False)
time.sleep(0.04)
except KeyboardInterrupt:
#Catch keyboard interrupt
GPIO.output(led,False)
os.system("sudo /sbin/ip link set can0 down")
print('\n\rKeyboard interrtupt')