Output
This week, I explored an output component on a CNC board. For my first test, I connected an LCD display to the Xiao ESP32-C6. The display successfully retrieves and presents real-time weather information for my city.
PCB Design
Footprints for the schematic:
-LCD Display 16x2 click here for footprint link -Xiao ESP32-C6 is the same as the ESP32-C3, and you can find it in the fab library -> Click here for the Fusion library of Xiao
Here is my schematic design. To determine the required voltage and pinout of the display, I referred to the datasheet click here for the datasheet.
For the Xiao ESP32-C6, most information can be found in Week 6 Electronic Design.
PCB Design and CNC process
Here is only a small information abput my CNC process, but how to work with the CNC machine (LPKF) you can see at Week 8 Electronic Design.
I used a single-layer PCB design without vias. The board itself serves as the ground plane, and I only included a bent pin header for the LCD display. This allows me to easily swap the display if I decide to use a different one in my final project. Additionally, producing fewer milled boards is more sustainable.
For the CNC process, using a single-layer design was also beneficial. It helps extend the lifespan of the machine’s tools.
Soldering
Required materials:
- LCD 1602A
- Xiao ESP32-C6
- Cables in different colors (Red, Black, White, Purple)
- Bent pin headers
- A CNC board (I used the design from last week – click here for Week 8)
- USB-C cable
- Soldering equipment
I started by soldering the pin headers. The GND pad was slightly problematic because something was on it. Make sure your pads are cleaner than mine.
In the second step, I soldered the ESP32-C6. Finally, I tested the setup.
Programming
I took some inspiration from this GitHub project: Click here for the GitHub project
First Test Code
To test the board and the LCD, I first used this code:
#include
#include
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change 16,2 to 20,4 if needed
void setup() {
Wire.begin(4, 5); // SDA = D4, SCL = D5 for Seeed XIAO nRF52840
lcd.begin();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Hello, world!");
}
void loop() {
lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
delay(1000);
}
Also you need for this some library:
Encountered Issues
I encountered some problems:
WARNING: library LiquidCrystal I2C claims to run on avr architecture(s) and may be incompatible with your current board which runs on esp32 architecture(s).
C:\Users\merry\AppData\Local\Temp\.arduinoIDE-unsaved2025231-7180-1a7291p.7zry\sketch_mar31a\sketch_mar31a.ino:19:3: error: extended character is not valid in an identifier
19 | delay(1000);
| ^
C:\Users\merry\AppData\Local\Temp\.arduinoIDE-unsaved2025231-7180-1a7291p.7zry\sketch_mar31a\sketch_mar31a.ino:19:3: error: extended character is not valid in an identifier
exit status 1
Compilation error: extended character is not valid in an identifier
I then tested it without Wire.begin
and without defining the pins, which worked well:
My research suggests that the Xiao has predefined pin configurations, which is why explicit definitions in the code are not necessary.
#include
#include
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Hello World!");
}
void loop() {}
Weather Code
To use the weather code, you need to register on the website OpenWeather to obtain an API key for free weather updates.
Then, I modified the program code with some libraries. More information about the libraries can be found in this GitHub project.
I also added an important WiFi setup and a string for the temperature. You can not see the libraries i used in the Code - So here are the libraries (ArduinoJson.h ; Wire.h ; LiquidCrystal_I2C.h ; WiFi.h ; HTTPClient.h) Here is the Code -I´dont know why the libraries is unvisible:
#include
#include
#include
#include
#include
const char* ssid = "Koixxxxxxx"; // Edit your WiFi name here
const char* password = "xxxxxxxxxxxxxxxxxx"; // Edit your WiFi password here
const char* api_key = "xxxxxxxxxxxxxxxxxxx"; // Edit your API key here
const char* city = "Essen,de"; // Edit your city here
LiquidCrystal_I2C lcd(0x27, 16, 2);
String getTemperature() {
HTTPClient http;
String url = "http://api.openweathermap.org/data/2.5/weather?q=" + String(city) + "&units=metric&appid=" + String(api_key);
http.begin(url);
int httpCode = http.GET();
String temperature = "Error";
if (httpCode == 200) { // Correct HTTP response
String payload = http.getString();
StaticJsonDocument<512> doc;
DeserializationError error = deserializeJson(doc, payload);
if (!error) {
float temp = doc["main"]["temp"];
temperature = String(temp, 1) + " C"; // Temperature in Celsius
} else {
temperature = "JSON Error";
}
} else {
temperature = "HTTP Error";
}
http.end();
return temperature;
}
void setup() {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
int timeout = 15; // 15-second timeout for WiFi connection
while (WiFi.status() != WL_CONNECTED && timeout > 0) {
delay(1000);
timeout--;
}
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
if (WiFi.status() == WL_CONNECTED) {
String temp = getTemperature();
lcd.print(temp);
} else {
lcd.print("WiFi Error");
}
}
void loop() {
// delay(60000); // Optional: Update temperature every 60 seconds
}
Here you can see it works so good. Only a problem with the °-symbole. So I changed it to an only “C”.
My gerber files from this week
click here for my outline gerber file
click here for my top layer gerber file
Group assignment
In this week we check out some power consumption of an output device. Through this experiment, I learned how different colors affect power consumption and how RGB channels contribute to energy usage. Check out our Group website click here