{"id":15020690,"url":"https://github.com/luxedo/rpi_mcp3008","last_synced_at":"2025-10-26T04:30:49.576Z","repository":{"id":47174115,"uuid":"46588418","full_name":"luxedo/RPi_mcp3008","owner":"luxedo","description":"RPi_mcp3008 is a library to listen to the MCP3008 A/D converter chip, as described in the datasheet.","archived":false,"fork":false,"pushed_at":"2024-06-18T02:13:25.000Z","size":37,"stargazers_count":8,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-31T14:21:53.941Z","etag":null,"topics":["analog-digital-communication","gpio","mcp3008","python","python-library","raspberry-pi","rpi","spi","wiring"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/mcp3008/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luxedo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-20T21:43:59.000Z","updated_at":"2024-09-15T20:51:48.000Z","dependencies_parsed_at":"2022-08-19T01:31:31.198Z","dependency_job_id":null,"html_url":"https://github.com/luxedo/RPi_mcp3008","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luxedo%2FRPi_mcp3008","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luxedo%2FRPi_mcp3008/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luxedo%2FRPi_mcp3008/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luxedo%2FRPi_mcp3008/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luxedo","download_url":"https://codeload.github.com/luxedo/RPi_mcp3008/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238258990,"owners_count":19442511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analog-digital-communication","gpio","mcp3008","python","python-library","raspberry-pi","rpi","spi","wiring"],"created_at":"2024-09-24T19:55:26.563Z","updated_at":"2025-10-26T04:30:49.257Z","avatar_url":"https://github.com/luxedo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RPi_mcp3008\nRPi_mcp3008 is a library to listen to the MCP3008 A/D converter chip with a RPi.\nThis library implements the example communication protocol described in the [datasheet](https://www.adafruit.com/datasheets/MCP3008.pdf).\n\n\nCommunication is made through RPi SPI port using [SpiDev](https://github.com/doceme/py-spidev)\n\n## Wiring\nConnect the SPI data cables in the tables below. Choose either CE0# or CE1# to connect to CS.\n\n### RPi SPI GPIOs\n\n| RPi GPIO  | Mode |\n|-----------|:-----|\n| GPIO 07   | CE1# |\n| GPIO 08   | CE0# |\n| GPIO 09   | MISO |\n| GPIO 10   | MOSI |\n| GPIO 11   | SCLK |\n\n\n### MCP3008 Pinout\n\n| Pin | Description | Pin | Description |\n|-----|:------------|:----|:------------|\n| 01  |     CH0     | 09  | Vdd - Supply voltage (2.7V - 5.5V) |\n| 02  |     CH1     | 10  | Vref - Reference voltage |\n| 03  |     CH2     | 11  | AGND - Analog ground |\n| 04  |     CH3     | 12  | CLK - SPI Clock (SCLK) |\n| 05  |     CH4     | 13  | Dout - Data out (MISO) |\n| 06  |     CH5     | 14  | Din - Data in (MOSI) |\n| 07  |     CH6     | 15  | CS - Chip select (CE0# or CE1#) |\n| 08  |     CH7     | 16  | DGND - Digital ground |\n\nPlease check the [Adafruit guide](https://learn.adafruit.com/reading-a-analog-in-and-controlling-audio-volume-with-the-raspberry-pi/connecting-the-cobbler-to-a-mcp3008) on the MCP3008 for more information about wiring\n\n\n## Usage\n\nRPi_mcp3008 uses the `with` statement to properly handle the SPI bus cleanup.\n```python\nimport mcp3008\nwith mcp3008.MCP3008() as adc:\n    print(adc.read([mcp3008.CH0])) # prints raw data [CH0]\n```\nIt's possible instantiate the object normally, but it's necessary to call the close method before terminating the program.\n```python\nimport mcp3008\nadc = mcp3008.MCP3008()\nprint(adc.read([mcp3008.CH0])) # prints raw data [CH0]\nadc.close()\n```\nThe initialization arguments are `MCP3008(bus=0, device=0, max_speed_hz=976000)` where:\n`MCP3008(X, Y)` will open `/dev/spidev-X.Y`, same as `spidev.SpiDev.open(X, Y)`\nBoth arguments are optional and have a default value of `0`.\nThe default max SPI driver speed is 976 kHz.\n\n### Methods\nCurrently there are two implemented methods:\n```python\ndef read(self, modes, norm=False):\n    '''\n    Returns the raw value (0 ... 1024) of the reading.\n    The modes argument is a list with the modes of operation to be read (e.g.\n    [mcp3008.CH0,mcp3008.Df0]).\n    norm is a normalization factor, usually Vref.\n    '''\n```\n\n```python\ndef read_all(self, norm=False):\n    '''\n    Returns a list with the readings of all the modes\n    Data Order:\n    [DF0, DF1, DF2, DF3, DF4, DF5, DF6, DF7,\n     CH0, CH1, CH2, CH3, CH4, CH5, CH6, CH7]\n    norm is a normalization factor, usually Vref.\n    '''\n```\n* The `modes` argument must be a list with at least one of 16 modes listed below\n* The `norm` argument is a normalization factor that rescales raw data, usually Vref\n\n### Fixed mode\nYou can also declare the class with a `fixed mode`, which will make the instance callable and always return the value of the listed modes.\nAgain you can normalize the data with the norm argument when calling the instance.\n\n```python\nimport mcp3008\nwith mcp3008.MCP3008.fixed([mcp3008.CH0, mcp3008.DF0]) as adc:\n    print(adc())     # prints raw data [CH0, DF0]\n    print(adc(5.2))  # prints normalized data [CH0, DF0]\n```\n\n## MCP3008 Operation Modes\nMCP3008 has 16 different operation modes:\nIt can listen to each of the channels individually **Single Ended** or in a pseudo-differential mode **Differential**\n\n| Single Ended | Differential |\n|--------------|:-------------|\n| CH0  | DF0  (CH0 = IN+; CH1 = IN-) |\n| CH1  | DF0  (CH0 = IN-; CH1 = IN+) |\n| CH2  | DF0  (CH2 = IN+; CH3 = IN-) |\n| CH3  | DF0  (CH2 = IN-; CH3 = IN+) |\n| CH4  | DF0  (CH4 = IN+; CH5 = IN-) |\n| CH5  | DF0  (CH4 = IN-; CH5 = IN+) |\n| CH6  | DF0  (CH6 = IN+; CH7 = IN-) |\n| CH7  | DF0  (CH6 = IN-; CH7 = IN+) |\n\nUse the table above as the operation mode when calling `MCP3008.read(modes)` or setting the `MCP3008.fixed(modes)` mode. (e.g. `MCP3008.read([mcp3008.CH0, mcp3008.DF1])`)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluxedo%2Frpi_mcp3008","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluxedo%2Frpi_mcp3008","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluxedo%2Frpi_mcp3008/lists"}