RPi::PIGPIO::Device::ADC::MCP300x - access the ADC convertor MCP3004 or MCP3008
Communicate with the MCP3004 or MCP3008 analog-to-digital convertors
This convertors offer 10 bit conversions (range 0-1023) for 4 or 8 chanels
Comunication is done via harware SPI so MAKE SURE YOU ENABLED SPI on your RPi (use raspi-config command and go to "Advanced")
raspi-config
See https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus
use feature 'say'; use RPi::PIGPIO; use RPi::PIGPIO::Device::ADC::MCP300x; my $pi = RPi::PIGPIO->connect('192.168.1.10'); my $mcp = RPi::PIGPIO::Device::ADC::MCP300x->new(0); say "Sensor 1: " .$mcp->read(0); say "Sensor 2: " .$mcp->read(1);
Create a new object
Usage:
my $mcp = RPi::PIGPIO::Device::ADC::MCP300x->new(0);
Arguments: $pi - an instance of RPi::PIGPIO $spi_channel - SPI channel from which you want to read (0 or 1 corresponding to SPI CE0 / GPIO8 or SPI CE1 / GPIO 7) $baud - clock speed for SPI communication (optional, defaults to 32K)
Read the value for a sensor connected to MCP3004 or MCP3008
Usage :
my $value = $mcp->read(0);
To install RPi::PIGPIO, copy and paste the appropriate command in to your terminal.
cpanm
cpanm RPi::PIGPIO
CPAN shell
perl -MCPAN -e shell install RPi::PIGPIO
For more information on module installation, please visit the detailed CPAN module installation guide.