Saturday, June 27, 2020

ESP32-DevKitC + 2.8inch 240x320 SPI TFT (ILI9341) using TFT_eSPI library

This post show how to use ESP32-DevKitC to drive a 2.8inch 240x320 SPI TFT (wih ILI9314 using serial interface), using TFT_eSPI library.




Connection:


I connect ESP32-DevKitC and Display board follow the default setting of TFT_eSPI library.
TFT_MISO 19
TFT_MOSI 23
TFT_SCLK 18
TFT_CS   15
TFT_DC    2
TFT_RST   4

I found the Fritzing parts here:
ESP32S-HiLetgo Dev Boad with Pinout Template
https://forum.fritzing.org/t/esp32s-hiletgo-dev-boad-with-pinout-template/5357

2.2 320x240 TFT ILI9341.fzpz (it should be logically same as the 2.8" display I use)
https://forum.fritzing.org/t/2-2-ili9342-tft/1813

Setup Library in Arduino IDE:
Menu > Sketch > Include Library > Manager Libraries...
Search and install TFT_eSPI


Then have to edit User_Setup.h to fix your circuit.


- Confirm ILI9341_DRIVER is defined

- comment the original define of:
TFT_CS, TFT_DC and TFT_RST.

- un-comment the pin define under "For ESP32 Dev board (only tested with ILI9341 display)"
TFT_MISO, TFT_MOSI 23, TFT_SCLK, TFT_CS, TFT_DC and TFT_RST.

Then, you can try any example under TFT_eSPI.



Using TFT_eSPI, if you load a new copy of TFT_eSPI then it will over-write your setups if they are kept within the TFT_eSPI folder. It's suggested to create a new folder in your Arduino library folder called "TFT_eSPI_Setups". You then place your custom setup.h files in there. After an upgrade simply edit the User_Setup_Select.h file to point to your custom setup file.

check it:
ESP32 + 1.3 inch 240x240 IPS LCD (ST7789 SPI interface), using TFT_eSPI library



Thursday, June 25, 2020

Install ESP32/ESP8266 to Arduino IDE on Ubuntu 20.04, with setup Pythton & serial

After install JDK (OpenJDK) and Arduino IDE on Ubuntu 20.04, you can add support of ESP32 (or ESP8266).

May be you will be with Python 2 related error of:
exec: "python": executable file not found in $PATH
ModuleNotFoundError: No module named 'serial'

In 20.04 LTS, the python included in the base system is Python 3.8. Python 2.7 has been moved to universe and is not included by default in any new installs. (referene: Ubuntu 20.04 LTS (Focal Fossa) release notes)

Here show how to fix it:


First, install board to Boards Manager:

Menu > File> Preferences
Enter the url in the "Additional Board Manager URLs":
https://dl.espressif.com/dl/package_esp32_index.json (for ESP32)
http://arduino.esp8266.com/stable/package_esp8266com_index.json (for ESP8266)

To enter more than one URL, separate it with a comma.

Menu > Tools > Board > Boards Manager…
Search and install ESP32 (or ESP8266)

When you build your code for ESP32/ESP8266, if you report with error of :
exec: "python": executable file not found in $PATH

It's because Python 2 is not installed on Ubuntu 20.04. You can create a symlinks /usr/bin/python to python3 by installing python-is-python3.

$ sudo apt install python-is-python3

Optionally, you can prevent Python 2 from being installed as a dependency of something in the future:

$ sudo apt-mark hold python2 python2-minimal python2.7 python2.7-minimal libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib

Then you may be report with error:
ModuleNotFoundError: No module named 'serial'

Because pyserial is not installed in Python 3 by default. Install with pip:

$ sudo apt install python3-pip
$ pip3 install pyserial

Additionally, if you cannot download your code to board caused by:
avrdude: ser_open(): can't open device "/dev/xxx": Permission denied

Add permission to your user:

$ sudo usermod -a -G dialout <username>
$ sudo chmod a+rw /dev/xxx


Next:
ESP32-DevKitC + 2.8inch 240x320 SPI TFT (ILI9341) using TFT_eSPI library
ESP32 + 1.3 inch 240x240 IPS LCD (ST7789 SPI interface), using TFT_eSPI library
NodeMCU (ESP8266) + 1.44" 128x128 TFT with ST7735 SPI driver (KMR1441_SPI V2), using ssd1306 library

Wednesday, June 24, 2020

Install Arduino IDE 1.8.13 on Ubuntu 20.04

To run Arduino IDE, you have to install Java on Ubuntu, refer last post Install JDK (OpenJDK) on Ubuntu 20.04.


Visit https://www.arduino.cc/ to download Linux 64 bits version.

Extract the downloaded file and more to where you want. Switch to the folder and run:
$ sudo ./install.sh

You will be reported with error of:

An error occurred while uploading the sketch
avrdude: ser_open(): can't open device "/dev/ttyACM0": Permission denied

You can add you (the user) to the group own permission of the upload port:

$sudo usermod -a -G dialout <username>
$sudo chmod a+rw /dev/ttyACM0

change username and ttyACM0 according to your setup.

logout and login.



Basically, the steps to install Arduino IDE on Ubuntu 20.04 are same as install on previous version of Ubuntu. But if you target to develop for ESP32/ESP8266, very likely you will be with error of:
exec: "python": executable file not found in $PATH
ModuleNotFoundError: No module named 'serial'

Check next post - Install ESP32/ESP8266 to Arduino IDE on Ubuntu 20.04, with setup Pythton & serial

Install JDK (OpenJDK) on Ubuntu 20.04


Install JDK 14.0.1 (from Oracle) on Ubuntu 20.04

- Visit https://jdk.java.net/ to download latest JDK of Linux/x64, currently openjdk-14.0.1_linux-x64_bin.tar.gz

- Extract the downloaded file:
$ tar -zxvf openjdk-14.0.1_linux-x64_bin.tar.gz

-  Create a folder in /opt/java where jdk will be stored.
$ sudo mkdir -p /opt/java

- Move the extracted folder to /opt/java
$ sudo mv jdk-14.0.1 /opt/java

- Set default java and javac using update-alternatives:
$ sudo update-alternatives --install /usr/bin/javac javac /opt/java/jdk-14.0.1/bin/javac 1
$ sudo update-alternatives --install /usr/bin/java java /opt/java/jdk-14.0.1/bin/java 1
$ sudo update-alternatives --config javac
$ sudo update-alternatives --config java


Saturday, June 13, 2020

Arduno Uno + GY-521 module (MPU-6050)

GY-521 module is a breakout board for the MPU-6050 - with I2C interface features a 6-Axis sensors (gyroscope and accelerometer) and temperature sensor.



The MPU-60X0 is the world’s first integrated 6-axis MotionTracking device that combines a 3-axis
gyroscope, 3-axis accelerometer, and a Digital Motion Processor™ (DMP) all in a small 4x4x0.9mm
package. With its dedicated I2C sensor bus....

...Additional features include an embedded temperature sensor...

Read it's details from MPU-6000 and MPU-6050 Product Specification, and Product Page.

Notice on the Product Page, stated that it is in production, but Not Recommended for New Design. Recommended Alternate is ICM-20602 (Interchangeability is not guaranteed.)


Anyway, I have a sample unit of GY-521 on hand. It's a exercise of using Arduino Uno to read GY-521 via I2C, using MPU6050_tockn, using Arduino library for easy communication with MPU6050.

Connect Arduino Uno with GY-521:



- Start Arduino IDE, make sure you select the correct board and port.

- Menu : Sketch > Include Library > Manage Library... to open Library Manager.

- Search MPU6050 to install MPU6050_tockn library.


- Menu : File > Examples > MPU6050_tockn > GetAllData



- Upload to Uno, and open Serial Monitor. To check the output.


Now we modify a little bit, such that we can see the result more easy visually.


#include <MPU6050_tockn.h>
#include <Wire.h>

MPU6050 mpu6050(Wire);

long timer = 0;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu6050.begin();
  mpu6050.calcGyroOffsets(true);
  Serial.println();
}

