ankitaggarwal011 / PiScope

Turn your Raspberry Pi into an Oscilloscope/XY Plotter with Python
http://blog.ankitaggarwal.me/PiScope/
MIT License
182 stars 20 forks source link

IOError: [Errno 2] No such file or directory [Raspberry Pi 2] #3

Closed audioninja closed 8 years ago

audioninja commented 8 years ago

Hello I'm a newbie to the Pi and Python I'm getting this error with my new Raspberry Pi 2 but this code worked flawlessly with my old Raspberry Pi Model B. Any Suggestions on what might be causing this error? Thanks

root@raspberrypi:/home/pi/PiScope# python example_oscilloscope.py Initializing the PiScope... Setting up the channels... Plotting will start in a new window... Reading channels... Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1437, in call return self.func(_args) File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 498, in callit func(_args) File "/home/pi/PiScope/PiScope.py", line 122, in draw self.read() #read current values File "/home/pi/PiScope/PiScope.py", line 111, in read adc = ADS1x15() File "/home/pi/PiScope/Adafruit_ADS1x15.py", line 142, in init self.i2c = Adafruit_I2C(address) File "/home/pi/PiScope/Adafruit_I2C.py", line 40, in init busnum if busnum >= 0 else Adafruit_I2C.getPiI2CBusNumber()) IOError: [Errno 2] No such file or directory Quitting program.

ankitaggarwal011 commented 8 years ago

Hi, @audioninja , try and check if your device is connected using this command:

sudo i2cdetect -y 1

I think this issue is related to the recent Raspberry Pi update. Are you running a recent Raspberry Pi (3.18 kernel or higher)? You can check that by typing uname -a in the terminal.

If yes, you will also need to update the /boot/config.txt file. Edit it with sudo nano /boot/config.txt and add this text at the bottom:

dtparam=i2c1=on
dtparam=i2c_arm=on

Reboot the Pi after this is done.

sudo reboot

You can read more about the configuration over here.

Let me know if this works.

audioninja commented 8 years ago

Hi Ankitaggarwal011,

thanks for the fast response! I do have the dtparam=i2c1=on, dtparam=i2c_arm=on edits at the end of my /boot/config.txt file. And the Pi is seeing my ADC and DAC as I get this when I run sudo i2cdetect -y 1.

root@raspberrypi:/home/pi# sudo i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- 62 -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
root@raspberrypi:/home/pi#

And here is my kernel Linux raspberrypi 4.1.7-v7+ #817 SMP PREEMPT Sat Sep 19 15:32:00 BST 2015 armv7l GNU/Linux

Thanks again for the help! Any ideas? Could this be a symbolic link thing? I did notice when I try and run your python Adafruit_I2C.py I get, Error accessing default I2C bus. When I run the same command within Adafruit-Raspberry-Pi-Python-Code it gives me, Default I2C bus is accessible. I tried moving their code into your PiScope folder but it didn't work.

Thanks!

ankitaggarwal011 commented 8 years ago

Hi @audioninja

Replace the Adafruit_I2C.py in the PiScope folder with this file: Adafruit_I2C.py.

Now, run the example program again. Could you please try this out and see if it works. Please let me know.

I am using the older version of this file, and I see a number of relevant changes in the file for newer Raspberry Pi models, so most probably this might be the issue. Good work, @audioninja. In case this turns out to be the problem, can you open a pull request here with this change on a separate branch. Thanks.

audioninja commented 8 years ago

That worked!!! I must have not copied the right updated Adafruit_I2C.py code when I tried it before. So I'm confirming that this Adafruit_I2C.py is the right code that made it work on my Raspberry Pi 2! Unless you did some custom Python magic to it? Either way, it works great now! So much faster on the Raspberry Pi 2. Thanks again. I'll open up a pull request now.

ankitaggarwal011 commented 8 years ago

Thanks @audioninja. Could you please try the new code with the old Raspberry Pi as well. Thanks. Closed via #4.

audioninja commented 8 years ago

Hello Ankitaggarwal011,

Sorry for the delay. The updates to this code do not appear to be compatible with the old Raspberry Pi models. I ran cat /proc/cpuinfo and this is the model I have for people out there that might run into the same issue.

processor          :0
model name         :ARMv6-compatible processor rev 7 (v6l)
BogoMIPS           :2.00
Features           :half thumb fastmult vfp edsp java tls 
CPU implementer    :0x41
CPU architecture   :7
CPU variant        :0x0
CPU part           :0xb76
CPU revision       :7
Hardware           :BCM2708
Revision           :000d
Serial             :000000003562e4

Let me know if you have any ideas. I'll tinker around with this as well to see if there might be a way to successfully run this code on both old and new Pi's.

audioninja commented 8 years ago

Here is the error that I get with my old Raspberry Pi Model B Revision 2.0.

root@raspberrypi:/home/pi/PiScope# python example_oscilloscope.py
Traceback (most recent call last):
  File "example_oscilloscope.py", line 1, in <module>
    from PiScope import Plotter
  File "/home/pi/PiScope/PiScope.py", line 27, in <module>
    from Adafruit_ADS1x15 import ADS1x15
  File "/home/pi/PiScope/Adafruit_ADS1x15.py", line 187
    print "ADS1x15: Invalid pga specified: %d, using 6144mV" % sps
    ^
IndentationError: expected an indented block
ankitaggarwal011 commented 8 years ago

Hi @audioninja, Thanks for trying this out. It's very helpful. This appears to be a Python syntax error which occurred during importing from the original file ADS1x15.py.

I have reindented this file and it's suitable for use now. Would you please download the new code once again and test it with both the RPIs. Thanks a lot.