Raspberry Pi PICAN2 Hat User Guide - Microsoft Azure

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

Transcript of Raspberry Pi PICAN2 Hat User Guide - Microsoft Azure

Page 1: Raspberry Pi PICAN2 Hat User Guide - Microsoft Azure

PiCAN2RevBV1.2

SKPangElectronicsLtd©2016www.skpang.co.uk

1

Productname PICANCAN-BusBoardforRaspberryPi

Modelnumber RSP-PICAN2

Manufacturer SKPangElectronicsLtd

PiCAN 2 USER GUIDE

V1.2

Page 2: Raspberry Pi PICAN2 Hat User Guide - Microsoft Azure

PiCAN2RevBV1.2

SKPangElectronicsLtd©2016www.skpang.co.uk

2

Contents

TableofContents

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

2. HardwareInstallation..............................................................................................31.2. ConfiguringDB9Connector.........................................................................................................................41.3. OBDIICable.........................................................................................................................................................41.4. CANCable.............................................................................................................................................................41.5. ScrewTerminal..................................................................................................................................................51.6. 120ΩTerminator.............................................................................................................................................51.7. LED..........................................................................................................................................................................51.8. NotFittedItems.................................................................................................................................................53. SoftwareInstallation...............................................................................................61.9. BringUptheInterface....................................................................................................................................7

4. WritingYourOwnSoftware.....................................................................................81.10. ApplicationinPython...................................................................................................................................81.11. ApplicationinC...............................................................................................................................................9

Page 3: Raspberry Pi PICAN2 Hat User Guide - Microsoft Azure

PiCAN2RevBV1.2

SKPangElectronicsLtd©2016www.skpang.co.uk

3

1. IntroductionThisPiCANboardprovideCAN-BuscapabilityfortheRaspberryPi2.ItusestheMicrochipMCP2515CANcontrollerwithMCP2551CANtransceiver.ConnectionsaremadeviaDB9or4wayscrewterminal.Thisboardisalsoavailablewitha5v1ASMPSthatcanpowerthePiiswellviathescrewterminalorDB9connector.

EasytoinstallSocketCANdriver.ProgrammingcanbedoneinCorPython.

1.1. Features• CANv2.0Bat1Mb/s• HighspeedSPIInterface(10MHz)• Standardandextendeddataandremoteframes• CANconnectionviastandard9-waysub-Dconnectororscrewterminal• CompatiblewithOBDIIcable• SolderbridgetosetdifferentconfigurationforDB9connector• 120Ωterminatorready• SerialLCDready• LEDindicator• Footprintfortwominipushbuttons• Fourfixingholes,complywithPiHatstandard• SocketCANdriver,appearsascan0toapplication• InterruptRXonGPIO25

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

Page 4: Raspberry Pi PICAN2 Hat User Guide - Microsoft Azure

PiCAN2RevBV1.2

SKPangElectronicsLtd©2016www.skpang.co.uk

4

1.2. ConfiguringDB9ConnectorTheCANconnectioncanbemadeviatheDB9connector.Theconnectorbeconfiguredfordifferentpinout.DependifyouareusinganOBDIIcableoraCANcable.

1.3. OBDIICableClosethesolderbridgesonthelefthandsideonSJ1,SJ2andSJ3asshownwithareddot.

1.4. CANCableClosethesolderbridgesontherighthandsideonSJ1,SJ2andSJ3asshownwithagreendot.

DB9Pinnumber

Function

2 GND3 CAN_H5 CAN_L

DB9Pinnumber

Function

3 GND7 CAN_H2 CAN_L

Page 5: Raspberry Pi PICAN2 Hat User Guide - Microsoft Azure

PiCAN2RevBV1.2

SKPangElectronicsLtd©2016www.skpang.co.uk

5

1.5. ScrewTerminalTheCANconnectioncanalsobemadeviathe4wayscrewterminal.

Note:The+12vInisonlyusedonthePiCAN2boardwithSMPSoptionfitted.

1.6. 120Ω TerminatorThereisa120Ωfittedtotheboard.Tousetheterminatorsoldera2wayheaderpintoJP3theninsertajumper.

1.7. LEDThereisaredLEDfittedtotheboard.ThisisconnectedtoGPIO22.

1.8. NotFittedItemsTheboardhasfootprintfortwominipushbuttonsS1andS2,theyareconnectedtoGPIO24andGPIO23respectively.

JP5canbeusetopoweraserialLCDwithdataonTXDlinefromthePi.Thereisalso5vsupplyonJP5.

Switchmodepowersupply,thisisa5vmodulethatcanpowerthePi.Ithasaninputvoltagerangeof6vto30v.

U2isaEEPROMforIDuse.

Pinnumber Function1 CAN_H2 CAN_L3 GND4 +12vIn

Page 6: Raspberry Pi PICAN2 Hat User Guide - Microsoft Azure

PiCAN2RevBV1.2

SKPangElectronicsLtd©2016www.skpang.co.uk

6

3. SoftwareInstallationItisbesttostartwithabrandnewRaspbianimage.Downloadthelatestfrom:

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

Afterfirsttimebootup,doanupdateandupgradefirst.

sudo apt-get update

sudo apt-get upgrade

sudo reboot

Addtheoverlaysby:

sudo nano /boot/config.txt

Addthese3linestotheendoffile:

dtparam=spi=on

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

dtoverlay=spi-bcm2835-overlay

RebootPi:

sudo reboot

Page 7: Raspberry Pi PICAN2 Hat User Guide - Microsoft Azure

PiCAN2RevBV1.2

SKPangElectronicsLtd©2016www.skpang.co.uk

7

1.9. BringUptheInterfaceYoucannowbringtheCANinterfaceup:

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

DownloadandcopytheCANtestprogramstothePi.

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

ConnectthePiCAN2toyourCANnetworkviascrewterminalorDB9.

TosendaCANmessageuse:

./cansend can0 7DF#0201050000000000

ThiswillsendaCANIDof7DF.Data020105–coolanttemperaturerequest.

ConnectthePiCANtoaCAN-busnetworkandmonitortrafficbyusingcommand:

./candump can0

Youshouldseesomethinglikethis:

Page 8: Raspberry Pi PICAN2 Hat User Guide - Microsoft Azure

PiCAN2RevBV1.2

SKPangElectronicsLtd©2016www.skpang.co.uk

8

4. WritingYourOwnSoftwareYoucanwriteyourownapplicationsoftwareineitherCorPython.

1.10. 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 9: Raspberry Pi PICAN2 Hat User Guide - Microsoft Azure

PiCAN2RevBV1.2

SKPangElectronicsLtd©2016www.skpang.co.uk

9

Toreceivedmessagesanddisplayonscreentype:

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

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