0

Adafruit_BBIO problems
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit_BBIO problems

by denys on Fri Aug 10, 2018 1:44 am

Hi all.
Quite some time ago, I struggled for a couple of weeks to get a test program written and working in Python.
I have made a BBB cape that has an MCP23017- 14 inputs and 2 outputs, , A4950 motor drive, analog in, CAN and RS485.
To test this board, I use the outputs to reset and then pulse an external counter. This counter has a 16 to 1 decoder whose output is fed to the cape inputs. So only one input is on at a time.
The BBB code reads the inputs and displays the result. And indicates if there is an error.
Also, the 4 analog inputs are read and displayed.
The motor is ramped up and down in both directions.
I was really pleased with this as it was quite an effort for me to write, this is my first Python project. (to quote, "My favorite programming language is solder")
One foul day, I plugged it in wrong and blew up the BBB!
Now I have tried for a couple of months to get it going again. But the libraries have changed and I have no clue at all hoe to fix them.
I've tries on a forum elsewhere but to no avail.

Is there anyone Out There who can help me, or modify this code so it will work on the latest libs?
Most of the errors mean absolutely nothing to me.

for instance,

File "OMCB_IO_9A.py", line 8, in <module>
import Adafruit_BBIO.ADC as ADC
ImportError: No module named Adafruit_BBIO.ADC
root@beaglebone:~#

It all was working really well but I cannot figure out how to fix it.

Here is the code...

Code: Select all | TOGGLE FULL SIZE
# run as unbuffered...
# python ADC_Test
# same as version 5 but much longer loop.
# also added counter reset to eack loop so I can se the FET switching.
# try to read input and compare it to expected result.
# add error counter

import Adafruit_BBIO.ADC as ADC
ADC.setup()
import Adafruit_BBIO.PWM as PWM
import time
import smbus
from mcp23xxx import MCP23017   # mcp23017 is no longer working. Trying others..
mcp=MCP23017()

mcp.set_iodira(0x3f) # 8-13 inputs, 14 & 15 outputs
mcp.set_iodirb(0xff) # 0-7 inputs
mcp.set_gpioa(0x3f)  # 8-13 high, 14 & 15 low
mcp.set_gpiob(0xff)  # 0-7 high
mcp.set_gppua(0x3f)  # pullups 8-13
mcp.set_gppub(0xff)  # pullups 0-7

mcp.set_olata(0)      # both FETs off
mcp.set_olata(64)    # FET2 on = reset counter
time.sleep(.01)
mcp.set_olata(0)      # both FETs off

# enable PWM but with motor off.
#optionally, you can set the frequency as well as the polarity from their defaults:
PWM.start("P9_14", 0, 2000, 1)
PWM.start("P9_16", 0, 2000, 1)

