Message Boards Message Boards

IoT: Monitoring Analog Devices Using Wolfram Cloud

Posted 9 years ago

My past two posts were about using the Beaglebone Black to take some input from a user through the Wolfram Cloud and subsequently use those to directly change the state of a digital device connected to the BBB. Here, we are going to be doing the reverse: taking input from the BBB, and uploading it to the cloud where the user can view the data.

Parts Used

  • 1 x 10K Potentiometer
  • 3 x Jumper Wires
  • 1 x Beaglebone Black

Pinout

Here, I'll be connecting the potentiometer to the +3.3V, Ground, and AIN0 pins.

Fritzing

First, we need to set up our analog input pins so that we are able to read the input from the potentiometer. We can do this with the following command (as root):

echo cape-bone-iio > /sys/devices/bone_capemgr.*/slots

Next, we define the following two functions, where the first one constructs a file path so that we can access the BBB's analog pins and the second one uses cat to read the state of the pin.

file[pin_Integer, "value"] := First[FileNames["helper.*", FileNames["ocp.*", "/sys/devices"]], ""] <> "/AIN" <> ToString[pin] /; pin < 9
inputPin[pin_Integer] := ToExpression[RunProcess[{"cat", file[pin, "value"]}, "StandardOutput"]]

Having done all that, we use CloudConnect to connect to the Wolfram Cloud and then set up a ScheduledTask to read the pin value every 15 seconds and write it to a cloud object.

RunScheduledTask[CloudPut[inputPin[0], "sentvalue"], 15]

If you would like to stop this scheduled task at any time you can run:

RemoveScheduledTask[ScheduledTasks[]]

Moving on, we now need to take the value that was written to the CloudObject by the BBB and create a neat AngularGauge function to display the value for us:

CloudDeploy[
 Delayed[ExportForm[
   AngularGauge[
    CloudGet[
     CloudObject[
      "CLOUD_URL_HERE"]], {0, 1800}], "PNG"], 
  UpdateInterval -> 15], "AngularGauge"]

Where "CLOUD_URL_HERE" is the URL associated with the CloudObject "sentvalue".

This last function should give you a link to an AngularGauge function that will update every 15 seconds to show a new value on the potentiometer:

Angular Gauge

Questions? Comments? Leave them down below as I'm eager to see your responses!

POSTED BY: Armeen Mahdian

enter image description here - another post of yours has been selected for the Staff Picks group, congratulations !

We are happy to see you at the tops of the "Featured Contributor" board. Thank you for your wonderful contributions, and please keep them coming!

POSTED BY: EDITORIAL BOARD
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract