AndreaFavero71 / CUBOTino_micro

The World's smallest Rubik's cube solver robot: Repository for the relevant files (3D printing, code, instructions, etc)
Creative Commons Attribution 4.0 International
7 stars 1 forks source link

print(f' SyntaxError python Cubotino_m_servos.py --set 0 #1

Closed mugginsjm closed 1 year ago

mugginsjm commented 1 year ago

pi@rubicPI:~ $ cd /home/pi/cubotino_micro/src pi@rubicPI:~/cubotino_micro/src $ source .virtualenvs/bin/activate (.virtualenvs) pi@rubicPI:~/cubotino_micro/src $ python Cubotino_m_servos.py --set 0 File "Cubotino_m_servos.py", line 876 print(f'servo_angle out of range at string pos:{i}') # info are printed ^ SyntaxError: invalid syntax (.virtualenvs) pi@rubicPI:~/cubotino_micro/src $

AndreaFavero71 commented 1 year ago

This suggests the virtualenvs has a python2 interpreter instead of a python3 (forced as python). I think something went wrong during the installation. if you type python3 it will work: (.virtualenvs) pi@rubicPI:~/cubotino_micro/src $ python3 Cubotino_m_servos.py --set 0 This is a workarround, not the solution. You might want to repeat the installation, perhaps on a second microSD if you'd like to keep going with the robot...

mugginsjm commented 1 year ago

Strange because I downloaded the most recent RPI legacy file. Anyway thanks, I'll start again. I've printed all the parts and have now got most of the hardware. Exciting !!

AndreaFavero71 commented 1 year ago

I'm not sufficiently expert to suggest a correction. Once activated the virtualenv, type python to check which version is loaded

(.virtualenvs) pi@cubotino:~/cubotino_micro/src $ python
Python 3.7.3 (default, Oct 31 2022, 14:04:00) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

it should be a 3.7.

mugginsjm commented 1 year ago

yes just as you said.. but don't know why. pi@rubicPI:~ $ cd /home/pi/cubotino_micro/src pi@rubicPI:~/cubotino_micro/src $ source .virtualenvs/bin/activate (.virtualenvs) pi@rubicPI:~/cubotino_micro/src $ python Python 2.7.16 (default, Oct 10 2019, 22:02:15) [GCC 8.3.0] on linux2 Type "help", "copyright", "credits" or "license" for more information.

AndreaFavero71 commented 1 year ago

I'm afraid I don't know either. Last saturday I have repeated the full process from scratch, to test a little change on the setup.sh file, and it went smooth. At the setup end, before entering "Y" to reboot, you might want to select the complete printout and save it to a text file for a later check; To do this, one single click at the start and keep hoovering with mouse til the end. Once all text is selected DO NOT RIGHT CLICK, just open a text file and paste (the highlighted text is already memorized) As reference you could compare the printout at https://github.com/AndreaFavero71/CUBOTino_micro/blob/main/doc/Installation_printout.pdf

AndreaFavero71 commented 1 year ago

BTW, you might kep the current installation as is, and use python3 instead of python. On a later moment, or on a second microSD card, you might try for a clean installation. If you'll proceed in this way:

  1. edit the Cubotino_m_bash.sh file and add the suffix "3" to python.
  2. in case of an update, the Cubotino_m_bash.sh will be overwrite
  3. recall to take a note of your settings, before repeating the setup
mugginsjm commented 1 year ago

Using RPI installer and loading RPI (legacy) and before loading any of your firmware I get pi@rubicPI:~ $ python Python 2.7.16 (default, Oct 10 2019, 22:02:15) [GCC 8.3.0] on linux2 Type "help", "copyright", "credits" or "license" for more information.

Is it because my Zero is quite old V1.1 ?

AndreaFavero71 commented 1 year ago

From the same shell type python3 to check the python3 version.

The OS is delivered with both python2 and python3; if you don't specify python3 then python2 interpreter is loaded when you type python. Things change when you make a virtual environment by specifying the intention to use python3; In that case python3 will be loaded when you type python.

mugginsjm commented 1 year ago

pi@rubicPI:~ $ python3 Python 3.7.3 (default, Oct 31 2022, 14:04:00) [GCC 8.3.0] on linux

OK I can proceed now.

mugginsjm commented 1 year ago

I get (.virtualenvs) pi@rubicPI:~/cubotino_micro/src $ python3 Cubotino_m_servos.py --set 0 Traceback (most recent call last): File "Cubotino_m_servos.py", line 34, in from Cubotino_m_display import display as s_disp File "/home/pi/cubotino_micro/src/Cubotino_m_display.py", line 17, in import ST7789 # library for the TFT display with ST7789 driver ModuleNotFoundError: No module named 'ST7789' (.virtualenvs) pi@rubicPI:~/cubotino_micro/src $

AndreaFavero71 commented 1 year ago

if you 'pip3 list' you'll get the installed libraries list, ordered by names, and based on above error the ST7789 is not installed. It's still failing during the installation.....Have you checked if errors/warnings during the installation? Also saved the printout? In case you can send it to andreaDOTfavero71ATgmailDOT com

This should be how it looks like the installation of that library:

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting st7789==0.0.4
  Downloading https://files.pythonhosted.org/packages/39/b5/99dd0f9b8bbee0c42f94388216da30502718a971fbfa2c26987020f5fa18/ST7789-0.0.4-py3-none-any.whl
Installing collected packages: st7789
Successfully installed st7789-0.0.4

you can install it manually, on the activated venv: pip3 install st7789==0.0.4

I have the feeling that if that library didn't initially install, probably also other didn't. Below the list of libraries to install manually, one command at the time: pip3 install numpy==1.21.4 pip3 install "picamera[array]" pip3 install st7789==0.0.4 pip3 install RubikTwoPhase==1.1.1 pip3 install getmac==0.8.3 pip3 install https://www.piwheels.org/simple/opencv-contrib-python/opencv_contrib_python-4.1.0.25-cp37-cp37m-linux_armv6l.whl

I don't know where the problem lies. I assume you're following the chapter 12 of the instructions. In case you have a second microSD, I'll consider to give it a try.....

mugginsjm commented 1 year ago

I did a fresh install and then did a git clone then "edit the Cubotino_m_bash.sh file and add the suffix "3" to python." then sudo ./install/setup.sh

Now I have python 3 and no errors in running "python Cubotino_m_servos.py --set 0" except for the fact that the servos do not move. I'll investigate further. I'll send you the install results anyway. thanks for your patience. Great project and very well documented.

AndreaFavero71 commented 1 year ago

if servos were delivered to their mid position then it is correct if don't rotate. try differen targets, i.e. -1 or 1: python Cubotino_m_servos.py --set 1

AndreaFavero71 commented 1 year ago

btw, if 'python Cubotino_m_servos.py --set 0' do not return errors (by using python and not python3), then you can remove the suffix 3 from the bash file

mugginsjm commented 1 year ago

OK