Coder Social home page Coder Social logo

metaln00b / canopen-raspberrypi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mpcrowe/canopen-raspberrypi

0.0 1.0 0.0 336 KB

a CanOpen Raspberry Pi Project that integrates several other projects

License: Apache License 2.0

Makefile 1.63% C 97.38% Shell 0.99%

canopen-raspberrypi's Introduction

canopen-raspberrypi

##Background Have you ever needed an inexpensive control system to control a water fountain or animated haunted house display? CAN-Bus and CAN-Open were designed for applications like this. While the most common place to find CAN-Bus is in your car's OBDII interface, it isn't used too much in low cost control systems because of the high cost hardware.

CAN-Open is protocol that sits above the CAN-Bus Physical/Data layer, but it can also sit above other data layers. By a using a clever tool such as socat, we can route CAN-Bus data traffic onto a datagram port, allowing devices such as cell phones and tablets direct access to the CAN-Bus data layer.

This project aims to create a low cost CAN-bus to wifi interface on a RaspberryPi, see the block diagram below. The Pi allows an Android apps to connect to the can bus and directly send and recieve messages. Additionally, a bus master application runs on the PI to configure nodes on a CAN-Open network. The project has been broken down into several sub projects;

Block Diagram The magic of the project is socat. This tool makes CAN-Bus interface available on a UDP port. Once the CAN-Bus is available on a UDP port, any number of devices may connect to it through any Internet style interface (Ethernet, Wifi,...).

#Hardware you will need ##Raspberry Pi 3 Other versions of Pi's can be made to work, but the magic bullet for us was the built in Wifi interface on the Pi 3. The wifi hotspot integration is picky about which wifi hardware is used. We were not able get it to work with a Edimax N150 USB dongle. We aren't saying it can't be done, it just worked when we used the Pi 3's internal Wifi interface.

An SPI/CAN bus card

We initially used the PiCan2, which uses the Microchip MCP2515 "Stand-Alone CAN Controller with SPI Interface".
During later development we used our own in-house boards with the same IC. This IC is pretty well supported with the RasberryPI linux distrobution.

CAN-Open slave nodes

These things are availble, but are pretty expensive. We rolled our own. Llook for blatent product plug here in the near future. Many embedded microcontrollers have CAN-Bus interfaces on them. There don't seem to be many CAN-Open stacks available that support them. Again, we rolled our own. Until we can support selling low cost nodes, good luck to you! ##An Android tablet with Wifi We developed our app with two different tablets, A Samsung Galaxy Tab 4, and a Boox e-ink device. The Boox e-ink device has a slow screen update rate and is B&W, but it works awesomely when using it in the full sun.

Setting up the Raspberry Pi Can Bus Interface

From a fresh Raspberry Pi install, install the following packages

sudo apt-get update 
sudo apt-get dist-upgrade
sudo apt-get install joe can-utils hostapd udhcpd rsync socat git
sudo raspi-config
	enable spi 
	expand filesystem
	enable i2c
	set hostname

to setup the can bus interface sudo joe /boot/config.txt

Add these 3 lines to the end of file:

# can-bus see interface http://skpang.co.uk/blog/archives/1165 for details 
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25 
dtoverlay=spi-bcm2835

This will install the basic packages to allow you to bring up a can0 interface on the mcp2515 spi-can interface chip. The can0 interface is used with socat to allow wifi connections to the canbus interace

Setting up the socat server

run ./runsocat.sh from ~/canopen-raspberrypi which will bring up the interface and start a session of socat to put can0 on port 2000. Verify that can0 is up with ifconfig

Wifi hotspot configuration

Setting up the wifi hotspot on the rasberry pi is beyond the scope of this project. An excellent tutorial is given at RPI-Wireless-Hotspot. You can ignore setting up the dns tools if the Pi will not be connecte to the internet.

#Packages needed to use CanFestival The bus master software uses CanFestival, it will need to be installed in order to compile. Other packages that you will need to edit and compile CanFestival applications

  • python-wxgtk2.8 python-wxglade, to use the python ObjDict editor in CanFestival
  • diffuse, a nice gui text diffing tool
  • libxml2-dev, required to compile the busMaster tool later on All of these packages can be installed with the standard sudo apt-get install <pkg-name> syntax

Installing canfestival socket drivers

Get the Canfestival code.

busMaster

CAN-Open is a distributed internodal communications system. A master/slave relationship exists in CAN-Open parlance, but the master is more of a dynamic information repository and state transition tool than it is a true master even though it can act like one. This busMaster tool relies heavily on CanFestival for the underlying CAN-Open infrastructure.

The busMaster software does a few things.

  • it configures the dynamic information on the system when a new node comes online. The dynamic information is contained in config.xml
  • it sends out periodic sync signals
  • it puts nodes into the operational state once configured

To add nodes to the bus unfortunatly, busMaster must be edited and recompiled with the new node ID. This requires the use of wxWidgets to add the correct SDO parameters.

#to start canopen bus master .../busMaster ./run.sh

#Android app The Android app is used to control and monitor nodes on the can bus. It is a slave device which the busMaster configures when connected. This most excellent package is available at [Android CAN-Open Demo] (https://github.com/Awalrod/AndroidCanOpenDemo)

#CAN-Open-Java This package is used by the android app, but is kept separate because it is usefull as a generic java package.
This package can be found here

canopen-raspberrypi's People

Contributors

awalrod avatar mpcrowe avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.