回目录 《硬件基础与物联网IOT》


Safety first! Safety first!

Please be careful when working with high voltage. Seriously, it may shock you or even take your life. If you’re NOT 100% sure what you are doing, do yourself a favor and don’t touch anything. Ask someone who knows!


In the early 1970s, two American companies, Intel and Texas Instruments, introduced microprocessors and microcontrollers to the world. These companies envisioned a future dominated by single-chip integrated computers.

the microcontroller system accepts at least one input, performs some action on that input, and prodces one or more outputs. The inputs and outputs of a microcontroller system are voltages that we can use to determine the state of external devices. The microcontroller reads the voltages from an input device and uses this information to decide on the correct voltage to output.

A microcontroller system is embedded in an integrated circuit (IC). A typical microcontroller includes a processor, program memory, RAM, input/output pins, and more on a single chip.

Microcontrollers can be used to control a wide variety of electronic devices. They are perfect for applications requiring multiple repetitive operations or high-speed computations. Here’s a list of some devices that a microcontroller could be used to control:




microprocessor(in personal computer) VS microcontroller

The main processor in a desktop computer or laptop will be a microprocessor. But the computer may have microcontrollers as well, to perform peripheral functions.

The main difference between a microprocessor and microcontroller, is that microprocessors generally don’t have much memory inside the chip, except for perhaps cache memory, since these systems generally have GBs of RAM and that is too much to put on a processor chip. Microcontrollers generally have both their program and data memory on chip, but it is in the range of KBs and perhaps MBs at the most.

Another major difference between the two is microcontrollers have way more peripherals on chip than a microprocessor. Serial interfaces like UART, I2C, SPI, CAN, LIN, USB etc., along with parallel I/O ports, ADC(s), DAC(s), comparators, timer/counters, and DMA. A microprocessor used in a desktop or laptop will a PCI interface, memory interface, and possibly a graphics co-processor and interface.

So if a desktop of laptop PC needs some of the serial interfaces listed above, it will require extra components. About a year ago, I wrote code for a “USB bridge” for a ARM Cortex-M0+ microcontroller. It connects to the main processor via USB, and provides virtual I/O ports, I2C, and SPI interfaces. Inside the microprocessor, calls to drivers for these peripherals are sent to the USB bridge instead. It’s going into production this year inside laptops from one of the major laptop vendors.

embedded operating system vs microcontroller


An embedded system is a microprocessor- or microcontroller-based system of hardware and software designed to perform dedicated functions within a larger mechanical or electrical system.

At the heart of most embedded systems there is a microcontroller or microprocessor running the application. Embedded systems are generally more basic and rudimentary than microcontrollers since they often do not have logic to run the system.

Let’s go back to the Lego analogy for a second. The Legos, when put together, create a larger more complete system. Each Lego however has a specific task and use case. The embedded systems are typically told what to do by the CPU or Central Processing Unit of a computer. When the CPU tells an embedded system to do something the CPU generally communicates with a microcontroller that is part of the embedded system. Think of the microcontroller as the brains of the embedded system. Once the CPU tells the microcontroller to do something the microcontroller then directs the components of the embedded system to execute its specific tasks.



MCU 中是电路已经固定,它的编程是只能做固有的几十条指令的动作。而且是一条条的执行。

PLD 中电路未定,它的编程是电路的编程,也就是电路模块的设计。模块间是并行式的。


PLD 中电路未定,想做成几个定时器,或中断,或PWM输出,或别的什么模块。由程序决定。



PLC vs 单片机

PLC技术采用单片机技术,但 PLC技术并非单片机技术的延伸。此处我们若将单片机比作一张白纸, PLC是已绘制在白纸上的表格,那么使用单片机技术就像在白纸上写字,用 pcl技术就是填写表格,而用单片机技术则是填写表格。因此,掌握两种技巧,相当于学习在一张白纸上书写、看表格、填表。

