I have a very beautiful bedside lamp at home . This time I want to learn knowledge through this competition training activity and transform this previous work into an Internet of Things device.
I chose left and right, and finally chose the stc15f104w microcontroller.
I didn't really want to use stc15f104w because I felt that the IO port was not enough, but after counting the functions, I used the serial port to transmit data with esp-01s, which occupies two ios; it connects to the touch sensor chip BS801B, which occupies one; ws2812 uses esp-01s That one IO port control can even create a few more IOs.
Let me talk about the advantages of using stc15f104w
I have also considered old microcontrollers such as stm32f103c8t6 and 80c51, but the former is a waste of IO, and the latter requires peripheral circuits, such as crystal oscillators and capacitors, which take up space. After the above comparative analysis, I finally made up my mind to use stc15f104w.
What you probably need to use are STC15F104w, ESP-01s, AMS1117, BS801B, NCE3401AY, etc.
The voltage parameters of these components are as follows
name | Working voltage(V) | Remark |
---|---|---|
STC15F104w | 3.8-5.5 | |
ESP-01s | 3.0-3.6 | |
BS801B | 2.2~5.5 |
This is a step that makes people bald
But once done, it can provide excellent guidance for the entire development process.
The frame of the casing of my lamp is made of wooden strips, and the place where the circuit is stored looks like this:
As you can see, the thickness of the wooden frame with the type-c interface on the left is 5mm.
This means that I have to choose a longer type-c female socket, otherwise the male plug cannot be reached.
After I went through all the sockets in Lichuang Mall, I only found a few that fit the requirements:
Reason for not using it: If you use this, the welded port will face upward and the position is wrong. Although it is said that he can get a separate small board for him, but... it is troublesome. He has to connect the small board and so on. This is too troublesome.
Reasons for not using it: Same as above, and I am a bad welder, but there are too many pins and it is SMD (I have learned a painful lesson in soldering type-c like this), and...
Reason for adoption: There are fewer pins. When drawing the board, just re-edit the package and move the pin end to the edge of the board.
BUT...
Just when I was happily drawing the schematic diagram, I found a problem
(The picture on the left is from the mall specification sheet)
? ? ? ? ? ? What is all this for? Which is which? ? ? ? ? ?
After thinking about it for a while, I think this should be included in the pin definition of type-c. Let the browser take a look ~
As expected
OK, I can finally draw the power supply part happily~
note: The four "0"s are the four holes of the metal shell of the female socket, which can be grounded or left unconnected. I chose not to ground the soldering iron because I felt that the power of the soldering iron was not enough. If the soldering iron was grounded, the heat would dissipate too quickly and it would be difficult to solder (referring to the case of laying a large area of copper for grounding).
note: Check the manual. In the application circuit diagram recommended by the manual, Kout is connected to a pull-up resistor.
I don't quite understand the issue of pull-up resistors, but my understanding is:
Using a pull-up resistor, you can force the level on this signal line to a stable state, and use pull-up/pull-down to select the state to be configured, that is, whether it is usually high or low. If the signal to be detected on this signal line is high level, configure it as a pull-down resistor; if the signal to be detected is low, then configure a pull-up resistor.
Taking this design as an example, my circuit diagram configuration is: if there is a touch output low level, then the pull-up resistor is set as a pull-up resistor. When there is no touch, the signal line is always at a high level, and when a person touches it, Kout outputs a low level. At this time, the pull-up resistor circuit generates a current flowing into the BS801B, and the Kout output of a low level is equivalent to Grounding, in this way, the signal line is pulled low, and a low-level signal that the microcontroller wants to detect is generated on the line.
Therefore, the schematic diagram is modified and a pull-up resistor is added:
I drew the switch MOS directly according to the manual, the manual picture of NCE3401AY:
Another big problem...
The schematic diagram shows the STC15f104w microcontroller, it’s on meEating hot pot and singing songsWhile looking up information and listening to the song, I discovered
it! without! have! string! mouth! ! ! What should I do? I don’t necessarily know how to write a virtual serial port!
What to do~
As the old saying goes: the official website is a good thing
It’s too complicated to search online, so let’s go to the official website first~_~
Eye-catching as always , scroll down
Damn what did I see?
Library functions are a good thing!
What a great experience! !
This is its description, it smells so good
The definition method of analog serial port pins is as follows:
Summary: The stc15f100 series does not have a hardware serial port, so if you want to use the serial port, you should use software to simulate the serial port. P3.0 (pin 5) of the microcontroller is RXD, and P3.1 (pin 6) is TXD of the microcontroller. These two ports are also used when downloading, and a cold start is required.
I don’t want to use P3.0 and P3.1 as serial ports to communicate with ESP-01s, because when debugging the program, I need to download the code repeatedly for verification. If I use 3.0 and 3.1 ports, I have to keep unplugging and plugging in the ESP-01s, which is very troublesome. Troublesome. And due to height restrictions (the board height needs to be less than 1cm), I probably won’t use the pin header, but directly solder the ESP-01s to the board, so I have to find another IO.
So the schematic became like this
Perfect, just enough to use all IO. At the beginning, there was still a surplus in the calculation, but now it is just right, neither more nor less.
When drawing the schematic diagram of this, I encountered a problem: serial port level matching problem.
The following is the solution process
note: The high level output by the serial port of the microcontroller is consistent with its power supply voltage.
The serial port level of ESP-01s is 3.3V, and the maximum tolerance is also 3.3V.
In other words, its RXD cannot receive the ttl serial port level from the 5V microcontroller STC15f104w, which will cause damage to the ESP-01s.
However, (3.3V) TXD --> RXD (5V) does not need to be processed. Why?
By viewing the manual
From the manual of the STC15 series microcontroller, we can find that as long as the input voltage is greater than 2V, it will be judged as high level. The high level of ESP-01s is 3.3V, which will be recognized and judged as 1, high level.
After the above analysis, we know that we only need to match the voltage of (5V) TXD --> RXD (3.3V).
After the help of many people in the group, I finally chose the 74LVC1T45 level conversion IC
Arrange it on the TXD of the microcontroller
Now you can proceed to the next step: drawing the ESP-01s circuit.
There are a few things to note >
The schematic is as follows
notes: When testing the ws2812 light strip, I directly connected the input terminal of the light strip to the pins at first, but found that the phenomenon was very strange. It works inexplicably now and then not, it's very unstable and I can't figure it out.
But I quickly discovered a point that I ignored: voltage matching again
The high level of the io output voltage of esp-01s is the same as its vdd, which is 3.3V. And 3.3V may not cause the ws2812 chip to be judged as high level.
This is the manual for ws2812. From here I found that ws2812 considers signal voltage higher than 0.7*VDD as high level. The VDD of my ws2812 is 5V. Therefore, signals higher than 3.5V will be treated as high level; that is to say, the 3.3V high level of our esp-01s is treated as low level, and the signal input terminal of ws2812 It's always low.
Make a voltage conversion on the output of esp-01s before it can be used.
I used 1N4148 instead of 1N4007 because the switching speed of 4148 is faster than that of 4007 and there will be no other problems.
The schematic diagram of esp-01s posted earlier is a completed circuit diagram with level conversion of the IO port.
The picture above contains the debugging download interface and the startup mode (run/download) switch of esp-01s
At this point, the schematic part has been successfully completed.
Actually, there’s not much to say. Just follow the official tutorial on how to draw the board. I won’t do the trick.
Design the board size according to the size of the shell space
Design the layout according to this size. Then debug and test the board and fix it into the case with hot melt glue.
Because my board does not involve high-speed circuits, the wiring can be laid out casually under DRC rules. It is basically a connect-and-connect game.
(The automatic wiring function can be used to verify whether the current layout is feasible. I have modularized the schematic diagram and can manually route the modules.)
The only thing to pay attention to is the layout of esp-01s. Its manual is as follows:
Okay, let’s start drawing board
It probably looks like this:
Add 100 million points of annotation to the silk screen:
hardware | develop software | Libraries used |
---|---|---|
ESP-01s | arduino | FastLED library, Blinker library |
STC15F104w | keil | STC15 series official library |
blinker Arduino support library
FastLED library documentation-Tai Chi Maker
Code: Not finished yet
To be continued…
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet