From ArduinoInfo
Revision as of 07:55, 1 February 2019 by TerryKing (talk | contribs) (Created page with "From Idahowalker *** Full Member Posts: 181 Karma: 8 [add] Logged Re: ESP32 Arduino Woes Serial on the ESP32: Ther...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search



Full Member Posts: 181 Karma: 8 [add] Logged

Re: ESP32 Arduino Woes

Serial on the ESP32:

There are 4 serial ports Serial, Serial1, Serial2, Serial3

Serial3 is on GPIO pins 9,10 ( see above ). Serial is on pins GPiO 1 and 3 used to communicate with the monitor and flash, native, do not use Serial2 is on pins GPIO 16,17 Serial1 is on GPIO pins 12, 13

Define your serial ports in the following fashion to use them:

  1. include <HardwareSerial.h>

HardwareSerial SerialTFMini( 2 ); HardwareSerial SerialGPS( 1 ); //// serial(1) = pin12=RX, pin13=TX //// serial(2) = pin16=RX, pin17=TX Serial and Serial3 can be redefined and used, with the ESP32 API. Serial is used for the monitor, Serial3 native is shared with a flash pin.

Both serial ports (1,2) can be used at the same time.

ALso, look into using freeRTOS, it is native to the ESP32 and allows tasks to be assigned to a spicific core.

There are 2 SPI ports, HSPI and VSPI. Both can be used at the same time. Default SPI is VSPI and does not require declaring to use.

// Serial.println(MOSI); // 23 Master Out Slave In, SDI, DIN

// Serial.println(MISO); // 19 Master In Slave Out, SDO
// Serial.println(SCK); // 18 Clock
// Serial.println(SS); // 5 Slave Select, Chip Seclect

For those libraries that take a SPI port as a input parameter HSPI is the one to use.

Such as the MPU9250 Bolderflight 9250 library: //SPIClass SPI0(VSPI); SPIClass SPI1(HSPI); // HSPI: CS 15, MOSI 13, MISO 12, SCK 14 // MPU9250 IMU( SPI1, 15 ); MPU9250FIFO IMU( SPI1, 15);

// Wire.setClock( 100000 ); Wire.setClock( 2000000 ); // should use pullups << wire runs real well at this speed on the ESP32 //Wire.setClock( 3400000 ); // pullups needed

Adafruit libraries like to give Guru Meditation errors.

Run the A:D converters using the ESP32 API for stable operations.

  1. include <driver/adc.h>

in setup: // // set up A:D channel adc1_config_width(ADC_WIDTH_12Bit); adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_11db);

reading the a:d: Vbatt = ( (uPvolts * float(adc1_get_raw(ADC1_CHANNEL_0)) / ADbits) / r2 * ( r1 + r2) );

Run the ESP32 on its own 5 volt power source. Connect a hub between the ESP32 and the computer used to program the ESP32. If you look at the ESP32 schematic you'll see that the 5V is a straight from your programming computer to the ESP32. Blow something up on the ESP32 and your programming computer takes a hit.

If you use the ESP32 WROVER (the +4MB RAM for a total of 8MB RAM), there are 2 more pins on the WROVER so ware the pin out is slightly different.

Overall, I am very happy with the ESP32. Using freeRTOS it reads 50ish FIFO readings from the MPU9250, averages the readings, does the MahonyQuaternionUpdate, calculates and send servo torque values all in about 240uSeconds.

Oh, and when developing tasks use: // Serial.print(uxTaskGetStackHighWaterMark( NULL ));

  //    Serial.println();
  //    Serial.flush();

Also, flush all serial prints. The uxTaskGetStackHighWaterMark( NULL ) will give you an idea of how much stack size to set. Using the U8G2_SSD1327_EA_W128128_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); with full buffer size takes a good chunk of stack: xTaskCreatePinnedToCore( fUpdateDisplay, "fUpdateDisplay", TaskStack15K, NULL, Priority4, NULL, TaskCore1 ); // assigned to core 1. On the other hand I got 4MB RAM to work with.

Also, note there are 3 cores on a ESP32. The third core is the ULP and only takes assembly code for programming.