ESP32 + analogRead()

The ESP32 is the new chip-on-the-block for Internet of Things, having both wi-fi and bluetooth. I have a breakout board from doit.am. They are coming down in price and can be found for under £7. This breaks out many(but not all) of the pins. I wanted to use a temperature sensor TMP36 and use analogRead() like in https://makerhacks.com/thermometer-esp8266-arduino/. That example was for the ESP8266.

However, being relatively new, the ESP32 does not support reading an analog input using that simple analogRead() that you find in the arduino ide.

Actually, I just worked out it dosen’t support analogWrite() at  the moment, analogRead() works fine. However, it gave me a chance to learn about other environments for the esp32.

So it’s off to download and install the “Espressif IoT Development Framework” https://github.com/espressif/esp-idf
esp32

Read the docs on ADC http://esp-idf.readthedocs.io/en/latest/api-reference/peripherals/adc.html

The ADC driver API currently only supports ADC1 (9 channels, attached to GPIOs 32-39).

The doit.am only goes to GPIO 35, so we have 4 to play with. Compiling and flashing the adc1_test, in /examples/peripherals/adc/main/adc1_test.c
ADC1_CHANNEL_4 is used, from the docs ADC1 channel 4 is GPIO32

<pre class="lang:c decode:true">/* ADC1 Example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>;
#include <string.h>;
#include <stdlib.h>;
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/gpio.h"
#include "driver/adc.h"

#define ADC1_TEST_CHANNEL (4)

void adc1task(void* arg)
{
    // initialize ADC
    adc1_config_width(ADC_WIDTH_12Bit);
    adc1_config_channel_atten(ADC1_TEST_CHANNEL,ADC_ATTEN_11db);
    while(1){
        printf("%d\n",adc1_get_voltage(ADC1_TEST_CHANNEL));
        vTaskDelay(1000/portTICK_PERIOD_MS);
    }
}

void app_main()
{
    xTaskCreate(adc1task, "adc1task", 1024*3, NULL, 10, NULL);
}

The analog read worked, but the temperature sensor was a bit funny. So I tested it with a rain-detector, which seemed to give reasonable results.

 

 

Been Quiet Here, hasn’t it.

Transitlab has always been the sometimes blog, the blog that i did when I have Time, Inclination and Energy. Thats why it has been so quiet. So few times has this been true. Don’t be surprised if there is a flurry of posts, as I clear backlogs of thoughts in journals and documentation of shows. I haven’t actually been so unbusy….my projects shows that I have been around a few places.

My idea is to try and make interesting, or if not interesting at least useful posts.

Topics I am interested in writing about are super varied. From machine learning to bio printing.

Actually, however I love research, so please leave a comment on something you are interested in, and I will see what I can do!