Python Forum
Data transfer from Arduino to Pyhton
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Data transfer from Arduino to Pyhton
#1
Hi

I am having trouble with getting this code to work. I am working on a project where I want to transfer data from Arduino through a com terminal and having Python grabbing it. The problem is that the serial module does not seem to work. I have installed serial using "pip install serial" and it said that it installed sucessfully, but I am not so sure. Lastly, I do not have anything plugged into the com port or Arduino IDE running. To me this should not matter, but I am a noob :/

By the way, I am watching a youtube video by Paul McWorther, Using an Arduino with Pyhton LESSON 3: Passing Data From Arduino to Pyhton

This is the code so far:
import vpython
import time
import serial

arduinoData = serial.Serial('COM6',9600)

time.sleep(1)

while True: 
    while(arduinoData.inWaiting()==0):
        pass
    dataPacket = arduinoData.readline()
    print(dataPacket)
This is the console message I get back:
Error:
Users/user/Programmering/vPython') Traceback (most recent call last): File C:\ProgramData\Anaconda3\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec exec(code, globals, locals) File c:\users\user\programmering\vpython\vpython_test.py:13 arduinoData = serial.Serial('COM6',9600) AttributeError: module 'serial' has no attribute 'Serial'
deanhystad write Jan-29-2025, 08:43 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
(Jan-29-2025, 06:52 PM)code_noob Wrote: I have installed serial using "pip install serial"

That's the problem. The "serial" package is not for serial/UART communications, but for serializing some data structures.

The previous video (LESSON 2) showed the installation of the libraries and there he does "pip install pyserial". This is the package you want.
Gribouillis likes this post
Reply
#3
You have installed this: https://pypi.org/project/serial/
But you need this: https://pypi.org/project/pyserial/

pip uninstall serial
pip install pyserial
Another source for error could be a file next to your program called serial.py. The path of your program is the first place, where Python tries to import modules. If there is a serial.py next to your program, you import this instead of pyserial.

Another source of errors: Names of packages you can install via pip, could differ of the package/module name you've to import. You install pyserial, but you've to import serial. You've installed serial and imported serial.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Vlookup function in Pyhton antozas 1 1,345 Oct-02-2023, 04:16 AM
Last Post: vikraman
  Trying to Get Arduino sensor data over to excel using Python. eh5713 1 3,373 Dec-01-2022, 01:52 PM
Last Post: deanhystad
  Setup host for consistent data transfer to client via TCP Gustav97 0 1,367 Jun-27-2022, 07:33 PM
Last Post: Gustav97
Information Estimating transfer function from frd data ymohammadi 0 2,100 Feb-10-2022, 10:00 AM
Last Post: ymohammadi
  Reading Multiple text Files in pyhton Fatim 1 2,677 Jun-25-2021, 01:37 PM
Last Post: deanhystad
  Password protected xls data transfer to master OTH 1 4,337 Feb-15-2021, 08:28 PM
Last Post: OTH
  Save Arduino data in mysql server via raspberrypi rithikvg 1 4,135 Jun-24-2020, 10:59 PM
Last Post: Larz60+
  Pyhton code help from head first with python Shaikat_99 3 4,289 Jun-07-2020, 09:12 AM
Last Post: snippsat
  start interactive pyhton shell with pre-loaded custom modules Viktor 2 2,896 Apr-09-2020, 08:25 AM
Last Post: Viktor
  Help Graphing Arduino Data Real Time in Python nschulz 0 3,352 Mar-12-2020, 06:15 PM
Last Post: nschulz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020