A-Okay Here,
I have this ADC source that gets called in an application. The ADC source is output to terminal well but not how I need it to be output.
I need the input of the ADC to output to the application and change something in the application.
For instance:
I use ADC_One.py
here…
#!/usr/bin/python3
from: docs.beagleboard.org
#//////////////////////////////////////
# analogin.py
# Reads the analog value of the light sensor.
#//////////////////////////////////////
from time import sleep
import os
pin = "0" # Sonar Sensor, P9_39
IIOPATH='/sys/bus/iio/devices/iio:device0/in_voltage'+pin+'_raw'
print('Hit ^C to stop')
f = open(IIOPATH, "r")
# I could put in a class here...
def Trial():
while True:
f.seek(0)
x = float(f.read())/4096
print('{}: {:.1f}%, {:.3f} V'.format(pin, 100*x, 1.8*x), end = '\r')
sleep(0.4)
But…I need to have the output of that source be read by another set of tools in the application.
So, what I did was put the source in a class
and within a function
:
Then, I use Motor_Drive.py
here:
#!/usr/bin/python3
from PySabertooth import *
from flask import Flask, render_template
import serial
from time import sleep
# on the beaglebone related boards, use a known, working UART port on the headers.
# For instance, attach P9_21 to S1 on the sabertooth 2 x 12 and attach GND on the sabertooth to GND on your BBB.
# "/dev/ttyS2" has changed in time. Check for changes...
saber = Sabertooth("/dev/bone/uart/2", baudrate=9600, timeout=0.1)
# start and enable a service, start a cron job, or make an executable .sh file for use when booting into this file.
app = Flask(__name__)
@app.route("/")
@app.route("/<state>")
def sab(state=None):
# adc = Am335xAdc()
if state == "F":
print ("Robot Moving Forward")
try:
saber.drive(1, 70)
saber.drive(2, 70)
except adc <= 0.1: # something like "adc = the_class:"
print("Accessing AI...")
saber.drive(1, -5)
saber.drive(2, -5)
pass
So, basically, this application would run on the server for a motor driver, like the Motor Cape or the Motor Cape, from the beaglebone black, report the "adc"
input to output, read the output in the remaining source, and then execute specific tasks due to what the input of the "adc"
is reading to output.
Is that possible or am I just guessing incorrectly?
Seth
P.S. I was making some bots for show and tell time. For some reason, I cannot do two while loops in the same section of source to allow for I/O from one peripheral to another I/O.