A speedometer is a device that takes signals from the vehicle it is mounted on and shows the speed at which it is moving.
In a car or bicycle, these signals come from the wheels or some point in the transmission and have a direct relationship with the speed of movement. The measurement is quite accurate, but the installation of the sensors or meters can be somewhat complex.
In the case of a GPS, speed is derived from the distance traveled between two measurements: knowing the distance traveled and the time taken, you can calculate the speed with a simple division. This value might not be as accurate, but it has the great advantage of not requiring any type of sensor connection.
Of course, using a GPS solely for this function might be excessive, but if we already have it to determine the position, we can take advantage of the additional speed data for other purposes.
In this case, we are going to read the speed information provided by the GPS to display it on the screen and add a couple of additional functions: we will compare the speed with a maximum limit, such as the one set by law on roads or highways, and alert with an alarm if we exceed it (to avoid fines). Additionally, we will determine the maximum speed reached and also display it on the screen as a reference.
The Mini GPS/BDS ModuleThe Mini GPS/BDS is a module from M5Stack that features a UART interface which can be connected to various devices through a Grove connector.
Like other modules from M5Stack, it can be accessed from different platforms and programming languages, such as Arduino, Python or UIFlow.
The blocks available in UIFlow Version 1 are as follows:
As you can see, there are several blocks to read the data provided by the GPS, including Latitude and Longitude, Date and Time, number of satellites in view, and Speed. The latter is the one we will use in this project.
The ProgramIn the following image, you can see the interface of the M5Stick. Below, I'll explain the meaning of each element.
- Label0: Current speed read from the GPS.
- Label1: Contains the text "MAX:" to indicate the maximum speed reached.
- Label2: Contains the fixed text "Km/h".
- Label3: Battery voltage in volts.
- Label4: Maximum speed reached.
- Label5: Contains the fixed text "LIM:" to display the configured speed limit.
- Label6: Value of the speed limit.
- Label8: Current time value.
- Label9: Contains the text "BAT:"
(Label 7 seems to have been deleted in some modification)
The code blocks can be seen below:
As you can see, it has two events in yellow: Setup with the preparation blocks and Loop containing the blocks that repeat indefinitely.
Under Setup, the GPS module is configured to indicate that it is connected to UART1 and then the Time Zone is set to -3, which is my time zone. You should set this value according to your specific time zone so that the time is displayed correctly on the screen.
Then, the Vmax variable (Maximum Speed) is initialized to 0 and Vlim (Speed Limit) to 110. This is the value against which the speed is compared to determine if the maximum limit has been exceeded. You should also change it according to local values. (In a future version, I will make this modifiable from the program itself).
The last Setup block ensures that the color of label0 (the speed) is white.
At the beginning of the Loop, various values are updated on the screen, such as battery voltage, time, the value of the speed limit, current speed, and maximum speed. The current speed case deserves special attention since the GPS reading block returns a value in text format and must be converted to a number (float) for subsequent comparison (otherwise, an error occurs). Additionally, it is rounded to discard decimals.
Then we find two comparisons using if/do/else blocks.
In the first one, the current speed is compared with the speed limit. If the current speed is higher than the limit, an alarm sounds and the speed value changes to red, indicating that we are exceeding the speed limit. If not, the speed color remains white, and the alarm does not sound.
The next comparison is to update the maximum speed value. If the current speed is higher than the maximum, the maximum speed value is updated; otherwise, it remains unchanged.
Finally, a 2-second delay is added before continuing, so that the values on the screen do not change too quickly.
Image GalleryHere are some pictures of the M5Stick mounted with the GPS module using a SandwichC Brick accessory (optional).
The speedometer in action
The M5StickC Plus2 is a great device for programming a wide variety of applications. In combination with M5Stack's peripheral modules, you can create projects from the simplest to the most complex without needing to get tangled up in hardware intricacies.
In this project, I showed you how to take advantage of the Mini GPS/BDS module for a not-so-conventional GPS application, such as a speedometer, which also served to learn a bit more about the basics of programming with UIFlow
Comments