Hi, I would like to ask for advice about the implementation of code for my application.
I have an ESP32 mcu with Arduino, a Notecarrier and Notecard and a ultrasonic level sensor (A02YYUW Waterproof Ultrasonic Distance Sensor (3~450cm, UART, IP67) - DFRobot). I need the ESP32 and sensor to be in powered down and only power it once a day at 04:00h in the morning to make a water level measurement, transmit data and power down again.
Can you give me advice about the implementation/Arduino sketch for this?
This shows how the code is structured when booting the host MCU based on Notecard ATTN pin state. It also shows how to power down the host MCU via the call to the Notecard to change the state of the ATTN pin.
This may be a bit more sophisticated than what you’re looking for, but it has a lot of the components you’d look for in this type of application.
Notecarrier F Switch
Be sure to flip the ATTN pin switch to enable the Notecard to control the power to the host MCU.
Sensor Power
You may also want to cut the power supply to the sensor when the host MCU is off. According to the link you provided, the sensor supports 3.3V as a supply.
Looking at the schematic for the Notecarrier F
The ATTN pin control F_BAT voltage which broken out to the Notecarrier F headers. I didn’t check the current draw of the sensor, but if it’s too much, you may need a secondary converter wired to the battery that’s enabled by the ATTN pin. The ATTN pin is also broken out on the Notecarrier F headers.
Scheduling 4 AM measurements
The Notecard doesn’t have a way to wake up the host at a specific time, though that seems like a good feature request.
Prior to putting the host to sleep, use the card.time request to get the current time, and compute the number of seconds until the next 4AM, and use this as the input number of seconds the host MCU should sleep for. This may actually be the trickiest part of the whole application.
Remember the card.time request won’t return the time if it doesn’t have the Unix Epoch available yet, so you’ll need a strategy for resets of the device, and decide if you want the application to measure on device reset, or only at the selected interval.
Also card.time is in UTC. It does return an offset in minutes to compute the local time if you want to use 4AM local time. The local time offset is estimated from Notecard location. This will generally be based on cell tower location estimate (there are rare cases where the cell tower location will be wrong just because the information returned by the database lookup is wrong, so you may want an override mechanism in the Notecard environment variables to set the time zone offset manually if it’s way off)
Diagnostics
I recommend either using the hub.log request, or create your own Notefile to send some host MCU application diagnostics to the Notehub. That way when you’re device is behaving weird, you have some info about the behavior without needing to physically retrieve the device.
Host Firmware Updates
I recommend investing in enabling this feature prior to deploying the hardware. If you discover you need to change the host MCU firmware, and it’s not readily accessible, this will slow progress substantially. We’ve had other users in this situation before
It looks like you have an older Notecarrier F, but it does have the outboard DFU capabilities!
Use the switch labelled DFU, and make sure it’s pushed to “ON” side.
IMPORTANT
It is still possible to perform host firmware updates without these connections. But it requires the host MCU to manage it’s own update process. It can grab the bytes from the Notecard over it’s communication connection with the Notecard and install them manually.
So you don’t have to use this wiring to enable firmware updates, but it does make it easier from the point of view of developing the host MCU application.
Please find attached my code. I was hopping it would transmit data and power down my Feather board until 24 hours past by and does the measuring again. But it does not power down my Feather. What is wrong with my sketch?
Nothing is jumping out as a problem in the Sketch code.
Please check to make sure that
The Feather does not have a USB cable plugged in
The Notecarrier F Feather PWR switch is set to “switched”
USB Power
For (1), the power from the USB connector on the Feather bypasses the power supply that’s controlled by the ATTN pin on the Notecard.
If you want to output debug information from the Feather, use a F_RX/F_TX pair from the Feather with a USB<—> UART converter (usually an FTDI chip of some kind). For that you will need to set the debug serial in your sketch to be a different serial port. The Serial port you select depends on which Feather you are using.
Feather PWR Switch
This switch is set to either continuously provide power to the Feather, or only enable power when the Notecard ATTN pin is high.
To test if this pin is doing what it should be, I recommend following a procedure like the following:
Find the Blink LED example for your Feather MCU.
Compile, download, and run the Blink LED example for your Feather
Verify the LED on the Feather is blinking
Remove the USB from the Feather (if one is plugged in)
Plug a USB into the connector on the Notecarrier F with a Notecard installed
(if one is already plugged in, remove it, and all other power sources, then plug the USB back into the Notecarrier F. We want the Notecard to boot for this to be reproducible.)
Enter the following request in the terminal prompt {"req":"card.attn"}
The response should include the pair "set": true in the response
Enter the following request to set the ATTN pin low for 7 seconds {"req":"card.attn","mode":"rearm","seconds":7}
The response should not include the "set" field. The LED on the Feather should be off, and not blink.
Wait for 7 seconds
Verify the Feather has rebooted, and the LED is now blinking.
If that procedure does not cause the LED on the Feather to stop blinking, change the state of the Feather PWR switch on the Notecarrier F, and repeat steps 9 through 11
(it’s possible I have the state definitions flip-flopped )
Thank you very much. I want to switch fron Notecarrier F to notecarrier A. Does something change? Can you sketch a connection diagram of the MCU and notecarrier? Thank you very much!