PiCAN GPS USER GUIDE V1 - SK Pangskpang.co.uk/catalog/images/raspberrypi/pican/PICANGPS_UGV1.pdf ·...
Transcript of PiCAN GPS USER GUIDE V1 - SK Pangskpang.co.uk/catalog/images/raspberrypi/pican/PICANGPS_UGV1.pdf ·...
PiCAN2GPSRevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
1
Productname PiCANGPSCAN-BusBoardforRaspberryPi
Modelnumber RSP-PICANGPS
Manufacturer SKPangElectronicsLtd
PiCAN GPS USER GUIDE
V1.0
PiCAN2GPSRevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
2
Contents
TableofContents
1. Introduction............................................................................................................31.1. Features................................................................................................................................................................3
2. HardwareInstallation..............................................................................................31.2. ScrewTerminal..................................................................................................................................................41.3. 120ΩTerminator.............................................................................................................................................41.4. LED1.......................................................................................................................................................................41.5. LED2.......................................................................................................................................................................41.6. NotFittedItems.................................................................................................................................................41.7. ExternalGPSAntennaandBackupBattery...........................................................................................4
3. SoftwareInstallation...............................................................................................51.8. BasicGPSTest....................................................................................................................................................61.9. UsingGPSD..........................................................................................................................................................71.10. ExternalGPSAntenna..................................................................................................................................81.11. BringUptheCANInterface........................................................................................................................9
4. WritingYourOwnSoftware....................................................................................101.12. ApplicationinPython.................................................................................................................................101.13. ApplicationinC.............................................................................................................................................11
PiCAN2GPSRevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
3
1. IntroductionThisPiCANGPSboardprovidesCAN-BuscapabilityfortheRaspberryPi2and3.ItusestheMicrochipMCP2515CANcontroller.CANconnectionsaremadevia4wayscrewterminalplug.GPSisprovidedbya66channelsMTK3339chipsetmodule.AnonboardbatteryholderforaCR1220cell.Thebackuppowerisfortherealtimeclockandhelptoreducefixtime.TheGPSmodulehasbuiltinpatchantennabutanexternalactiveantennacanalsobeuseviatheuFLconnector.
EasytoinstallSocketCANdriver.ProgrammingcanbedoneinCorPython.
1.1. Features• CANv2.0Bat1Mb/s• HighspeedSPIInterface(10MHz)• Standardandextendeddataandremoteframes• CANconnectionviascrewterminal• 120Ωterminatorready• SerialLCDready• LEDindicator• Fourfixingholes,complywithPiHatstandard• SocketCANdriver,appearsascan0toapplication• InterruptRXonGPIO25• MTK3339chipset• -165dBmsensitivity,10Hzupdates,66channels• RTCbatteryholder• FixstatusLED• Onboardpatchantenna• uFLconnectorforexternalactiveantenna
2. HardwareInstallationBeforeinstallingtheboardmakesuretheRaspberryisswitchedoff.Carefullyalignthe40wayconnectorontopofthePi.Usespacerandscrew(optionalitems)tosecuretheboard.
PiCAN2GPSRevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
4
1.2. ScrewTerminalTheCANconnectioncanalsobemadeviathe4wayscrewterminal.
1.3. 120Ω TerminatorThereisa120Ωfittedtotheboard.Tousetheterminatorsoldera2wayheaderpintoJP2theninsertajumper.
1.4. LED1ThereisaredLEDsfittedtotheboard.ThisisconnectedtoGPIO04.Itcanuseasageneralpurposeindicator.
1.5. LED2TheLEDblinksatabout1Hzwhileit'ssearchingforsatellitesandblinksonceevery15secondswhenafixisfound.
1.6. NotFittedItemsJ2canbeusetopoweraserialLCDwithdataonTXDlinefromthePi.Thereisalso5vsupplyonJ2.
1.7. ExternalGPSAntennaandBackupBattery
CAN0(J3)Pinnumber Function1 n/c2 GND3 CAN_H4 CAN_L
AnexternalGPSantennacanbefittedviaconnectorX1.ThisisanuFLconnector.AuFLtoSMAcableadapterisnormallyrequired.
AbackupbatterycanbefittedfortheRTCandhelptoreducefixtime.
PiCAN2GPSRevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
5
3. SoftwareInstallationThefollowingprocedureisfortheRaspberryPi3.
ItisbesttostartwithabrandnewRaspbianJessieimage.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
Addthese4linestotheendoffile:
dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
dtoverlay=spi-bcm2835-overlay
enable_uart=1
PiCAN2GPSRevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
6
Editthecmdline.txtby:
sudo nano /boot/cmdline.txt
Change
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
to
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
Thatisremoveconsole=serial0,115200
RebootPi:
sudo reboot
1.8. BasicGPSTestTherawdatacanbereadby:
stty -F /dev/ttyS0 raw 9600 cs8 clocal –cstopb
Nowreadthedata
cat /dev/ttyS0
Ifyouseethedatawithlotsofcommasthenitmeansthemodulehasnotgotafixyet.MakesuretheGPSmodulehasaclearviewofthesky.AlternativelyconnectanexternalGPSantennatotheboardandplacetheantennaoutdoor.
Youshouldseesomethinglikethis:
PiCAN2GPSRevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
7
1.9. UsingGPSDAprogramcalledGPSDcanbeusetoviewthedatainaformattedway.
ToinstallGPSD,type:
sudo apt-get install gpsd gpsd-clients python-gps
YouneedfirsttodisablesystemdservicethatGPSDinstalls:
sudo systemctl stop gpsd.socket
sudo systemctl disable gpsd.socket
TostartGPSD,type:
sudo gpsd /dev/ttyS0 -F /var/run/gpsd.sock
gpsmon
Youshouldseethisscreen:
PiCAN2GPSRevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
8
1.10. ExternalGPSAntennaThePiCAN-GPSboardhasbuiltinpatchantennawhichprovidesa-165dBmsensitivity.Howeverifyourprojectisinaboxanddoesnothaveaclearviewoftheskythenanexternalantennaismoresuitable.
TheoptionalexternalantennahasaSMAconnectorandanuFLtoSMAcableadapterisrequired.
PiCAN2GPSRevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
9
1.11. BringUptheCANInterfaceYoucannowbringtheCANinterfacesup:
sudo /sbin/ip link set can0 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:
PiCAN2GPSRevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
10
4. WritingYourOwnSoftwareYoucanwriteyourownapplicationsoftwareineitherCorPython.
1.12. 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)
PiCAN2GPSRevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
11
Toreceivedmessagesanddisplayonscreentype:
notifier = can.Notifier(bus, [can.Printer()])
1.13. 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