PLC vs 嵌入式

嵌入式系统从广义上讲凡是以应用为中心,软硬件可裁减的的控制系统都可以叫做嵌入式系统,它包括的范围更为广阔,他包括PLC和单片机,不过现代人很多把嵌入式理解为嵌入式操作系统,嵌入式操作系统有嵌入式window CE,或者Linux系统等,我们可以把操作系统嵌入到存储器里,可以实现更为强大的功能,比如可以PDA、手机等。

To make a generalization… All PLCs are embedded systems, but not all embedded systems are PLCs.

A PLC is a readymade embedded system that can be deployed “in situ” meaning in to an end application with very little engineering overheads. The application design engineer(s) don’t have to worry about the power requirement, or yes withstanding industrial conditions such as extended temperature ranges or EMI RFI noise. They can straight away concentrate on meeting the requirements of the end application. The I/O points on a PLC are already protected. The PLC takes a microcontroller … builds a set of peripherals around it and then offers all of it to the outside world … with the appropriate protection circuitry for the I/o pins in place of course. It does this by having a special type of high level programming language that lets you build applications quickly without having to be bothered about nitty gritty of microcontroller programming such as how the microcontroller communicates with its peripherals or how it manages memory. In a sense it adds a layer of abstraction in the same way for example as a PC allows you to create programs without having to bother about the low level bios calls or managing access to storage media such as hard drives.

An embedded systems design engineer, on the other hand, is dealing directly with the hardware and all the issues that go with it….such as for example managing power requirements, managing the current sourcing / sinking capacity of i/o pins, what bus to use for peripherals communication, or how much non-volatile memory to allocate and so on.

So there is a price trade-off for the extra features you get with PLCs, making them more expensive than the embedded counterparts. Initial cost of deploying an embedded system would be very high compared to a PLC, going down as quantities increase and vise versa for PLCs. So clearly a PLC cannot be a solution in a price sensitive application… automobiles for example

Likewise an embedded system would not be a good solution where a quick turnaround time is a criterion ….. such as a proof of concept for automation of a material handling application

Typical examples where PLCs make them a good choice:

Car wash automation Material handling over conveyor belts in a plant Robotic arms handling radioactive waste Laser cutting machines Washing machines Elevators Pouch filling machines Mail sorting system in a postal department. Gravimetric batching control system All of the above can indeed be realized with embedded systems. Typical examples where it makes more sense to use them would be:

Automotive electronics such as Engine control units, Anti lock braking, cabin climate control etc. Pouch filling machines UPS or power management systems Data loggers for physical parameters such as temperature, pressure, flow, liquid level etc in chemical plants. Protection equipment for HV transformers Static and dynamic weighing applications. Solar inverters Fuel dispensers Communication equipment such as gateways, routers and converter In conclusion, I should mention one major difference between these two. The application program of an embedded system cannot be reprogrammed or modified in a short time in the same way it can be done for a PLC.




Microcontroller 不能运行操作系统,所以需要烧录程序到 flash memory 或 ROM; 对于个人电脑,ROM存储BIOS,硬盘存储操作系统,编译程序是跑在操作系统上甚至是操作系统之上的虚拟机如JVM里,所以不存在烧录; 所以对于集成了 Microcontroller 的 无操作系统的Arduino 来说就是只能烧录程序,而对于像树莓派这种集成了 Microprocessor 的微型电脑来说可以跑操作系统;




欧姆公式 http://www.54benniao.com/view/28.html https://zhidao.baidu.com/question/78519916

电子元器件 Electronic Components


R 电阻: 色环图 快速:两个红色 220欧, 一个红色 10k,一个黄一个紫色 4.7k,没有比较亮的颜色(棕黑黑) 1k

LED 长正短负

C 电容


模拟引脚(analog) 频率HZ 周期(微秒) 100Hz不是直接等于多少毫秒的问题;它是交流电频率与周期的关系,并且是倒数关系:周期T=1/100=0.01秒=10毫秒。

