Skip to content

hat interface

marcobergman edited this page Jul 7, 2023 · 2 revisions

WORK IN PROGRESS JUL-2023

Software module

The HAT interface is primarily a software module that supports the raspberry's GPIO pins for keys, an LCD screen, and an infrared (IR) interface.

To enable the module, type sudo systemctl enable pypilot_hat and sudo systemctl start pypilot_hat (on the tinypilot distribution, replace systemctl with sv).

To make it work without the additional hat arduino (more about this later), you might have to edit /etc/systemd/system/pypilot_hat.service and change '44444' into 'none'.

For debugging purposes, run it by hand and then it should look like this:

pi@openplotter:~/pypilot $ pypilot_hat none
have gpio for raspberry pi
loading config file: /home/pi/.pypilot/hat.conf
failed to load /proc/device-tree/hat/custom_0 : [Errno 2] No such file or directory: '/proc/device-tree/hat/custom_0'
overriding driver default  to command line none
arduino process on  28138
renice: failed to set priority for 28138 (process ID): Permission denied
warning, failed to renice hat arduino process
No hat config, arduino not found
28139 (process ID) old priority 0, new priority 19
(30 seconds pause)
web process 28139
web config {'remote': False, 'host': 'pypilot', 'actions': {'auto': [], 'menu': [], 'up': [], 'down': [], 'select': [], 'left': [], 'right': [], 'engage': ['gpio18'], 'disengage': ['gpio23'], '1': [], '-1': [], '2': [], '-2': [], '10': [], '-10': [], 'compassmode': [], 'gpsmode': [], 'windmode': [], 'tackport': [], 'tackstarboard': []}, 'pi.ir': False, 'arduino.ir': False, 'arduino.nmea.in': False, 'arduino.nmea.out': False, 'arduino.nmea.baud': 4800, 'lcd': {'contrast': 60, 'invert': False, 'backlight': 200, 'flip': False, 'language': 'en', 'bigstep': 10, 'smallstep': 1, 'remote': False, 'hue': 27}}
web process on port 33333
web client connected c9fb01fcb0ac415a91e56d8432098268
apply ('gpio23', 1) 168451.776421598
apply ('gpio23', 2) 168451.776693334
apply ('gpio23', 0) 168451.776797443

Configuration

The pypilot_hat software module can be manually configured by editing ~/.pypilot/hat.conf. For instance, if you don't have an infrared sensor, set pi.ir to False in this file.

This pypilot_hat software module also provides a web interface at socket :33333 that can be used to configure these same things. Note that the web interface at port :33333 has a startup delay of 30 seconds.

The hat interface is preconfigured for use with the hardware hat (see below). If you want to use keys directly attached to your pypilot raspberry, you must reconfigure the keys with this interface:

  • Open the web interface, hit a key (in my test, I shorted GPIO26 to ground). You should see this happen in the interface. Then, within a few seconds, click one of the actions (in my test, I clicked 'engage'). From then on, shorting GPIO26 to ground engages the autopilot.

Hardware

The pypilot_hat software module can also connect to an extra arduino that additionally provides a RF433 wireless remote, NMEA0183 I/O and a buzzer. This extra arduino would need to be programmed with the hat.ino sketch. The reference schematics for this hardware is at https://pypilot.org/schematics/pypilot_tinypilot.pdf.

A few notes to interpret this diagram:

  • The communication between this extra HAT arduino and the raspberry takes place via SPI, that is, the MISO, MOSI, SCK and AR_SS (CE1) signals.
  • The RF433 signal comes in at J9, pin2, as DATA and connects to the HAT arduino on PD2.
  • An additional line from the pi's GPIO16 to the arduino's RESET allows the pi to reset the arduino and upload the (equivalent of hat.ino) software to it with make upload.
  • There is an i2c eeprom in the schematics. If attached, the pypilot_hat software module will read it and use the hardware specifications from it. Without it, it assumes the hardware described in hat.conf. This mechanism allows for the Pypilot Hat hardware to be installed and work without additional configuration, that is, hardware autodetection.

The main reason for this extra HAT arduino is to offload the raspberry. Besides, the signal that comes out the RF433 module is serial, but too long in term of bits and too non-standard to be handled by a standard UART. It needs to be sampled (as in bitbanging) and there is no way the raspberry could do that as well, next to being autopilot and all.

Pypilot Hat

This hardware module as described in the reference schematics can be bought ready-made at the pypilot web shop.


Step 5: The HAT interface >>>

Clone this wiki locally