error_count ==0
for j in range(1000000):  # a loop sounter
       if (j&31) == 0:       # wink the reset?
          mcp.set_olata(64)    # FET2 on = reset counter
          time.sleep(.01)
          mcp.set_olata(0)   # both FETs off.
          Expected = 0x3ffe     # expected read back of inputs.


       print('\r'),

       PA = (mcp.get_gpioa())
       PB = (mcp.get_gpiob())
       PX = PB + (PA * 256)
       if (PX == Expected):

        print("PortA="),
        print'{:06b}'.format (PA),  # print PortA inputs
        print("  PortB="),
        print'{:08b}'.format (PB),  # printb PortB inputs

        print("  Anl1="),
        print'{:4.2f}'.format (23.8*(ADC.read("AIN0"))),    #print Analog 1 input
        print("  Anl2="),
        print'{:4.2f}'.format (23.8*(ADC.read("AIN1"))),    #print Analog 2 input
        print("  Supply="),
        print'{:2.2f}'.format (35.9*(ADC.read("AIN2"))),    #print Volts
        print("V "),
        print("  Motor_I="),
        print'{:4.2f}'.format (3.125*(ADC.read("AIN3"))),    #print AUX cutrrent
       else:
          error_count = error_count + 1
          print
          print("Expected="),
          print'{:14b}'.format (Expected),
          print("  Read="),
          print'{:14b}'.format (PX),
          print(" Errors="),
          print error_count

       # ramp the AUX PWM up and down, switching the o/p FETS as indicators.
       if (j&192) == 0:
          PWM.start("P9_14",((j&63)*1.56),2000,1)  # Motor fwd, ramp up
          PWM.start("P9_16",0,2000,1)
          if (j&192) == 64:        # FET1 on
             PWM.start("P9_14",((63-(j&63))*1.56),2000,1) #Motor fwd, ramp down
             PWM.start("P9_16",0,2000,1)
          if (j&192) == 128:   # FET2 on
             PWM.start("P9_14",0,2000,1)   # Motor rev, ramp up
             PWM.start("P9_16",((j&63)*1.56),2000,1)
          if (j&192) == 192:
             PWM.start("P9_14",0,2000,1)   # Motor rewv, ramp down.
             PWM.start("P9_16",((63-(j&63))*1.56),2000,1)

          if (j&1) == 1:         # inc input sounter every 2 loops
             mcp.set_olata(128)    # FET1 on = pulse the counter
             time.sleep(.01)
             mcp.set_olata(0)   # both FETs off
             Expected = (((Expected * 2) +1)& 0x3fff)
          time.sleep(.1)
   PWM.stop("P9_14")   # PWM off.
   PWM.stop("P9_16")




Any help with rewriting this to make it work as Before Smoke will be great!
OMCB-BTM.jpg
OMCB-BTM.jpg (84.46 KiB) Viewed 283 times

OMCB-BTM.jpg
OMCB-BTM.jpg (84.46 KiB) Viewed 283 times
Attachments
OMCB-TOP.jpg
OMCB-TOP.jpg (92.51 KiB) Viewed 278 times

denys
 
Posts: 49
Joined: Fri Aug 10, 2018 1:08 am

Re: Adafruit_BBIO problems

by silver2row on Sat Aug 11, 2018 1:01 am

Hello,

I think that error means that either the Adafruit_BBIO you are using, and if indeed it got updated, was updated. Sometimes I can see my issue has to do w/ current items of interest. Here the item of interest is your hardware and making the software work w/ it.

I am not really familiar w/ your hardware but I have used other capes that are accessed via i2c or UART. I do not know which image you have on your BBB either.

Seth

P.S. If you want to try to downgrade to a previous version of Adafruit_BBIO, you are allowed. There is a chat back and forth from me and another individual here. He explained to me that erasing the library works and then adding the library back works too. I am just hinting at you downgrading the version of the Adafruit_BBIO to 1.0.3. It may work. If not, there are other knowledgeable people here that may be able to help too.

silver2row
 
Posts: 149
Joined: Sat Jan 30, 2016 3:42 pm

Re: Adafruit_BBIO problems

by denys on Sat Aug 11, 2018 4:05 am

Thank you very much for the reply.
I may be interested in downgrading I think, if it cannot be made to run on the new libs.
But if the code can be made to run on the later libs, that may be better for future stability, but I an really struggling to even understand how to drive the libs anyway. A few months of searching has not helped. Most answers assume the questioner knows how to drive things and I do not. Even the error messages do not help as I have no clue how to fix them.
Another option is I may be able to make an adapter to run my boards from an Arduino and make it work that way as I just need to test them. But as the final project is run on a BBB, it would be best to test it there if it can be done.
Python is quite new to me and, for instance, the white space having significance was a trap.
Yet another trap for me, it took me a good week to figure out the code was not outputting to the SSH terminal the status as I was not running it with the -u command for unbuffered. Quite straight forward, as long as you know the question to ask for the answer.
I would just like the code to be fixed so it will run. It is very frustrating to me as it was working so well.
Why do libs have to be changed and break stuff in the first place!

denys
 
Posts: 49
Joined: Fri Aug 10, 2018 1:08 am

Re: Adafruit_BBIO problems