void loop() {
  mpu6050.update();

  if(millis() - timer > 200){

    Serial.print(mpu6050.getAngleX());
    Serial.print(",");
    Serial.print(mpu6050.getAngleY());
    Serial.print(",");
    Serial.println(mpu6050.getAngleZ());
    timer = millis();
    
  }

}



- Save As another file, Verify and Upload.

- Open Serial Plotter instead of Serial Monitor


- Now you can rotate the module and check the reading graphically.


DONE

Thursday, June 11, 2020

TFT Touch Screen shield (ILI9341 8 bit) + Uno, calibration and simple touch drawing example.


Last post how to drive 2.8" 320*240 TFT Touch Screen shield (ILI9341 8 bit interface) on Uno, using MCUFRIEND_kbv/Adafruit GFX Libraries on Platform IO. Now show how to calibrate the touch x-y, and run a simple touch drawing with MCUFRIEND_kbv examples.


The MCUFRIEND_kbv examples can be found here: https://github.com/prenticedavid/MCUFRIEND_kbv/tree/master/examples.

Make sure libraries of MCUFRIEND_kbv, Adafruit GFX and Adafruit TouchScreen are installed in your VS Code/Platform IO IDE.

Calibration:

Create a new Project in Platform IO IDE for Calibration, target Arduino Uno.

