super_star

[Training Camp_Advanced Class] Internet of Things Infinite Space Bedside Lamp

 
Overview

prospect

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.

Tossing records

Quick jump

  • Production and assembly of circuit boards and enclosures: Blog link
  • Code: Gitee link

    Selection

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.

-3acacb048b3f3b07

Let me talk about the advantages of using stc15f104w

  • The number of IO ports is suitable
  • I have written the stc15f104w program before and am quite familiar with it.
  • It has a SOP-8 package, with fewer pins and a small size.
  • It has a built-in crystal oscillator, which can be used immediately after power-on and does not require external circuitry (I like this very much).
  • Wide voltage range power supply: 5.5-3.8V

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

Draw circuit structure logic diagram

This is a step that makes people bald

image-20200806184355537

But once done, it can provide excellent guidance for the entire development process.

  • Functional mind map
Bedside lamp function
  • Circuit principle and overall structure block diagram

Circuit and principle structure block diagram

  • Power supply structure block diagram

Power structure

Drawing schematic diagram

The frame of the casing of my lamp is made of wooden strips, and the place where the circuit is stored looks like this:

image-20200806144921324

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:

  • Vertical-1
image-20200806145219037

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.

  • Vertical-2
image-20200806150020512

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...

image-20200806150033981image-20200806150246766
  • Horizontal - straight plug
image-20200806145620528

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

image-20200806150644587

(The picture on the left is from the mall specification sheet)

TIM picture 20200806182907

image-20200809123442792

? ? ? ? ? ? What is all this for? Which is which? ? ? ? ? ?

image-20200806151121824

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 ~

image-20200806150918511

As expected

image-20200806150943044image-20200806151856061

OK, I can finally draw the power supply part happily~img

  • TYPE-C power interface
image-20200806152357724

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).

  • 3.3V power supply
image-20200806151241432
  • Green Wave Electric Dragon (filter capacitor)
image-20200806151505333
  • touch chip
image-20200806161136628

note: Check the manual. In the application circuit diagram recommended by the manual, Kout is connected to a pull-up resistor.

image-20200806161618186

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:

image-20200806163125941
  • WS2812 light strip part
image-20200806173331833

I drew the switch MOS directly according to the manual, the manual picture of NCE3401AY:

image-20200806144546147

 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

image-20200806163843785

it! without! have! string! mouth! ! ! What should I do? I don’t necessarily know how to write a virtual serial port!image-20200806164350545

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~_~

image-20200806164529991

Eye-catching as always img, scroll down

Damn what did I see? image-20200806164749020

Library functions are a good thing!

image-20200806164901322

What a great experience! !

image-20200806165013221

This is its description, it smells so good

image-20200806165150731

The definition method of analog serial port pins is as follows:

image-20200806165338652

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

image-20200806174241407

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.

img

  • ESP-01s

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

image-20200806201518699

image-20200806201357169

Arrange it on the TXD of the microcontroller

image-20200806202455840

Now you can proceed to the next step: drawing the ESP-01s circuit.

There are a few things to note >

  • I want to solder esp-01s directly on the board, so its download/run mode switching circuit is required.
  • When downloading through the serial port, you need to disconnect the serial port of esp-01s from the pins of the microcontroller, because the IO state of the microcontroller is not high-impedance by default, which will interfere with downloading.

The schematic is as follows

image-20200809144436865

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.

img

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.

image-20200809120630745

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.

7AF8DB40BAC79745FBBD4BFB71B0B607

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.

  • External debugging download interface
image-20200809122035173

The picture above contains the debugging download interface and the startup mode (run/download) switch of esp-01s

  • CH340 download circuit
image-20200809144646905

image-20200809144706549

At this point, the schematic part has been successfully completed.

img

Drawing circuit diagrams

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

image-20200809125201072

image-20200809125314066

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:

image-20200809125846613

Okay, let’s start drawing board

img

It probably looks like this:

image-20200809150023547

Add 100 million points of annotation to the silk screen:

image-20200809151627613

Software

Software development information

hardware develop software Libraries used
ESP-01s arduino FastLED library, Blinker library
STC15F104w keil STC15 series official library

Reference URL

blinker Arduino support library

FastLED library documentation-Tai Chi Maker

  • In the ESP-01s part, you can choose the IoT platform and the LED driver library you want to use. Blinker also supports custom software layouts like Alibaba Cloud, and can also support Tmall Genie, which is quite good.

Code: Not finished yet

To be continued…

参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-05-15 00:19:44
  • 【Beetle ESP32-C3】VI. OLED, AHT10 and TCP (Arduino)
  • Logic Synthesis for High Design Reliability in DO-254 (Part 2)
  • Waterproof shoe covers
  • Consulting on the voltage range of the LT6100 op amp
  • My STM32 two-wheeled balancing car
  • FPAG beginner, can't find the problem

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号