1.杜邦线 dupont line 贴片元件的焊接教程 - 拖焊技巧 http://www.elecfans.com/article/89/140/2012/20120522273004.html Solderless Breadboard http://www.petervis.com/Raspberry_PI/Solderless_Breadboard/Solderless_Breadboard.html spring clips 弹簧卡子 copper strips 铜带 multimeter 万用表 jumper 跳线 rail 引脚

power regulator oxidation semiconductor transistor 晶体管 MB102 Breadboard Power Supply Module 3.3V 5V http://www.petervis.com/Raspberry_PI/Breadboard_Power_Supply/YwRobot_Breadboard_Power_Supply.html http://www.petervis.com/Raspberry_PI/Breadboard_Power_Supply/Breadboard_Power_Supply.html Provide two different voltages on the two supply lines of the breadboard as needed.However, you should be careful about on which side of the breadboard the module been attached. Check that is minus (-) really is on the blue line and plus (+) on the red line, otherwise it may cause the circuit arrangement evil confusing! Specifications: jumper adjustable output voltage: 3.3V and / or 5V DC – directly on the breadboard additional: 2x 3.3V and 2x 5V plug connections on top USB connector power supply connector (input voltage 6.5V – 12V DC, already tested with 6V) maximum output current: 700mA status LED on/off switch suitable breadboard types: MB-102, ZY-60 dimensions: 52mm x 34mm 可编程逻辑电源/新能源MEMS/传感技术测量仪表嵌入式技术制造/封装模拟技术连接器EMC/EMI设计光电显示存储技术EDA/IC设计处理器/DSP接口/总线/驱动控制/MCURF/无线

引脚高低电平 内部拉起?拉电流弱 外部:接电阻,又5v引脚供电,又称低电平控制/负极控制,灌电流强

PCB-Printed Circuit Board 印制电路板 - 芯片的载体

PCB类型,如何通过板子画出电路图? 电路板上如何区分交流直流

如何用万用表测找出电路板的坏的地方?电容爆炸? https://www.elecfans.com/d/1695230.html http://news.eeworld.com.cn/Test_and_measurement/ic521913.html https://www.youtube.com/watch?v=ejDGCiJ-aVs

http://news.eeworld.com.cn/Test_and_measurement/ic514591.html 1、看元件的状态 拿到一块出故障的电路板,首先观察电路板有没有明显的元件损坏,如电解电容烧毁和鼓胀、电阻烧坏以及功率器件的烧损等。

2、看电路板的焊接 如印制电路板有没有变形翘曲;有没有焊点脱落、明显虚焊;电路板覆铜皮有没有翘起、烧糊变黑。

3、观察元件的插件 如集成电路、二极管、电路板电源变压器等方向有没插错。

4、电阻电容电感的简单测试 使用万用表对量程内的电阻、电容、电感等可怀疑元件进行简单的测试,测试有否电阻阻值变大、电容短路、开路和容值变化、电感短路和开路等现象。

5、上电测试 经过上述简单观察和测试后,无法排除故障,可进行上电测试。首先测试电路板供电是否正常。如电路板的交流电源是否异常、稳压器输出是否异常、开关电源输出和波形是否异常等

6、刷程序 对于有单片机、DSP、CPLD等可编程元件,可考虑重新刷一遍程序,排除程序运行异常造成的电路故障。





https://xie.infoq.cn/article/30387388381a0d915b2494f91 https://bbs.hassbian.com/thread-11256-1-1.html


iot apps






digital logic 电平标准/电气协议(逻辑电平的表示方式):

Hard resetting via RTS pin https://electronicsinnovation.com/hard-resetting-via-rts-pin-fixed-explained/


数模转换 ADC

