ESP320

From Electronic Sweet Peas
Revision as of 08:21, 1 November 2016 by Pontus (Talk | contribs) (Demonstration)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Esp-210-1-iso.png

Picture showing the ESP210, but the ESP320 looks pretty much the same... but cooler of course



Introduction

The ESP320 is an ESP32 based processor module with a USB transceiver, 3.3V voltage regulator (you can run it from 5v or the USB port), a 16MByte FLASH memory and a whopping 520KByte SRAM. It comes ready to go so to start playing with it you only need to plug it in to your computers USB port. The device will take all of its power from the USB port. The ESP32 also has a user definable LED on the board so you can start of by running your first blink test.

Information

The ESP32 micro controller

The ESP32 chip from Espressif is a fantastic little device. Here's a short brief with its most important features.

CPU and Memory

• Xtensa® Dual-Core 32-bit LX6 microprocessors, up to 600 DMIPS
• 448 KByte ROM
• 520 KByte SRAM
• 16 KByte SRAM in RTC
• QSPI Flash/SRAM, up to 4 x 16 MBytes
• Power supply: 2.2 V to 3.6 V

Clocks and Timers

• Internal 8 MHz oscillator with calibration
• Internal RC oscillator with calibration
• External 2 MHz to 40 MHz crystal oscillator
• External 32 kHz crystal oscillator for RTC with calibration
• Two timer groups, including 2 x 64-bit timers and 1 x main watchdog in each group
• RTC timer with sub-second accuracy
• RTC watchdog

Advanced Peripheral Interfaces

• 12-bit SAR ADC up to 18 channels
• 2 × 8-bit D/A converters
• 10 × touch sensors
• Temperature sensor
• 4 × SPI
• 2 × I2S
• 2 × I2C
• 3 × UART
• 1 host (SD/eMMC/SDIO)
• 1 slave (SDIO/SPI)
• Ethernet MAC interface with dedicated DMA and IEEE 1588 support
• CAN 2.0
• IR (TX/RX)
• Motor PWM
• LED PWM up to 16 channels
• Hall sensor
• Ultra low power analog pre-amplifier

Security

• IEEE 802.11 standard security features all supported, including WFA, WPA/WPA2 and WAPI
• Secure boot
• Flash encryption
• 1024-bit OTP, up to 768-bit for customers
• Cryptographic hardware acceleration:
– AES
– HASH (SHA-2) library
– RSA
– ECC
– Random Number Generator (RNG)

The USB transceiver

The ESP320 includes a Silabs CP2104 USB to serial transceiver with TX and RX connected to the ESP32 device. The outputs of the CP2104 are defined as open collector and have an internal weak pull up. This allows you to use the RX/TX signals of the ESP32 freely in your application. The CP2104 will not interfere when not used. The same applies to the RTS and DTR signals which are connected to the ESP reset and GPIO0 respectively.

The CP2104 allows you to load firmware into the ESP32 with speeds up to 921600 baud. This drastically reduces the time it takes to flash the ESP320 and when doing heavy development work this is a really nice to have feature. The module supports up to 430800 baud standalone and if you want to have the full 921600 bauds you need to connect a strong (4.7Kohm) pull up (to 3.3Volt) resistor to pin GPIO3.

A Linux quirk If you are developing code and connecting the ESP320 to a Linux computer you need to be aware on how Linux handles serial ports. By default Linux will pulse RTS while lowering the DTR line. This is a part of an ancient protocol to talk to a modem. For embedded systems this is normally not a problem since standard embedded systems will not have the RTS or the DTR lines connected to reset or any other pins to set the system in boot mode. On the ESP320 we do just that ! The RTS is connected to reset and DTR is connected to GPIO0 that determines the running mode it will enter when reset (RTS) is released. So by simply opening a serial port on Linux the ESP320 will go into programming mode.

