robot navigation
 
Notifications
Clear all

robot navigation

46 Posts
5 Users
3 Likes
4,801 Views
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
Topic starter  

@byron 

Uninstalled Python and then installed a different version of Python.
Tried the pc to arduino example and I was able to connect and turn the LED on/off from a python program. Success I thought.
However was unable to install python-opencv !!
Uninstalled Python again and reinstalled another version.
This time I installed python-opencv successfully and tried your program and it worked!!

cvImageOutput

However when I tried the program to connect to the arduino it no longer worked.
AttributeError: module 'serial' has no attribute 'Serial'
A search on the internet is yet to come up with an explanation that fixes my problem.
Spent some hours on all this so will give it a rest.

 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@robotbuilder 

Posted by: @robotbuilder

AttributeError: module 'serial' has no attribute 'Serial'
A search on the internet is yet to come up with an explanation that fixes my problem.
Spent some hours on all this so will give it a rest.

Maybe a silly question... but a lot of times there is an incompatibility due to case amongst systems. Did you check the header file for case?


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1121
 

@robotbuilder

In a previous post you may not have noticed it included a hyperlink to where it is discussed that pyserial and serial are two different modules that both use the namespace of serial.  

A suggested fix :

  • Run pip3 uninstall serial 
  • Then install pyserial if not already installed by running pip3 install pyserial 

Its a bit confusing.

When in a python REPL you can do

>>> help('modules')

which will list all the modules in your python distribution.  In my case I see a module called 'serial' but whether this is because it was installed via pyserial or serial I dont know.

if you then import the serial module

>>> import serial

and then do a dir on serial

>>> dir(serial)

you will get a list of all the calls you can make with serial.

In my case the list is as follows:

['CR', 'EIGHTBITS', 'FIVEBITS', 'LF', 'PARITY_EVEN', 'PARITY_MARK', 'PARITY_NAMES', 'PARITY_NONE', 'PARITY_ODD', 'PARITY_SPACE', 'PortNotOpenError', 'PosixPollSerial', 'SEVENBITS', 'SIXBITS', 'STOPBITS_ONE', 'STOPBITS_ONE_POINT_FIVE', 'STOPBITS_TWO', 'Serial', 'SerialBase', 'SerialException', 'SerialTimeoutException', 'Timeout', 'VERSION', 'VTIMESerial', 'XOFF', 'XON', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'absolute_import', 'basestring', 'importlib', 'io', 'iterbytes', 'os', 'protocol_handler_packages', 'serial_for_url', 'serialposix', 'serialutil', 'sys', 'threaded', 'time', 'to_bytes', 'tools', 'unicode', 'urlhandler']

And as you can see somewhere in that list 'Serial' is shown.

Meaning that serial.Serial() is valid for my serial module.

I think it would be worth a go with unistalling serial and installing pyserial as that appears to have got rid of the problem for some folk.

Its odd that for you it was working until you installed python-opencv, rather indicating that action must have dragged in the 'serial' module as a dependancy.  Its certainly an unnecessary PIA I must say.

 

 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@byron, @robotbuilder

Posted by: @byron

@robotbuilder

In a previous post you may not have noticed it included a hyperlink to where it is discussed that pyserial and serial are two different modules that both use the namespace of serial.  

A suggested fix :

  • Run pip3 uninstall serial 
  • Then install pyserial if not already installed by running pip3 install pyserial 

Its a bit confusing.

When in a python REPL you can do

>>> help('modules')

which will list all the modules in your python distribution.  In my case I see a module called 'serial' but whether this is because it was installed via pyserial or serial I dont know.

if you then import the serial module

>>> import serial

and then do a dir on serial

>>> dir(serial)

you will get a list of all the calls you can make with serial.

In my case the list is as follows:

['CR', 'EIGHTBITS', 'FIVEBITS', 'LF', 'PARITY_EVEN', 'PARITY_MARK', 'PARITY_NAMES', 'PARITY_NONE', 'PARITY_ODD', 'PARITY_SPACE', 'PortNotOpenError', 'PosixPollSerial', 'SEVENBITS', 'SIXBITS', 'STOPBITS_ONE', 'STOPBITS_ONE_POINT_FIVE', 'STOPBITS_TWO', 'Serial', 'SerialBase', 'SerialException', 'SerialTimeoutException', 'Timeout', 'VERSION', 'VTIMESerial', 'XOFF', 'XON', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'absolute_import', 'basestring', 'importlib', 'io', 'iterbytes', 'os', 'protocol_handler_packages', 'serial_for_url', 'serialposix', 'serialutil', 'sys', 'threaded', 'time', 'to_bytes', 'tools', 'unicode', 'urlhandler']

