In this project I put together a custom PCB for handling level shifting for the Xiao footprint. This project is a board I designed to replace my earlier inline DIY level shifter I’ve used for various projects.
The PCB itself can be found on my oshwlab page: https://oshwlab.com/timo6141/xiao-level-shifter_copy
This article goes into some detail related to the PCB but if you want more detail my website has additional documentation: https://www.cranberrygrape.com/mini-projects/level-up-board/
Project SponsorshipI would like to thank PCBWay for sponsoring the PCB such that I could work on this project. It came quickly and works well so I'm very grateful.
I have three uses for this board:
- If I want to use UART serial communication with a 5V board I need to level shift for the signals and power to avoid hurting the Xiao with its 3V3 pins
- There are some 5V only i2c devices such as the Seeed Vision AI sensor v2 (you can attach the Xiao directly to the board to get around this but my projects usually use multiple sensors so I prefer attaching it via a cable)
- There are some actuators that require 5V like the Seeed Water Atomization module
In the past I took care of this by assembling an inline DIY level shifter. It works well but I prefer simplicity with enclosures and it makes things a bit more difficult as each DIY board has slightly different dimensions.
SchematicSo first I want to describe the logic here and give an example circuit to play around with it. This falstad circuit is the one I put together to verify my assumptions prior to ordering the PCB. With this setup you can see four different circuits. The top two are 3V3 to 5V which is a fairly normal setup for level shifting while the bottom two are 3V3 to 3V3 so demonstrating the behavior when not level shifting at all. The left two circuits are setup to allow toggling of the logic level on the LV side while the right two allow toggling on the HV side. In this way both 3V3 and 5V can be tested as the HV to confirm they will continue working.
For how it works I’ve included my text from my DIY level shifting entry below.
I believe this works by (my understanding came from this great reddit answer):
- When the LV side is LOW it causes a Vgs of 3V3 which is more than the 1V5 needed to fully activate the mosfet. Once activated it causes current to flow and pulls the HV side down as well. When it’s high the Vgs is 0 so current doesn’t conduct and with the pull up resistors both sides are kept at their respected voltage.
- When the HV side is brought LOW it causes the diode to become reverse biased (from what I’ve gathered) which in turn allows the body diode to allow current through it. This in turn causes the source voltage to drop in turn causing the Vgs to climb until the mosfet is fully activated and the LV side is also brought fully to LOW.
The schematic of the circuit just utilizes this shifting for 4 pins with the HV side using a jumper to select if it's 3V3 or 5V.
AssemblyI used a hot air gun to heat the elements after using solder paste. I then went back and fixed a few solder joints as the paste was lacking (I didn't use a stencil).
The reverse side of the board has no components just traces.
TestingPlease refer to my video to see the test process. I did some continuity testing for the various pins and components and then followed up with some checks to confirm when the associated pins were in a high voltage state that they were properly showing the correct voltage based on the jumper.
Test CircuitsTo properly test the logic I opted to create 3 mini projects utilizing the board.
- A water atomization project utilizing the Seeed Water Atomization module (humidifier or ghost gas for halloween, very fun)
- An i2c based Seeed Vision AI 2.0 module project utilizing face tracking (just their demo code so nothing special on my part)
- A serial test between 5V with the Arduino Uno and 3V3 with the Xiao ESP32S3 powered via the Grove cable's 5V line
The code for this project is rather simple. The atomization module only has an enable pin so once you've turned that you have yourself a humidity generating device (not really useful for me most of the time given Florida is like one giant humidity generating state but neat for Halloween).
void setup() {
pinMode(D7, OUTPUT);
digitalWrite(D7, HIGH);
}
void loop() {
}
Super simple, eh? But yeah with it plugged into my i2c port (for use of the D7 pin) and the jumper set to 5V it works great when plugged in.
Seeed Vision AI V2Technically Seeed did all the work here. As such I'm not inclined to copy their code to this article. I will link it though! If you have the module you should get setup to use it and then it's as simple as using the 5V jumper, connecting via i2c, and running the example there. I used the built in "Inference" example for the purposes of this guide. To see it running with bounding boxes please refer to the video.
Xiao ESP32S3 to Arduino Uno (5V) SerialFor this example project I setup a serial test circuit by utilizing an Arduino Uno, Base Shield V2, a Grove Buzzer, a Grove buzzer, and my Level Up board.
Given the Uno board only allows for one serial connection I opted for Software Serial utilizing the NeoSWSerial library with a slower baud rate.
When the button on the Xiao side (with my level up board) is pressed it sends a message across the serial connection. On the Uno side the logic listens for commands and when it receives the associated message it triggers the buzzer.
I've included the code below.
Comments
Please log in or sign up to comment.