david_1234
Posts: 40
Joined: Mon Jan 01, 2018 2:14 pm

How can I connect Canbus and RFID to the same PI?

Wed Sep 12, 2018 7:11 pm

Hello ,
I wanted to know how can I connect canbus interface with this setting:
https://www.raspberrypi.org/forums/view ... p?t=141052
and RFID
https://pimylifeup.com/raspberry-pi-rfid-rc522/

to the same Pi ?

I'm using PI 3
and every setup alone is working
but can I connect both of them and make them run at the same time ?
(I ask becasue I see they both use pins 19,21,23,24)

Thanks ,

scotty101
Posts: 3185
Joined: Fri Jun 08, 2012 6:03 pm

Re: How can I connect Canbus and RFID to the same PI?

Wed Sep 12, 2018 7:21 pm

Both devices are SPI devices. You should be able to have them share common GPIO pins with the exception of pin 24. One device will connect to pin 24 (CE0) and the other will connect to pin 26 (CE1).

The software should support addressing both devices. I'd keep the RFID device on CE0 since changing the config for the CAN device looks easier.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

david_1234
Posts: 40
Joined: Mon Jan 01, 2018 2:14 pm

Re: How can I connect Canbus and RFID to the same PI?

Thu Sep 13, 2018 8:36 am

Great I will try it and see if i have any problems...

Thanks ,

david_1234
Posts: 40
Joined: Mon Jan 01, 2018 2:14 pm

Re: How can I connect Canbus and RFID to the same PI?

Sun Sep 16, 2018 9:57 am

can you help me with finding where to change the CEO pin for the canbus?

I thought its in the /boot/config - but no

couldn't find anywhere

but if I llo at the MFRC522.py file , Ionly get the reset pi ?

[code
def __init__(self, dev='/dev/spidev0.0', spd=1000000):
spi.openSPI(device=dev,speed=spd)
GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.OUT)
GPIO.output(self.NRSTPD, 1)
self.MFRC522_Init()
[/code]



Thanks,

danjperron
Posts: 3073
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: How can I connect Canbus and RFID to the same PI?

Sun Sep 16, 2018 1:46 pm

Check in /boot/overlays/README

If you want your canbus on SPI0 CE1 then
dtoverlay=mcp2515-can1,oscillator=8000000,interrupt=12


If you want your rc522 on CE1 then you will have to change the code in the class MFRC522.py line 112

Code: Select all

 def __init__(self, dev='/dev/spidev0.1', spd=1000000):
But I think that the best way will be to change the SimpleMFRC522 class to enable the change of SPI device.

something like,

Code: Select all

  def __init__(self, dev='/dev/spidev0.0'):
    self.READER = MFRC522.MFRC522(dev=dev)
Then it is simple to change it in your main code

Code: Select all

reader = SimpleMFRC522.SimpleMFRC522(dev='/dev/spidev0.1')

david_1234
Posts: 40
Joined: Mon Jan 01, 2018 2:14 pm

Re: How can I connect Canbus and RFID to the same PI?

Thu Sep 27, 2018 9:14 am

I have change the boot/config.txt like you told me

Code: Select all

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on
dtoverlay=mcp2515-can1,oscillator=8000000,interrupt=12
dtoverlay=spi-bcm-overlay

and it's working -
Thanks ,


I will ask if I have any other problems

david_1234
Posts: 40
Joined: Mon Jan 01, 2018 2:14 pm

Re: How can I connect Canbus and RFID to the same PI?

Tue Oct 16, 2018 9:54 am

strange thing
I have try to do this with another PI
the RFID is working
the Cnabus not
I have took the Canbus and connected it to my first PI - and it's working (so the problem is not in the device itself)

I copy the config file as is - and still not working
check the connections - all are good :
INT - PIN 32
SCK - PIN 23
SI - PIN 19
SO - PIN 21
CS - PIN 26 (CE#1)
GND - PIN 6
VCC - PIN 2

this is the line in the config :\
# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on
dtoverlay=mcp2515-can1,oscillator=8000000,interrupt=12
dtoverlay=spi-bcm-overlay
And as you can see I don't see the can0 interface

Code: Select all

[email protected]:~ $ sudo ip link show 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether b8:27:eb:ef:17:4f brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DORMANT group default qlen 1000
    link/ether b8:27:eb:ba:42:1a brd ff:ff:ff:ff:ff:ff

ls /sys/bus/spi/devices/spi0.1/
modalias    of_node/    power/      statistics/ subsystem/  uevent


* mean while the RFID is working - so the CLK,SI,SO - it OK

What am I missing \ doing wrong ?


* when I replace the SD card on both PI :
none of them show me the canbus device

danjperron
Posts: 3073
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: How can I connect Canbus and RFID to the same PI?

Tue Oct 16, 2018 2:51 pm

Go back to the basic,

- Check if it is working without the RFID on chip select 0. (set overlay for chip select 0).
- Is spidev there ?
ls -l /dev/spi*
- Is device in module
lsmod
- Is any error on boot up
dmesg | grep mcp
dmesg | grep spi

- Is your 8Mhz clock oscillate ? (you need a oscilloscope or a logic probe).


Did you install can-tools?

sudo apt-get install can-utils


The mcp2515 is 5V. What do you do to convert the 5V to 3.3V on MISO,MOSI,CLK and CE ?

Return to “Beginners”