microprocesser 完全是 digital device, can only understand digital signals, 所以连接一些模拟信号类型的传感器等设备就需要 microcontroller 进行AD转换, 然后也有很多终端设备需要接受模拟信号,比如老式的CRT TV,所以microcontroller又需要将digital signals模拟成 analog output输出给这些设备;

Analog (Analog Voltage Signal)-to-Digital(Digital Signal) Converter,常称ADC, 是指将连续变量的模拟信号转换为离散的数字信号的器件,比如将模温度感器产生的电信号转为控制芯片能处理的数字信号0101,这样ADC就建立了模拟世界的传感器和数字世界的信号处理与数据转换的联系。 解释

DAC 数模转换

Arduino 本身已经带有ADC和DAC(PWM),可以进行 analog的读写和digital的读写 但是raspberry pi没有(不能直接读analog,可以模拟写),所以连接模拟信号传感器的时候需要跟ADC一起工作


convert from uart to USB

cp210X ch9102 TTL - Transistor-Transistor Logic,晶体管晶体管逻辑电路

从稳定性来看,ft3232 > cp210X(cp2102) > ch340(ch340K)

windows驱动,device manager=》Ports(COM&LPT)


RC522和PN532的区别 协议支持的类型PN比RC系列更多,PN支持NFC协议,RC主要是ISO14443A/B


RP2040 vs STM32 vs ESP32 vs ESP8266

Common tips 1.install correct drive 2.cannot find serial port Change the usb cable 3.Upload speed 波特率 Device Manager Port(Com and LRT) USB-SERIAL CH340/341 (pre-install successful, install ‘ 驱动精灵’ and connect USB will auto detect drive) 芯片类型 STC90C5XX 晶振频率 调整波特率一超时 – 改用低速下载






PCB 入门教程 http://dword1511.info/dword/gswpcb_zhcn/ news: http://www.guancha.cn/Industry/2015_12_09_344069.shtml

Tools http://fritzing.org

NodeMcu vs Esp32 vs esp8266

“NodeMcu” is the name of a firmware originally for the ESP8266 microcontroller, with support for the ESP32 microcontroller added more recently, that allows you to program these microcontrollers using the Lua programming language.

In the early days of the hobbyist community’s adoption of the ESP8266, ESP8266 development boards were marketed with the name NodeMcu and the term “NodeMcu” started to be associated more with the hardware than the firmware. It is common for people with no interest in the Lua programming language to buy “NodeMcu” boards and program them with the Arduino IDE, which erases the NodeMcu firmware from the board. To make things more confusing, multiple companies marketed boards with the name “NodeMcu”, but with small hardware differences. Over time, the NodeMcu boards became less popular in the Arduino world because the similarly priced WeMos D1 Mini came out with the same functionality, but in a smaller form factor. Now, the “NodeMcu” name is being used to market ESP32 boards as well.

ESP32 is the name of a microcontroller made by Espressif. You will find this microcontroller on a variety of development boards, in a variety of forms. You can also purchase the ESP32 module, without the support components provided by the development boards.

ESP8266 is the name of a microcontroller made by Espressif. You will find this microcontroller on a variety of development boards, in a variety of forms. You can also purchase the ESP8266 module, without the support components provided by the development boards.

Espressif ESP*** Based Development Board

what’s wrrom wrover… wroom mini wrover pico

品牌 lolin lilygo

Esp32 vs esp8266 https://makeradvisor.com/esp32-vs-esp8266/ M5stack https://docs.m5stack.com/#/en/core/basic M5stickC https://docs.m5stack.com/#/zh_CN/core/m5stickc https://docs.m5stack.com/#/zh_CN/quick_start/m5stickc/m5stickc_quick_start_with_arduino_Windows https://github.com/m5stack/M5StickC/tree/master https://www.hackster.io/herbert-stiebritz/very-simple-m5stickc-clock-08275b


