This module provides analog-to-digital conversion capabilities for MCP3004 and MCP3008 SPI ADCs. Written in Go, board agnostic. Tested on Raspberry Pi and Jetson Orin.
The values you get from the readings will be proportional to the voltage and you will need to interpret it depending on which sensor you hook up to the MCP300x.
You can add as many analog sensors as your MCP300x allows and get readings from them concurrently (this depends on how many channels it has, so for MCP3004 that is four channels, and for MCP3008 that is eight).
To use this module, follow the instructions to add a module from the Viam Registry and select the hazalmestci:sensor:mcp3004-8-go
model from the mcp3004-8
module.
Note
Before configuring your mcp3004-8
, you must create a machine.
Navigate to the Config tab of your machine's page in the Viam app.
Click on the Components subtab and click Create component.
Select the sensor
type, then select the hazalmestci:sensor:mcp3004-8-go
model.
Click Add module, then enter a name for your sensor and click Create.
On the new component panel, copy and paste the following attribute template into your sensor’s Attributes box:
Note
For more information, see Configure a Machine.
{
"chip_select": "0",
"spi_bus": "0",
"pins": {
"moisture": 0,
"temperature": 1,
"humidity": 2
}
}
Save your config.
The following attributes are available for a mcp3004-8
sensor:
Name | Type | Inclusion | Description |
---|---|---|---|
chip_select |
string | Required | The `chip_select`` pin you are using. |
spi_bus |
string | Required | the spi_bus you are using. |
pins |
string | Required | The pins you are using for moisture, temperature, and humidity. |
{
"name": "my-mcp3004",
"model": "hazalmestci:sensor:mcp3004-8-go",
"type": "sensor",
"namespace": "rdk",
"attributes": {
"chip_select": "0",
"spi_bus": "0",
"pins": {
"moisture": 0,
"temperature": 1,
"humidity": 2
}
},
"depends_on": []
}
To use the mcp3004-8
module with a local install, clone this repository to your machine’s computer, navigate to the module
directory, and run:
go build
On your robot’s page in the Viam app, enter the module’s executable path, then click Add module. The name must use only lowercase characters. Then, click Save config.
- To test your sensor, go to the Control tab and test that you are getting readings.
- Once you can obtain your readings, configure the data manager to capture and sync the data from all of your machines.
- To retrieve data captured with the data manager, you can query data with SQL or MQL or visualize it with tools like Grafana.
Copyright 2021-2023 Viam Inc.
Apache 2.0