Wiki
Clone wikiEngineMonitor / Networking_EngineMonitor
There is demand for networking the EngineMonitor so the measurements can be displayed on charplotters or tablets like an iPad or Android.
There are many options to accomplish this and I'm looking for recommendations on which protocol to use and how to do it.
NMEA 2000
This is the formal marine networking protocol and is supported by all modern chartplotters. However this is not native to the iPad or Android. A wifi or bluetooth transceiver must be installed on the NMEA 2000 network for tablets to receive the data. NMEA 2000 is a proprietary protocol so there might be a licensing issue. Technically it is more difficult to integrate NMEA 2000 into an Arduino.
WiFi
This allows the EngineMonitor to expose a web server. The server can display data in an HTML table, or it can return JSON strings for a mobile app to use. WiFi would require the boat to have a WiFi router onboard, or the system could use peer-to-peer however that is not simple to configure on the tablet.
Bluetooth
This would require an app to be developed and loaded on the tablet. There are also considerations for range of Bluetooth
NMEA
http://forum.arduino.cc/index.php?topic=50893.45 https://github.com/ttlappalainen
SignalK
SignalK requires significant and complex boilerplate JSON messages. There are no suitable client apps or libraries to display the output data. The analog-style dial gauges in some of the reference projects are interesting, but they are also available in much simpler js libraries.
Decision
Host a website on the RPi that returns pages with analog-style gauges in addition to tabular-style data. Subsequent versions can load the sensor values into a simple database for data logging and charting values over time.
Technology
Integrating a Raspberry PI with the Arduino seems the simplest approach.
We can have the Raspberry PI running a web server and running as a WiFi access point. This eliminates the need for a separate WiFi router onboard. Your iPad or tablet can load a web page hosted on the RPI. The webpage can query the Arduino for the sensor values and embed them in a page. This page can be a human-readable HTML page, with AJAX to keep the sensor values updated without a page refresh. We can also expose the data as JSON or XML for integration with SignalK-compliant displays.
After we have the WiFi-webserver option running we can tackle integrating the RPI with NMEA 2000.
Architecture: Arduino Serial Pins and RPI GPIO
This approach uses a logic level shifter to convert from 5V on the Arduino to the 3.3V on the RPI. Since we already have spare pins on the logic level break out board this seems like a good apprach. Arduino digital pins 0 and 1 are connected to the GPIO pins with the logic level converter in the middle. A good example is found at http://blog.oscarliang.net/raspberry-pi-and-arduino-connected-serial-gpio/
Arduino
The main loop is modified to look for input on the serial-in pin. It can then send data back over the serial-out pin. This example parrots back a number received. In our implementation the Arduino can send back a string of values for each sensor.
void loop(){ if (Serial.available()) { number = Serial.read(); Serial.println(number, DEC);
RPI Code
Flask with RPi.GPIO is common implementation and is well documented at http://mattrichardson.com/Raspberry-Pi-Flask/ and https://pypi.python.org/pypi/RPi.GPIO
We can use a python library to communicate with the Arduino via the RPi GPIO pins. The Arduino then sends the sensor values back to Python. All this can run in a web server. Flask is a popular lightweight web framework for running python on a RPI. There are several examples online, such as https://www.raspberrypi.org/learning/python-web-server-with-flask/.
There are examples of Python libraries online that can query the Arduino. The Arduino is listening for commands on the serial port. To start out, we could simply pass a "1" to the Arduino and it could return a JSON string with the values for all the sensors.
pyserial is the library used for the Python to talk to the GPIO pins and request updated sensor values.
HTML Display
There are many tools for creating analog-style gauges in javascript. https://github.com/Nirvason/jsgauge seems to be the best. Check out file:///D:/Workspace/MarineEngineMonitor/RPi_v2.0/jsgauge-master/src/example/gauge.html for an example.
Setting up the RPi as an Access Point
This eliminates the need for a separate wifi router onboard.
See: https://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point/install-software
Raspberry Pi with NMEA
There is a python library for NMEA 0183 at https://github.com/Knio/pynmea2
CANboat
https://github.com/canboat/canboat/wiki/CANboat
Options passed up
Nanpy
Nanpy takes over the Arduino and no other code may run on the Arduino. All the programming is done in Python and the Arduino is simply a slave of the controlling PC/RPI. Since we have considerable code on the Arduino we instead need a library that can talk to the Arduino instead of remotely controlling it. Nanpy: https://pypi.python.org/pypi/nanpy
I2C connects to the analog pins 4 and 5 on the Arduino as well as the ground.
http://blog.oscarliang.net/raspberry-pi-arduino-connected-i2c/
http://www.bajdi.com/controlling-an-arduino-through-a-rapsberry-pi-webserver/
https://www.raspberrypi.org/magpi-issues/MagPi07.pdf
Web Server Options * Flask * CherryPy * Django
Updated