{"id":18689254,"url":"https://github.com/endail/pico-scale","last_synced_at":"2025-04-12T05:53:28.051Z","repository":{"id":53934147,"uuid":"512379952","full_name":"endail/pico-scale","owner":"endail","description":"A scale API for a Raspberry Pi Pico (RP2040) using the hx711-pico-c library.","archived":false,"fork":false,"pushed_at":"2023-07-18T11:50:13.000Z","size":1598,"stargazers_count":18,"open_issues_count":0,"forks_count":6,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-12T05:53:20.239Z","etag":null,"topics":["c","hx711","iot","load-cell","loadcell","raspberry-pi","raspberry-pi-pico","rp2040","scale","scales","weight"],"latest_commit_sha":null,"homepage":"https://endail.github.io/pico-scale","language":"C","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/endail.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":"2022-07-10T08:10:47.000Z","updated_at":"2025-01-28T23:48:51.000Z","dependencies_parsed_at":"2024-11-07T10:43:35.078Z","dependency_job_id":"0741e0cd-5da2-4abc-a32f-55369dd03001","html_url":"https://github.com/endail/pico-scale","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endail%2Fpico-scale","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endail%2Fpico-scale/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endail%2Fpico-scale/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endail%2Fpico-scale/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/endail","download_url":"https://codeload.github.com/endail/pico-scale/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525156,"owners_count":21118616,"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":["c","hx711","iot","load-cell","loadcell","raspberry-pi","raspberry-pi-pico","rp2040","scale","scales","weight"],"created_at":"2024-11-07T10:41:54.903Z","updated_at":"2025-04-12T05:53:28.028Z","avatar_url":"https://github.com/endail.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pico-scale\n\n## NOTE: DOCUMENTATION IS OLD. REFER TO [the test code](tests/main.c) for an example\n\nA scale API for a Raspberry Pi Pico (RP2040).\n\n![resources/hx711_serialout.gif](resources/hx711_serialout.gif)\n\nThe .gif above illustrates the [current example code](main.c) obtaining data from a HX711 operating at 80 samples per second. Each line shows the current weight calculated from all samples obtained within 250 milliseconds, along with the minimum and maximum weights of the scale since boot. I applied pressure to the load cell to show the change in weight.\n\n## Clone\n\n### Method 1\n\nIf you want to use this repository as-is with the example code, clone the respository and initialise the `hx711-pico-c` submodule.\n\n```console\ngit clone --recurse-submodules --remote-submodules https://github.com/endail/pico-scale\n```\n\nThen `#include` as follows:\n\n```c\n#include \"../include/hx711_scale_adaptor.h\"\n#include \"../include/scale.h\"\n```\n\nRun CTest to build the example and calibration programs. The `.uf2` files you upload to your Pico will be found under `build/tests/`.\n\n### Method 2\n\nAlternatively, if you want to use the scale functionality as an API in your own project, add `pico-scale` as a submodule and then initialise it.\n\n```console\ngit submodule add https://github.com/endail/pico-scale extern/pico-scale\ngit submodule update --init --remote --recursive\n```\n\nThen, from your own code, `#include` the relevant files as follows and initialise the hx711:\n\n```c\n#include \"extern/pico-scale/include/hx711_scale_adaptor.h\"\n#include \"extern/pico-scale/include/scale.h\"\n```\n\nSee the explanation [here](https://github.com/endail/hx711-pico-c#custom-pio-programs) for why you need to manually include the PIO program.\n\n## Documentation\n\n[https://endail.github.io/pico-scale](https://endail.github.io/pico-scale/)\n\n## Initialise the HX711\n\nYou will always need to initialise the HX711 before using it as a scale. See [here](https://github.com/endail/hx711-pico-c#how-to-use) for how to do that.\n\n## How to Use the HX711 as a Scale\n\n```c\nscale_t sc;\n\n// the values obtained when calibrating the scale\n// if you don't know them, read the following section How to Calibrate\nmass_unit_t scaleUnit = mass_g;\nint32_t refUnit = -432;\nint32_t offset = -367539;\n\nscale_init(\n    \u0026sc,\n    \u0026hx, // pass a pointer to the hx711_t\n    scaleUnit,\n    refUnit,\n    offset);\n\n// 3. Set options for how the scale will read and interpret values\n\n// SCALE_DEFAULT_OPTIONS will give some default settings which you\n// do not have to use\nscale_options_t opt = SCALE_DEFAULT_OPTIONS;\n\n// scale_options_t has the following options\n//\n// opt.strat, which defines how the scale will collect data. By default,\n// data is collected according to the number of samples. So opt.strat\n// is set to strategy_type_samples. opt.samples defines how many samples\n// to obtain. You can also set opt.strat to read_type_time which will\n// collect as many samples as possible within the timeout period. The\n// timeout period is defined by opt.timeout and is given in microseconds\n// (us). For example, 1 second is equal to 1,000,000 us.\n//\n// opt.read, which defines how the scale will interpret data. By default,\n// data is interpreted according to the median value. So opt.read is set\n// to read_type_median. You can also set opt.read to read_type_average\n// which will calculate the average value.\n//\n// Example:\n//\n// opt.strat = strategy_type_time;\n// opt.read = read_type_average;\n// opt.timeout = 250000;\n//\n// These options mean... collect as many samples as possible within 250ms\n// and then use the average of all those samples.\n\n// 4. Zero the scale (OPTIONAL) (aka. tare)\n\nif(scale_zero(\u0026sc, \u0026opt)) {\n    printf(\"Scale zeroed successfully\\n\");\n}\nelse {\n    printf(\"Scale failed to zero\\n\");\n}\n\n// 5. Obtain the weight\nmass_t mass;\n\nif(scale_weight(\u0026sc, \u0026mass, \u0026opt)) {\n\n    // mass will contain the weight on the scale obtanined and interpreted\n    // according to the given options and be in the unit defined by the\n    // mass_unit_t 'scaleUnit' variable above\n    //\n    // you can now:\n\n    // get the weight as a numeric value according to the mass_unit_t\n    double val;\n    mass_get_value(\u0026mass, \u0026val);\n\n    // convert the mass to a string\n    char buff[MASS_TO_STRING_BUFF_SIZE];\n    mass_to_string(\u0026mass, buff);\n    printf(\"%s\\n\", buff);\n\n    // or do other operations (see: mass.h file)\n\n}\nelse {\n    printf(\"Failed to read weight\\n\");\n}\n```\n\n## How to Calibrate\n\n1. Modify [the calibration program](tests/calibration.c#L68-L73) and change the clock and data pins to those connected to the HX711. Also change the rate at which the HX711 operates if needed.\n\n2. Build by running `CTest`.\n\n3. Copy `calibration.uf2` in the `build/tests/` directory to the Raspberry Pi Pico.\n\n4. Open a serial connection to the Pico at a baud rate of 115200 and follow the prompts.\n\n## FAQ\n\nQ: __\"Which mass units are supported?\"__\n\nA: The following `mass_unit_t`s are available.\n\n- `mass_ug`: micrograms\n- `mass_mg`: milligrams\n- `mass_g`: grams\n- `mass_kg`: kilograms\n- `mass_ton`: metric tons\n- `mass_imp_ton`: imperial tons\n- `mass_us_ton`: US tons\n- `mass_st`: stones\n- `mass_lb`: pounds\n- `mass_oz`: ounces\n\nQ: __\"How do I get the weight in pounds/ounces/tons/etc...?\"__\n\nA: You can either: set the `scale_t` or change the `mass_t`.\n\n```c\n// 1. setting the scale_t\n\n// when you initialise the scale\nscale_init(\n    \u0026sc,\n    \u0026hx,\n    mass_imp_ton, //change the scaleUnit to your chosen mass_unit_t\n    refUnit,\n    offset);\n\n// or, if you've already initialised the scale\nsc.unit = mass_imp_ton;\n\n\n// 2. change the mass_t\n\n// if, for whatever reason, you are initialising a mass_t\nmass_init(\n    \u0026m,\n    mass_lb, //your desired mass_unit_t\n    val);\n\n// or, if you've already initialised a mass_t\nm.unit = mass_lb;\n```\n\nQ: __\"How do I perform math on the weights?\"__\n\nA: You can either: get the underlying value and operate on that, or use the in-built functions to operate on two `mass_t` structs.\n\n```c\n// 1. get the underlying value\ndouble val;\nmass_get_value(\u0026m, \u0026val);\n\nif(val \u003e= 10.5) {\n    //do something if val is greater than or equal to 10.5\n}\n\n//2. built-in functions\nif(mass_gteq(\u0026m1, \u0026m2)) {\n    //do something if m1 is greater than m2\n}\n```\n\nThe advantage of using the built-in functions is that the `mass_t` structs can be of different units. So you can check if, for example, `m1` is greater than or equal to `m2`, even if `m1` is is in pounds and `m2` is in kilograms. The conversion is taken care of for you.\n\nQ: __\"Which math functions are available?\"__\n\nA:\n\n- `mass_add(mass_t* lhs, mass_t* rhs, mass_t* res)`: add `lhs` and `rhs` and store result in `res`\n- `mass_sub(mass_t* lhs, mass_t* rhs, mass_t* res)`: subtract `rhs` from `lhs` and store result in `res`\n- `mass_mul(mass_t* lhs, mass_t* rhs, mass_t* res)`: multiply `lhs` and `rhs` and store result in `res`\n- `mass_div(mass_t* lhs, mass_t* rhs, mass_t* res)`: divide `lhs` by `rhs` and store result in `res`, returns false if `rhs` is 0\n- `mass_addeq(mass_t* self, mass_t* rhs)`: add `rhs` to `self`\n- `mass_subeq(mass_t* self, mass_t* rhs)`: subtract `rhs` from `self`\n- `mass_muleq(mass_t* self, mass_t* rhs)`: multiply `self` by `rhs`\n- `mass_diveq(mass_t* self, mass_t* rhs)`: divide `self` by `rhs`, returns false if `rhs` is 0\n- `mass_eq(mass_t* lhs, mass_t* rhs)`: return true if `lhs` equals `rhs`\n- `mass_neq(mass_t* lhs, mass_t* rhs)`: return true if `lhs` does not equal `rhs`\n- `mass_lt(mass_t* lhs, mass_t* rhs)`: return true if `lhs` is less than `rhs`\n- `mass_gt(mass_t* lhs, mass_t* rhs)`: return true if `lhs` is greater than `rhs`\n- `mass_lteq(mass_t* lhs, mass_t* rhs)`: return true if `lhs` is less than or equal to `rhs`\n- `mass_gteq(mass_t* lhs, mass_t* rhs)`: return true if `lhs` is greater than or equal to `rhs`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fendail%2Fpico-scale","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fendail%2Fpico-scale","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fendail%2Fpico-scale/lists"}