Introduction: POI Hunter
Hello Makers, I share my first NodeMCU project with you.
The device you can see in my GPS holder is the POI hunter. It is an easy DIY hw (hardware) and some sw (software). It shows the distance between my car and the nearest POI (point of interest) which's GPS co-ordinates are saved into a database.
I could save my work / home co-ordinates, or co-ordinates of a lot of different nice places into it. Instead I saved the co-ordinates of the fix cameras of Véda system, which is a traffic controlling and speed measuring (speedcam) system in Hungary. This easy hw depending on the sw could have a lot of different functions, but I built this POI hunter to be my speedcam or Véda hunter. It shows the distance of the nearest fix speedcam, and alerts me if I am near to it.
In this instructable I show you how can you build this hw and how can you customize my program and the database to make a device according to your demands.
Step 1: How Is It Working?
- At first the program reads the current GPS co-ordinates of my car
- After that the program checks the database and chooses the nearest POI
- Depending on the distance between my car and the nearest POI the program has different outputs:
- If distance > 10 km, the output is a general screen. It shows the number of the synchronized satellites, the speed of my car and the distance to the next POI.
- If 1 km < distance < 10 km, the focus on the POI. The screen shows the number (the ID) of the highway, the type* of the POI, the name of the nearest town or village, and the distance.
- If 0.5 km < distance 1 km, the content of the screen is same as the previous, but it is inverse.
- if 0.5 km > distance, then you can see the alert screen. You can see only the type of the POI, and the distance in meter.
- If you passed by the POI (the current distance is bigger than the previous), the screen changes back from the inverse status.
Of course this device calculates the shortest distance between two points and don't reckon with the real path you follow. This feature will cause two things:
- The distance you have to drive to the POI can be longer as the calculated.
- Your way can avoid the nearest POI shown on the screen. Thats the reason why I show the ID of the highway where the POI is.
* There is a field in the database, which contains the POI type. It can be speedcam (Véda), home, work, or whatever you want.
Step 2: Items You Need
At first I started this project with Arduino. Nano is small enough to make a compact device with it, but the program memory of ATMega328 wasn't enough for this project. I continued with two Nanos. They communicated through I2C and I shared the tasks between the two cores. (It was a dual core project. :-) It was an interesting challenge and worked well, but it wasn't compact enough.
The next step was a Mega. The memory was more then enough, the hw is able to do much more then I needed, but it wasn't so compact. I used a relative big (compared with Nano) Mega board, a 16x2 LCD, an Ublox GPS and an SD card and module to store the database. That time I received an unknown gadget from China, a NodeMCU board.
The components I used (see this eBay collection):
- NodeMCU board (CP2102 or CH340)
- 0.96" I2C OLED screen
- Ublox NEO-6M GPS module
- Single side universal PCB
- 250V, 500mA fuse and fuse holder
- a project box
- a panel mount power connector
- an USB to 5.5x2.1 power cable
- male-female single row header
- some small screws
- some sponge
Tools:
- a small manual scroll saw to cut the PCB
- a hand drill and bits
- some small files
- soldering device
- screw driver
As you can see, you don't need SD card and SD module.
Step 3: The NodeMCU Module
Browsing the net you can find a lot of good sites about the NodeMCU board and about it's programming. I'm unable to compete with them. Here you will find some things I learned in the last few weeks.
- It is based on an ESP8266 WiFi MCU. Hmmm. OK.
- All I/O works on 3.3 Voltage level!
- It can be feeded through the micro USB or Win by 5 V.
- It can be programmed using Lua, but can be programmed by Arduino IDE also. (More details from Magesh.)
- It has 4 MB memory. 1 MB for program and parameters and additional 3 MB SPIFFS.
- What a hack is SPIFFS and why am I unable to upload more than 1 MB program?
- SPIFFS is a file system where you can store files similar way as on an SD card. More details here.
- You can use I2C and SPI bus, or serial (and software serial) to communicate with NodeMCU.
- If you use Arduino IDE to program it (as I did), you don't need to flash the firmware.
Step 4: Other Components
I use an Ublox NEO-6M GPS module to check the current position of my car. It is an easy to use device.
Connection:
- Vcc to 3-5V supply of your MCU (e.g. Vcc of your Arduino or NodeMCU)
- GND to GND of your MCU (the common ground of your DC devices is essential)
- TX to software RX of your MCU
- RX to software TX of your MCU
The easiest way to test its work, to upload the NewSoftSerialExample to your MCU. Don't forget to set the mySerial speed to 9600 bps. Launching the serial monitor you can see the data from your GPS on your screen. When the blue LED blinks then your device connected to the satellites.
Using some string functions you can cut the info you need from this data, or you can choose the easiest way: use the TinyGPS (or the TinyGPS++) library. (In my code you will find TinyGPS.)
An instructable from MSuzuki777 about the details.
The last main component I use is a 0.96" 128x64 pixel OLED screen.
Connection:
- Vcc to 3-5V supply of your MCU (e.g. Vcc of your Arduino or NodeMCU)
- GND to GND of your MCU (the common ground of your DC devices is essential)
- SDA to SDA of your MCU
- SCL to the SCL of your MCU
You need two libraries to use the screen. A hw library (SSD1306 library) and a sw library (GFX library).
Here you can find a great step-by-step instructable from Jean0x7BE about the use of the OLED screen.
If your OLED shows only 32 rows instead 64, you have to modify the "Adafruit_SSD1306.h" file in the "Adafruit_SSD1306-master" library. See the picture in the header.
Step 5: Build the Hw
Prepare the PCB
- At first cut a piece from your single side prototype universal PCB, which fits into the project box.
- I cut it through the holes. The dimension is 37 columns (3,7"; 94 mm) and 22 rows (2,2"; 55 mm).
- Bore four holes into the PCB aligned with the screw holes of the project box.
- Place it into the project box (soldering side down), and try to align the components.
- USB of the NodeMCU next to the wall of the box.
- Screen aligned to the center of the box.
- Other components as you want. You can see my solution in the picture above.
- If you are satisfied with the component positions mark the holes you will use.
- After installing the power connector you need to cut a space for it from the PCB also.
Prepare the box
- Measure the USB position of your NodeMCU, and draw the needed cutting on the box wall from outside.
- Measure the position of the power connector and make a hole for it.
The connector I chose do not fits below the PCB. If you assembly it above the PCB, then you will be unable to take out the PCB, so I decided to assemble it near into the PCB height.
How to make holes into the box?
- I suggest at first measure and draw the position into you want to make a hole.
- After that independently from the final hole diameter make a small hole only. This can be made easily and it will position the bigger bore bit.
- If the the difference is to big between the first and the final bore bit's diameter you can use an intermediate bit also.
- After that use the bit which makes the desired hole diameter.
- Finally use a much bigger bore bit to cut the edge of the hole.
How to make cuttings into the box and the lid?
- Start here with the measuring and the sketch also. Work on the back side of the lid, so you will not scrape its face. You have to work on the outside of the box. Be careful!
- Choose a small bore bit (1-1.5 mm in diameter) and make holes next to each other as tight as you can following the sketch. The holes have to be in the material you want to remove.
- Use an exacto knife to cut through the remaining material between the holes and push out the material you don't need.
- Cut the big remaining unnecessary particles and finally shape the cutting by a file.
Step 6: Populate the PCB
Hack the fuse holder
The fuse holder is to high and don't fits into the projectbox.
- So cut the plastics from the fuse holder.
- Make two big holes into the PCB and put the metal components of the holder into it.
- Bend the pins to the PCB and solder it to the PCB
Hack the OLED screen
I use a male-female header to lift up the screen to the lid. The header is high enough to place the screen partially above the NodeMCU, but unfortunately the screen's PCB is in the height of the lid. I should reduce the height of the header, which wasn't easy. Instead I removed the plastic bar from the screen's pins. So I won about 2 mm, and the screen fits into the box.
I put some insulating tape to the bottom of the screen to eliminate shortcuts if the screen is pushed to the metal cover of the ESP8266 module.
According to the marks you made on the PCB put the components into it, and solder their legs.
- I suggest to shorten the legs of the MCU because using same box you have only 6 mm space between the PCB and the box. The legs are much longer you need to solder them to the PCB or to wires and cutting the legs you will have more space.
- After soldering the components connect the legs according to the schematic.
- Glue some sponge to the PCB which will support the screen.
- Connect the center of the supply socket to the PCB.
- Check the connections and remove the unwanted shortcuts to eliminate excess heat and black smoke. :-)
- Screw the PCB into the box.
Step 7: Awake Your Device
When your hw is ready you can start working on the sw.
- At first download the software (veda_06e.zip is the English version) and unzip it.
- Next to the "veda_06e.ino" which is the Arduino source file, you will see a "data" folder, with "poi_04.txt" in it.
- Connect the hw to your PC, and make the needed settings. Follow this instructable.
- Before launch the program you have to upload content of the "data" folder into the SPIFFS.
- Read through this site, and following the instructions upload "poi_04.txt" into the SPIFFS.
- Finally upload the program "veda_06e.ino" into the NodeMCU.
Connect the device to 5 V supply.
- At first you will see only the "GPS search" message.
- After some seconds a blue led will start blinking on the GPS module. It shows, the module synchronized with satellites and sends out valid data through its serial port.
- This time you will see one of the screens you can see in step1 depending of the POI distance.
Attachments
Step 8: The Software
The program is very simple.
- At first it reads the data from the GPS, and using the functions of TinyGPS library grabs parameters from the stream.
- After that it looks for the data of the nearest POI, and picks it from the database.
- Calculates the distance between the device and the POI.
- Depending on the distance the loop calls functions to write the info to the screen.
There is only one thing which needed some trials to find the right way to calculate the distance between two points.
I found a lot method on the internet. There were some, which gave relative good results in big distances, but were terrible in some kilometers. After some trial I found the stackoverflow forum and the "haversine" method which calculates good results in small distances also.
Step 9: The Database
You can see a print screen about the database in the picture above.
Each rows contains info about one POI. The columns are the next:
- Latitude of the POI.
- Longitude of the POI.
- Type of the POI.
- Highway ID.
- Name of the settlement in which the POI is (or which is near to the POI).
- Remark about the POI position. It is inside or outside the settlement.
Following this structure you can make your own POI database. You can remove or add POIs, or you can add other info to each POI (e.g. the allowed maximum speed).
After the modification don't forget to upload the new file into the SPIFFS.
You can see the POIs of the current database in a map here.
Step 10: What About the WiFi?
The core of NodeMCU is an ESP WiFi module. Of course I made trials with the WiFi also. Watching the program you can see commented lines and functions.
Before some program versions I programmed a WiFi access point into my device. The OLED screen is small, and there should be a lot of interesting GPS info which I wanted to see independently from the status of the OLED screen.
It worked, but wasn't firm enough. Sometimes freezed the MCU, another time was unable to serve the client, so I eliminated it from the sw. You can make trials wit it and I wait your solution if you will be able to do it.