{"id":20761016,"url":"https://github.com/tophercantrell/robots-topherbot","last_synced_at":"2026-05-27T05:12:57.383Z","repository":{"id":62829929,"uuid":"76077430","full_name":"topherCantrell/robots-TopherBot","owner":"topherCantrell","description":"Similar to the snapBot","archived":false,"fork":false,"pushed_at":"2022-11-09T12:46:24.000Z","size":38705,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-21T15:11:25.685Z","etag":null,"topics":["adafruit-motor-shield","propeller-spin","raspberry-pi","robots"],"latest_commit_sha":null,"homepage":null,"language":"Propeller Spin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/topherCantrell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-09T23:16:52.000Z","updated_at":"2024-09-01T13:30:57.000Z","dependencies_parsed_at":"2023-01-21T18:04:21.083Z","dependency_job_id":null,"html_url":"https://github.com/topherCantrell/robots-TopherBot","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/topherCantrell/robots-TopherBot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/topherCantrell%2Frobots-TopherBot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/topherCantrell%2Frobots-TopherBot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/topherCantrell%2Frobots-TopherBot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/topherCantrell%2Frobots-TopherBot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/topherCantrell","download_url":"https://codeload.github.com/topherCantrell/robots-TopherBot/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/topherCantrell%2Frobots-TopherBot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28020069,"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","status":"online","status_checked_at":"2025-12-25T02:00:05.988Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["adafruit-motor-shield","propeller-spin","raspberry-pi","robots"],"created_at":"2024-11-17T10:17:09.183Z","updated_at":"2025-12-25T05:10:36.291Z","avatar_url":"https://github.com/topherCantrell.png","language":"Propeller Spin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# robots-compass-bot\n\nExperiments with a Compass Module\n\n![](art/CompassBot5.jpg)\n\n![](art/CompassBot3.jpg)\n\n## Hardware\n\n### Two wheel robot base ($13)\nhttps://www.amazon.com/dp/B01LXY7CM3\n\n![](art/chassis.jpg)\n\n### Robot control board ($15)\nhttps://www.adafruit.com/product/5129\n\n![](art/pico.jpg)\n\nhttps://github.com/CytronTechnologies/MAKER-PI-RP2040\n\nWriteable filesystem:\n\nhttps://learn.adafruit.com/circuitpython-essentials/circuitpython-storage\n\n### Compass module LSM303DLHC ($8)\nhttps://www.amazon.com/HiLetgo-LSM303DLHC-Compass-Accelerometer-Magnetometer/dp/B07X3GFKYD\n\n![](art/compass.jpg)\n\n```\n\u003e\u003e\u003e import machine\n\u003e\u003e\u003e i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))\n\u003e\u003e\u003e i2c.scan()\n[25, 30]\n\u003e\u003e\u003e\n```\n\n!(https://www.st.com/resource/en/datasheet/lsm303dlhc.pdf)[https://www.st.com/resource/en/datasheet/lsm303dlhc.pdf]\n\n![](art/maglibs.jpg)\n\nHex 19: 00011001 (Linear acceleration)\n\nHex 1E: 00011110 (Compass)\n\nhttps://github.com/adafruit/Adafruit_CircuitPython_LSM303DLH_Mag\n\n### Wheel encoder readers (for future projects) ($9 for the pair)\nhttps://www.amazon.com/dp/B00EERJDY4 \n\n![](art/encoders.jpg)\n\n## 3D point plotter\n\n```\n\n# py -m pip install matplotlib\n\nimport json\nwith open('data.txt') as f:\n    data = json.load(f)\n\nimport matplotlib.pyplot as plt\nfig = plt.figure()\nax = plt.axes(projection='3d',xlabel='X',ylabel='Y',zlabel='Z',title='Compass Spin')\n\nax.scatter3D(0,0,0,c='blue',s=100)\n\nplt.show()\n```\n\n## Graphs\n\nThese graphs were made by spinning the compass module in a circle about the gravity vector. The Z axis of\nthe compass is parallel to gravity. The (x, y) plane is parallel to the Earth.\n\n### With and without motors\nMade with `plot_base.py`.\n\nThe motors have magnets (and iron) in them. How do the motors affect the compass reading? Let's spin the\ncompass/controller/batteries with and without the robot base attached.\n\n![](art/plot_base.jpg)\n\nInterestingly, the motors bend the readings closer to ideal (zero slope in Z).\n\n### Magnet and iron mounted to robot\nMade with `plot_mounted.py`.\n\nHow does a magnet attached to the robot affect the compass readings? How does a chunk of iron attached to\nthe robot affect the compass readings? Let's spin compass/controller/batteries with iron attached.\n\n![](art/plot_mounted.jpg)\n\nWith no magnet and no iron, the readings (black curve) are offset from center. This is caused by hard and soft\niron built into the compass/controller/batteries. Mounting screws and header pins contribute to this offset.\n\nThe magnet pushes the readings (red curve) away from the origin. The iron (blue curve) does too, but less noticeably.\n\n### Magnet and iron external to robot\nMade with `plot_externals.py`.\n\nHow does a magnet placed near the robot (but not attached) affect the compass readings? How does a chunk of iron\nplaced near the robot (but not attached) affect the compass readings?\n\n![](art/plot_externals.jpg)\n\nThe iron I used is a square tube stood upright along the Z axis. Notice how the blue curve is distorted along the Z axis.\n\nThe magnet wreaks havoc with the readings (red curve).\n\n### Running motors\nMade with `plot_motors.py`.\n\nWhen a motor is running, the current creates an electromagnet within each motor. Does this affect the compass readings?\n\nLet's run the motors at full and half power both backwards and forwards.\n\n![](art/plot_motors.jpg)\n\nThe Z-axises of these curves have been tweaked to separate the curves visually. Just looking at the (x, y) values we find that\nall of the curves are nearly identical. The readings are affected the same whether the motors are running or not.\n\n### Calibration\nMade with `calibrate.py`\n\nThe Z slope is slight. We will ignore the compass readings on the Z axis. The (x, y) offsets are easy to calculate and adjust for.\nThe distortion, or squashing, of the circle by soft-iron is harder to correct for. We'll use the \"simple\" correction factor because\nit is computationally cheap.\n\n![](art/plot_calibrate.jpg)\n\nNotice that the final (black) curve is not a perfect circle. The \"simple\" correction algorithm leaves a little error, but it is close\nenough to perfect for our use.\n\n# Heading\n\nTODO - REPEAT THIS EXPERIMENT. Use the line of LEDs as an indicator of facing north and compare to the compass.\n\nI tried to mount the compass so that forward for the robot is right down the Y axis. Actually, negative on the Y axis because of how \nthe circuit board is laid out.\n\nI pointed the robot to head straight north and took samples. I would expect the X,Y-to-heading math to result in 180 degrees. Instead\nmy calculations say 160, which agrees with the plotted data:\n\n![](art/plot_north.jpg)\n\nThat's close. Is my error in mounting the compass or lining the robot up pointing north. I'll test driving to 160 and to 180 and see\nwhich matches the actual compass better.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftophercantrell%2Frobots-topherbot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftophercantrell%2Frobots-topherbot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftophercantrell%2Frobots-topherbot/lists"}