Home ESP32 Accessing various ESP32 functionality using Micropython

Accessing various ESP32 functionality using Micropython

by shedboy71

In this article we look at some of the features of the ESP32 and how you can use these in Micropython.

In particular we focus on the internal hall sensor, internal temperature and the touch pad functionality that is available on various pins.

 

Parts Required

The good news is that to try the examples out you do not need any external components just a board, we used a Lolin32

Name Link
LOLIN32 ESP32 WeMos Mini D1 LOLIN32 ESP32

 

Hall Sensor

A Hall effect sensor is a device that is used to measure the magnitude of a magnetic field. Its output voltage is directly proportional to the magnetic field strength through it.

Hall effect sensors are used for proximity sensing, positioning, speed detection, and current sensing applications.

The ESP32 is able to measure the magnitude and direction of magnetic field around the chip but it is not very accurate

Code

I used Thonny for development

[codesyntax lang=”python”]

import esp32
import time

while True:
   print (esp32.hall_sensor())# read the internal hall sensor
   time.sleep(0.5)

[/codesyntax]

Output

In the REPL windows you should see something like this

141
143
143
144
145
143
139
141
138

Touch

Small numbers are common when a pin is touched, larger numbers when no touch is present. However the values are relative and can vary depending on the board and surrounding composition so some calibration may be required.

There are ten capacitive touch-enabled pins that can be used on the ESP32 these are pins 0, 2, 4, 12, 13 14, 15, 27, 32, 33.

Code

I used Thonny for development

[codesyntax lang=”python”]

from machine import TouchPad, Pin
import time

t = TouchPad(Pin(14))
while True:
   print (t.read())# Returns a small number when touched
   time.sleep(0.5)

[/codesyntax]

 

Output

This is what you should see in the REPL window

539
431
374
337
312
293
306
124
82
66

Link

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/touch_pad.html

Internal Temperature

You can read the internal temperature of the ESP32, which may be handy if the chip was to start overheating but remember the temperature will be very different from the external environment

Code

I used Thonny for development

[codesyntax lang=”python”]

import esp32
import time

while True:
   print (esp32.raw_temperature())# read the internal temperature of the MCU, in Farenheit
   time.sleep(0.5)

[/codesyntax]

Output

This is what you should see in the REPL window, as stated do not worry about the high value, this is the internal temperature of the chip

118
118
118
118
118
118

You may also like

Leave a Comment