GPS_4G_HAT_BG77X
Python drivers for Finamon GPS 4G shield onboard devices and peripheral interfaces
- Quectel BG77/BG770 4G Modem
- Accelerometer MC3419/MC3479
- Other shield HW parts: inputs/outputs, button, LED
Basic examples showing how to work with Finamon GPS 4G shield onboard devices using Python.
- demo_echo.py
- demo_geofences.py
- demo_GPS_4G_HAT.py
- demo_mqtt.py
Raspberry Pi Config
In your Raspberry Pi configuration within the Interfaces section, please make sure that
- I2C is enabled
- Serial Port is enabled
- Serial Console is disabled
Global setup
If you prefer to setup your projects using global package installations, please take a look at the prerequisites below.
With newer versions of Python you might experience the message error: externally-managed-environment
In this case try using pip's argument--break-system-packages
or add the following lines to ~/.config/pip/pip.conf:
[global]
break-system-packages = true
-
To be able to parse NMEA messages install package
pynmea2
:
pip install pynmea2
-
For access to SIM card account information install
python-dotenv
:
pip install python-dotenv
Virtual Enivironment
If you prefer to setup your projects using virtual environments, the necessary steps to be able to run the examples are:
- Download or clone the repository (see section below)
- Open the termianl and change into the repository folder
- Even using the virtual environment the project needs access to a global package to work with GPIOs
- Run
sudo apt update && sudo apt install python3-libgpiod
- Run
- Now you can create the virtual environment
python3 -m venv .venv --system-site-packages
- The parameter
--system-site-packages
allows to access packages from outside of the virtual environment
- The parameter
- Activate the environment via
source .venv/bin/activate
- (use the command
deactivate
to leave the virtual environment)
- (use the command
- Install the dependencies to run the demo scripts
python3 -m pip install pynmea2 python-dotenv pyserial smbus
- Now you can continue with the installation steps in the following sections to install the GPS 4G HAT library and execute the demo scripts
-
Clone git repository https://github.com/finamon-de/gps-4g-hat-library
-
Change directory
cd gps-4g-hat-library/gps4ghat/dist/
-
Install
gps4ghat
python package
pip install gps4ghat-0.1.0-py3-none-any.whl
-
Change directory to
gps-4g-hat-library
-
Copy example.env file to .env file and edit SIM account data:
CONTEXT_APN
CONTEXT_USERNAME
CONTEXT_PASSWORD
\ -
Start examples
python examples/demo_xxxx.py
- By default the GPS 4G HAT is configured to use the internal/onboard GSM antenna and the external GNSS RF antenna (that is part of the deliverables). You can ensure this configuration by having a look at the resistors close to antenna connectors.
- When you use your SIM card for the first time or after a long period, you may experience that the examples return a message containing
+CEREG: 0,2
. This message indicates that it was not possible to establish a connection with the base station but it is possible to retry - that's what the 2 indicates. When the connection is established the message will be+CEREG: 0,5
, the 5 indicating that the connection is succesfully created. While testing different SIM cards, we expirienced (very) long timespans until the first connection to the base station was possible - up to 60 minutes sometimes. After the first successful connection reconnecting is not an issue.