Issue related to CAN protocol? do I need to use CAN? - can-bus

We are building Electric Vehicle for Formula students competition, for communication protocol between modules we have to use CAN method. Do we need every module to know data from the other modules. For eg. we are using Micro-controller raspberry pi Pico to collect data from sensor and based on data perform action by same microcontroller itself. But CAN method says that data should be routed and shared in network where other receiver would collect. so one thing we thought was to use one microcontroller to collect data from all sensor and share data with CAN controller to another micro-controller to perform the action. But it is increase in complexity, and CAN was designed to reduce complexity. so I am confused how to apply CAN protocol. I am not getting when some data where it is collected can be used then why do we have to share. Or may be i am just going wrong so please help to clarify this concept. thank you.

CAN Bus and the upper layer protocols based on it (like CANopen) generally provide a messaging medium for publisher & subscriber pattern.
Publisher Nodes: They produce data and publish this data to the bus.
Sensor nodes are good examples of publisher nodes.
Subscriber Nodes: They subscribe to one or more data packages on the
bus and consume these data. For example, a motor driver may subscribe
to some speed command and drive the motor accordingly.
A node can both produce and consume data, acting as a publisher and a subscriber at the same time. For example, the main control unit in the car can read various sensor data from the bus, process them and publish command data for the actuator nodes (like motor drivers).
When using CAN Bus, instead of inventing your own protocol, it may be a better idea to use an existing protocol, like CANopen. I suggest you to read CiA 301 document which explains the fundamentals of CANopen. Even if you don't use it, it will give you some ideas.

Related

Can STM32F1 (as part of MXChip) support CAN Bus

Background
I'm very new to electronics/IoT dev. I'm trying to create a solution to be able to read my wife's Car's CAN Bus signal (messages) and store it to an SD card. I hope to analyze the data and build a dashboard based on the car's telemetry.
This specific question is in relation to a chip (STM32F1) on an IoT board (MXChip AZ3166) I already own, which I hope to incorporate into my overall solution as the data acquisition layer.
For reference the:
Chips is the: STMicroelectronics STM32F103C8T6, 32bit ARM Cortex M3 Microcontroller
and the IoT board is the: (MXChip AZ3166 IoT DevKit)
Reading the MXChip AZ3166 board's spec and after doing some research, I have found out that the MXChip AZ3166 comprises two main chipsets:
Vendor
Part Number
Ref Link
STMicroelectronics
STM32F103C8T6
https://uk.rs-online.com/web/p/microcontrollers/1023545
MXChip
EMW3166
https://www.mxchip.com/en/products/module/54
Main Question
The product specification mentions the STM32F1 features Comprising of motor control peripherals plus CAN and USB full speed interfaces, it also states it has 1x CAN Channel. Does that mean I can interface the MXChip AZ3166 board featuring this chip via the GPIO pins to the CAB bus in my wife's car and receive the CAN Bus signals (I presume adhering to the
ISO 11898-1 CAN data communication protocol).
How would I find out which pins to connect to the CAN Hi & CAN low connections on the cars CAN Bus?
Concerning power, how would I determine that the CAN signal received doesn't fry the MXChip Board with a stated max Operation voltage of 3.3v?
Yes you'll want an MCU with a built-in CAN controller for communicating on a CAN bus. However, the CAN standard only covers the physical and data link layers. You need to know the application layer in order to meaningfully interact with a bus.
The application layer on a car may or may not be proprietary. It may even be encrypted. If you don't know what protocol is uses, then no can do. Reverse-engineering CAN protocols is hackish, hard and dangerous. Plugging into a CAN bus where you have no clue about timing considerations etc is also very dangerous.
But cars usually have an "on-board diagnostics" (OBD) port used for service purposes, with standardized application layers, through which you may have access to various parts of the car. There's lots of different standards for OBD and older ones didn't even use CAN. It depends on the car model.
In case of the OBD port the pinouts are standardized and you can find them on the Internet. Otherwise it is very simple to find out which signal that's CANH and CANL with an oscilloscope. CANH goes 2.5V +1V and CANL 2.5V -1V. A more hacky solution is to measure this with a multimeter, but it's perfectly possible since one signal with be slightly above 2.5V and the other slightly below.
CAN is standardized so if you have a CAN bus on the board, you connect there. In some cases there may be 12V supply wired together with the signal and that's the only one which could fry something.
Overall, please note that the project you describe here is very difficult and not a beginner task. It sounds as you have next to no experience of electronics/embedded systems, so I would recommend picking a far simpler project.
Furthermore, modifying car electronics or installing your own electronics in a car is illegal in most parts of the world. Third party type approvals with EMC tests are mandatory (and very expensive). If your car is involved in an accident and they find custom electronics without type approval in it, you could be facing serious legal consequences.

