Seth
Published

LDR or PhotoResistor and the BeagleBone Black Wireless

Reading is keen, photoresistors are nice, and educating on Ideas from Books are both!

BeginnerProtip1 hour1,144
LDR or PhotoResistor and the BeagleBone Black Wireless

Things used in this project

Hardware components

BeagleBone Black Wireless
BeagleBoard.org BeagleBone Black Wireless
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
Jumper wires (generic)
Jumper wires (generic)
×10
Through Hole Resistor, 470 ohm
Through Hole Resistor, 470 ohm
×1
Resistor 330 ohm
Resistor 330 ohm
×1
General Purpose Dual Op-Amp
Texas Instruments General Purpose Dual Op-Amp
×1

Software apps and online services

sysfs
C++
Python

Hand tools and fabrication machines

Breadboard, 270 Pin
Breadboard, 270 Pin

Story

Read more

Schematics

BBBW

Code

Dr. Molloy did it!

C/C++
/** Simple LDR Reading Application
* Written by Derek Molloy for the book "Exploring BeagleBone: Tools and
* Techniques for Building with Embedded Linux" by John Wiley & Sons, 2018
* Please see the file README.md in the repository root
* directory for copyright and GNU GPLv3 license information.            */

#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
using namespace std;

#define LDR_PATH "/sys/bus/iio/devices/iio:device0/in_voltage"

int readAnalog(int number){
   stringstream ss;
   ss << LDR_PATH << number << "_raw";
   fstream fs;
   fs.open(ss.str().c_str(), fstream::in);
   fs >> number;
   fs.close();
   return number;
}

int main(int argc, char* argv[]){
   cout << "Starting the readLDR program" << endl;
   int value = readAnalog(0);
   cout << "The LDR value was " << value << " out of 4095." << endl;
   return 0;
}

Adafruit_BBIO and making Python Almost Work

Python
Enjoy!
import Adafruit_BBIO.ADC as ADC
import Adafruit_BBIO.GPIO as GPIO
import time

GPIO.setup("P9_12", GPIO.OUT)
ADC.setup("P9_39")

def loop():
    status = 1
    while True:
        print('Value: ', ADC.read("P9_39"))
        time.sleep(2)

if __name__ == '__main__':

    try:
        loop()
    except KeyboardInterrupt:
        pass

Credits

Seth

Seth

32 projects • 12 followers
Stay there and someone will find you...
Thanks to Dr. Molloy.

Comments