SEA:ME 2nd Project
Before start
- Before following this document, You must have to do first.
- Assemble Pi Racer & Move
- Simple project architecture
- Receive sensor data from Arduino and transfer it to Raspberry Pi using CAN Bus
- Raspberry Pi uses the DBus server to manage the data it receives and delivers the data it needs for each application
- Micro Controller
- Small electronic device that can easily handle various movements such as read data from sensors or use data to control motors.
- C language (or C++) and Arduino IDE enable simple coding
- Consists of Regulator, Circuit Element, GPIO
- Peripherals allow direct control of external devices
- More Information of Arduino
GPIO
- General Purpose Input/Output
- Uncommitted digital signal pin on an integrated circuit or electronic circuit board which may be used as an input or output, or both, and is controllable by software.
- Micro Processor
- Similar to Arduino, but called Processor because it can have various OSs
- Unlike Arduino, there is no peripheral device and controls the device using an internal transistor
- Powerful performance in computational processing, which is useful for complex computational processing such as video and graphics
- Raspberry Pi official document
- Standard communication protocol to allow microcontrollers and devices to communicate with each other's applications without a host computer
- ECUs in the vehicle communicate using the CAN protocol
ECU
- Electronic Control Unit
- Electronic control device used in a car
-
Multi-Master
- All nodes are bus masters and whenever the bus is empty they can send information
-
Twisted Pair Wire
- Strong against disturbance due to electrically differentiated communication using two lines : CAN_H, CAN_L
add picture
- Strong against disturbance due to electrically differentiated communication using two lines : CAN_H, CAN_L
-
Scalability
-
Message-Oriented Protocol
- Use ID based on message priority. Use them to distinguish messages
- Multiple messages come in at the same time, carry out the priority ID message
-
System for IPC(Inter-Process Communication)
-
A bus system that enables various processes with different characteristics to communicate with each other
-
D-Bus is a service daemon that runs in the background that uses the bus daemon to communicate functions and communications between applications
- Two type of D-Bus daemon
- D-Bus System bus
- Communicate with kernel and system-wide events
- Any application is prevented from spoofing
- D-Bus Session bus
- daemon attached to each user session
- Used to communicate with other applications within the same system
- Receive messages from the system bus
- D-Bus System bus
- Two type of D-Bus daemon
Check D-bus service in terminal
ps -ef | grep dbus-demon
Separated by behind word
--system
or--session
- Bus name(Service name)
- Unique name for 1 connection
- Automatically generated when connected to D-Bus daemon and can be set up by the user themselves
- Names once used are non-reusable and must not be duplicated
- Object path
- D-bus is a Peer-to-Peer protocol in which all messages sent and received are source and purposeful
- Address used to send and receive messages
- Written like "/org/example/Test"
- Multiple object paths can be assigned differently than a business name
- Object provides one or more interfaces
- Interface
- Name of grouping Method and Signal
- Interface is used as the namespace for each method
- example
<?xml version="1.0" ?> <node name="/org/freedesktop/DBus/Example/Echo"> <interface name="org.freedesktop.DBus.EchoDemo"> <method name="HelloString"> <arg type="s" name="name" direction="in"/> <arg type="s" name="greeting" direction="out"/> </method> <signal name="EchoCount"> <arg type="y" name="count"/> </signal> </interface> </node>
- Method
- Can be called by another object
- Can optionally have Input and Output
- Signal
- Kind of broadcast message. Send to one object to all objects registered with that signal
- Method
- Message
- Data passed between processes
- Method Call Message
- Method Return Message
- Error Message
- Signal Message
- Header and Body
Pi RacerPro & Raspberry Pi | Can Module MCP 2515 * 2 | Arduino Nano(HIMALAYA |
- Basically, These materials can make communication. After connecting, you can connect Arduino with other modules(speed sensor, temperature sensor, etc) using Breadboard.
Raspberry Pi <-> MCP2515 <-> MCP2515 <-> Arduino Nano <-> other modules
Raspberry Pi | MCP2515 |
---|---|
GND[20] | GND |
GPIO25[22] | INT |
GPIO8[24] | CS |
GPIO10[19] | SI |
GPIO9[21] | S0 |
GPIO11[23] | SCK |
5V | VCC |
- VCC & 5V
- You must find another 5Voltage socket in Pi Racer. Raspberry Pi 5V is already used for connecting Raspberry Pi & Pi Racer.
Arduino Nano | MCP2515 |
---|---|
D2 | INT |
D13 | SCK |
D11 | SI |
D12 | S0 |
D10 | CS |
GND | GND |
5V | VCC |
- Use Breadboard to connect Arduino and MCP2515
- Later, Sensors can be connected to Arduino with Breadboard
MCP2515 | MCP2515 |
---|---|
CAN_H | CAN_H |
CAN_L | CAN_L |
- Raspberry-Pi and Arduino communication with CAN communicate library
-
Setting CAN interface on Raspberry Pi
-
Add the following line to your /boot/config.txt file:
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25 dtoverlay=spi-bcm2835-overlay
- oscillator : should be set to the actual crystal frequency found on your MCP2515
- interrupt : specifies the Raspberry PI GPIO pin number
-
Reboot your Raspberry Pi and Check this line
[ 20.248951] CAN device driver interface [ 20.499256] mcp251x spi0.0 can0: MCP2515 successfully initialized.
-
-
Bring up the CAN interfaces
2-1. Manually bring up- Follow this command in terminal
sudo /sbin/ip link set can0 up type can bitrate 500000
- Check your CAN bus bitrate and write correct number
2-2. Automatically bring up on boot
- Edit your
/etc/network/interfaces
file and add this lineauto can0 iface can0 inet manual pre-up /sbin/ip link set can0 type can bitrate 500000 triple-sampling on restart-ms 100 up /sbin/ifconfig can0 up down /sbin/ifconfig can0 down
- Follow this command in terminal
-
CAN-utils
- CAN-utils is a collection of extremely useful debugging tools using the SocketCAN interface
- list of applications
- candump : Dump can packets – display, filter and log to disk.
- canplayer : Replay CAN log files.
- cansend : Send a single frame.
- cangen : Generate random traffic.
- canbusload : display the current CAN bus utilisation.
- Install CAN utils
- CAN-utils Git repository
- Pre-compiled binaries can be installed using:
sudo apt-get install can-utils
-
CAN data send or receive with CAN utils
- Make random data
cangen can0
- Receive can data and check in terminal
candump can0
- Make random data