And as you can see somewhere in that list 'Serial' is shown.

Meaning that serial.Serial() is valid for my serial module.

I think it would be worth a go with unistalling serial and installing pyserial as that appears to have got rid of the problem for some folk.

Its odd that for you it was working until you installed python-opencv, rather indicating that action must have dragged in the 'serial' module as a dependancy.  Its certainly an unnecessary PIA I must say.

Python is a great language, as are many others, and I like it a lot, as I do many others I work with.

...but this is the problem with languages such as python and others... they don't make it trivially easy to transition/transpose ones code easily to another target language, especially on different platforms, so a lot of people feel intimidated in learning something new.

I'm sure this will improve over time in future, but at this point in time it is still a great point of contention that requires some study and experimentation... saying that however, there are new languages been written every day, trying to take the place of true and time tested ones... but what really matters in my mind the most is in understanding programming fundamentals, for example; data structures and programming constructs - Without these fundamentals, it would be pretty difficult to build anything of technical significance.

I guess what I am trying to say is, that there is no shortcuts to learning something properly... all good things take time and commitment, and if you want to get there, then that's what it takes.

Cheers.


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1121
 

@robotbuilder

Another thought crossed my mind, something of which I expect you are fully aware, but it catches us all from time to time, and that is never name your python program the same as a module name.  So if you happened to call your nice serial comms program serial.py then you can expect trouble. 🙂 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@robotbuilder

Posted by: @byron

@robotbuilder

Another thought crossed my mind, something of which I expect you are fully aware, but it catches us all from time to time, and that is never name your python program the same as a module name.  So if you happened to call your nice serial comms program serial.py then you can expect trouble. 🙂 

Another reason why python is so ignored and feared by many... you have to do a lot of work to make it play.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
Topic starter  

There is no file to name in direct mode using IDLE so a serial label can't be it, also the name I used was comArduino.py.

It occurred to me some conflict between installing OpenCV and the serial stuff. I read that Python was a bit flaky on these things. Anyway at this stage I need a break from it all. When in the mood again I will again load up a version of Python and give it another try. I have also had trouble with the internet examples of interfacing Processing with the Arduino. Maybe I should just stick to FreeBASIC as it works fine 🙂

@frogandtoad
How do you find the header file for case? I don't remember a header file.

@byron
I did mess about with installing and uninstalling serial and pyserial in different combinations.
Thanks for all the other stuff help('modules') dir(serial) and so on will give that a go when I reinstall Python again. I also tried Processing but that example failed as well. They "updated" to Processing4 warning it may not work with code written for the previous incarnations. Reminds me of Window10 always updating and messing everything up. It is also intimidating saying lets now do xyz and I am thinking lets not I am happy with the way it is.

I noticed you used pip3 whereas all I have is pip is there any difference relevant to the issue?

What does pip3 do that pip can't?


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1121
 
Posted by: @robotbuilder

What does pip3 do that pip can't?

It depends if you have a version 2.x of python on you computer.  The likes of the mac comes with python 2 pre installed and when I started out in the mac world there were warnings of not to remove it as some os routines may still use it. I don't know if this still applies (probably not)  Anyway pip installed stuff to python 2.x and pip3 to python 3.x  However if you just have python 3 installed then I think just pip will do.  On Raspberry Pi's which come with python 2 and 3 installed I always set an alias so that pip always = pip3 and I don't get confused.

I did have another quick look and this serial malarky and its definitely pyserial that you want, and it will install as a module called serial.  Just in case you want to get dangerous then here is a link to the pyserial docs

https://pythonhosted.org/pyserial/pyserial_api.html#module-serial.aio

It seems that a 'serial' package as was has now been renamed, but its still in some repositories for installing with pip or pip3 in case yet other packages made use of it and would break if removed. A bit of a doggies dinner.

