ADC from am335x to Source Code to Something...

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.

The top source was begotten by docs.beagleboard.org.

The second set, the below set of source, was a mash up of many, different applications that I have made run via the beaglebone black for running on boot to control robots but:

  1. The server does not run if and only if the ADC source is part of the entire set, e.g. either in the second set or with calling the class from the file that is outside of the second set.
  2. I get a flask error since I am in debug=True mode which states as output:
    a. adc is reporting nothing back
    b. I can see my output on terminal reporting back
    c. I am not attempting to run the flask application with the ADC source within the online server
  3. The main source is running everything but the ADC output to server.

Let me recall the files and name them to better instruct what I am doing:

  1. First file: ADC_One.py
  2. Second file: Motor_Drive.py

Seth

P.S. Off to the files!

I got the source down pat (I think).

Off to test if the actual sonar can stop this heavy bot!

Seth

P.S. I may promote my findings if people need to know how to incorporate the docs.beagleboard.org MaxBotix sonar sensor and some Flask applications for bot movement. Until then, testing will ensue!