+ All Categories
Home > Documents > PiCAN2 DUO USER GUIDE

PiCAN2 DUO USER GUIDE

Date post: 27-Jan-2022
Category:
Upload: others
View: 16 times
Download: 0 times
Share this document with a friend
8
PiCAN 2 DUO Rev B V1.1 SK Pang Electronics Ltd © 2016 www.skpang.co.uk 1 Product name PiCAN2 DUO CAN-Bus Board for Raspberry Pi Model number RSP-PICAN2DUO Manufacturer SK Pang Electronics Ltd PiCAN2 DUO USER GUIDE V1.1
Transcript
Page 1: PiCAN2 DUO USER GUIDE

PiCAN2DUORevBV1.1

SKPangElectronicsLtd©2016www.skpang.co.uk

1

Productname PiCAN2DUOCAN-BusBoardforRaspberryPi

Modelnumber RSP-PICAN2DUO

Manufacturer SKPangElectronicsLtd

PiCAN2 DUO USER GUIDE

V1.1

Page 2: PiCAN2 DUO USER GUIDE

PiCAN2DUORevBV1.1

SKPangElectronicsLtd©2016www.skpang.co.uk

2

Contents

TableofContents

1. Introduction............................................................................................................31.1. Features................................................................................................................................................................3

2. HardwareInstallation..............................................................................................31.2. ScrewTerminal..................................................................................................................................................41.3. 120ΩTerminator.............................................................................................................................................41.4. LED..........................................................................................................................................................................41.5. NotFittedItems.................................................................................................................................................43. SoftwareInstallation...............................................................................................41.6. BringUptheInterface....................................................................................................................................6

4. WritingYourOwnSoftware.....................................................................................71.7. ApplicationinPython.....................................................................................................................................71.8. ApplicationinC..................................................................................................................................................8

Page 3: PiCAN2 DUO USER GUIDE

PiCAN2DUORevBV1.1

SKPangElectronicsLtd©2016www.skpang.co.uk

3

1. IntroductionThisPiCAN2DUOboardprovidetwoindependentCAN-BuschannelsfortheRaspberryPi2.ItusestheMicrochipMCP2515CANcontrollerwithMCP2551CANtransceiver.Connectionsaremadevia4wayscrewterminal.Thisboardisalsoavailablewitha5v1ASMPSthatcanpowerthePiiswellviathescrewterminal.

EasytoinstallSocketCANdriver.ProgrammingcanbedoneinCorPython.

1.1. Features• CANv2.0Bat1Mb/s• HighspeedSPIInterface(10MHz)• Standardandextendeddataandremoteframes• CANconnectionviascrewterminal• 120Ωterminatorready• SerialLCDready• LEDindicator• Fourfixingholes,complywithPiHatstandard• SocketCANdriver,appearsascan0andcan1toapplication• InterruptRXonGPIO25andGPIO24

2. HardwareInstallationBeforeinstallingtheboardmakesuretheRaspberryisswitchedoff.Carefullyalignthe40wayconnectorontopofthePi.Usespacerandscrew(optionalitems)tosecuretheboard.

Page 4: PiCAN2 DUO USER GUIDE

PiCAN2DUORevBV1.1

SKPangElectronicsLtd©2016www.skpang.co.uk

4

1.2. ScrewTerminalTheCANconnectioncanalsobemadeviathe4wayscrewterminal.

Note:The+12vInisonlyusedonthePiCAN2boardwithSMPSoptionfitted.

1.3. 120Ω TerminatorThereisa120Ωfittedtotheboard.Tousetheterminatorsoldera2wayheaderpintoJP1andJP2theninsertajumper.

1.4. LEDTherearetworedLEDsfittedtotheboard.ThisisconnectedtoGPIO04andGPIO26.

1.5. NotFittedItemsJP5canbeusetopoweraserialLCDwithdataonTXDlinefromthePi.Thereisalso5vsupplyonJP5.

Switchmodepowersupply,thisisa5vmodulethatcanpowerthePi.Ithasaninputvoltagerangeof6vto30v.

U2isaEEPROMforIDuse.

3. SoftwareInstallationItisbesttostartwithabrandnewRaspbianimage.Downloadthelatestfrom:

https://www.raspberrypi.org/downloads/raspbian/

CANB(J4)Pinnumber Function1 CAN_L2 CAN_H3 GND4 n/c

CANA(J3)Pinnumber Function1 CAN_L2 CAN_H3 GND4 +12vIn

Page 5: PiCAN2 DUO USER GUIDE

PiCAN2DUORevBV1.1

SKPangElectronicsLtd©2016www.skpang.co.uk

5

Afterfirsttimebootup,doanupdateandupgradefirst.

sudo apt-get update

sudo apt-get upgrade

sudo reboot

Addtheoverlaysby:

sudo nano /boot/config.txt

Addthese4linestotheendoffile:

dtparam=spi=on

dtoverlay=mcp2515-can0-overlay,oscillator=16000000,interrupt=25

dtoverlay=mcp2515-can1-overlay,oscillator=16000000,interrupt=24

dtoverlay=spi-bcm2835-overlay

RebootPi:

sudo reboot

Page 6: PiCAN2 DUO USER GUIDE

PiCAN2DUORevBV1.1

SKPangElectronicsLtd©2016www.skpang.co.uk

6

1.6. BringUptheInterfaceYoucannowbringtheCANinterfacesup:

sudo /sbin/ip link set can0 up type can bitrate 500000

sudo /sbin/ip link set can1 up type can bitrate 500000

DownloadandcopytheCANtestprogramstothePi.

http://www.skpang.co.uk/dl/can-test_pi2.zip

ConnectthePiCAN2toyourCANnetworkviascrewterminal.

TosendaCANmessageoncan0(CANBJ4)use:

./cansend can0 7DF#0201050000000000

ThiswillsendaCANIDof7DF.Data020105–coolanttemperaturerequest.

TosendaCANmessageoncan1(CANAJ3)use:

./cansend can1 7DF#0201050000000000

ConnectthePiCANtoaCAN-busnetworkandmonitortrafficbyusingcommand:

./candump can0

Youshouldseesomethinglikethis:

Page 7: PiCAN2 DUO USER GUIDE

PiCAN2DUORevBV1.1

SKPangElectronicsLtd©2016www.skpang.co.uk

7

4. WritingYourOwnSoftwareYoucanwriteyourownapplicationsoftwareineitherCorPython.

1.7. ApplicationinPythonDownloadthePython-CANfilesfrom:

https://bitbucket.org/hardbyte/python-can/get/4085cffd2519.zip

Unzipandinstallby

sudo python3 setup.py install

BringtheCANinterfaceupifitisnotalreadydone:

sudo /sbin/ip link set can0 up type can bitrate 500000

Nowstartpython3

python3

Tosentamessageouttypethefollowinglines:

import can

bus = can.interface.Bus(channel='can0', bustype='socketcan_native')

msg = can.Message(arbitration_id=0x7de,

data=[0, 25, 0, 1, 3, 1, 4, 1],

extended_id=False)

bus.send(msg)

Page 8: PiCAN2 DUO USER GUIDE

PiCAN2DUORevBV1.1

SKPangElectronicsLtd©2016www.skpang.co.uk

8

Toreceivedmessagesanddisplayonscreentype:

notifier = can.Notifier(bus, [can.Printer()])

1.8. ApplicationinCBringtheCANinterfaceupifitisnotalreadydone:

sudo /sbin/ip link set can0 up type can bitrate 500000

Downloadthesourcecodeandexamplefilesbytypingthefollowinginthecommandprompt:

wget http://skpang.co.uk/dl/cantest.tar

Unpackthetarfileandchangeintodirectoryby:

tar xf cantest.tar cd linux-can-utils

Theexamplefileiscalledcantest.ctoeditthisfile,typethefollowinginthecommandprompt:

nano cantest.c

Line77istheCANmessagetobesentout.

unsigned char buff[] = "7DF#0201050000000000";

7DFisthemessageIDand0201050000000000isthedata.Changethedatatosuit.PressCTRL-Xtoexit.Tocompiletheprogramtype:

make

Checktherearenoerrors.Toruntheprogramtype:

./cantest


Recommended