If you are going to use the USB connection for anything else than programming you will need to address this. The simplest way to do this is to select a serial terminal software that can control RTS and DTR when the port has been opened. This way you can set both DTR and RTS to the correct states and the ESP320 will function normally. What I use is the Python program Miniterm which is an integral part of the pySerial library. The following line will start the terminal emulator, reset the ESP320 and start showing what comes on the USB line.

 python -m serial.tools.miniterm --rts=0 --dtr=0 --baud=115200 /dev/ttyUSB0

Mac/Windows Drivers

If you intend to connect the ESP320 to a windows machine or a Mac, you need to install the appropriate driver. Instructions and downloads can be found here: http://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx

If you are a Windows user and need a good and simple terminal software to log your debug prints we can recommend Termite (http://www.compuphase.com/software_termite.htm). This terminal works very well together with the ESP320. Just remember to set Flow Control to XON/OFF and you are good to go.

Power

The ESP320 can be powered in a few different ways, here's a list of different options:

  1. USB, when powered by USB the internal voltage regulator generates the required 3.3Volts.
  2. Pin 16, This pin can be used to supply the ESP320 with +5V. This pin is also connected to the VUSB (through a polyfuse) so be careful not to exceed 5V when having it connected to a USB port at the same time. If the ESP320 never gets connected to a USB port this pin can handle up to +7.5Volts.
  3. Pin 15, When the ESP320 is powered by a USB cable or by pin 16 this is an output containing +3.3Volts. This pin can also be used to supply the ESP320 with +3.3Volts. The supply must be +3.3Volts ±5%

When the ESP320 is powered through USB or Pin 16 it will get slightly warm. This is as it should be and comes from the on board linear voltage regulator.

GPIO and pinout

The ESP320 has essentially the same pinout as the ESP210, here's a table with all pins listed:

Pinout.png

Unlike the ESP210 the ESP320 does not have a 4.7 Kohm pull up resistor attached to GPIO2. Instead it relies on the internal pull ups found on the ESP32 device.

The board has an on board blue LED that is connected to GPIO5. The LED is controlled using normal logic, i.e. setting the port to 1 (HIGH) will light the LED and setting it to 0 (LOW) will turn the LED off. The LED is connected through a MOSFET driver which allows you to use the pin both as an input as well as an output pin. If you use the pin as an input the LED will show you the state of the pin which can be useful to debug your design.

Developing using the Arduino IDE

Not ready yet, but this is how we do it today. Pretty much the same as the ESP210 stuff.

You can also use the standard Arduino IDE to develop your software. For simplicity and stability we currently recommend that you use this way of working with the ESP320.

  • Make sure you have the Arduino IDE installed.
  • Open the preferences dialog. You will find this under "File->Preferences".
  • Enter the following URI in the "Additional Boards Manager URLs" field: http://xxxx.xxxxx.xxx and click on OK
  • Open Boards Manager from "Tools->Board" menu and install esp32 platform (This will take a few minutes)
  • Select the ESP320 board from the "Tools->Board" menu.

That's it. You are ready to rock. We have ourselves tested a number of Arduino libraries and so far everything seem to work much better than we anticipated.

To run the Arduino Blink example:

  • In Arduino IDE, select File->Examples->01.Basics->Blink
  • In the Blink file change the pin number from 13 to 5. (ESP320 has a blue led connected to pin 5).
  • Upload

As mentioned previously you can upload using serial speeds up to 921600 baud (with a pull up) which is very handy since the binaries tend to become quite big.

Over The Air (OTA) updates information

Not ready yet.

A quick note about using GPIO0 as SCL instead if GPIO14

In the case where you want to use both I2C and SPI in your application you need to move SCL to pin 0 instead of pin 14. This is because the SPI interface shares the clock signal (SCK) with the I2C interface.

All +One modules are prepared for this and can easily be reconfigured using on board solder jumpers.

When using Pin 0 (GPIO0) as SCL you will end up in a situation similar to that in the OTA case. When opening your host USB connection to the ESP320 device, the USB transceiver will pull the DTR signal low, creating a conflict with the SCL signal and corrupting your I2C transaction.

The solution to this problem is make sure you have a terminal software that does not pull the DTR low. The python miniterm terminal is a good choice for this.

Technical Specifications

  • Xtensa® Dual-Core 32-bit LX6 microprocessors, up to 600 DMIPS
  • 802.11 b/g/n Wi-Fi radio built-in
  • Bluetooth v4.2 BR/EDR and BLE
  • 16MB of Flash, 520 KB RAM
  • 11 Digital I/O Pins (interrupts on 10 digital pins)
  • 1 Analog Pin (Analog input 0 - 1Volt)
  • PWM on all Digital Pins (up to 6 active at a time)
  • Sleep and Deep Sleep modes for low power usage
  • Ability to read the voltage of its power source (for battery monitoring)
  • Board dimensions: 27.5mm x 17.8mm
  • Serial Speeds up to 921600 baud
  • Voltage Regulator: 3.3V max 800mA

Demonstration

This simple example shows you just how easy it is to connect the ESP320 to the internet.

/*
 * ----------------------------------------------------------------------------
 *            _____ _           _                   _
 *           | ____| | ___  ___| |_ _ __ ___  _ __ (_) ___
 *           |  _| | |/ _ \/ __| __| '__/ _ \| '_ \| |/ __|
 *           | |___| |  __/ (__| |_| | | (_) | | | | | (__
 *           |_____|_|\___|\___|\__|_|  \___/|_| |_|_|\___|
 *            ____                   _   ____
 *           / ___|_      _____  ___| |_|  _ \ ___  __ _ ___
 *           \___ \ \ /\ / / _ \/ _ \ __| |_) / _ \/ _` / __|
 *            ___) \ V  V /  __/  __/ |_|  __/  __/ (_| \__ \
 *           |____/ \_/\_/ \___|\___|\__|_|   \___|\__,_|___/
 *
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * <pontus@sweetpeas.se> wrote this file. As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return - Pontus Oldberg
 * ----------------------------------------------------------------------------
 *
 *  This sketch simply retrieves tha content of a static test page on our
 *  SweetPeas web site.
 *
 */
 
#include <WiFi.h>
 
const char* ssid     = "your-network";
const char* password = "your-password";
 
const char* host = "www.sweetpeas.se";
const char* url = "testdata/test.txt";
 
void setup()
{
    pinMode(5, OUTPUT);
    digitalWrite(5, LOW);
    Serial.begin(115200);
    delay(10);
    WiFi.mode(WIFI_AP_STA);
 
    // We start by connecting to a WiFi network
 
    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);
 
    WiFi.begin(ssid, password);
 
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
 
    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
}
 
int value = 0;
 
WiFiClient client;
const int httpPort = 80;
 
void loop()
{
    delay(5000);
    ++value;
 
    Serial.print("connecting to ");
    Serial.println(host);
 
    // Use WiFiClient class to create TCP connections
    if (!client) {
      Serial.println(F("Client not connected, connect to host"));
      if (!client.connect(host, httpPort)) {
          Serial.println("connection failed");
          return;
      }
    } else 
      Serial.println(F("Client connected"));
 
    Serial.print("Requesting URL: ");
    Serial.println(url);
 
    digitalWrite(5, HIGH);
    // This will send the request to the server
    client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                 "Host: " + host + "\r\n" +
                 "Connection: close\r\n\r\n");
    unsigned long timeout = millis();
    while (client.available() == 0) {
        if (millis() - timeout > 10000) {
            Serial.println(">>> Client Timeout !");
            client.stop();
            return;
        }
    }
 
    // Read all the lines of the reply from server and print them to Serial
    while(client.available()) {
        String line = client.readStringUntil('\r');
        Serial.print(line);
    }
    client.stop();
 
    Serial.println();
    Serial.println("closing connection");
    digitalWrite(5, LOW);
}


Downloads

Nothing here yet

Tips, Tricks and useful links

Nothing here yet.