esp8266 A Beginner’s Guide to the ESP8266 https://tttapa.github.io/ESP8266/Chap01%20-%20ESP8266.html esp8266 esp-12 https://www.youtube.com/watch?v=8J7zflVO8K0

ESP32 ESP8266 ESP8266真会是Arduino Killer么? https://blog.csdn.net/eezata/article/details/49884179 https://esp32.com/viewtopic.php?t=86 Arduino for esp32&esp8266开发环境搭建 https://www.jianshu.com/p/8088d461fd11


NodeMCU is an open source Lua based firmware for the ESP32 and ESP8266 WiFi SOC from Espressif and uses an on-module flash-based SPIFFS file system. NodeMCU is implemented in C and is layered on the Espressif ESP-IDF.

official site: http://www.nodemcu.com forum: http://bbs.nodemcu.com/ source code: https://github.com/nodemcu

Setup: download: http://yunpan.cn/c3qQbdCTK7dtb 访问密码 ef05 win7 users may need cp2102 usb to uart bridge controller driver, CP210x USB to UART Bridge VCP Drivers https://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx

NodeMCU Amica Driver: https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers Sample: WebServer https://www.teachmemicro.com/simple-nodemcu-web-server/ MessageQueue-PubSub https://www.losant.com/blog/getting-started-with-platformio-esp8266-nodemcu https://github.com/Losant/losant-mqtt-arduino/blob/master/examples/esp8266/esp8266.ino

nodemcu是基于8266,nodemcu32是基于 esp32?

Raspberry Pi RP2040


  51单片机是对所有兼容Intel8031指令系统的单片机的统称,这一系列的单片机的始祖是Intel的8031单片机,后来随着flash ROM技术的发展,8031单片机取得了长足的进展成为了应用最广泛的8bit单片机之一,他的代表型号就是ATMEL公司的AT89系列。


3. 简单案例


4. IOT

what? The Internet of Things - IOT is the network of physical objects - devices, vehicles, buildings and other items embedded with electronics, software, sensors, and network connectivity - that enables these objects to collect and exchange data. A global infrastructure for the information society, enabling advanced services by interconnecting(physical and virtual) things based on existing and evolving interoperable information and communication technologies. Pervasive computing+Networking

when we talk about IOT, what’s in/ comes to your mind? question marks? circuit board. collect data,visualize data,analysis data,perform actions show business case: self-driven car / robot arm automation now we talk about smart city, smart nation, but from my point of view, these ideas are somehow unrealistic for now. but smart home and smart factory are relatively much more easy to achieve. At least, machines can take over such kind of tedious jobs like : https://mp.weixin.qq.com/s?__biz=MzA3OTM2NDM2Mw==&mid=2649732684&idx=5&sn=37c3be90ebcf347d9e637066c57aed8b&scene=0#rd someone may feel worried that our jobs may be taken over by machines, but think in this way, we humans can spend more time on tasks require more creative energy.

Why? this concept came out many years ago, why iot is rising today, why now: http://iotindiamag.com/2016/08/10-reasons-iot-rising-today/ sensors developing fast, and getting cheaper https://www.linkedin.com/pulse/iot-business-boost-economy-next-decades-posted-success-scodiero?articleId=8372849347531761698 show raspberry pi & arduino price comparison main stream with these, you can quickly build up your prototype from scratch. comparison: raspberry is a computer looks not like a computer microcomputer, just like your smart phone, besides standard inputs like keysroke/camera/your voice/GPS singal/Radio singal, it also can read from all kinds of sensors it’s cheap and full functional, but the downside is it’s a single computer,the kernel is a microprocessor, but aruino: controller board, an old fashioned feature phone without os. Microcontrollers are designed to perform specific tasks. Specific means applications where the relationship of input and output is defined. for example, the drone, quadrocopter, 6 channles, yaw, rotate, forward/backward… fly control is a microcontroller https://www.quora.com/How-feasible-is-it-to-use-a-Raspberry-Pi-as-the-control-system-on-an-autonomously-flying-quadcopter http://www.engineersgarage.com/tutorials/difference-between-microprocessor-and-microcontroller

