Step 6 The Arduino controller
WARNING: this information has been written in 2021, when pypilot version was 0.24 and Openplotter was 2.0. In 2023 these versions have by far been superceded and information in this chapter is most likely to be partly obsolete. Work in progress will be documented in the Workbook Release Notes.
As said, the pypilot software component is not complete without the motor controller software, and this has to run on an Arduino. As far as I know always an Arduino Nano is used, the small version.
Try not to buy a cheap clone. There are some settings on an Arduino that require ugly tricks to set right. These settings are called fuses, and I compare them with BIOS settings on a PC. If you buy a proper Arduino, the fuses are set all right. If you purchase them from a major retailer, this will increase your chances to get a proper Arduino. If your fuses are wrong, pypilot will give you an clear error message saying your fuses are wrong.
Next is to get the sketch. You need two files and you best get them from github: https://github.com/pypilot/pypilot/tree/master/arduino/motor. The files are motor.ino and crc.h.
To get the sketch onto the Arduino, the easiest way is to do it with a USB cable. There are two options: you program the Arduino the Linux way, or the Windows way.
- The Linux way is explained in the github readme. It requires a program called avrdude that is not on the openplotter image, so you would have to install it with
sudo apt-get install avrdude
. Don't forgetsudo apt install arduino
as well. - The windows way requires the download and installation of the Arduino IDE. Put the two files in a directory called ‘motor’, double-click on motor.ino, in the Arduino IDE Tools menu set Board=Arduino Nano, Processor=ATMega328P, set the com-port, and hit Upload (CTRL U).
When the tool says 'upload completed', the next step is to connect your arduino to the pypilot. The easiest way to hook up a Nano to your pypilot is to use the same USB cable that you programmed it with *). Like this:
The USB-attached Nano will enumerate as a serial device and Pypilot will probe all serial interfaces periodically, meaning that after a while, the pypilot will automatically recognize the presence of the Arduino. When this happens, the first thing you should notice, is that the Tx and Rx LED’s on the Nano will start blinking. This means that pypilot is talking to the Nano. In the autopilot control, you will see top-left the word Arduino appear, in the middle the word SYNC, and sometimes BADVOLTAGE_FAULT. These are the tell-tale signs that a brilliant system is starting to become alive. Judging by the word FAULT, we’re not there yet, but if you got this far, you really deserve a proper drink.
We are doing this step just to recognize what functionality starts working at what stage. At this stage you should see the following:
- Both Tx and Rx should blink, meaning that there is two-way traffic between pypilot and the Nano. With a USB connection they both blink or they both don’t. When you connected another way it might be that Rx blinks and Tx does not. If that is the case, give a shout.
- If you enable the autopilot (‘AP’) you should see the word ‘Engaged’ in the autopilot control, and on the Arduino another red LED should burn.
- There will be random error messages next to the word SYNC, and this can be expected. These error messages are called ‘flags’ in pypilot parlour, and at this point they are caused by the input pins on the Arduino being left open. Open input pins are bad practice in electronics; if they are left 'floating' they are susceptible to electrostatic influences and worse, damage.
*) If you don't use the USB serial, but the TTL serial, there's a few things more to do - check out Step 14: The Pypilot Motor Controller
Pypilot Workbook
- Introduction
- What is pypilot
- The software component
- The hardware component
- The User Interface component
- Pypilot functions
- Data connections
-
The steps
- OLD
- Step 1: Install Openplotter Headless
- Step 2: Install pypilot
- Step 3: The openplotter user interface
- Step 4: The browser interface
- Step 5: The HAT interface
- Step 6: The Arduino controller
- Step 7: OpenCPN Pypilot Plugin
- Step 8: Looking under the hood
- Step 9: Wiring up the Nano
- Step 10: Installing Tinypilot
- Step 11: Tinypilot under the hood
- Step 12: Using openplotter tools remotely
- Step 13: SignalK connections
- Step 14: The Pypilot Motor Controller
- Step 15: Understanding motor.ino
- Parameters
- Gains
- NEW
- Step 1: Installing pypilot
- Step 2: Web interface
- Step 3: OpenCPN pypilot plugin
- Step 4: Installing the arduino
- Step 5: Wiring the arduino
- Step 6: Setting up data connections
- Step 7: SignalK connections
- Step 8: HAT interface
- Step 9: Debian under the hood
- Step 10: Tinypilot under the hood
- Step 11: Openplotter details
- Updating pypilot: debian
- Updating pypilot: tinypilot
- Feedback
- Todo
- Finally
- Autopilot Route Plugin
- Watchdog
- Workbook Release Notes