{"id":13802288,"url":"https://github.com/robert-hh/CS1237","last_synced_at":"2025-05-13T13:30:31.070Z","repository":{"id":242547568,"uuid":"809800118","full_name":"robert-hh/CS1237","owner":"robert-hh","description":"MicroPython driver for the CS1237 Load Cell Interface/ADC","archived":false,"fork":false,"pushed_at":"2024-10-12T14:51:40.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-18T17:51:28.691Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robert-hh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-03T13:25:27.000Z","updated_at":"2024-10-12T14:53:50.000Z","dependencies_parsed_at":"2024-06-14T08:53:19.068Z","dependency_job_id":null,"html_url":"https://github.com/robert-hh/CS1237","commit_stats":null,"previous_names":["robert-hh/cs1237"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robert-hh%2FCS1237","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robert-hh%2FCS1237/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robert-hh%2FCS1237/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robert-hh%2FCS1237/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robert-hh","download_url":"https://codeload.github.com/robert-hh/CS1237/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253949917,"owners_count":21989273,"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":[],"created_at":"2024-08-04T00:01:41.150Z","updated_at":"2025-05-13T13:30:30.788Z","avatar_url":"https://github.com/robert-hh.png","language":"Python","readme":"# CS1237: MicroPython class for the CS1237 Load Cell driver/ADC\n\nThis is a short and simple class for the CS1237 ADC. It supports reading\nthe ADC value, reading the temperature and configuring the various device\nmodes.\n\nTested with MicroPython ports for RP2040, STM32, SAMD, i.MX RT (e.g. Teensy),\nESP32, ESP8266, NRF52840 and W600. Approximate times for reading an ADC value:\n\n- RP2040 at 125 MHz: 450 µs  \n- PYBD SF6 at 192 MHz: 250 µs  \n- Teensy 4.1 at 600 MHz: 100 µs  \n- SAMD51 at 120 MHz: 450 µs   \n- SAMD21 at 48 MHz: 1.2 ms   \n- ESP32 at 160 MHz: 900 µs  \n- ESP8266 at 80 MHz: 1.2 ms  \n- NRF52840: 800µs.  \n- Renesas RA6M2 at 120 MHz: 600µs\n- W600 at 80 MHz: 900 µs  \n\nThe nrf port has the problem that the device cannot be configured when using the IRQ based driver.\nNRF52840 based devices have worked in the test\nusing the polling driver. Otherwise the CS1237 operates at it's default\nmode, which is gain=128, rate=10, channel=0.\npin.irq() seems not to work at the Renesas port, at least not with the tested EV-RA6M2 board.\nIt can be configured, but refuses to work. The polling driver works.\n\n\n## Constructor\n\n### cs1237 = CS1237(clock_pin, data_pin[, gain=1, rate=10, channel=0])\n\nThis is the GPIO constructor. data_pin and clock_pin are the pin objects\nof the GPIO pins used for the communication. The arguments for gain, rate and channel\nare optional and can later be re-configured using the init() method.\n\n## Methods\n\n### cs1237.init(gain=None, rate=None, channel=None)\n\nConfigures or re-configures the ADC. All arguments are optional.\nAccepted values for **gain** are 1, 2, 64, 128 and for\n**rate** are 10, 40, 640, 1280.\nChannel values are:\n\n- 0 : ADC reading\n- 1 : Chip retention (sleep?)\n- 2 : Temperature reading\n- 3 : Internal short of the input\n\nAt data rates of 640 and 1280 reading with a slow MCU may return wrong\nvalues, and configuring the device may fail. Then only a power cycle\nwill reset the device. Since the current consumption of the CS1237 is\nlow, it can be supplied by a GPIO output, making power cycling easy.  \n\nAccording to the test, Teensy 4.x and PYBD SF6 work fine at a rate\nof 1280. The RP2040, SAMD51 and Renesas RA6M2 work fine at a rate at 640\nand can still be configured back.  \nESP32, ESP8266, nrf52, SAMD21 and W600 can be configured once for a rate\nof 640, but cannot reset back to a lower rate and do not support\ntemperature reading when set to the 640 rate.\n\n\n### result = cs1237.read()\n### result = cs1237()\n\nReturns the actual reading of the ADC or temperature.\n\n\n### cs1237.get_config()\n\nReturns the tuple of (gain, rate, channel) as read back from the ADC.\n\n\n### cs1237.config_status()\n\nReturns True if a new configuration has been properly updated.\n\n\n### cs1237.calibrate_temperature(temp [, reference_value])\n\nSet the calibration values for the temperature sensor. temp is the actual\n°C value. If both the temperature and a reference value are supplied,\nit is taken as the calibration tuple of the sensor. If not, the\nreference value is read from the sensor.\nThe reference value can be obtained by configuring the sensor for temperature\nreading and calling cs1237.read().\n\n### cs1237.temperature(temp)\n\nReturn the actual temperature reading. The reference point has to be\nconfigured before using calibrate_temperature().\n\n### cs1237.power_down()\n\nSet the CS1237 device to sleep mode.\n\n### cs1237.power_up()\n\nSwitch the CS1237 on again.\n\n\nMore methods exists but are used only internally by the CS1237 class.\n\n## Examples\n\n\n```\n# Connections:\n# Pin # | CS1237\n# ------|-----------\n# 12    | data_pin\n# 13    | clock_pin\n#\n\nfrom cs1237 import CS1237\nfrom machine import Pin\n\ndata = Pin(12)\nclock = Pin(13)\n\n# Create a CS1237 instance with default values for gain, rate and channel\ncs1237 = CS1237(clock, data)\n\n# get ADC readings\nvalue = cs1237.read()\n# Alternative for reading the value\nvalue = cs1237()\n\n# change the gain\ncs1237.init(gain=2)\nvalue = cs1237.read()\n\n# return the ADC settings\ngain, rate, channel = cs1237.get_config()\n\n# Alternative for showing the properties\nprint(cs1237)\n\n# Calibrate the temperature reading\ncs1237.calibrate_temperature(22.1)\n\n# get the temperature\ntemp_celsius = cs1237.temperature()\n\n# Calibrate the temperature reading using a known set point\n# which has to be determined only once for a device.\ncs1237.calibrate_temperature(20.0, 769000)\n\n```\n\n## Files\n\n- **cs1237.py** CS1237 driver using Interrupts.\n- **cs1237_poll.py** CS1237 driver use polling to detect the sync pulse. The\ndriver may fail on slow devices like ESP8266, SAMD21 or W600.\n- **README.md**  Documentation file.\n\n","funding_links":[],"categories":["Libraries"],"sub_categories":["IO"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobert-hh%2FCS1237","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobert-hh%2FCS1237","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobert-hh%2FCS1237/lists"}