by silver2row on Sat Aug 11, 2018 9:06 pm

Hello,

I am not a master in the field of programming but I have dealt w/ the Adafruit_BBIO library before and other BBB related ideas, i.e. PWM, i2c, UART, and other ideas for peripherals.

PWM is difficult to test at times. Do you have any books on this situation? Do you have any books on PWM and how to use it? I saw your software and it seems you are knowledgeable in the field of programming. At least, I was not able to copy what you have done and understood the output.

Okay. I think I can help. What did you do before things got odd and stopped working? For instance, what image are you running on your BBB: uname -a prints what and cat /etc/dogtag prints what?

I am currently running a specific image on my BBBW machine:

uname -a:
Code: Select all | TOGGLE FULL SIZE
Linux beaglebone 4.14.49-ti-r54


cat /etc/dogtag:
Code: Select all | TOGGLE FULL SIZE
BeagleBoard.org Debian Image 2018-06-17


I can set up ideas on my machine to test it out w/ you, e.g. software, I can get those error codes, and I can try to solve them.

Seth

P.S. If you need ideas relative to this idea, look to your Forum ideas on PWM, Adafruit_BBIO, and on GitHub.com at https://github.com/adafruit/adafruit-be ... -io-python.

silver2row
 
Posts: 149
Joined: Sat Jan 30, 2016 3:42 pm

Re: Adafruit_BBIO problems

by silver2row on Sat Aug 11, 2018 9:15 pm

Hello,

I am going to type up this software on my BBBW and test it. It is silly to test the software the way I do it b/c there are other avenues on testing what is happening internally when software is run.

Linux is delicate at times.

Seth

P.S. Should we be looking to set up PWM or ADC first?

silver2row
 
Posts: 149
Joined: Sat Jan 30, 2016 3:42 pm

Re: Adafruit_BBIO problems

by denys on Sat Aug 11, 2018 9:29 pm

Hi again.
Is there a guide somewhere that explains how to use the Adafruit_BBIO (or whatever it is now) so I can try to rewrite the code?
The posts I have found so far don't help me.
I need to find real example of driving the MCP23017, PWM, ADC and BBB port pins.
CAN and serial could help too, as I have not tested that at all.
There seems to be quite a lot of Raspberry Pi stuff around, but not BBB.
I think this is what I used originally...
https://learn.adafruit.com/setting-up-i ... k/overview
but I made the mistake of updating as this time it had an error, something about the ADC not being free.

Or do you have a link to the info on how to downgrade again?

denys
 
Posts: 49
Joined: Fri Aug 10, 2018 1:08 am

Re: Adafruit_BBIO problems

by silver2row on Sat Aug 11, 2018 9:33 pm

Hello,

I am so sorry for all these posts but I will need your library/module for mcp23xxx so I can set up the environment to see what is working. So far, I changed this amount of software and I am receiving cannot import module mcp23xxx basically b/c i do not have it in my possession.

Seth

P.S. Here is what I changed:

Code: Select all | TOGGLE FULL SIZE
import Adafruit_BBIO.ADC as ADC
import Adafruit_BBIO.PWM as PWM
import time
import smbus
from mcp23xxx import MCP23017   # mcp23017 is no longer working. Trying others..

mcp=MCP23017()
ADC.setup()


and...

Code: Select all | TOGGLE FULL SIZE
PWM.stop("P9_14")   # PWM off
PWM.stop("P9_16")

silver2row
 
Posts: 149
Joined: Sat Jan 30, 2016 3:42 pm

Re: Adafruit_BBIO problems

by silver2row on Sat Aug 11, 2018 9:39 pm

Okay and Hello Once More,

Code: Select all | TOGGLE FULL SIZE
sudo pip uninstall Adafruit_BBIO
 
sudo pip install Adafruit_BBIO==1.0.3


That is how to adjust your version of Adafruit_BBIO.

...

The software at the bottom where you type PWM.stop("Px.xx") needs to be at the left of the screen. That was my first error. Then, I needed python-smbus. I installed it w/ sudo apt install python-smbus.

Then, I got an import error b/c I do not have your library/module to work from or to import from.

Seth

P.S. Look here for the ideas on GitHub.com for Adafruit_BBIO: https://github.com/adafruit/adafruit-be ... -io-python. Oh and look to other info. on this forum for PWM, ADC, CAN, and etc... People have listed a bunch of info. through the ages.

silver2row
 
Posts: 149
Joined: Sat Jan 30, 2016 3:42 pm

Re: Adafruit_BBIO problems

by silver2row on Sat Aug 11, 2018 10:07 pm

Hello,

These chips are more complex than I once thought. See here: http://ww1.microchip.com/downloads/en/D ... 01952C.pdf. Is this what you are describing?

Seth

P.S. I found a bunch of info. but I would not know what you are discussing unless you state it. Please, when you can find time, let me know what image you have and what kernel you are using. Thank you.

silver2row
 
Posts: 149
Joined: Sat Jan 30, 2016 3:42 pm

Re: Adafruit_BBIO problems

by denys on Sun Aug 12, 2018 12:52 am

I really appreciate you spending the time to try to help me. It must be a bit frustrating talking to a Python dummy like me.
My field is in hardware design, and have made industrial control equipment for quite a few years. Another guy working with me put the Magic Code in to make the boards work.

The spacing of the PWM lines is from the external editor I used. The code was running ok on the BBB for a couple of months before I killed the board.

root@beaglebone:~# uname -a
Linux beaglebone 4.1.15-ti-rt-r43 #1 SMP PREEMPT RT Thu Jan 21 20:13:58 UTC 2016 armv7l GNU/Linux

Uninstalled Adafruit_BBIO as per your instructions.
Then proceeded with the installation as from..
https://learn.adafruit.com/setting-up-i ... -on-ubuntu

First error I get is..
root@beaglebone:~# sudo ntpdate pool.ntp.org
sudo: ntpdate: command not found

I don't think it matters much.

Then..
sudo apt-get update
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus -y
.
.
.
.
After all that finishes, I try again..

root@beaglebone:~# python -u OMCB_IO_9A.py
Traceback (most recent call last):
File "OMCB_IO_9A.py", line 8, in <module>
import Adafruit_BBIO.ADC as ADC
ImportError: No module named Adafruit_BBIO.ADC
root@beaglebone:~#

Edited the code to comment out all calls to the ADC, so now..

root@beaglebone:~# python -u OMCB_IO_9B.py
Traceback (most recent call last):
File "OMCB_IO_9B.py", line 12, in <module>
import Adafruit_BBIO.PWM as PWM
ImportError: No module named Adafruit_BBIO.PWM
root@beaglebone:~#

So I do not know how to fix this.
Have the Adafruit_BBIO.ADC and PWM modules been deleted? If so, why???????????
Or are they renamed?

How do I find out how to use the Adafruit_BBIO library?

It would be real nice if there were an easy to understand full examples instruction on how to drive every command in the Adafruit_BBIO library.
And have it written in real code example, not pseudo instructions.

Thanks again Seth, for taking time to help.

Denys.

denys
 
Posts: 49
Joined: Fri Aug 10, 2018 1:08 am

Re: Adafruit_BBIO problems

by silver2row on Sun Aug 12, 2018 3:33 pm

Hello,

Your image is outdated. It will be difficult to get current support for that specific image/kernel. W/ that in mind, try to forget the info. about ntpdate for updating your Adafruit_BBIO.

You can use, once you update your image and kernel, sudo dpkg-reconfigure tzdata. That cmd will help you set up current times and dates for your BBB. After you type that cmd and hit enter/return, the prompt is easy-to-understand.

So...let me know what you want to do. Make it a statement and confirm it is really what you want. I can take time out to help. This is not the issue. I just do not want to help if my help is not wanted. Okay. I said my peace. Let me know.

Seth

P.S. I do not have to give up yet. I can still help you but what I think needs to happen is to update your image on your BBB. Instead of their old overlay info, they have updated to u-boot overlays (mostly). What do you want to do as of now? Will you consider updating your image/kernel to 4.9.x or 4.14.x? I am asking b/c that is what I am using and that is the current, stable info. they have posted as of now.

silver2row
 
Posts: 149
Joined: Sat Jan 30, 2016 3:42 pm

Re: Adafruit_BBIO problems

by denys on Sun Aug 12, 2018 6:37 pm

Good morning Seth.
At least, it is here in Oz :)

Current default time zone: 'Australia/Melbourne'
Local time is now: Mon Aug 13 08:27:59 AEST 2018.
Universal Time is now: Sun Aug 12 22:27:59 UTC 2018.

root@beaglebone:~#

Yes, I am quite happy to update the image version or whatever it takes to get it all working again.
A code rewrite is ok, I just do not know how to do it.
There is no real reason it needs to stick with Python either. That is what it was originally.

denys
 
Posts: 49
Joined: Fri Aug 10, 2018 1:08 am

Re: Adafruit_BBIO problems

by silver2row on Sun Aug 12, 2018 8:15 pm

Sir,

Still, I would need the library/module you use to call line number six in your original software:

Code: Select all | TOGGLE FULL SIZE
from mcp23xxx import MCP23017


That line tells me that you are using a library from somewhere. I do not have that specific library on hand. You would have to share it but if you cannot share it, I cannot go further down this path w/ you.

The newer kernel and images from BBB.io/latest-images are what I think you should grab and install on your machine (BBB).

If you do this and if the task goes as expected, you should be able to use the updated version of Adafruit_BBIO or using the 1.0.3 version should suffice.

To tell you the truth, I cannot go further w/ you on this path b/c the library is not in my control. Where can I grab this library?

Seth

P.S. Please let me know what you want to do. Please try to be specific. For instance, if you have Win 10, save your files and then install them w/ WinSCP back to the BBB. If you have a Linux Distro, do your thing and then add those files back to your BBB after the new image has been updated. Please remember, if you plan or are willing to apply a new image, your entire record of data will be destroyed. Save and back up as usual. Oh and I would rather stick w/ Python.

silver2row
 
Posts: 149
Joined: Sat Jan 30, 2016 3:42 pm

Re: Adafruit_BBIO problems

by denys on Mon Aug 13, 2018 3:13 am

Thanks Seth.
I will upgrade to the latest Linux.
Do you prefer Angstrom or Debian?
I'm running on Macs but that is not important as I use nano via ssh to do the editing on the BBB.
If I get a chance later today I'll get the BBB Linux distro updated.
And as far as I know, originally I followed the instructions on the Adafruit site to get it going
https://learn.adafruit.com/setting-up-i ... k/overview
But I may have used something from elsewhere although I can't remember how it was set up.
I really do not care how it is to be setup now, just as long as I can get my code, or a modified version of it, going again.
Once the libs that talk to the I2C, ADC and PWM work, I can fix my code, probably ;)
Denys.

denys
 
Posts: 49
Joined: Fri Aug 10, 2018 1:08 am

Re: Adafruit_BBIO problems

by denys on Mon Aug 13, 2018 7:50 pm

It is now sitting there with http://debian.beagleboard.org/images/bo ... 4gb.img.xz loaded :)

debian@beaglebone:~$ uname -a
Linux beaglebone 4.14.49-ti-r54 #1 SMP PREEMPT Fri Jun 15 22:14:13 UTC 2018 armv7l GNU/Linux
It is running from the SD card and when I get it to work, I'll image it to guard against later failures!!!!!

Now all I need is info on how to access the MCP23017, PWM and ADC in Python. Once I know how to do that, I can modify my code to suit.
A bash script enabled me to toggle pins on the MCP23017, so I know it works. But I don't think I can do much more that way.

denys
 
Posts: 49
Joined: Fri Aug 10, 2018 1:08 am

Please be positive and constructive with your questions and comments.