Code Monkey home page Code Monkey logo

dac8532's Introduction

DAC8532

DAC8532 library for RaspberryPi. Requires BCM2835 library (which is compatible with BCM2836 and BCM2837 chips, so it should work under RPi2, 3 and Zero as well). BCM2835 library can be downloaded here: http://www.airspayce.com/mikem/bcm2835/

Usage

References (very poorly generated, i'd recommend looking at docs in .hpp file) can be found in Wiki. Compile with g++ -c DAC8532.cpp -lbcm2835 and link with your code. Or just compile everything at whole. Maybe i'll provide makefile soon. To be honest, provided example should be enough. If not sure, read comments inside .hpp and you should be fine.

IMPORTANT Oh, and remember - by default, the channels are in high impedance mode. To use them, you have to set their power down mode to none. It's all in the example.

Example

#include "DAC8532.hpp"
#include <chrono>
#include <thread>
#include <iostream>

using namespace std::chrono_literals;

int main() {
    DAC8532 dac(23);

    try {
        dac.initialize();
    } catch (BCMInitException e) {
        std::cout << e.what() << std::endl;
        return 1;
    }

    dac.set_power_down_mode(DAC8532::Channel::A, DAC8532::PowerDownMode::None);
    dac.set_power_down_mode(DAC8532::Channel::B, DAC8532::PowerDownMode::None);

    for(double i = 0.; i < 5.; i += 0.1) {
        dac.write_voltage(DAC8532::Channel::A, i);
        dac.write_voltage(DAC8532::Channel::B, 5. - i);

        auto info_a = dac.get_channel_info(DAC8532::Channel::A);
        auto info_b = dac.get_channel_info(DAC8532::Channel::B);
        std::cout << "A voltage: " << info_a.voltage << ", B voltage: " << info_b.voltage << '\n';

        std::this_thread::sleep_for(50ms);
    }

    dac.set_power_down_mode(DAC8532::Channel::A, DAC8532::PowerDownMode::HighImpedance);

    for(double i = 0.; i < 5.; i += 0.1) {
        dac.write_voltage(DAC8532::Channel::B, i);
        dac.write_voltage(DAC8532::Channel::A, 5. - i);

        auto info_a = dac.get_channel_info(DAC8532::Channel::A);
        auto info_b = dac.get_channel_info(DAC8532::Channel::B);
        std::cout << "A voltage: " << info_a.voltage << ", B voltage: " << info_b.voltage << '\n';

        std::this_thread::sleep_for(50ms);
    }

    dac.cleanup();
}

dac8532's People

Contributors

steelph0enix avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.