Raspberry Pi OS Update Breaks Sphero RVR SDK

So, I downloaded the disk image yesterday for the Sphero SDK version of Raspberry Pi OS and it worked fine, letting me drive the car, use set_all_leds.py, etc on my Raspberry Pi 3B+. However, after I updated the operating system by typing sudo apt-get update and sudo apt-get upgrade, the Sphero Python scripts no longer work. However, there is no error message.

If I run set_all_leds.py, it will say “Checking RVR Firmware” and then return to command prompt without turning the lights red. The only difference from when it worked is that I ran the latest OS updates.

1 Like

try to run the .py scripts with $ sudo

1 Like

I did. No improvement.

1 Like

Hi @geekinchief,

I’m sorry to hear that you’ve run into problems with our SDK. Although we did put a lot of work into our recent SDK update, you’ve pointed out two holes in our process:

  1. I don’t think I updated anything on my Pi other than the Sphero SDK after initial setup, so it’s certainly possible that something broke and you’re the first to report it.
  2. The Raspbian image linked from https://sdk.sphero.com/docs/getting_started/raspberry_pi/raspberry_pi_setup/ was left out of the release process, so it still contains the original v1.0.0 SDK release. This image should really be brought up to date, and I’ve added it to our backlog.

In the meantime, I’d like to figure out what’s going wrong for you. Here’s an initial debugging list:

  1. Update your SDK. There was a bug in the v1.0.0 SDK release that was just fixed a couple weeks ago, and sometimes caused SDK scripts to hang at the firmware update check. You can update by navigating to the top level SDK directory (for me, this is ~/sphero-sdk-raspberrypi-python), and running git pull
    After updating the SDK, you’ll also want to update your RVR’s firmware (details here) to make sure you have firmware that supports all the new features in the latest SDK.
  2. Check your GND wiring. Make sure you have GND connected between the RVR and the Pi. If you’re powering the Pi from RVR’s USB port, it will have a GND via the USB cable. Otherwise, you’ll need a wire from GND on the RVR expansion port to one of the GND pins on the Pi I/O header.
  3. Check your UART wiring. Make sure that RX on the Pi is connected to TX on RVR, and vice versa. If you’re unsure, just swap the wires and try it - you won’t hurt anything if it’s backwards.
  4. Go through the RVR Raspberry Pi setup instructions again to make sure you have your Python virtual environment set up with the correct Python version and your Pi settings are correct for the serial port (enabled) and serial console (disabled).

If none of that works, let me know and we can enable verbose logging to dig deeper.

Thanks,
Jim

1 Like

So I updated the firmware and now nothing works. I cannot update the SDK because when I type “git pull” it gives me a “could not read from remote repository” error.

Edit: I got this to work by deleting the sphero-sdk folder and doing a new git clone. I still haven’t updated the OS completely. will try that now.

1 Like

So I updating the OS broke the SDK again in the sense that it doesn’t give any error messages but still fails to actually perform any of the commands. Have you guys tested this with all the latest Raspberry Pi OS updates installed?

1 Like

Have you considered flashing the native Raspbian disk image on a new MMC and then installing the latest SDK via a new git pull?

John Vaccaro

Good Fast Cheap, Pick Any Two…

1 Like

Hi @geekinchief,

Sorry it took me a while to get back to this thread, community forum support is a side project that I try to keep up with around my main engineering tasks. I tried to reproduce your issue but my setup works fine. Here are the steps I followed on my Pi 3B+:

  1. I downloaded the RVR Raspbian image linked from https://sdk.sphero.com/docs/getting_started/raspberry_pi/raspberry_pi_setup/#connecting-your-raspberry-pi-to-your-rvr and flashed it on a 16 GB micro SD card.
  2. I connected a keyboard, mouse, and monitor and booted the Pi, skipping the initial setup GUI prompts.
  3. Ran sudo raspi-config --expand-rootfs
  4. Ran sudo reboot
  5. Ran:
    sudo apt update
    sudo apt dist-upgrade
    sudo apt clean
    sudo reboot
  6. I deleted the existing SDK working copy at ~/sphero-sdk-raspberrypi-python-sdk by running rm -r ~/sphero-sdk-raspberrypi-python-sdk to avoid the problem you ran into with not being able to pull the SDK update without setting up SSH access.
  7. I cloned the SDK (from ~/) with git clone https://github.com/sphero-inc/sphero-sdk-raspberrypi-python.git
  8. I navigated into the SDK: cd sphero-sdk-raspberrypi-python-sdk
  9. I started my python virtual environment: pipenv shell
  10. I then ran python getting_started/asyncio/api_and_shell/echo.py successfully. I also tested python getting_started_asyncio/driving/drive_tank_si.py.

I’m not sure what’s different between your setup and mine, but applying updates on the Pi didn’t seem to hurt anything. Can you try following the steps above exactly?

