PiCAN GPS + Gyro +Accelerometer USER GUIDE V1 -...
Transcript of PiCAN GPS + Gyro +Accelerometer USER GUIDE V1 -...
PiCANGPS+Gyro+Acc+RevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
1
Productname PiCANGPS+Gyro+AccelerometerCAN-BusBoardforRaspberryPi
Modelnumber RSP-PICANGPSACC
Manufacturer SKPangElectronicsLtd
PiCAN GPS + Gyro +Accelerometer
USER GUIDE
V1.0
PiCANGPS+Gyro+Acc+RevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
2
Contents
TableofContents
1. Introduction............................................................................................................31.1. Features................................................................................................................................................................3
2. HardwareInstallation..............................................................................................41.2. ScrewTerminal..................................................................................................................................................41.3. 120ΩTerminator.............................................................................................................................................41.4. LED1.......................................................................................................................................................................41.5. LED2.......................................................................................................................................................................41.6. NotFittedItems.................................................................................................................................................51.7. ExternalGPSAntennaandBackupBattery...........................................................................................51.8. GPS1PPS(PulsePerSecond)......................................................................................................................51.9. MPU-6050I2CAddress..................................................................................................................................5
3. SoftwareInstallation...............................................................................................61.10. MPU-6050Test...............................................................................................................................................71.11. BasicGPSTest.................................................................................................................................................81.12. UsingGPSD........................................................................................................................................................91.13. ExternalGPSAntenna................................................................................................................................101.14. BringUptheCANInterface......................................................................................................................11
4. WritingYourOwnSoftware....................................................................................121.15. ApplicationinPython.................................................................................................................................121.16. ApplicationinC.............................................................................................................................................13
PiCANGPS+Gyro+Acc+RevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
3
1. IntroductionThisPiCANGPSboardprovidesCAN-BuscapabilityfortheRaspberryPi2and3.ItusestheMicrochipMCP2515CANcontroller.CANconnectionsaremadevia4wayscrewterminalplug.GPSisprovidedbya66channelsMTK3339chipsetmodule.AnonboardbatteryholderforaCR1220cell.Thebackuppowerisfortherealtimeclockandhelptoreducefixtime.TheGPSmodulehasbuiltinpatchantennabutanexternalactiveantennacanalsobeuseviatheuFLconnector.
TheMPU-6050providessixaxisgyroandaccelerometerwithanonboardDigitalMotionProcessor™(DMP™)capableofprocessingcomplex9-axisMotionFusionalgorithms,theMPU-6050doesawaywiththecross-axisalignmentproblemsthatcancreepupondiscreteparts.
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• I2CDigital-outputof6or9-axisMotionFusiondatainrotationmatrix,
quaternion,EulerAngle,orrawdataformat• InputVoltage:2.3-3.4V• SelectableSolderJumpersonCLK,FSYNCandAD0• Tri-Axisangularratesensor(gyro)withasensitivityupto131LSBs/dpsanda
full-scalerangeof±250,±500,±1000,and±2000dps• Tri-Axisaccelerometerwithaprogrammablefullscalerangeof±2g,±4g,±8g
and±16g• DigitalMotionProcessing™(DMP™)engineoffloadscomplexMotionFusion,
sensortimingsynchronizationandgesturedetection• Embeddedalgorithmsforrun-timebiasandcompasscalibration.Nouser
interventionrequired
PiCANGPS+Gyro+Acc+RevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
4
2. HardwareInstallationBeforeinstallingtheboardmakesuretheRaspberryisswitchedoff.Carefullyalignthe40wayconnectorontopofthePi.Usespacerandscrew(optionalitems)tosecuretheboard.
1.2. ScrewTerminalTheCANconnectioncanalsobemadeviathe4wayscrewterminal.
1.3. 120Ω TerminatorThereisa120Ωfittedtotheboard.Tousetheterminatorsoldera2wayheaderpintoJP2theninsertajumper.
1.4. LED1ThereisaredLEDsfittedtotheboard.ThisisconnectedtoGPIO04.Itcanuseasageneralpurposeindicator.
1.5. LED2TheLEDblinksatabout1Hzwhileit'ssearchingforsatellitesandblinksonceevery15secondswhenafixisfound.
CAN0(J3)Pinnumber Function1 n/c2 GND3 CAN_H4 CAN_L
PiCANGPS+Gyro+Acc+RevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
5
1.6. NotFittedItemsJ2canbeusetopoweraserialLCDwithdataonTXDlinefromthePi.Thereisalso5vsupplyonJ2.
1.7. ExternalGPSAntennaandBackupBattery
1.8. GPS1PPS(PulsePerSecond)TheGPSmodulehasa1PPSoutputthatcanbeconnectedtothePi’sGPIO.Tousethe1PPSclosesolderbridgeSJ7.ThepulseswillnowappearonGPIO26.
1.9. MPU-6050I2CAddress
AnexternalGPSantennacanbefittedviaconnectorX1.ThisisanuFLconnector.AuFLtoSMAcableadapterisnormallyrequired.
AbackupbatterycanbefittedfortheRTCandhelptoreducefixtime.
ThedefaultI2CaddressfortheMPU-6050is0x68.
Analternativeaddressis0x69.Tochangetheaddressto0x69,cutthetracklinkingthedefaultsolderbridgeontherighttwopadsonSJ4.Applyasolderbridgelinkingthelefttwopads.
PiCANGPS+Gyro+Acc+RevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
6
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
Addthese5linestotheendoffile:
dtparam=i2c_arm=on
dtparam=spi=on
enable_uart=1
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
dtoverlay=spi-bcm2835-overlay
Editthecmdline.txtby:
sudo nano /boot/cmdline.txt
Change
PiCANGPS+Gyro+Acc+RevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
7
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.10. MPU-6050TestFirstinstallthei2c-toolspackageby:
sudo apt-get install i2c-tools
NowcheckiftheMPU-6050canbedetected.
sudo i2cdetect -y 1
Thescreenshouldlooklikethis:
Nextinstallthepython-smbuspythonmodule:
sudo apt-get install python-smbus
Nowinstallexamplepythonfiles
git clone https://github.com/skpang/MPU-6050-examples.git
cd MPU-6050-examples
PiCANGPS+Gyro+Acc+RevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
8
Runthetestprogram
python3 mpu6060_test.py
Tiltandshaketheboard,youshouldseethevaluechanges.
1.11. BasicGPSTestTherawdatacanbereadby:
stty -F /dev/ttyS0 raw 9600 cs8 clocal –cstopb
Nowreadthedata
cat /dev/ttyS0
Ifyouseethedatawithlotsofcommasthenitmeansthemodulehasnotgotafixyet.MakesuretheGPSmodulehasaclearviewofthesky.AlternativelyconnectanexternalGPSantennatotheboardandplacetheantennaoutdoor.
Youshouldseesomethinglikethis:
PiCANGPS+Gyro+Acc+RevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
9
1.12. 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:
PiCANGPS+Gyro+Acc+RevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
10
1.13. ExternalGPSAntennaThePiCAN-GPSboardhasbuiltinpatchantennawhichprovidesa-165dBmsensitivity.Howeverifyourprojectisinaboxanddoesnothaveaclearviewoftheskythenanexternalantennaismoresuitable.
TheoptionalexternalantennahasaSMAconnectorandanuFLtoSMAcableadapterisrequired.
PiCANGPS+Gyro+Acc+RevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
11
1.14. 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:
PiCANGPS+Gyro+Acc+RevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
12
4. WritingYourOwnSoftwareYoucanwriteyourownapplicationsoftwareineitherCorPython.
1.15. 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)
PiCANGPS+Gyro+Acc+RevBV1.0
SKPangElectronicsLtd©2017www.skpang.co.uk
13
Toreceivedmessagesanddisplayonscreentype:
notifier = can.Notifier(bus, [can.Printer()])
1.16. 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