DeLorme USB GPS into Raspberry Pi using Python - python

I have a DeLorme Earthmate LT-40 USB GPS device that I used years ago with a Windows XP program. Out of curiosity I plugged it into my Raspberry Pi to see if I could read the data. I've managed to see data using sudo gpsmon at the command prompt so I would like to take this a step further and write a Python program to read the data. Not knowing very much about Python I've searched YouTube and google for possible solutions. It looks like that I need to import pynmea2. I used pip install pynmea2 to install the module. I keep getting
"ModuleNotFoundError: No module named pynmea2"
when I try to run my script. I tried to reinstall pynmea2 again which gave me
Requirement already satisfied: pynmea2 in ./.local/lib/python2.7/site-packages(1.15.0).
I don't understand what I'm doing wrong. Any help would be greatly appreciated. Thank you.

I have the older version LT-20 of that GPS and usually it presents itself as ttyUSB0 (in my case) when I plug it on Raspberry.
Just do a dmesg command to see in which port it is being recognized, then you can do a cat /dev/ttyUSB0 command and you see all the messages coming from your GPS. The messages start with a $GP for each type of frame. See detailed $GP description at: http://aprs.gids.nl/nmea/ .
Then from your python program, you can open /dev/ttyUSB0 as a file (as read only) and handle each frame and interpetting it according to its format.
Best regards
Flavio

Related

Error displaying video stream using Opencv on raspberry pi

I'm trying to access a live video feed from my Raspberry Pi with a PiCam attached. I have enabled the camera in the interface settings and even tested it by snapping some pictures and videos using the PiCam library. However, OpenCV is giving me troubles. I installed open CV following this tutorial (shoutout to Adrian Rosenbrock).
Check out the screenshot below for the code and the error message. I'm running everything from within a virtual environment with OpenCV installed, like Adrian suggests.
Code and error message
VIDEOIO ERROR: V4L: can't open camera by index 0
From what I've read from other problems people have had, this error is sometimes resolved by playing with the index value. If i change the index value to -1 or 1, like most solutions suggest, i either get the same thing or a slightly different "can't access camera" error.
I'm relatively new to OpenCV and RPi so I might just be missing something simple. Any suggestion is much appreciated, thanks!
You may need to enable access to the camera. Try typing:
sudo modprobe bcm2835-v4l2 in terminal on your RPI.

I have trouble with PyAudio does not detect input device

I made this thread in Raspberry PI Stack Exchange and my problem was solved. Until last week I tried to run my Python application again (both in Raspbian and Ubuntu 16.04) this error appeared again.
OSError: [Errrno -9996] Invalid input device (no default output device)
What I have done so far.
pyaudio.PyAudio().get_device_count() returns 0.
arecord --device=hw:1,0 --format S16_LE --rate 44100 -c1 test.wav returns this error.
ALSA lib pcm_hw.c:1700:(_snd_pcm_hw_open) Invalid value for card
arecord: main:722: audio open error: No such file or directory
I have properly installed PortAudio version 19 stable.
I can still use my microphone for other activities like video call, ....
I am using Python 3.
Well the problem is definitely in the PyAudio part. However, some threads mention that the main culprit is miss-connection between PyAudio and PortAudio (although, I have already compiled proper PortAudio version 19 stable).
At this point my solution is to use pyalsaaudio from https://github.com/larsimmisch/pyalsaaudio. For Python 2.x you can just install it with pip install pyalsaaudio, however for Python 3.x you need to compile it from the source codes (see instruction in its GitHub page). Note to mention is that pyalsaaudio only works for Linux. With pyalsaaudio my Python application is working like usual.
This is not really intended to be an answer but it might be helpful to print a list of all the devices available to pyaudio and see if your USB soundcard is even being recognized.
(Some code from a previous project):
p = pyaudio.PyAudio()
for i in range(p.get_device_count()):#list all available audio devices
dev = p.get_device_info_by_index(i)
print((i,dev['name'],dev['maxInputChannels']))
You may also want to look into alsa and some techniques to list available devices and possibly alsamixer as well.

Python Illegal instruction on Raspberry Pi Zero

When I try to run a python script I get Illegal instruction and that's it, it doesn't give any more details so I have no idea what's going on, is there a way to find out what is causing the Illegal instruction error?
Also, I run the code using sudo I don't get any output, the program just exits.
UPDATE:
The script I'm running is the simple-agent script from bluez:
https://github.com/pauloborges/bluez/blob/master/test/simple-agent
Also, I ran line by line like #buratino said and I got the error in the second line:
from gi.repository import GObject
Like #Notlikethat said, the Illegal instruction error happens when the code being executed was compiled for a different architecture, Raspberry Pi uses ARM.
That said, I found out that GObject seemed to be causing the problem. Anyway, I uninstalled every bluetooth related package I had installed and reinstall them using the raspbian repository and now the Illegal instruction is gone and the script executes correctly.
Why did this happen? Well, I have a Raspberry Pi Zero which means I don't have an Ethernet port, before I bought a WiFi dongle I installed a few packages by downloading them on my computer and storing the .deb in the SD card, of course this means I have to manually check that I'm downloading the right version of the package, I must've messed up in one of them.
Lesson learned, never try to manually install packages, let apt-get do all the work!

How do I use python scripting to communicate with a Keysight/Agilent Network analyzer

I have downloaded the pyivi.0.08 package but experience an error when run the command import pyivi. I have also installed the NI Visa and the 488.2 package.
Is there any other package to be installed before running this command.
I am trying to communicate with a Keysight/Agilent Network analyzer through a GPIB using python scripting.
Thanks in advance.
The package pyivi.0.08 is supported on the Python package index and has a nice set of documentation here: https://pypi.python.org/pypi/pyivi/0.0.8
If the documentation doesn't get you started, please list the specific error, and mention how far you were able to work through the documentation. I'll update my answer to respond to your error message.

Python pyVISA GPIB connection issue

I'm trying to connect to a GPIB instrument using pyVISA but I get an error. I'm following the simple example on the pyVISA website: http://pyvisa.readthedocs.org/en/master/
I type the following code into the IPython console:
import visa
rm = visa.ResourceManager()
rm.list_resources()
Out[4]:
(u'USB0::0x0957::0x0D0B::MY49431510::INSTR',
u'USB0::0x0957::0x17BC::MY52400338::INSTR',
u'ASRL1::INSTR',
u'ASRL2::INSTR',
u'ASRL5::INSTR',
u'ASRL6::INSTR',
u'ASRL7::INSTR',
u'ASRL8::INSTR',
u'ASRL9::INSTR',
u'ASRL10::INSTR')
However, my GPIB instruments do not show up, just the serial ports and my USB instruments. When I launch the Agilent Connection Expert (or NI MAX) I can see all my GPIB instruments and can communicate with them. I also am able to communicate with the instruments without issue with Matlab.
So when I try and connect to the instrument with the line:
inst = rm.open_resource('GPIB0::19::INSTR')
It throws an error:
VisaIOError: VI_ERROR_INTF_NUM_NCONFIG (-1073807195): The interface type is valid but the specified interface number is not configured.
I've also tried to connect with the USB instruments that show up when I list the resources and they do not throw this error. However, when I try and do a simple query:
inst = rm.open_resource('USB0::0x0957::0x0D0B::MY49431510::INSTR')
inst.query("*IDN?")
Nothing gets returned and no errors get thrown.
I'm using Python(X,Y) 2.7.9.0 with Python version 2.7.9 32 bit
pyVISA version is 1.6.3
NI bitness is 32
Any guidance is appreciated as I'm new to Python.
Thanks
You probably need to start the resource manager with:
rm = ResourceManager('Path to library')
where Path to library is the location of the NI Vista Library.
Also try:
python -m visa info
to ensure that you have it installed with the same word length as the python version that you are running.
I was having the same issue, and did manage to fix it by setting the path address to: 'C:/Program Files/IVI Foundation/VISA/WinNT/agvisa/agbin/visa32.dll'. If you haven't found the solution, I hope it works for you as well.
I had exactly the same problem - USB resources showed up, GPIB resources didn't. I tried to open the resource exactly as you did, inst = rm.open_resource('GPIB0::22::INSTR') (with the GPIB address changed to that of one of my instruments) with exactly the same result. Some inspired random guessing led me to
inst = rm.open_resource('GPIB1::22::INSTR')
which worked perfectly! Once the instrument is open it shows up in the list of resources, as expected. I have no idea why the interface is seen as GPIB1.
I am using the Keysight/Agilent/HP IO libraries suite as my VISA library (the NI library is not installed), and an Agilent 82357B USB to GPIB interface. I did not have to do any customisation of my pyVisa installation to get this working. Which is nice.
Hope this helps!
I had the same problem (running 32-bit python 2.7 on a 64-bit win7), I got it fixed using
rm = ResourceManager('C:/Program Files (x86)/IVI Foundation/VISA/WinNT/agvisa/agbin/visa32.dll')
which is the 32-bit VISA path given in the "About Agilent IO Control" Information.
I have ni-visa and Agilent visa installed on my computer. However, pyvisa cannot access the Agilent 82357B device due to pointing to the wrong library.
I used this command to specify the right library, it worked for me. Couples of notes:
Find the right library for the device which is visa32.dll located in different installation directories depends on each visa packet.
Use forward slash for delimiting characters even it is on windows.
Specify visa packet in the command: rm = visa.ResourceManager('c:/....')
I had the same issue. The problem was that the automatically installed Windows driver was wrong and my device showed up as USB0::0x3923::0x702A::010A65AB::RAW in NI MAX.
It was solved by an update of the driver (device manager-> properties) from C:\Program Files\National Instruments\NI-488.2 (or where your driver is installed).
Now GPIB works also from python.
I observed same error report when running on a PC with visa library from Keysight. Replacing with visa dll from National Instruments solved the problem.

Categories

Resources