From MCUFRIEND_kbv TouchScreen_Calibr_native example:
- Copy the code of TouchScreen_Calibr_native.ino to your main.cpp.
- Copy TouchScreen_kbv.cpp and TouchScreen_kbv.h to your project.

As you try Arduino example on PlatformIO. PlatformIO may throw many "not declared in this scope" errors. Because PlatformIO require Forward Declaration of function.  To fix it, copy to define the function prototype before the functions called, as show in the video.

Edit platformio.ini to add "lib_deps = Wire" to fix the error of "Wire.h: No such file or directory". And specify upload_port if the IDE cannot detect your port.

Build and upload the program to Uno, then open Platform IO Serial Monitor. Once calibration finished, the calibration data will be show in Serial Monitor, copy it.

Here is the result of my board:
*** COPY-PASTE from Serial Terminal:
const int XP=8,XM=A2,YP=A3,YM=9; //240x320 ID=0x9341
const int TS_LEFT=169,TS_RT=941,TS_TOP=176,TS_BOT=927;

Simple Touch to draw example:

Create another Project in Platform IO IDE for simple Touch to draw example, target Arduino Uno.

Copy the code of MCUFRIEND_kbv Touch_shield_new example to main.cpp.

Replace the calibrate data (copy from the above program) in the code:



Edit platformio.ini to add "lib_deps = Wire" to fix the error of "Wire.h: No such file or directory". And specify upload_port if the IDE cannot detect your port.

Build and upload, and DONE.




Wednesday, June 10, 2020

2.8" 320*240 TFT Touch Screen shield (ILI9341 8 bit I/F) on Uno, using MCUFRIEND_kbv/Adafruit GFX Libraries on Platform IO

It's a 2.8" 320*240 TFT Touch Screen shield, with driver ILI9341 connected using 8 bit parallel interface. Support Arduino UNO and Mega2560 direct plug-in use without wiring.




Reference: Product page of LCDWiki 2.8inch Arduino Display

You can find the details of the TFT Touch Screen Shield from the above link. Also provide Program Download with examples. But I prefer use libraries come with Platform IO IDE. This video show how to:


- This exercise tested on VS Code/Platform IO IDE on Ubuntu 20.04.

- Install libraries of MCUFRIEND_kbv and Adafruit GFX.

- Copy example from MCUFRIEND_kbv library, it's diagnose_TFT_support in my exercise.

- Edit platformio.ini to specify upload_port and add "lib_deps = Wire" to fix the error of "Wire.h: No such file or directory".

- Build and upload.



Next:
Calibration and simple touch drawing example



Wednesday, June 3, 2020

Fixed fatal error: Wire.h: No such file or directory - for platform IO/Arduino

When I tried exercise using Wire library, it's reported:

fatal error: Wire.h: No such file or directory


Solution, it work for me:

Open platformio.ini, add the line:

lib_deps = Wire

(or lib_deps = SPI for fatal error: SPI.h: No such file or directory)

Build again: