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
# 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!