How? I will show you a video https://www.youtube.com/watch?v=0kzjqBacF1k https://www.youtube.com/watch?v=onZ4KMM94yI because we can do it? that’s not enough, why we build it? back to ‘auto driven car’, shared economy

if the car hit someone or another car, who will be responsible for it? programmer? liabilities must be clear. right? agree?

business value, security, risks emerged

how are we going to build IOT system. I would like to introduce some tools here. raspberry pi&arduino facilitate us play with IOT.

tools facilitate your iot development python script i2tool https://www.shodan.io/

The last job on Earth: imagining a fully automated world – video https://www.theguardian.com/sustainable-business/video/2016/feb/17/last-job-on-earth-automation-robots-unemployment-animation-video

LPWAN+CNN低功耗加卷积网络 https://www.matchx.io/getstarted/

IoT Live Demo: 100.000 Connected Cars With Kubernetes, Kafka, MQTT, TensorFlow https://dzone.com/articles/iot-live-demo-100000-connected-cars-with-kubernete


长江智动 http://www.cjmcu.com/


单片机里的程序是如何运行的? https://www.cnblogs.com/hyper99

Blogs&Forum https://www.teachmemicro.com/tutorials/

废物利用:改造旧充电宝 https://ezo.biz/Technolog/fix-powerbank.html 树莓派UPS:用充电宝改造的不间断电源 https://www.quwj.com/2018/12/13/ups-for-raspberry-pi.html

微雪学堂 http://www.waveshare.net/study/portal.php 物联网快速开发(基础篇) http://edu.csdn.net/course/detail/923 DemoBoard 开发板专题: raspberrypi 树莓派 https://www.raspberrypi.org/ https://www.pretzellogix.net/2015/01/14/the-best-raspberry-pi-starter-kits-compared-and-reviewed/ https://learn.adafruit.com/category/learn-raspberry-pi nodemcu http://www.nodemcu.com/ http://www.doit.am/ http://www.doit.am/ Microduino https://www.microduino.cc/ http://www.leiphone.com/tag/Microduino http://www.geekpark.net/topics/212704 arduino https://www.arduino.cc/ http://www.leiphone.com/tag/arduino TinyDuino

物联网工具 https://www.relayr.io/ http://nodered.org/ http://thethingsystem.com/

Shopping: http://www.ickey.cn/

开源工具: https://processing.org/tutorials/electronics/ http://www.datamation.com/open-source/35-open-source-tools-for-the-internet-of-things-1.html

产品: http://www.faxsun.com/ http://skyworksas.com/eedu/

http://36kr.com/p/5038505.html http://www.leiphone.com/news/201509/vp9Fi4Oeuwgx0CU6.html

单片机入门 http://www.elecfans.com/soft/33/2012/20120821285311.html 51、AVR、PIC、MSP430、ARM、DSP http://www.eeskill.com/article/index/id/20643 51单片机 vs 8051 ESP8266 http://www.esp8266.com/ nodemcu based on ESP8266 Arduino 与树莓派 Raspberry P http://www.zhihu.com/question/20755144 https://www.quora.com/What-can-the-Arduino-do-that-the-Raspberry-Pi-cant-and-vice-versa arduino or 8051 https://www.quora.com/Which-is-better-arduino-or-8051-microcontroller

http://www.elecfans.com/zhuanti/DIY_Robot.html http://www.leiphone.com/news/201501/iSmdLPJvuDFiJuVF.html http://www.instructables.com/contest/robotics2015/

MEETINGS: http://solidcon.com/internet-of-things-2015/public/schedule/detail/40797

automated dinosaur game bot https://www.reddit.com/r/arduino/comments/c5o4kf/i_made_an_automated_dinosaur_game_bot/ LDR sensor 光敏电阻