Looks just like the Uno. It is the same thing but different. Here is a photo of the Wemos D1 R32 board along with the LCM12864 shield. Available from different manufacturers sometimes with different names. Google for espduino and most hits will be this board.
Espressif is a maker of RISC processor chips. The ESP32 and ESP8266 are faster than the AVR chip running an Arduino Uno. They have more flash and more RAM. Made for bigger programs, more complicated calculations.
But when you get up close and look at the "silk-screen" labels on the pins you see a different set of numbers. Board designers are trying to make a very different chip fit into the Uno package. To keep the UART, SPI and I2C pins in the same place things got moved around.
Our project is to program the ESP32 board to an LCM12864 shield from YWRobot. Monochrome, the product number says it is 128x64 resolution and it breaks out unused pins from the board. It connects with pins 4 to 8 on a Uno and we have to change these numbers for our sketch to work.
Arduino IDEYou can buildroot embedded Linux and put a limited operating system onto this board. The manufacturer calls this ESP-IDF and it is a different experience.
We are going to setup our Arduino IDE to handle Espressif ESP32 microcontrollers. A lot of other MCUs set up this same way. Menu File -> Preferences.
This panel is where you add repositories for new boards with ARM, STM and Espressif processors. You can also increase the font size.
Click on the verbose output upload box so that we can see programmer operation. If you check the compilation box you can watch Tensilica build your binary file.
Go to Additional Boards Manager URLs: box and copy in this address
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
You really have to click OK for the settings to change.
Menu Tools -> Board -> Boards ManagerThere will be a refresh as the new board information downloads.
Search for ESP32. ESP8266 is a different processor from the same company. We only need to add the ESP32 build system.
This is a sizable package, download and install will take several minutes. When ready use the board manager to select DOIT ESP32 DEVKIT V1. Arduino IDE will now use files of information on the board to compile the sketch.
The bottom right corner shows the selected board, connection speed and port.
There are so many choices because Espressif ESP32 chips are packaged onto different boards like the NodeMCU. The same sketch could possibly run on any of these boards. What differs is where pins are wired.
The Arduino IDE boards manager does have a file mapping out each of the boards in the list. We can take an Arduino sketch that uses the SPI and run it easily on the ESP32 board because our IDE knows what numbers to change around.
If you compile Blink from the example menu it will know that LED_BUILTIN = 2 instead of 13 on the Uno board. You have MISO and MOSI recognized as keywords already assigned to the correct pin numbers.
U8G2 Graphics Library
You can set and clear each bit in a display one-by-one. But a graphics library gives you methods to draw lines, circles, rectangles just with math.
Open library manager, find and install the U8G2 graphics library. Do you have any of the display modules in the lists? The library can talk to many SPI and I2C controllers.
Look in examples for U8G2 and look for GraphicsTest. There may be more than one version. Because this is a monochrome screen the examples are not colour.
Open the sketch and find the constructor list of supported controller chips. This library was made to work with many, many different displays. Normally, we would find our chipset and correct the pin values.
Replace all of the constructors with a single line of code. The sketch tells the MCU to use these pins in certain ways as clock or data.
U8G2_ST7565_NHD_C12864_F_4W_SW_SPI u8g2(U8G2_R2, /*ck*/ 12, /*dt*/ 14, /*cs*/ 27, /*dc*/ 16, /*rs*/ 17); // constructor for ESP32 board
The library contains a class of data objects that match this format. We are creating an instance or instantiating a data object.
Click the checkmark to verify the sketch. Compilation should have no errors. Notice the sketch sizes in bytes. The IDE is using the Tensilica toolset to generate programs for the ESP but this is transparent to the user.
ContrastThe sketch is ready to compile, if we verify the sketch it will pass. But if we upload the default contrast will be too dark and we will see nothing on the screen. We want to set the contrast to 63 out of 255.
In the sketch setup( ) add this line of code
u8g2.setContrast(63);
Loop ( )The library gives us the methods u8g2.clearBuffer and u8g2.sendBuffer, draw( ) is a function in this sketch. If we want to make changes to the sketch, start here. You should look at each function and how it is built.
Compilation time will be longer than Arduino. The program uploading to the device is esptool_py.exe not avrdude because it is a different toolchain. Some computers may need a CH340 driver to talk to the board.
The GraphicsTest sketch uses every method from the U8G2 library. You can, too. Go through the code and find functions you want to try. Make a very basic sketch to draw straight lines and make a box around the screen.
Go to each example sketch 1 - insert the constructor 2 - insert the contrast setting.
The other examples in the U8G2 library will work on this board if you make the same changes to the constructor and contrast. Try the ContrastTest.ino sketch, that's how I found out about the contrast setting.
Pin NumbersWhen I first saw the GPIO numbering on this ESPduino board I did not think Arduino shields could be used. All it took was figgering out what values to change.
Best way is to read the printing on the ESPduino board. We line up the board and the shield we can make a pin for pin correlation. We can take code that works on the Uno and just change pin numbers.
To run this sketch on the Arduino Uno we would use the constructor:
U8G2_ST7565_NHD_C12864_F_4W_SW_SPI u8g2(U8G2_R0, /*ck*/ 8, /*dt*/ 7, /*cs*/ 6, /*dc*/ 5, /*rs*/ 4); // constructor for Uno board
Let's run through the pins and what they do. ck clock Uno pin d8, dt data is pin d7, cs chip select is d6, dc data/command pin d5 and rs screen reset on d4.
YWRobot says these pins are an SPI signal but they are on non-standard pins. Usually SPI is on pins d10 to d13 and HW constructors use this as a shortcut. We are telling our MCU to use software SW to treat pins d4 to d8 as SPI. You may hear this called bit-banging.
To convert a program for the Arduino Uno so that it can run on the ESPduino board with the ESP32 MCU we need to change the Uno pin numbers. Pin for pin we get ck clock 12, dt data 14, cs chip select 27, dc data/command 16 and rs screen reset 17.
This is why we need the constructor to be
U8G2_ST7565_NHD_C12864_F_4W_SW_SPI u8g2(U8G2_R2, /*ck*/ 12, /*dt*/ 14, /*cs*/ 27, /*dc*/ 16, /*rs*/ 17); // constructor for ESP32 board
ReferenceWemos R32 with Arduino Hackster project.
Cnet review of the ESP32 dev board.
Comments