Overview
The ESP32C3 6 channel ADC is a flying hat for the Raspberry Pi family of boards. Flying means it can be disconnected from The Raspberry Pi and placed anywhere within WiFi range. Since it can be seperate from the Raspberry Pi, it is the perfect hat for your RPi 400. Th 12 bit ADC has a factory calibration that enables it to reach a precision in the range of 1 to 2%. In addition an on-board 1.25V reference can be used to further increase the accuracy. All Raspberry Pi GPIO pins are free for other uses, the ESP32C3 communicates wirelessly with the RPi over a UDP WiFi channel.
Additional resources on the ADC board include:
- 3 GPIO (outputs by default) can be reprogrammed to any functions supported by the ESP32C3 (In/Out/I2C/Serial/PWM
- One buffered DAC output with a default resolution of 8 bits.
- A battery interface.
- A resistor divider to measure battery voltage.
- A thermistor to measure temperature.
- A reset button.
- 2 user LEDs
- 4 power sources.
- Over-The-Air (OTA) firmware upgrade.
The ESP32C3 ADC hat comes with a pre-installed Arduino sketch that provides basic functionality. It is designed to auto connect with a Node-Red flow running on the Raspberry Pi. The software features include:
- Use of factory calibration to correct the raw ADC data on all channels.
- Average of 16 samples per ADC channel to eliminate noise.
- Programmable delay between sample bursts.
- Auto Hot-Spot to enter WiFi credentials if the WiFi connection fails.
- WiFi SSID and Password saved in EEPROM.
- Auto connect to the Node-Red flow.
- Auto reporting of ADC channel values.
- Over-The-Air firmware updates.
- UPD communications.
Power
The ESP32C3 6 channel ADC ha 4 possible power source.
- Raspberry Pi +5V and ground on the 40 pin connector. Pass-through headers are provided in the kit for these pins and the adjacent ones. This power source also charges the battery.
- A power only USB connector. This power source also charges the battery.
- A Lithium-Polymer battery connector. The maximum charging current is 74mA, rapidly diminishing as the battery voltage rises. Only batteries with integrated protection circuitry can be connected to this port.
- Power from the programming connector. Pin 4 of this connector accepts +3.3V. If power is connected to this pin, all other power source must be disconnected. The ESP32C3 can have bursts of over 300mA when transmitting. Some USB to serial converters cannot supply such current.
Inputs and Outputs
Battery and Temperature Measurements
To measure the battery voltage place a jumper between the BAT and the CH2_0 terminals. Multiply the results by 9.333 to obtain the battery voltage.
To measure the temperature, place the jumper between the C° and Ch2.0 terminals.
The thermistor’s characteristics are:
NTCG164LH104HTDS Electrical Characteristics
Resistance [at 25°C] |
|
Resistance Tolerance |
|
B value (Typ.) [25/50°C] |
|
B value (Typ.) [25/85°C] |
|
B value (Typ.) [25/100°C] |
|
B value Tolerance |
|
Max. Electric Power [at 25°C] ? |
|
Permissive Operating Current [at 25°C] ? |
|
Thermal Dissipation Constant [at 25°C] ? |
|
The Rth1( thermistor) value= (Vch2.0 x 100K) / (3.3V – Vch2.0)
The temperature can be calculated as follows:
float temperature;
#DEFINE R0 100000 // 100K
#DEFINE B0 4485 // up to 50C
temperature = Rth1 / R0; // (R/Ro)
temperature = log(temperature); // ln(R/Ro)
temperature /= B0; // 1/B0 * ln(R/Ro)
temperature += 1.0 / (25 + 273.15); // + (1/To) in kelvin
temperature = 1.0 / temperature; // Invert
temperature -= 273.15; // convert Kelvin temp to C
ADC2.0 can be used for other measurements its range is 0 to 2.5V. it cannot be configured for bipolar or higher voltages as are the ADc1 channels.
Note: ADC2.0 is sampled 16 times before the average is calculated. By default this takes 2:40 minutes.
ADC1 Channels 0 to 4
By default, these channels have a 10nF input filter capacitor and can accept a voltage of 0 to 2.5V.
Many possible configuration of these inputs are possible. Please see this link for a detailed explanation.
1.25V Reference
The reference can be used to power sensors or to re-calibrate any of the ADC channels. Note that there is a 82 ohms resistor in series with the output to protect against static discharges.
DAC
GPIO6 of the ESP32C3 is buffered and filtered by an Op-Amp. By default, the 8 bit AnalogWrite function is enabled on this output. Higher resolutions are possible.
GPIO 7 – 18 -19 LEDs
These are programmed as regular outputs. They can be re programmed with other functions. Two LEDs are defines as LED and LED2.
WiFi Communications with the Raspberry Pi
ESP32C3 ADC listens on UDP port 5044 and transmits to the Raspberry Pi on UDP port 5045. You will need a Raspberry Pi running Node-Red on the same network as the ESP32C3 ADC and our ADC flow, that can be found on GITHUB https://github.com/Seenov/Raspberry_Pi_ADC_HAT . 2 files are needed the flow file: NODE-RED.json and the list of modules file: package.json. If you do not know how to install this file, go to manage pallette in the flow menu and add all modules listed in the package.json file.
The first thing the RESP32C3 ADC does, after booting up, is to try to connect to a WiFi network. If it cannot connect, it will turn itself into a Hot-Spot (Access-Point).
Using a smartphone, find the network called ADC_xxyyzz, where xxyyzz are the ESP32C3’s 3 last mac address digits, and connect to it (no security required).
Open the smart phone’s web browser and go to page 192.168.4.1 and enter your networks SSID and Password. The ESP32C3 ADC will now connect to your network. The ESP32C3 ADC listens on UDP port 5044 and transmits to the Raspberry Pi on UDP port 5045.
Go to the Node-Red flow dashboard and open the Add Device tab (top left menu). Give your device a name and the type MUST be ADC1. Hit the find button and Node-red will do it’s magic. It will find its IP, generate the broadcast address and send out a message. The ESP32C3 ADC will receive the message, extract the source IP and start sending value updates to the Node-Red flow. The flow will signal it has found the device, extract the IP and peer-to-peer communications will be enabled.
The flow menu items are:
- Home – received ADC values
- Settings – change ADC settings
- Add device – add one ADC1, more are planned
- OTA – upload new firmware to the ESP32C3 ADC
- Documentation
Programming
The ESP32C3 ADC sketch was developed using Arduino 1.8.19. Arduino 2 has not been tested yet.
There are 2 ways to program the ESP32C3 ADC.
The first is using to OTA function. create and test your software and save the output .bin file where you can find it. Go to the Node-Red dashboard and select the OTA menu (top left). Hit the Start button. With a web browser go to http://esp32c3_adc.local page. The user and password are: admin admin. You will be directed to select a .bin file and start the update. Once to update is completed, the ESP32C3 ADC will reboot and start the new firmware. IMPORTANT: You must include the OTA functionality in your code or future over-the-air updates will not be possible.
The second way is to use a USB to serial converter and connect it to the programming header. Note that some USB to serial converters cannot provide enough power for the ADC board.
IMPORTANT: TxD of the ADC is connected to RxD of the adapter and RxD of the ADC is connected to TxD of the adapter.
Connect the serial to USB adapter as shown below:
Soldering
The ESP32C3 ADC uses a low temperature solder for the reflow of SMD components. Regular solder is used for the terminal blocks.
Durafuse™ LT
Durafuse™ LT is a patented low-temperature alloy system designed to provide high-reliability in low-temperature applications that require a reflow temperature below 210°C.
Durafuse™ LT provides improved drop shock resilience, outclassing bismuth-tin (BiSn) or bismuth-tin-silver (BiSnAg) alloys, and performing better than SAC305 with optimum process setup. Durafuse™ LT is made up of a low-melting indium-containing alloy and a higher-melting SAC alloy. The SnInAg alloy initiates joint fusion while the SAC alloy provides enhanced strength and durability. Durafuse™ LT is ideal for high-reliability applications, which utilize thermally sensitive components or boards and/or have a requirement for step soldering.