Hi
I am new to both Blynk and ESP8266. My programming level is Novice
I have managed to setup a project to measure waterflow temperature and humidity and send data to a Blynk device dashboard. I included a button to reset the data and packaged it into a 3D printed case. It works and is ready to be very useful for monitoring mainly water consumption on my Narrowboat.
My issue is I discovered the WIFI provisioning project after I completed and packaged my little device and would like to add that functionality to the project but using the existing button. Is it possible?
Wemos d1 mini v3 (cheap copy)
OLED on pin D1 and D2
Flowsensor on D6
DHT22 sensor on D5
Reset button on D0. Pull down resistor connected to ground goes high when button pressed. After 2 seconds of being pressed the data from the sensors is set to zero so the OLED screen reads zero and the Blynk dashboard is also zeroed.
The Edgent sketch for the 8266 suggests adding a button to GPIO0 that goes to ground when pressed but in order to do that I would need to remake my circuit and redesign the 3D printed case to accomodate the extra switch.
Aside from changing line 12 in Settings.h to digital pin D0 can anyone point me to the lines in the ResetButton. h that I would need to amend.
Very simple. The Settings.h tab of your project allows you to define this. In your case you’d set #define BOARD_BUTTON_ACTIVE_LOW to false …
#if defined(USE_NODE_MCU_BOARD) || defined(USE_WEMOS_D1_MINI)
#define BOARD_BUTTON_PIN 0 <<<< The FLASH Button
#define BOARD_BUTTON_ACTIVE_LOW true <<<< Pressing the button pulls the pin LOW
#define BOARD_LED_PIN 2 <<<< The LED is connected to GPIO2 (D4)
#define BOARD_LED_INVERSE true <<<< The LED lights when the pin is LOW
#define BOARD_LED_BRIGHTNESS 255 <<<< Make the LED shine at max brightness when lit
Gosh
I am blown away by the speed of response. Thank you very much.
I have seen and read the trouble shooting guide several times. I have loaded the standard sketch and reset the board with a jumper and it all works fine as explained in the guide.
I just could not get my head around what was happening in the button_change(void) function. The use of the Logical NOT ! with the digitalRead was new to me.
Thanks again for the help and for making all of this stuff accessible for people like me with limited knowledge.
Yes, the logical NOT is not very intuitive (no pun intended), but is extremely powerful. It’s also very easy to miss when scanning through code, so it’s a good idea to add some narrative in the comments when you’re using it.
But that doesn’t work yet, did I have to change anything in ResetButton.h ?
For confirmation. The WIFI provisioning works correctly if I keep the sketch standard and reset with a jumper on D3 (GPIO0). It doesn’t reset if I make the above change.
I know I have D0 correctly connected as I can measure it high when pressed with a multimeter and it works fine with my own project sketch.
Pete
I am using the standard Edgent_ESP8266 sketch from the examples page of the IDE
I edit the Edgent_ESP8266.ino tab to #define USE_WEMOS_D1_MINI and add Template ID and Device name.
With no other changes I upload the sketch and prove it works by resetting the board with a jumper on GPIO0. Works correctly.
Then edit the settings tab and upload the edited version. No other changes. The board does not reset using the button on D0. And just to confirm does not reset if I use a jumper on GPIO0
* Board configuration (see examples below).
*/
#if defined(USE_NODE_MCU_BOARD) || defined(USE_WEMOS_D1_MINI)
#if defined(USE_WEMOS_D1_MINI)
#warning "This board does not have a button. Connect a button to gpio0 <> GND"
#endif
#define BOARD_BUTTON_PIN D0
#define BOARD_BUTTON_ACTIVE_LOW false
#define BOARD_LED_PIN 2
#define BOARD_LED_INVERSE true
#define BOARD_LED_BRIGHTNESS 255
#elif defined(USE_SPARKFUN_BLYNK_BOARD)
#define BOARD_BUTTON_PIN 0
#define BOARD_BUTTON_ACTIVE_LOW true
#define BOARD_LED_PIN_WS2812 4
#define BOARD_LED_BRIGHTNESS 64
#elif defined(USE_WITTY_CLOUD_BOARD)
#define BOARD_BUTTON_PIN 4
#define BOARD_BUTTON_ACTIVE_LOW true
#define BOARD_LED_PIN_R 15
#define BOARD_LED_PIN_G 12
#define BOARD_LED_PIN_B 13
#define BOARD_LED_INVERSE false
#define BOARD_LED_BRIGHTNESS 64
#else
#warning "Custom board configuration is used"
#define BOARD_BUTTON_PIN 0 // Pin where user button is attached
#define BOARD_BUTTON_ACTIVE_LOW true // true if button is "active-low"
#define BOARD_LED_PIN 4 // Set LED pin - if you have a single-color LED attached
//#define BOARD_LED_PIN_R 15 // Set R,G,B pins - if your LED is PWM RGB
//#define BOARD_LED_PIN_G 12
//#define BOARD_LED_PIN_B 13
//#define BOARD_LED_PIN_WS2812 4 // Set if your LED is WS2812 RGB
#define BOARD_LED_INVERSE false // true if LED is common anode, false if common cathode
#define BOARD_LED_BRIGHTNESS 64 // 0..255 brightness control
#endif
/*
* Advanced options
*/
#define BUTTON_HOLD_TIME_INDICATION 3000
#define BUTTON_HOLD_TIME_ACTION 10000
#define BUTTON_PRESS_TIME_ACTION 50
#define BOARD_PWM_MAX 1023
#if !defined(CONFIG_DEVICE_PREFIX)
#define CONFIG_DEVICE_PREFIX "Blynk"
#endif
#if !defined(CONFIG_AP_URL)
#define CONFIG_AP_URL "blynk.setup"
#endif
#if !defined(CONFIG_DEFAULT_SERVER)
#define CONFIG_DEFAULT_SERVER "blynk.cloud"
#endif
#if !defined(CONFIG_DEFAULT_PORT)
#define CONFIG_DEFAULT_PORT 443
#endif
#define WIFI_CLOUD_MAX_RETRIES 500
#define WIFI_NET_CONNECT_TIMEOUT 50000
#define WIFI_CLOUD_CONNECT_TIMEOUT 50000
#define WIFI_AP_IP IPAddress(192, 168, 4, 1)
#define WIFI_AP_Subnet IPAddress(255, 255, 255, 0)
//#define WIFI_CAPTIVE_PORTAL_ENABLE
#define USE_TICKER
//#define USE_TIMER_ONE
//#define USE_TIMER_THREE
//#define USE_TIMER_FIVE
//#define USE_PTHREAD
#define BLYNK_NO_DEFAULT_BANNER
#if defined(APP_DEBUG)
#define DEBUG_PRINT(...) BLYNK_LOG1(__VA_ARGS__)
#define DEBUG_PRINTF(...) BLYNK_LOG(__VA_ARGS__)
#else
#define DEBUG_PRINT(...)
#define DEBUG_PRINTF(...)
#endif
The code is the entire settings.h tab.
Do you still want the .ino tab?
Okay, I’ve figured-out what’s happening here.
GPIO16 (Pin D0) doesn’t work with interrupts, and the Edgent sketch uses interrupts to detect the button presses.
So, it’s not the active HIGH/LOW that’s the issue but your choice of pin.
I really appreciate your help on this. Can you point me at the resource that informed you on this issue?
I guess I could move the button to gpio0 and then rewrite my own bit of code in my sketch to look for the pin going low instead of high.
It might take me awhile to work that out given my limited knowledge.
I think I will deploy my working version without Wi-Fi provisioning and then start again and do it properly from scratch. I will need to reorder all the components but it’s only about £20 and it’s easily worth it.
This is proving a challenging but very informative project.
It could be weeks before I catchup but I would be grateful if I could post again if I get stuck.
Thanks again for the helpful responses
I don’t really understand this comment, do you wnat to elaborate?
From your initial post you seem to want to add quite a bit of hardware yo your D1 Mini…
and you will also benefit from an LED to indicate the provisioning state.
As you’ll see from the link I provided, the D1 Mini/NodeMCU has limited useable pins, and you’re reaching that limit. You may be better switching an ESP32, as it has many more useable pins without a massive increase in form-factor. This would also give you scope for expansion in the future.
Also, the DHT range of temperature/humidity sensors are awful, so you might want to reconsider this choice. Given the environment that this will be working in, you might want to think about using the waterproof version of the SHT30 sensor but this uses an I2C interface, which requires two pins.
Pete,
That random nerds link is awesome. I wish I had read that before starting. It answered several problems that I ran into on the way.
I seem to have caused some confusion so I will try to make it clearer what I am trying to achieve. Who knows maybe someone else could use a similar project.
My goal was to have a means to monitor water consumption on a Narrowboat so that I know when I need to refill the tank…
As it stands I have a working project that will display water consumption on the OLED screen. It also connects to a Blynk dashboard and displays the info on my Iphone. When I refill the water tank I can hit the reset button and zero the data. Initially that was all I wanted to do. I added the DHT just because there were available pins to do it and I already had an OLED to display the data. I don’t live on the boat so It might be useful to know remotely when the onboard temperature is around zero in the winter so I can go and check things are OK and I can do that with the dashboard on the phone.
When I came across the wifi provisioning project I thought it would be a really useful addition but I had already packaged up the project in an enclosure designed to fit into an existing opening in a panel on the boat. This meant it would difficult to add another button to the enclosure hence my question about if it would be possible to use the existing button on my board to reset the wifi.
I confused you with my comment about moving the button.
What I was thinking was I could use the Edgent.ino sketch unaltered if I disconnected button from D0 and instead connected it to GPIO0. I was amused reading the above link that I managed to chose the only pin that didn’t support interrupts
I could then cut and paste my code into the Edgent sketch. However I would then need to change the coding for the button in my part of the sketch.
I don’t want to add anymore hardware to the project but I do want to add the wifi provisioning capability.
My circuit is assembled on proto perf board and it is scruffy and confused. Because of the way I have assembled it the onboard led is not visible outside the enclosure .
In conclusion I am going to take your advice and start again.
I will use an ESP32 and SHT30 as you suggest. But this time I will design the circuit properly and but it on a PCB and redesign the enclosure to incorporate an led as well as a pushbutton . Even then the enclosure will probably be half the size of what I have got now.
Once more thanks for the responses you have given. Much appreciated.
Have you thought about using an ultrasonic distance measuring system for checking the water level in the tank?
A bit more reliable than monitoring the flow and using dead-reckoning. Lots of examples of people who have built Blynk projects using this technology.
Personally, I do like to have everything on a PCB and have it all modular so that the ESP dev board can be easily swapped out, and connectors are used for all of the peripheral connections. They’re dead cheap to order from places like JLCPCB, and the EasyEDA software is easy to use.
This is an example of a board I made to monitor my solar charge controller. Although you can’t see it from the photo, the Wemos and the other boards are all socketed so you can easily swap them out…
Pete
Yes I thought about ultrasonic. The tank on the boat is built under the deck. No access unless you start dismantling internal fittings. Its a 150 gallon stainless steel box with a 50mm inlet which leads to a fill cap on the deck. A bit like a petrol filler on a car. You know when its full because water starts over flowing the filler so no space inside the tank for sensors. The outlet is 15mm. In transit water would be sloshing around and even just moving about the boat would disturb the level. Canal boats do have little collisions with things which would also slosh water about quite vigorously. I know that can be dealt with in code.
The flow sensor is a very simple solution as I just need to tap into the 15mm outlet pipe. I have tested it and after tweaking the calibration factor it seems pretty accurate.
I would never bet my life on it and there is always the fail safe which is if I can see my cathodes at the waterline I know my tank is low on water.
I like the look of your Charge control monitor.
That is the next project on my list. A solar dump that could heat some water when the batteries are full but the sun is still shining.