Yes, I am also upgrading the Data Logger Stage. This is the last entry for this challenge as it involves all hardware/software debugging. These to parts are merged to create a unity, a system!
I am changing some of the components. To be honest with you, a physical data logger was very interesting to star with, but we are in the IoT era! Hence, here is the components list for this stage:
- 1 x FireBeetle (ESP32)
- 1 x Current sensor (ACS712-30A)
- 1 x 1 kOhm resistor
- 1 x 120 Ohm resistor
- Blynk app installed in your phone!
You can use all documentation available on my previous logs to create the voltage divider and to calibrate the current sensor. I will comment here all changes needed in order to transfer your code from a conventional Arduino (or similar) to the ESP32.
Hardware changes
The ESP32 has very nonlinear ADCs (Analogue to Digital Converter) despite of a greater resolution (12-bit or 4096 div). I had a very big headache trying to get reliable readings until I realised that the ADC was not working like the Arduino one. I measure the maximum voltage allowed for analog measuring and was 3.14V, not 3.3V. I would recommend you to read the Espressif ADC documentation (just in case).
My test circuit was just a voltage divider, but I added two extra components, a first-order-filter and multiple sampling (image below):
Here are the input parameters:
- Vin -
- Vout -
- R1 - 1KOhm
- R2 -
- R3 - 10 KOhm
- C - 10nF
After these changes, readings were very stable, so I defined a "true voltage" calibration function and also implemented it in the code. The spreadsheet can be downloaded from GitHub. I have to point out that voltages below 0.114V were not considered by the ADC.
The current sensor requires 4.5 - 5.5V. My power banks were providing 5.016V but only around 4.3V were provided to the sensor as I had a diode for the DPDT (diagram here). The sensor worked just fine, but the reading from the module MUST go through the calibration function first (to avoid any painful headache).
Another thing I had to change in the hardware was the addition of voltage dividers for the LDRs readings. Unfortunately, I had them connected directly with the lights, so the voltage supplied was 5V instead of 3.3V.
Software changes
First of all, I planned to incorporate Blynk on my setup, so the bike rider will experience something similar to a car dashboard. Here is my dashboard setup:
I wanted to have:
- The power generated transmitted through BLE (Bluetooth Low Energy)
- The linear speed retrieved from the phone GPS sensor.
- LEDs to show that indicators, break light and beam light are ON/OFF
- The chance to switch ON/OFF the beam light manually any time and adjust the brightness.
Anything is possible with this app and your imagination. I encourage you to build something completely different and at your own choice, something that only you will find useful. That is why I chose Blynk!
After testing most of the codes regarding Blynk, sensors and light system separately, I finally created a unique file: imPulseMain. I had several issues with the ESP32 and now I understand why it is categorised as a developing board. No worries, all of them are listed in the code:
- FastLED library was not working properly until #define FASTLED_ALLOW_INTERRUPTS 0 was declared. I almost give up on this until I found the issue here.
- Interrupts are defined in a different way. This post was very useful.
- D2 and D3 in the ESP32 used in conjunction with interrupts is a VERY BAD idea. The interrupt count went crazy when D2 was enabled and the board was not able to reset (RST) when D3 was used.
- Some of the D/O (Digital Output) cannot send a LOW signal. It does not matter what you do.
However, the good news are that I managed to make everything work. Still minor bugs but will be fixed in future releases in conjunction with software upgrades:
- PID controller for LDRs
- Addition of the other two LDRs
- Startup protocols
- Hardware diagnosis
Now, the final video!
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.