Jim

1 Like

I have followed your process above and all your tests worked just fine.
But…
When I reran one of my programs that worked correctly under the old SDK I get this:
(sphero-sdk-raspberrypi-python) pi@raspberrypi:~/sphero-sdk-raspberrypi-python $ python my_projects/getbatterystate.py
Traceback (most recent call last):
File “my_projects/getbatterystate.py”, line 6, in
from sphero_sdk import SpheroRvrObserver
ModuleNotFoundError: No module named ‘sphero_sdk’

So the module is no longer found using the declaration:
from sphero_sdk import SpheroRvrObserver

I see sphero_sdk directory, so I assume something is missing configuration-wise after I deleted the old SDK.

How do I fix this?

John Vaccaro

1 Like

Hi @jvaccaro, I’m surprised by that result. Is your script in a different location from before, relative to the sphero_sdk directory?

The first thing that comes to mind is that you may have a missing or incorrect path for the interpreter to search for it. In all of our example projects and getting_started scripts, there is a path addition where we give a relative path to the root of the SDK working copy. For example, here is the line from rc_async_rvr.py

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))

If you have this in your script but the script location changed, then the SDK root directory might not be in your path.

Jim

1 Like

Thanks Jim;

My script is indeed in a different folder, but on the same level as the projects folder and aptly named myprojects.

I’m running the scripts from the same directory as before the upgrade, ie the parent folder to projects.

I’ll copy it back to projects and see if that makes a difference

Here’s a good thing to check:

import sys
for i in sys.path:
    print(i)

This will allow you to see whether the parent of sphero_sdk is showing up in your path. Snippet found in this article on packages vs modules.

Jim

1 Like

Jim;

Ran the snippet in the interpreter shell and got:
/home/pi/.local/share/virtualenvs/sphero-sdk-raspberrypi-python-M5SuJw2V/lib/python37.zip
/home/pi/.local/share/virtualenvs/sphero-sdk-raspberrypi-python-M5SuJw2V/lib/python3.7
/home/pi/.local/share/virtualenvs/sphero-sdk-raspberrypi-python-M5SuJw2V/lib/python3.7/lib-dynload
/usr/lib/python3.7
/home/pi/.local/share/virtualenvs/sphero-sdk-raspberrypi-python-M5SuJw2V/lib/python3.7/site-packages

Located sphero_sdk:

pi@raspberrypi:~ $ sudo find / -name sphero_sdk
/home/pi/sphero-sdk-raspberrypi-python/sphero_sdk

So I added a print statement to my code and adjusted the sys.path.append statement until it yielded /home/pi/sphero-sdk-raspberrypi-python

The sys.path.append statement now looks like this:

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(file), ‘…/’)))

When I ran my code from /home/pi/sphero-sdk-raspberrypi-python I got this:

(pi) pi@raspberrypi:~/sphero-sdk-raspberrypi-python $ python my_projects/getbatterystate0.py
/home/pi/sphero-sdk-raspberrypi-python
Traceback (most recent call last):
File “my_projects/getbatterystate0.py”, line 8, in
from sphero_sdk import SpheroRvrObserver
File “/home/pi/sphero-sdk-raspberrypi-python/sphero_sdk/init.py”, line 5, in
from sphero_sdk.common.enums.colors_enums import Colors
File “/home/pi/sphero-sdk-raspberrypi-python/sphero_sdk/common/enums/colors_enums.py”, line 1, in
from enum import Enum
ImportError: No module named enum

Any idea why it can’t find enum?

1 Like

So I have standardized on running any python script from the directory its located in, but I now realize this may break the path statement. I ran the supplied echo.py script from its home directory and got the same error. A cursory search of the sdk directory tree shows lots of occurrences of enums but not enum.

What is the best practice for running an arbitrary python script so that the libraries are in the PYTHONPATH?

Interestingly, the sample code works fine from the /home/pi/sphero-sdk-raspberrypi-python if I run it without invoking the pipenv shell command first.

I am considering reverting to the old raspbian-sphero boot image so I can keep coding

1 Like

I’m not a python expert by any means, so I can’t really advise about best practices there. In our example scripts, the path addition is relative to the location of the script itself, so you should be able to run from any directory and it will still work.

I don’t know what would be going wrong with enum. It seems like your pipenv virtual environment got messed up somehow. If you can run without it, that’s fine - the idea of using a virtual environment was to keep things isolated from any dependency updates that may break things in the future. I know some other users have found it more convenient to skip the virtual environment.

Jim

1 Like

I installed Rasbian Buster Lite some time ago, then just cloned the Sphero SDK repo inside a directory

Today I updated Raspbian and most of the example still work, and still with sudo

sudo python3 getting_started/observer/api_and_shell/echo.py

1 Like
SPHERO Email Marketing -