# Raspberry Pi Distance Moved

**URL:** <https://forum.core-electronics.com.au/t/raspberry-pi-distance-moved/14153>\
**Category:** Uncategorized\
**Created:** [21 May 2022 04:09 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-distance-moved/14153 "2022-05-21T04:09:32Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![David191372](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/david191372/32/6165_2.png) [@David191372](https://forum.core-electronics.com.au/u/David191372)\
**Post date:** [21 May 2022 04:09 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-distance-moved/14153/1 "2022-05-21T04:09:32Z")

</div>

Hi Guys,  
I have a little pi based rover and I’m looking to add a “distance moved” sensor. I’m thinking I could do this with some kind of Accelerometer but I don’t know much about them. My rover already has a distance to object measurement built in. I’d like to include a “north south” and “east west” measurement relative to a starting point.  
Also a third axis to measure rotation around the same plane. If I start off pointing north for example I should be able to keep track of my current location and orientation.  
The angle or slope isn’t really important but it might be fun to play with later on and adding extra features.  
I have done a bit of searching but most things I find measure distance to object. Any suggestions on what hardware could be used to do this?  
Once I know what hardware to use I may have more luck finding an example project to use as inspiration.

Thanks in advance  
David

---

<div class="post-metadata">

**Author:** ![Robert93820](https://avatars.discourse-cdn.com/v4/letter/r/ac91a4/32.png) [@Robert93820](https://forum.core-electronics.com.au/u/Robert93820)\
**Post date:** [21 May 2022 04:32 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-distance-moved/14153/2 "2022-05-21T04:32:15Z")

</div>

Hi David  
One of the Core guys (Michael I think) had this little add on board with I think a Magnetometer which he had displaying like a magnetic compass. This was a demo video a short time back. You should find it if you can filter out all the Core videos. It is a PicoDev product SKU:CE07937 and might do your job.  
Cheers Bob

---

<div class="post-metadata">

**Author:** ![Jeff105671](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/jeff105671/32/3729_2.png) [@Jeff105671](https://forum.core-electronics.com.au/u/Jeff105671)\
**Post date:** [21 May 2022 05:10 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-distance-moved/14153/3 "2022-05-21T05:10:17Z")

</div>

> [@David191372](#):
>
> have a little pi based rover and I’m looking to add a “distance moved” sensor.

Core has a good video on using the Pi with a gyroscope and acceleromter module to measure acceleration in three axes…

[![](https://img.youtube.com/vi/rcaA81l-spw/maxresdefault.jpg "PiicoDev Motion Sensor MPU-6050 | Raspberry Pi Pico Guide") ](https://www.youtube.com/watch?v=rcaA81l-spw)

It is possible to use that information to calculate position (an inertial navigation system) but it is difficult.  
For example:  
[Research on distance measurement method based on micro-accelerometer: AIP Advances: Vol 11, No 5 (scitation.org)](https://aip.scitation.org/doi/10.1063/5.0054463)  
is a comprehensive discussion of the whole problem that indicates the complexity of the maths. I can’t see that someone has actually done it and posted code, but you could try searching using terms from those references.

---

<div class="post-metadata">

**Author:** ![Liam120347](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/liam120347/32/5003_2.png) [@Liam120347](https://forum.core-electronics.com.au/u/Liam120347)\
**Post date:** [21 May 2022 07:02 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-distance-moved/14153/4 "2022-05-21T07:02:59Z")

</div>

Hi David,

Other than Bob and Jeffs suggestions I’d have a look at:

- [Encoders](https://core-electronics.com.au/mp-12v-motor-with-48-cpr-encoder-for-25d-mm-metal-gearmotors-no-gearbox.html) - they’ll get the overall displacement but not an as the bird flys distance from a specific point
- If you’re outdoors I’d have a look at a GPS
- Getting much pricier a [SLAMTEC 2D LIDAR](https://core-electronics.com.au/slamtec-rplidar-a1-360-laser-range-scanner.html) module makes a 2D map of the room you’re in (with a 12m range)

---

<div class="post-metadata">

**Author:** ![David191372](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/david191372/32/6165_2.png) [@David191372](https://forum.core-electronics.com.au/u/David191372)\
**Post date:** [21 May 2022 08:52 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-distance-moved/14153/5 "2022-05-21T08:52:18Z")

</div>

Thanks for the reply Bob. I’ll check it out.  
From another response the distance thing is looking more complicated than I first thought. At a minimum “you are now facing west” would be an interesting start.

---

<div class="post-metadata">

**Author:** ![David191372](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/david191372/32/6165_2.png) [@David191372](https://forum.core-electronics.com.au/u/David191372)\
**Post date:** [21 May 2022 09:13 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-distance-moved/14153/6 "2022-05-21T09:13:41Z")

</div>

Jeff,  
Your right. That looks complicated 🙂  
I haven’t given up. I’ll post my python library when it’s finished :))  
Thanks for the info that’s really helpful  
David

---

<div class="post-metadata">

**Author:** ![David191372](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/david191372/32/6165_2.png) [@David191372](https://forum.core-electronics.com.au/u/David191372)\
**Post date:** [21 May 2022 10:44 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-distance-moved/14153/7 "2022-05-21T10:44:47Z")

</div>

All,  
I found this example here with a formular that calculates distance based on time and acceleration

> **[Acceleration to Distance Calculator - Calculator Academy](https://calculator.academy/acceleration-to-distance-calculator/)**
>
> Enter the initial velocity, acceleration, and total time into the calculator to convert the acceleration into total distance.

I have ordered some pico-dev bits but unfortunately the main item is not in stock and requires 40+ days delivery. I’ll just have to wait it out.  
If I get it to work I’ll post my proto type code here.

---

<div class="post-metadata">

**Author:** ![James46717](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@James46717](https://forum.core-electronics.com.au/u/James46717)\
**Post date:** [22 May 2022 09:44 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-distance-moved/14153/8 "2022-05-22T09:44:03Z")

</div>

Investigated the Magnetometers on a Zumo Cart and a Micro:Bit to get simple North, South, East, West direction. It was not very successful. The Zumo was affected by the placement of the chip on the board, never got reliable readings. Even the batteries affected the reading.

The Micro:Bit was a little better but still was not very reliable.  
I would have liked something like the compass app on my phone, suspect the phone app uses more than just a Magnetometer.

The Zumo had a front infrared sensor looking down, supposed to follow a line. It did detect the line but the type of ink and width of the line was an issue.

Used encoders built into the motors that drove another cart. Proved to be the most successful way to determine distance travelled. Although both motors did not turn at the same rate, so the cart drifted to one side. Fixed it by using the encoder values to determine how far a motor had turned.

My conclusion was, determining the movement of a robot cart is much more complex than I thought.

Anyway … hope you have more success than me.  
Jim

---

<div class="post-metadata">

**Author:** ![David191372](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/david191372/32/6165_2.png) [@David191372](https://forum.core-electronics.com.au/u/David191372)\
**Post date:** [22 May 2022 23:09 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-distance-moved/14153/9 "2022-05-22T23:09:07Z")

</div>

Hi Jim,  
Interesting story. Thanks for all the detail.  
I ordered some bits that won’t break the bank.  
Will take 4+ weeks to arrive so I won’t have any results for a while. I did get a accelerometer that will be a challenge to interpret I reckon. I also bought a compass and noted in the description it said can also be used to detect local magnetic fields 🙂  
I think when performing an impossible task it’s important to give it to someone who doesn’t know it’s impossible:)  
I’ll try and post some results here.  
My initial goal is to build a web interface to control the car then publish that page on the net and see what happens. That bit is nearly finished.  
I wonder if people will try and break it or hack the OS.  
I’ll contain it to my office initially as it has a camera on the front. Hopefully people will just enjoy snooping around. It it goes well I’ll build a simulated Mars environment and set little tasks.  
The funny part is it could be total anarchy as there is no login or sharing. Anyone can do anything all at the same time which will be an experiment in itself.  
David

---

<div class="post-metadata">

**Author:** ![James46717](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@James46717](https://forum.core-electronics.com.au/u/James46717)\
**Post date:** [23 May 2022 05:00 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-distance-moved/14153/10 "2022-05-23T05:00:14Z")

</div>

Links to a cart I built with web interface, camera, etc.  
Kept the grandsons amused for a few hours, taking pics, driving it around.  
Happy for you to use whatever may be of use and happy to provide more details, if needed.

> [@Mini Robot Cart – Part One](https://forum.core-electronics.com.au/t/mini-robot-cart-part-one/9440):
>
> Mini Robot Cart – Part One Introduction This is the third robot cart I have built and arguably the best and most versatile. I wanted to see what I could fit in the small Jiffy Box and still work as robot cart. (actually the term robot is technically incorrect, remote control would be better in this instance) In my opinion it was successful because the grandkids had fun playing with it for over 2 hours, taking pics, turning the lights on and off, driving it in the dark. The brains …

> [@Mini Robot Cart - Part Two](https://forum.core-electronics.com.au/t/mini-robot-cart-part-two/9480):
>
> Mini Robot Cart – Part Two This document will list the major parts of the project and discusses some of the design decisions made. The pics show how the parts fit in the box. The aim of the project was a small device, controllable via a web page with some ability to make it autonomous in the future. Parts List Note: When documenting the parts listed here I found it distrubing that some are no longer available. But this is understandable, if something does not sell, why stock it and in the cas…

> [@Mini Robot Cart - Part Three](https://forum.core-electronics.com.au/t/mini-robot-cart-part-three/9692):
>
> Mini Robot Cart – Part Three This part will detail the software used. Software: I use PuTTY to SSH to the Pi and FileZilla to transfer files. Sublime Text to edit program script. My development platform is Windows 10. The Raspberry Pi sets itself up as a WiFi Hot Spot. This can then be connected to via a tablet or phone (I prefer the tablet as the screen is larger). Open a web brower on the tablet and select the IP address of the Pi and the port address for the web server, 192.168.4.1:5000. …

Regards  
Jim

---

<div class="post-metadata">

**Author:** ![David191372](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/david191372/32/6165_2.png) [@David191372](https://forum.core-electronics.com.au/u/David191372)\
**Post date:** [23 May 2022 07:01 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-distance-moved/14153/11 "2022-05-23T07:01:03Z")

</div>

Hi James,  
Very interesting project. My “cart” came as a kit from Freenove. Just add your own Pi and batteries. My pi has been lying around for nearly 10 years so it was a bit of a challenge getting it to work with all the latest stuff.  
I don’t have kids so I’ll have to get the general population to play with it.  
I’m not sure the wife will handle the cam driving around on its own. 🙂  
I’m toying with the idea of building a Mars scene on a large sheet of plywood.  
Recharging is going to be an issue. I’m wondering if I can come up with a docking station where the rover can park and contacts can hit a standard charger.  
All things to figure out.  
Thanks for your interest!

---

<div class="post-metadata">

**Author:** ![James](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/james/32/4400_2.png) [@James](https://forum.core-electronics.com.au/u/James)\
**Post date:** [26 May 2022 01:40 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-distance-moved/14153/12 "2022-05-26T01:40:37Z")

</div>

Hi David,

While @Liam is on the money with his suggestions for sensing the distance moved, if you exhaust other options, Pimoroni’s Optical flow sensor may be a non-invasive way to get that data. It only tracks movement in x and y (like a mouse), but if you mounted it off-axis on the robot, it could sense rotation and forward/backward movement.

> **[Pimoroni Near Optical Flow SPI Breakout (PAA5100JE)](https://core-electronics.com.au/pimoroni-near-optical-flow-spi-breakout-paa5100je.html)**
>
> Detect motion of close-up surfaces with this Breakout Garden compatible optical navigation breakout - great for floor tracking for ground-dwelling robots!

Let us know how you go with your project 🙂  
-James

---

<div class="post-metadata">

**Author:** ![Doug27394](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/doug27394/32/7961_2.png) [@Doug27394](https://forum.core-electronics.com.au/u/Doug27394)\
**Post date:** [26 May 2022 03:01 UTC](https://forum.core-electronics.com.au/t/raspberry-pi-distance-moved/14153/13 "2022-05-26T03:01:18Z")

</div>

> [@James](#):
>
> Pimoroni’s Optical flow sensor may be a non-invasive way to get that data

Off topic…  
That’s cool, I’d thought about hacking up a mouse (not a 🐁) to achieve that. Good to know there’s a purpose built part for it. Actually that’d be handy for one of those wall based ploters too.
