This post is part of a series about Controller Area Network (CAN Bus) Prototyping With the Arduino Uno.
While programming the Arduino can be exciting (especially since everything works so smoothly), the real fun comes when you can extend the Arduino’s reach to a PC running Windows.
Note: My apologies to all Mac and LINUX users for bringing a Windows programming example, but there is no better programming than using C# under Microsoft’s Visual Studio. I have enjoyed programming under OS-X and LINUX, but when it comes to producing quick and effective programming examples, I prefer to stay with Visual Studio. However, the experienced programmer should be able to replicate the functionality of the serial monitor.
To learn more about serial port programming (RS-232 and USB) under LINUX see http://www.teuniz.net/RS-232/. I consider this by far the most professional application for serial ports under LINUX. It also suits Windows applications but is primarily meant for compilers inferior to Visual Studio and/or for programming embedded systems.
In the following we assume that you have the Arduino USB driver installed under your Windows machine. The driver is automatically installed with the Arduino development environment.
As I have mentioned in my note, I am using Microsoft’s Visual Studio 2012, and I have designed the following GUI that may look very familiar to the Arduino developer. Basically, this very simple program is a replica of the Arduino serial monitor.
The screen elements are a textbox for data entry, a command button to send the entry to the Arduino, and another larger text box to display the data coming from the Arduino. Last, but not least, there is a combobox displaying all available USB COM ports (It is your task to determine the proper USB port; there is no auto detection).
What the program does not provide is the baud rate settings, which has been hard-coded as 9600 baud into the program but can be modified easily. Of course, this is not the professional way of doing it, but, after all, this programming sample serves as an example on reading/sending messages from/to the Arduino. In regards to the envisioned extended CAN network monitoring and diagnostics tool, you will need more and different screen elements, and the baud rate settings should be part of that project.
All screen elements in this project stick with their default settings, however with a few exceptions as shown in the following:
Note: Instead of showing the full listing here, please feel free to download the C# source code (zip file).
The handling of the USB port is based on
an article by Ryan Alford (with added content by Arjun Walmiki, Gregory
Krzywoszyja and Mahesh Chand) at:
At program start, the user first needs to select the applicable USB COM port, which initializes the port (SelectedIndexChanged event).
Beyond that, the program functions as a simple USB terminal: Messages are typed in the top text box and sent by clicking on the Send command button. The larger text box displays the received data.
The following shows screen shots taken through a session with our Arduino CAN Network Monitoring and Diagnostics program:
In this case, we sent two CAN Messages with the same ID (0100) but different data. Next, we received to messages through my standard test configuration (i.e. USB-to-CAN gateway with Windows monitoring tool as the second CAN node).
The previous two screen shots serve as evidence that the messages sent to/from the serial monitor via the Arduino CAN Shield were received/transmitted as expected.
At this point, after having accomplished all the necessary steps, it is easily possible to develop a professional, full-fledged CAN Network Monitoring, Diagnostics, and Simulation Software.
The groundwork has been laid for all necessary hardware and software components:
- A USB-to-CAN Gateway to provide CAN connectivity to the host system
- A communication protocol between the USB-to-CAN and the host system
- A graphical user interface (GUI) for the presentation of the CAN network
The PiCAN2 board provides Controller Area Network (CAN) Bus capabilities for the Raspberry Pi. It uses the Microchip MCP2515 CAN Bus controller with MCP2551 CAN Bus transceiver. Connections are made via a 4-way screw terminal or DSUB-9 connector. This board is also available with a 5VDC/1A SMPS (switch mode power supply) that can power both the Pi and [...]
This post is part of a series about Controller Area Network (CAN Bus) Prototyping With the Arduino Uno.The Arduino board in combination with the CAN Bus shield provides the hardware for a full-fledged CAN network monitoring tool, and this next Arduino program is a first step in that direction.However, before we get into more detail, let me issue [...]
The Arduino Project Handbook is a beginner-friendly collection of electronics projects using the low-cost Arduino board. With only a handful of components, an Arduino, and a computer, you will learn to build and program everything from light shows to arcade games to an ultrasonic security system.First, you will get set up with an introduction to the Arduino [...]
The PiCAN2 DUO board provides two independent CAN Bus interfaces for the Raspberry Pi. It uses the Microchip MCP2515 CAN Bus controller with MCP2551 CAN Bus transceiver. Connections are made via a 4-way screw terminal. This board is also available with a 5VDC/1A SMPS (switch mode power supply) that can power both the Pi and the [...]
Since the arrival of the Internet of Things (IoT), many developers feel the urge to build a thing or two to introduce the IoT capabilities into their business or operating environment. Unfortunately, the lack of available hardware elements and reliable development platforms has long been an issue.Seeed Studio has worked with Google and BeagleBoard.org to provide a [...]
The LIN (Local Interconnect Network) bus is an inexpensive serial communications protocol, which effectively supports remote application within a car's network. It is particularly intended for mechatronic nodes in distributed automotive applications, but is equally suited to industrial applications. It is intended to complement the existing CAN network leading to hierarchical networks within cars.Controller Area Network [...]
This post is part of a series about Controller Area Network (CAN Bus) Prototyping With the Arduino Uno.In this next, extended example, we use the same program as shown in the previous chapter but add a CAN receiving routine to it. The result, i.e. the received messages, will be displayed through the Arduino serial monitor.// Simple CAN Shield Test#include [...]
This post is part of a series about Controller Area Network (CAN Bus) Prototyping With the Arduino Uno.The most exciting part about this project is when it comes to the point where two CAN nodes communicate with each other. I started off with writing a simple program that sent messages that were received by my USB-to-CAN gateway and its [...]
This post is part of a series about Controller Area Network (CAN Bus) Prototyping With the Arduino Uno.As with any serial networking controller, the essential functions are: InitializationRead DataWrite DataCheck StatusIn case of the MCP2515 library, these functions are represented by: Initialization: CAN0.beginRead Data: CAN0.readMsgBuf incl. CAN0.checkReceive, CAN0.getCanIdWrite Data: CAN0.sendMsgBufCheck Status: CAN0.checkErrorFunction CallsFunction: CAN0.beginPurpose: Initializes the CAN controller and [...]