But before you go to the trouble of a complete python re-install, it would be worth trying to uninstall both pyserial and serial before re-installing just pyserial. 

 


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1121
 
Posted by: @robotbuilder

How do you find the header file for case? I don't remember a header file.

There are no header files in python.


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1121
 
Posted by: @robotbuilder

There is no file to name in direct mode using IDLE

If typing commands into a REPL then you do not need to save anything, but when running a program from an IDE, including the IDLE, then I think you will find the program text is always saved before the program will run which requires a filename.   If it has been saved in the passed then it will just re-save with the same filename.  But in any case you did not call your program 'serial.py' so this would not affect your serial woes. 


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
Topic starter  

@byron

@frogandtoad

Reinstalled Python 3.10 64 bit windows 10.

After much install uninstall of serial and pyserial the problem seems to have resolved itself.
I did find and remove some trash left over from something called pyCharm which I have a vague memory of downloading and not having much success with but I am not sure that was an issue although it did have a serial something html file.

It now all works! Byron's example works. Webcam capture works. Connection to Arduino works.

Now for some Python/OpenCV/Arduino projects 🙂

 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@robotbuilder 

Posted by: @robotbuilder

Reinstalled Python 3.10 64 bit windows 10.

After much install uninstall of serial and pyserial the problem seems to have resolved itself.
I did find and remove some trash left over from something called pyCharm which I have a vague memory of downloading and not having much success with but I am not sure that was an issue although it did have a serial something html file.

It now all works! Byron's example works. Webcam capture works. Connection to Arduino works.

Now for some Python/OpenCV/Arduino projects 🙂

Glad you got it working.

Just an FYI: - In future, you may also try to download a portable version of python (if available at the time)... that's what I currently do and it works fine - You only need to set an environment variable to point to python (any version you wish to use),and you're done. This saves messing up your operating system, leaving orphaned and conflicting files all over the place.

Cheers.


   
ReplyQuote
THRandell
(@thrandell)
Brain Donor
Joined: 3 years ago
Posts: 224
 
Posted by: @robotbuilder

I am using a Mega and an L298 to control the motors. 

I was meaning to ask you, how did you figure out how to connect your re-purposed vacumm cleaned to the AVR and driver?

To err is human.
To really foul up, use a computer.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
Topic starter  

@thrandell 

I was meaning to ask you, how did you figure out how to connect your re-purposed vacuum cleaner to the AVR and driver?

I never used the whole robot only salvaged some parts. The first time it was from a used second hand Roomba. It was a cheap way to get hold of some motorized encoder wheels. The battery had leaked acid and ceased to work. I just stuck the motors into a box. They used hall effect encoders which I found I could connect directly to the Arduino.

testRig

 

The parts I am using now come from a cheap simple Hoover robot. Again it was the cheapest way to get parts required. I decided to retain the framework that held the motors, battery and battery case and swivel wheel. The charging circuit was separate from the main board (which I threw away), and included a plug in wall charger and the on/off switch with the socket into which to insert the output of the wall charger, as well as the two motorized encoder wheels. Unlike the Roomba it used optical based encoders hidden inside the motor case so I had to figure out which wires connected to the LED receiver and which wires connected to the IR LED transmitter and which wires connected to the power. My regret was not keeping the whole case with the bumpers as I am finding it difficult to figure out how to add bumpers to the food tray that is the robot shell.

robotBase

The cost of building your own car from parts would be horrendous. Same with robots. You cannot beat the economy of scale. So a cheap simple vacuum robot is a good source of the encoder motorized wheels and a battery and even some sensors. The equivalent parts from a hobby robot supply shop would work out many times more costly. If I come across another simple cheap vacuum robot I will keep the whole case including the bumpers.

It was just a test base for playing with AI software. I will never be able to justify the expensive robots I believe Bill is still working on.

 


   
ReplyQuote
THRandell
(@thrandell)
Brain Donor
Joined: 3 years ago
Posts: 224
 
Posted by: @robotbuilder

so I had to figure out which wires connected to the

So to figure out the connections you employed the time honored technique of 'Trial and Error'.

To err is human.
To really foul up, use a computer.


   
ReplyQuote
Page 3 / 4