How to organize data shared between several viewControllers?

Currently the app I am working on uses Bluetooth LE to communicate with a microcontroller which has a sensor on it and collects data by measurements.
Microcontroller has a set of parameters which are all configurable. Those measurement settings are configured by sending AT commands via Bluetooth and that can be done from different screens in the app.
When a measurement is finished, I need to store all the collected data somewhere as well as settings under which that measurement was executed. Different screens need to display this data and I am wondering what the best way to this is. I was thinking about having Measurement as a singleton and all of the screens would then read properties of an object of Measurement class and then display that data, but I do not like that approach.
I am wondering how to keep my code as clean as possible, separating responsibilites among different classes (for example BluetoothManager does not need to know about anything specific about the measurement or configuration of microcontroller themselves).
Generally, I would like to get some good advice on clean code in Swift, maybe some resources or tutorials which handle this in a project. An example project with a similar theme such as this one (CoreBluetooth, handling data that is needed across the app) would be great.

How to decipher CAN bus message?

I want to to know is it possible to make a script that decipher and document CAN
message.
My goal is to define which id of CAN bus message is related to speedometer, odometer, Engine RPM etc.
You cannot know this without knowing the nature of the application layer protocol. CAN is just the lowest levels of the OSI model, it doesn't define anything related to data.

Software for sensor manipulation

I am searching for open source software for wireless sensors’ management in a wireless sensor network environment. More specifically, I have some 802.11-based temperature sensors which are connected with a pc using a 802.11 router. I need to put configurable open source software into the pc to manipulate the information that comes from the sensors. Any idea?
I've been using Zenoss Core Community edition to accomplish the task you mentioned. It allows you to monitor several temperature sensors, storing the information in circular databases. Once deployed, you don't need to perform too much housekeeping.
If your sensors implements SNMP (Simple Network Managment Protocol) all you need is to enable the protocol according to manufacturer specs and let zenoss to discover your devices.
You can create customized reports and trigger events based on your custom configuration (eg, send an email when temperature is over certain level).
Finally, if the monitoring info is retrieved using a different method other than SNMP, you can code custom scripts with Python, so that you help to zenoss to retrieve the info needed. Dig into the forums. Chances are the script is already available for your sensor.

What is a 'Stream', relating to cin and cout?

A tutorial is talking about cin and cout:
"Syntactically these streams are not used as functions: instead, data are written to streams or read from them using the operators <<, called the insertion operator and >>, called the extraction operator."
What is a 'stream'?
Consider a "Stream" as a physical hose, or pipe. At one end, someone may pour some water in. At the other end, it will come out. This is 'reading' and 'writing' to the stream.
A stream is just a place where data goes. It can be a 'socket stream' (over the internet) or a 'file stream' (to a file), or perhaps a 'memory stream', just data written to a place in-memory (ram).
A "stream" is an object that represents a source of data, or a place where data can be written.
Examples include file handles and pipes - things that you can read data from or write data to.
An important property of streams is that they share a common interface, so the same code can write to either a file or a pipe (for instance) without needing to be rewritten.
You should look at streams as abstractions on underlying 'sources' or 'sinks' of data. A source is something you read data from, and a sink is something you write data to.
The concept of streams allows you to perform I/O on various forms of media, network connections, pipes between applications, files, etc.
The stream abstraction is very valuable to us as developers as it allows us to simplify input and output, and it gives us the flexibility to arrange and reconnect the sources and destinations of these streams.
A good analogy is that of a hose. You can send and receive data through hoses, and you can connect these hoses to various things.
By allowing programs to talk through hoses, we allow all sorts of programs to talk to each other, and we increase interoperability and utility vastly.
This is at the heart of the UNIX philosophy, and supports some very powerful programming idioms.

Resources