MCP3208 examples
Single reading
1#include <chrono>
2#include <iostream>
3#include <thread>
4
5#include "mcp3208/mcp3208.hh"
6#include "spi_bus/spi.hh"
7
8int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) {
9 iplo::SpiConfig spiConfig;
10 spiConfig.mode = 0;
11 spiConfig.speedHz = 1350000;
12 spiConfig.bitsPerWord = 8;
13
14 iplo::SPI spi("/dev/spidev1.0", spiConfig);
15 iplo::MCP3208 mcp(spi);
16
17 for (int channel = 0; channel < mcp.channels(); ++channel) {
18 std::cout << "Channel: " << channel << " -- Value: " << +mcp.analogRead(channel) << "\n";
19 std::this_thread::sleep_for(std::chrono::seconds(2));
20 }
21
22 return 0;
23}
Differential reading
1#include <chrono>
2#include <iostream>
3#include <thread>
4
5#include "mcp3208/mcp3208.hh"
6#include "spi_bus/spi.hh"
7
8int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) {
9 iplo::SpiConfig spiConfig;
10 spiConfig.mode = 0;
11 spiConfig.speedHz = 1350000;
12 spiConfig.bitsPerWord = 8;
13
14 iplo::SPI spi("/dev/spidev1.0", spiConfig);
15 iplo::MCP3208 mcp(spi);
16
17 for (int channel = 0; channel < mcp.channels(); ++channel) {
18 std::cout << "Channel: " << channel << " -- Value: " << +mcp.differentialRead(channel) << "\n";
19 std::this_thread::sleep_for(std::chrono::seconds(2));
20 }
21
22 return 0;
23}