Raspberry Pi Arduino Serial with Python - python

I'm aware of this being the same question as in this thread. However, I tried the named solutions (yes, all of them [I think]) and it still gives the same error message.
I tried to establish a serial connection between my Raspberry and Arduino (Mega 2560). After installing the serial package (pip install serial, sudo apt-get install python-serial), my script file being called "arduino.py", the code being:
import serial
MySer = serial.Serial('/dev/ttyUSB0', 9600)
I still get the same error message (AttributeError: 'module' object has no attribute 'Serial').
Now did I do something inherently wrong? Do I have to set some permissions or... I'm a little lost here. ^^
Thanks in advance,
Tim

Thanks dda - that was the right direction.
I uninstalled serial and installed pyserial, now it works phenomenally (at least from what I gather in the few minutes between coffee and work).
Thank you so much!
Best of wishes,
Tim

Related

ModuleNotFoundError: No module named 'paho'

I am trying to make connection with my raspberry Pi and my PC windows through MQTT protocol. And I have a problem I cant solve on my PC - I can t import library that I have installed to my program:
import paho.mqtt.client as mqtt
Results in the error
ModuleNotFoundError: No module named 'paho'
The topic was already issued here (Import Error: paho.mqtt.client not found), but solution doesnt work for me.
I see it in the python folder:
C:\Users\mhucl\AppData\Local\Programs\Python\Python310\Lib\site-packages\paho\mqtt\client
I see it in the pip list. But the program can t find it. Do you know where could be the problem? I use python version 3.10.3. I tried it on different PC aswell and the same result. I followed all solutions on youtube, forums and nothing. Thank you very much.
Here are screenshots if someone would like to see:
https://uschovna.cz/zasilka/WLUWM5TNP7HP7GDG-XKP/UCKZFIZHCI
pip install paho-mqtt
https://pypi.org/project/paho-mqtt/
I solved my error by using this command

gpiozero.exc.PinPWMUnsupported: PWM is not supported on pin GPIO7 (Raspberry Pi 4B)

I am working on my first Raspberry Pi project while following a course for creating a line-following robot. This is the course. I followed all the instructions and connected the pins as it describes but when I run the code on the Raspberry Pi OS it throws an error:
gpiozero.exc.PinPWMUnsupported: PWM is not supported on pin GPIO7
This is the code:
from gpiozero import Robot
from time import sleep
my_robot = Robot(left=(7,8), right=(9,10))
my_robot.forward()
sleep(1)
my_robot.stop()
I tried to search for solutions and checked the official documentation but it hasn't been helpful. How can I fix this?
The likely reason for this error is that the user has installed gpiozero into a virtual environment without installing a pin library. gpiozero's built-in pin interface does not support PWM. You need to install RPi.GPIO to get the normal experience:
pip install gpiozero rpi-gpio
This is mentioned in the docs: https://gpiozero.readthedocs.io/en/stable/faq.html#why-do-i-get-pinfactoryfallback-warnings-when-i-import-gpiozero
I had the same problem with gpiozero's CamJamKitRobot and Robot classes when trying to run it in a pipenv (same issue may occur with a virtual env, but I have not tried). Running the script outside of the pipenv (therefore just using the system installed pip packages) resolved the issue for me.
After many checks, it resulted that the GPIO pins and the software were ok. The motors were connected to a L289N Driver Motor module, which wasn't getting enough power from the batteries and this was the cause of the error. In case someone has the same or similar hardware connections and faces this issue, check if the L289N module is powered on (it should turn on the red LED that's on the module).
I was following the guide on https://www.raspberrypi-spy.co.uk/2018/02/basic-servo-use-with-the-raspberry-pi/ with Micro Servo WS-SG90 and Raspberry Pi 3B+ and used the gpiozero Python library and ran into the same exception. In my case this was caused by running the program as non-root user. Running the program with sudo made the servo turn. The other alternative would be to use PiGPIOFactory with pigpiod which does not require to run the program with elevated privileges.

DeLorme USB GPS into Raspberry Pi using 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

Error importing from pyserial

I get a nameError when using Serial. I believe that i am not importing serial properly.
from serial import *
serialPort = Serial("COM3", 9600)
i've installed pyserial through pip. Am i doing something wrong? Has anyone else experienced this error?
You called your file serial.py, which will shadow the installed serial module.
Rename your file to something else, then it should work.

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!

Categories

Resources