8
PiCAN 2 DUO ISO Rev B V1.1 SK Pang Electronics Ltd © 2016 www.skpang.co.uk 1 Product name PiCAN2 DUO CAN-Bus ISO Board for Raspberry Pi Model number RSP-PICAN2DUO-ISO Manufacturer SK Pang Electronics Ltd PiCAN2 DUO ISO USER GUIDE V1.1

PiCAN2 DUO ISO USER GUIDE V1 - SK Pangskpang.co.uk/catalog/images/raspberrypi/pi_2/PICANDUOIGB.pdf · PiCAN2 DUO ISO USER GUIDE V1.1 . ... Before installing the board make sure the

Embed Size (px)

Citation preview

Page 1: PiCAN2 DUO ISO USER GUIDE V1 - SK Pangskpang.co.uk/catalog/images/raspberrypi/pi_2/PICANDUOIGB.pdf · PiCAN2 DUO ISO USER GUIDE V1.1 . ... Before installing the board make sure the

PiCAN2DUOISORevBV1.1

SKPangElectronicsLtd©2016www.skpang.co.uk

1

Productname PiCAN2DUOCAN-BusISOBoardforRaspberryPi

Modelnumber RSP-PICAN2DUO-ISO

Manufacturer SKPangElectronicsLtd

PiCAN2 DUO ISO USER GUIDE

V1.1

Page 2: PiCAN2 DUO ISO USER GUIDE V1 - SK Pangskpang.co.uk/catalog/images/raspberrypi/pi_2/PICANDUOIGB.pdf · PiCAN2 DUO ISO USER GUIDE V1.1 . ... Before installing the board make sure the

PiCAN2DUOISORevBV1.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....................................................................................................................................5

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

Page 3: PiCAN2 DUO ISO USER GUIDE V1 - SK Pangskpang.co.uk/catalog/images/raspberrypi/pi_2/PICANDUOIGB.pdf · PiCAN2 DUO ISO USER GUIDE V1.1 . ... Before installing the board make sure the

PiCAN2DUOISORevBV1.1

SKPangElectronicsLtd©2016www.skpang.co.uk

3

1. IntroductionThisPiCAN2DUOISOboardprovidetwoindependentisolatedCAN-BuschannelsfortheRaspberryPi2.ItusestheMicrochipMCP2515CANcontrollerwithISO1050isolatedCANtransceiver.Connectionsaremadevia4wayscrewterminalplugs.

EasytoinstallSocketCANdriver.ProgrammingcanbedoneinCorPython.

1.1. Features• TwogalvanicallyisolatedCANchannels• 70mA5voutputperchannelthatcanbeusetopowerotherCANnodes• 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 ISO USER GUIDE V1 - SK Pangskpang.co.uk/catalog/images/raspberrypi/pi_2/PICANDUOIGB.pdf · PiCAN2 DUO ISO USER GUIDE V1.1 . ... Before installing the board make sure the

PiCAN2DUOISORevBV1.1

SKPangElectronicsLtd©2016www.skpang.co.uk

4

1.2. ScrewTerminalTheCANconnectioncanalsobemadeviathe4wayscrewterminal.

The+5voutputcansourceamaximumof70mAperchannelthatcanbeusetopowerotherCANnodes.

1.3. 120Ω TerminatorThereisa120Ωfittedtotheboard.Tousetheterminatorsoldera2wayheaderpintoJP1andJP2theninsertajumper.

1.4. LEDTherearetworedLEDsfittedtotheboard.ThisisconnectedtoGPIO04(CANA)andGPIO26(CANB).

1.5. NotFittedItemsJ2canbeusetopoweraserialLCDwithdataonTXDlinefromthePi.Thereisalso5vsupplyonJ2.

3. SoftwareInstallationItisbesttostartwithabrandnewRaspbianimage.Downloadthelatestfrom:

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

Afterfirsttimebootup,doanupdateandupgradefirst.

CANA(J3)Pinnumber Function1 +5v(70mA)2 GND3 CAN_H4 CAN_L

CANB(J4)Pinnumber Function1 +5v(70mA)2 GND3 CAN_H4 CAN_L

Page 5: PiCAN2 DUO ISO USER GUIDE V1 - SK Pangskpang.co.uk/catalog/images/raspberrypi/pi_2/PICANDUOIGB.pdf · PiCAN2 DUO ISO USER GUIDE V1.1 . ... Before installing the board make sure the

PiCAN2DUOISORevBV1.1

SKPangElectronicsLtd©2016www.skpang.co.uk

5

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

1.6. BringUptheInterfaceYoucannowbringtheCANinterfacesup:

Page 6: PiCAN2 DUO ISO USER GUIDE V1 - SK Pangskpang.co.uk/catalog/images/raspberrypi/pi_2/PICANDUOIGB.pdf · PiCAN2 DUO ISO USER GUIDE V1.1 . ... Before installing the board make sure the

PiCAN2DUOISORevBV1.1

SKPangElectronicsLtd©2016www.skpang.co.uk

6

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 ISO USER GUIDE V1 - SK Pangskpang.co.uk/catalog/images/raspberrypi/pi_2/PICANDUOIGB.pdf · PiCAN2 DUO ISO USER GUIDE V1.1 . ... Before installing the board make sure the

PiCAN2DUOISORevBV1.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 ISO USER GUIDE V1 - SK Pangskpang.co.uk/catalog/images/raspberrypi/pi_2/PICANDUOIGB.pdf · PiCAN2 DUO ISO USER GUIDE V1.1 . ... Before installing the board make sure the

PiCAN2DUOISORevBV1.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