Thanks I took your advice and have invested in a https://shop.pimoroni.com/products/icm20948. The documentation is dire to say the least. I've managed to connect it to my Pi and using the examples given am able to see changes in orientation.
In the past your knowledge ad advice has always helped so am coming to you for more.
Converting output data from the sensor seems to be rather difficult. Can you suggest any Code that could convert this output data to degrees for direction 0-360 and also degrees for tilt.
Also how could I use this sensor with you XLoBorg examples?
Thanks
John
Hi, after fiddling with one of the examples included by Pimoroni with the https://shop.pimoroni.com/products/icm20948 I can eventually discern all compass points , 360 deg (North) (90 West) 180 (South) 270 (East), and all points in between.
The code prints the heading in Degrees. Initially I would like to alter the code to print the compass points North when reaching 360 and 180 South etc. I would at a later date like to have a LED that lights when reaching North etc. I realise this is pretty ambitious. Any help would be appreciated.
I've attached the script hopefully it may of use to others.
Cheers
John
Hi, after fiddling with one of the examples included by Pimoroni with the https://shop.pimoroni.com/products/icm20948 I can eventually discern all compass points , 360 deg (North) (90 West) 180 (South) 270 (East), and all points in between.
The code prints the heading in Degrees. Initially I would like to alter the code to print the compass points North when reaching 360 and 180 South etc. I would at a later date like to have a LED that lights when reaching North etc. I realise this is pretty ambitious. Any help would be appreciated.
I've attached the script hopefully it may of use to others.
Cheers
John
First you want to create a limit for how close to exactly north/south you want to be matched and some variables to hold the results in before the loop:
tolerance = 5 # How many degrees from exact to match
isNorth = False
isSouth = False
Then in the loop after you have calculated the heading you want to check if the new heading is within the specified limits.
You can see if the previous loop was already pointing the same way to do an action once, or simply repeat the action for each loop while it is pointing that way.
if (heading >= 360 - tolerance) or (heading <= 0 + tolerance):
# Pointing north
if not isNorth:
# This runs once each time you start facing north
print("North")
# This runs each loop while pointing north
isNorth = True
isSouth = False
elif (heading >= 180 - tolerance) and (heading <= 180 + tolerance):
# Pointing south
if not isSouth:
# This runs once each time you start facing south
print("South")
# This runs each loop while pointing south
isNorth = False
isSouth = True
else:
# Not pointing at any of the above
isNorth = False
isSouth = False
Thank you for the help I modified my working code but no matter what I do it wont run as expected. It runs without any issues but when passing through North /South nothing changes. Any ideas ?
The whole if (heading >= 360 - 5) or (heading <= 0 + 5): section needs to be indented so that it is within the while True: loop.
For example:
heading = round(heading)
if (heading >= 360 - 5) or (heading <= 0 + 5):
# Pointing north
if not isNorth:
# This runs once each time you start facing north
print("North")
Without the indentation this section is not being run during the loop, but after it ends. Since the loop never ends it is never run.
Morning, in my previous posts Ive been using https://shop.pimoroni.com/products/icm20948 sensor as a compass.
How would I be able to view my sensor readings on the diddyborg webui.
In that code the distances-once block takes the Ultrasonic readings and sends them back. The simplest thing would be to replace the code in this section so it performs a single read of the sensor and sends the result back.
Reading at a regular interval is a bit more work. In that case you would need to create a new thread in which your sensor reading code runs in its own loop. You can use a global value to pass the result back to the main thread. This time the distances-once section just needs to read the global result and send it back.
piborg
Sat, 05/01/2021 - 13:31
Permalink
XLoBorg has been discontinued
Unfortunately we had to discontinue XLoBorgs as one of the chips it uses is no longer in production.
As an alternative Pimoroni offer these three options:
The XLoBorg examples are not directly compatible with these boards, but they have their own Python library and examples provided :)
clankerr02
Mon, 05/17/2021 - 13:12
Permalink
Advice taken but help needed
Thanks I took your advice and have invested in a https://shop.pimoroni.com/products/icm20948. The documentation is dire to say the least. I've managed to connect it to my Pi and using the examples given am able to see changes in orientation.
In the past your knowledge ad advice has always helped so am coming to you for more.
Converting output data from the sensor seems to be rather difficult. Can you suggest any Code that could convert this output data to degrees for direction 0-360 and also degrees for tilt.
Also how could I use this sensor with you XLoBorg examples?
Thanks
John
clankerr02
Mon, 05/17/2021 - 17:05
Permalink
Help with Code
Hi, after fiddling with one of the examples included by Pimoroni with the https://shop.pimoroni.com/products/icm20948 I can eventually discern all compass points , 360 deg (North) (90 West) 180 (South) 270 (East), and all points in between.
The code prints the heading in Degrees. Initially I would like to alter the code to print the compass points North when reaching 360 and 180 South etc. I would at a later date like to have a LED that lights when reaching North etc. I realise this is pretty ambitious. Any help would be appreciated.
I've attached the script hopefully it may of use to others.
Cheers
John
clankerr02
Mon, 05/17/2021 - 17:05
Permalink
Help with Code
Hi, after fiddling with one of the examples included by Pimoroni with the https://shop.pimoroni.com/products/icm20948 I can eventually discern all compass points , 360 deg (North) (90 West) 180 (South) 270 (East), and all points in between.
The code prints the heading in Degrees. Initially I would like to alter the code to print the compass points North when reaching 360 and 180 South etc. I would at a later date like to have a LED that lights when reaching North etc. I realise this is pretty ambitious. Any help would be appreciated.
I've attached the script hopefully it may of use to others.
Cheers
John
piborg
Tue, 05/18/2021 - 12:44
Permalink
Identifying north and south
First you want to create a limit for how close to exactly north/south you want to be matched and some variables to hold the results in before the loop:
Then in the loop after you have calculated the heading you want to check if the new heading is within the specified limits.
You can see if the previous loop was already pointing the same way to do an action once, or simply repeat the action for each loop while it is pointing that way.
clankerr02
Tue, 05/18/2021 - 19:29
Permalink
Thanks but not working.
Thank you for the help I modified my working code but no matter what I do it wont run as expected. It runs without any issues but when passing through North /South nothing changes. Any ideas ?
John
piborg
Wed, 05/19/2021 - 09:30
Permalink
The whole if (heading >= 360
The whole
if (heading >= 360 - 5) or (heading <= 0 + 5):
section needs to be indented so that it is within thewhile True:
loop.For example:
Without the indentation this section is not being run during the loop, but after it ends. Since the loop never ends it is never run.
See https://www.askpython.com/python/python-indentation
clankerr02
Sun, 05/23/2021 - 15:52
Permalink
Thanks.
Thank you all working now My new mantra is check indentation! and count spaces 1..2..3..4.
Thanks again
clankerr02
Wed, 03/09/2022 - 09:58
Permalink
Compass readings on diddyborg webui .
Morning, in my previous posts Ive been using https://shop.pimoroni.com/products/icm20948 sensor as a compass.
How would I be able to view my sensor readings on the diddyborg webui.
Thanks in advance
piborg
Fri, 03/11/2022 - 14:57
Permalink
Different options
There are different options depending on if you need to read the sensor at a regular interval, or just when you need an update.
As a starting point, this example adds UltraBorg readings to the Web UI: Diddiborg with Ultraborg over Web UI.
In that code the
distances-once
block takes the Ultrasonic readings and sends them back. The simplest thing would be to replace the code in this section so it performs a single read of the sensor and sends the result back.Reading at a regular interval is a bit more work. In that case you would need to create a new thread in which your sensor reading code runs in its own loop. You can use a global value to pass the result back to the main thread. This time the
distances-once
section just needs to read the global result and send it back.Very basic example with two threads sharing a global value: https://www.adamsmith.haus/python/answers/how-to-use-a-global-variable-w...