Skip to content

Instantly share code, notes, and snippets.

@martin-vi
Last active March 12, 2021 12:12
Show Gist options
  • Save martin-vi/5206b6b26faf6f2d6121f6c8f300e44d to your computer and use it in GitHub Desktop.
Save martin-vi/5206b6b26faf6f2d6121f6c8f300e44d to your computer and use it in GitHub Desktop.

Instructions FortiusAnt

Build requirement

$ sudo apt install -y python3-pip python-virtualenv python3-virtualenv git build-essential
# Note: git only if, FortiusANT is checked out via git
$ sudo apt-get install -y libatlas-base-dev # for numpy, https://github.com/numpy/numpy/issues/11110

Note: pip may try to build the Python package wxPython from source code. This is sometimes too much, especially for weak hardware like the Raspberry Pi. This can be solved by installing the package globally in the system via:

$ sudo apt install -y python3-wxgtk4.0

Other packages such as numpy or pygame can also be provided via the system if necessary.

VirtualEnvironment for the encapsulation

$ virtualenv -p python3 --system-site-packages venv

Afterwards, the installation of packages for FortiusANT always requires the virtualv to be activated first. This also applies to starting FortiusANT.

This is done, inital after starting a new shell session:

$ source venv/bin/activate

FortiusANT

via git:

$ git clone https://github.com/WouterJD/FortiusANT.git

or via download

$ curl -L https://github.com/WouterJD/FortiusANT/archive/master.tar.gz | tar -xzvf -

Sadly, FortiusANT currently does not set any tags and therefore no releases. Otherwise you could directly address a special version.

Install FortiusANT dependencies:

# remember activated virtualenv required
$ pip install -r FortiusANT/pythoncode/requirements.txt  

USB Ant Module

Required to not run FortiusANT as root. Depending on the ANT-Stick a different entry appears with lsusb. In my example, "Dynastream Innovations, Inc. ANTUSB2 Stick" is used here.

$ lsusb
Bus 001 Device 005: ID 0fcf:1008 Dynastream Innovations, Inc. ANTUSB2 Stick
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. SMC9512/9514 USB Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Important here are the vendor id 0fcf and product id 1008.

We assign the Linux USB serial driver to the ANT stick by noting the driver with the id's:

$ sudo su
$ cat << EOF > /etc/modprobe.d/ant-usb2.conf
options usbserial vendor=0x0fcf product=0x1008
EOF

Furthermore we assign the device file to our user so that he can read and write to it. In my example the user is pi. Please also adjust the following example with your usb ids (vendor and product). It is also possible to assign Groups. See udev rules documentation or search the web for more examples.

$ sudo su
$ cat << EOF > /etc/udev/rules.d/garmin-ant2.rules
# https://stackoverflow.com/questions/3738173/why-does-pyusb-libusb-require-root-sudo-permissions-on-linux
SUBSYSTEM=="usb" ENV{DEVTYPE}=="usb_device" MODE="0664" GROUP="pi"
SUBSYSTEM=="tty" ACTION=="add" ATTRS{idProduct}=="1008" ATTRS{idVendor}=="0fcf" MODE="0665" GROUP="pi"
EOF

More general udev rules can be found here.

Now reload the 'usbserial' driver and update / reload the udev deamon. If in doubt, re-attach the dongle and/or reboot the system completely.

Now FortiusANT (here only command line) can be tested.

$ source venv/bin/activate # load the virtualenv, if not done before
$ cd FortiusANT/pythoncode
$ python FortiusAnt.py -s -a

With the option "-s" the Tacx Head-Unit is left out, only the Ant Dongle is tested with simulated date. Please consult the manual for more commandline parameters.

@MeanHat
Copy link

MeanHat commented Dec 3, 2020

Many thanks @martin-vi
a. Using sudo to run FortiusAnt.py results in an error: File "FortiusAnt.py", line 71
print ('i', end='')
^
SyntaxError: invalid syntax
b. logfile (without using sudo) attached at https://github.com/MeanHat/FortiusANT-logfiles.git
c. Here is the screen output from running FortiusAnt.py -s -a -d 127:
(venv) pi@raspberrypi:~/FortiusANT/pythoncode $ python FortiusAnt.py -s -a -d 127
11:12:54,859: FortiusANT started
11:12:54,862: -a
11:12:54,865: -d 127 (0b1111111)
11:12:54,868: -H None
11:12:54,869: -p 1.0
11:12:54,870: -s
11:12:54,876: ------------------
Traceback (most recent call last):
File "FortiusAnt.py", line 538, in
Console.Autostart()
File "FortiusAnt.py", line 167, in Autostart
if LocateHW(self):
File "FortiusAnt.py", line 90, in LocateHW
rtn = FortiusAntBody.LocateHW(self)
File "/home/pi/FortiusANT/pythoncode/FortiusAntBody.py", line 266, in LocateHW
AntDongle = ant.clsAntDongle()
File "/home/pi/FortiusANT/pythoncode/antDongle.py", line 276, in init
self.OK = self.__GetDongle()
File "/home/pi/FortiusANT/pythoncode/antDongle.py", line 334, in __GetDongle
(self.devAntDongle.manufacturer, self.devAntDongle.product,
File "/home/pi/.local/lib/python3.7/site-packages/usb/core.py", line 886, in manufacturer
self._manufacturer = util.get_string(self, self.iManufacturer)
File "/home/pi/.local/lib/python3.7/site-packages/usb/util.py", line 313, in get_string
raise ValueError("The device has no langid"
ValueError: The device has no langid (permission issue, no string descriptors supported or device error)

I really appreciate your help with this. Thank you in advance. Cheers, Keith

@YDA94
Copy link

YDA94 commented Dec 29, 2020

Hi Keith, had same issues like you.
The following changes helped for me in the rules file on a RPi4:

SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", MODE="0664", GROUP="ant2"
SUBSYSTEM=="tty", ACTION=="add", ATTRS{idProduct}=="1008", ATTRS{idVendor}=="0fcf", MODE="0666", GROUP="ant2"

=> use GROUP instead of USER, separate all options with comma

then
sudo add group ant2
sudo adduser pi ant2

sudo reboot
You should now see

lsusb -v

the ant2 device with
iManufacturer 1 CYCPLUS
iProduct 2 ANT USBStick2
iSerial 3 123

and the FortiusANT should run.

@MeanHat
Copy link

MeanHat commented Dec 31, 2020 via email

@MeanHat
Copy link

MeanHat commented Dec 31, 2020

Hi @YDA94
Thank you very much for your notes. They worked and I'm now happily running FortiusANT on a RPi0W.
I wonder if it would be helpful to add a page to the User Manual @WouterJD has produced for his FortiusANT to cover RPi? I'd be happy to draft this if you (or @martin-vi) would like to check it before we submit it. What do you think?
Cheers - Keith

@martin-vi
Copy link
Author

@MeanHat sorry for my inactivity. I am glad to hear that it works now. Thanks @YDA94 for your support and correction. I looked up my udev rules again and indeed USER and not GROUP is used. Here I have made a mistake. I have adjusted it in the gist. The use of commas does not seem necessary. At least it works for me without.

In the meantime there are more rbpi users working on documentation, see WouterJD/FortiusANT#192. I think this will result in improved documentation.

@ManInAGarden
Copy link

@martin-vi I succesfully did
sudo apt install -y python-wxgtk3.0
on my brand new raspperry pi 4B but during
pip install -r FortiusANT/pythoncode/requirements.txt
it errors out while trying to build wxPython.
The error seems to happen in this command issued by during the above pip install:
build_wx wxWidgets build options: ['--wxpython', '--unicode', '--gtk3']
and I also find this in the very long error message
for GTK+ - version >= 3.0.0... Package gtk+-3.0 was not found in the pkg-config search path.

I thought that no wheel building for wxPython should be done. Am I wrong?

@mikeherriman
Copy link

@ManInGarden
I found that I could not get the wxPython to install.
I did find a link to wxPython 4.1.1 https://drive.google.com/file/d/1Uk1TSc6iLArx14QH8q85c9ytrw0IKLIn/view?usp=sharing
I downloaded and installed this wxPython whl file and all is well.

@ManInAGarden
Copy link

ManInAGarden commented Jan 13, 2021

Downloading the wxPython wheel from https://drive.google.com/file/d/1Uk1TSc6iLArx14QH8q85c9ytrw0IKLIn/view?usp=sharing Is oK when you're installing FortiusAnt on one of the newer Raspberry Pis. It worked well on my brand new Raspperry pi 4B. Newer Raspberry pis are based om ARM7.1 architecture. The very old ones, like my two raspberry PI 1 boards are based on ARM6.1. I even tried to build that wxPython wheel myself but failed. After several redos I gave up when my raspberry PI told me after tow days of compiling and linking that it's SD-Card (only 8GB) was to small for that.
On the other hand I'm convinced that a raspberry 1 is capable of running FortiusANT in a headless (without GUI) mode. The only thing we'd need for that is wxPython for ARM6.1 or - even better a version of FortiusANT without wxPython which is only needed for the GUI part which is more or less not needed on a raspberry pi. Another idea I had was to replace the GUI with a simple GUI made with something like ncurses for the Rasperry pis.

@MeanHat
Copy link

MeanHat commented Jan 13, 2021 via email

@martin-vi
Copy link
Author

martin-vi commented Jan 13, 2021

Maybe the virtualenv is not set up correctly? pip install -r FortiusANT/pythoncode/requirements.txt should not try to install or build wxpython because the system provides it.

I think I have the wrong package name listed here. python-wxgtk3.0. python-wxgtk3.0 is apparently only for python2, but we use python3 here (see also https://packages.debian.org/buster/python-wxgtk3.0, deps are python (<< 2.8) and python (>= 2.7~)). Sorry my fault (again).

Please try sudo apt install -y python3-wxgtk4.0 this is for python3. After that, check with python3 -c "import wx" with and without activated virtual environment. This should not exit with an error in both cases.

I will cross check the package name with my FortiusAnt-RPi installation.

@ManInAGarden
Copy link

I'm setting up one of my good old Raspberry PI 1s now to give that a try. I start with a buster light (means without GUI) to find out what has to be installed for that. I'll report my results here.

@ManInAGarden
Copy link

ManInAGarden commented Jan 13, 2021

@martin-vi: Thanks a lot! I tried it on a raspberry PI 1(!) with buster light (without GUI) freshly setup on a 8GB SD card. I did the following:

Getting everythung up to date with
`$ sudo apt update

`$ sudo apt upgrade

And then

$ sudo apt install -y python3-pip python3-virtualenv git build-essential

`$ sudo apt install libatlas-base-dev

`$ sudo apt install python3-venv

Setting up a virtual environment named venv with the python3 venv command:

`$ python3 -m venv –system-site-packages venv

Activating the virtual environment in venv:

`$ source venv/bin/active

Cloning ForiusAnt with:

`$ git clone https://github.com/WouterJD/FortiusANT.git

Getting all the requiremtns for FortiusAnt into the environment which are not already installed system wide:

`$ pip install -r FortiusANT/pythoncode/requirements.txt

This fetched an installed some wheels and amomg many messages I also found this:
'Requirement already satisfied: wxPython in /usr/lib/python3/dist-packages (from -r FortiusANT/pythoncode/requirements.txt (line 5)) (4.0.4)

So that did work - no tries to compile that requirement for wxPython here.

And a first start with

`$ python3 FortiusAnd/pythoncode/FortiusAnt.py -a

Only complained about not finding the trainer on USB and also not findig an ANT+ dongle.

@martin-vi
Copy link
Author

martin-vi commented Jan 13, 2021

I just checked my installation and python3-wxgtk4.0 is the correct Debian package.

$ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.__file__
'/usr/lib/python3/dist-packages/wx/__init__.py'
>>>
$ dpkg -S /usr/lib/python3/dist-packages/wx/__init__.py
python3-wxgtk4.0: /usr/lib/python3/dist-packages/wx/__init__.py

Sorry again for the error in the the manual draft 🤦 fixed the last gist revision.

@ManInAGarden
Copy link

In the meantime I also adjusted the usb-rules but used groups like @YDA94 did in his comment (see above). I did a short testride through rainy London town via ZWIFT this morning and the combination of Raspberry PI 1 + FortiusAnt and Dynastream ANT+ dongle worked without any errors.
I should mention that at first lsusb did not show the ANT+ dongle and I had to replug it. This reminded my of the fact that a raspi1 has very weak USB Ports. So maybe one should use an additional USB Hub to connect to the trainer and to the ANT+ dongle. Maybe it's only a matter of power on sequences. I think switching on the trainer in advance before powering the raspberry pi should work without an usb-hub.

I have a raspberry PI model 4B and a model 1 running with FortiusAnt now. In both cases it worked using the above installation description with the exception of using the group ant2 and adding the user pi to that group instead directly mentioning the users in the garmin-rule file.

@hasise
Copy link

hasise commented Mar 3, 2021

The installation as such worked fine, many thanks for that @martin-vi
When testing the Ant dongle(python FortiusAnt.py -s -a) it toggles between "Dongle - GetDongle - ANT dongle in use" and something like no Ant Dongle found.
The vendor and product are the same as in the example (Using a Tacx ANT+ dongle) so the commands where copied directly without
any modifications but still the ANT Dongle seems to be misconfigured in some way or at least I think so.

In addition I followed the instructions in the end to configure the Tacx USB port, except for the GROUP that I set to pi
Now when testing without the -s flag it finds the Tacx hardware. Here is a snippet of the log file:
20:28:27,496: GetDongle - Exception: [Errno 13] Access denied (insufficient permissions)
20:28:27,497: Dongle - GetDongle - ANT dongle in use
20:28:27,506: Connected to Tacx Trainer T1932
20:28:27,810: Motor Brake Unit Firmware=0x1902 Serial=0 MotorBrake=False
20:28:27,911: FortiusAnt applies the MagneticBrake power curve
20:28:28,012: Retry because short buffer (len=64) or incorrect header received (expected: 0x21303 received: 0xc03)
20:28:28,114: Tacx - Connected to Tacx Trainer T1932
20:28:28,114: AntHRM - Heartrate expected from Tacx Trainer
20:28:28,114: FortiusAnt ended

So something is not correct, maybe someone has examples of /etc/modprobe.d/ant-usb2.conf and
the equivalent for the Tacx usb conf file?

https://github.com/decodeais/FortiusANT/blob/Raspi-Status-LED/doc/HeadlessRaspi.md
"Diagnose the hardware Tacx and ANT+ Stick
lsusb
…... Bus 001 Device 006: ID 3561:1932
Bus 001 Device 007: ID 0fcf:1009 Dynastream Innovations, Inc. ANTUSB-m Stick

In this example the first number is the Tacx Trainer, the second is the Antstick. The ID's can differ from model to model. Create the file and adapt the ID's in the file (1932/1009) !!

sudo nano /etc/udev/rules.d/ANT_USB.rules
Copy and paste the following text into nano editor.

SUBSYSTEM=="usb", ATTRS{idVendor}=="0fcf", ATTRS{idProduct}=="1009", RUN+="/sbin/modprobe usbserial vendor=0x0fcf product= 0x1009",MODE="0666", OWNER="pi", GROUP="dialout"
SUBSYSTEM=="usb", ATTRS{idVendor}=="3561", ATTRS{idProduct}=="1932",MODE="0666", OWNER="pi", GROUP="dialout"

@WouterJD
Copy link

WouterJD commented Mar 6, 2021

@martin-vi thanks for this work, do you follow WouterJD/FortiusANT#192 (comment)?

@hasise
Copy link

hasise commented Mar 6, 2021

A short comment, the USB issue is now resolved, just changed the rules file s bit. Still having an issue starting the UI but that is handled in issue #262

@WouterJD
Copy link

Thanks for the commands and comment; I have added it to the installation scripts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment