or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
Networking and communications
Copying machine.
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Internet is the most complex copying machine ever invented. If you think about it, at the end a network of devices are only copying bits from one place to another. When you access a website your'e only copying a file from one computer to yours.
If you agree with the previous statement then you will agree with the fact that The cloud does not exist, only hard drives on other people computers.
Some thoughts on the internet
Network tools
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Why?
The use of communication networks and protocols is based on the idea of distributing and connecting systems by any of the following reasons:
And maybe… why not?
Do you really need to be always connected? try local first, and maybe, if there is a reason, go up one layer at a time.
Some numbers about Loneliness and (networked) Social Connections
Knowledge, ethics and generally culture are related to where you live (in the physical world), a lot of clues indicate that this is related to communication capabilities. What happens when the relation between geography and culture is broken? can ethics be unrelated to your context?
Protocols & networks
A network (in the context of this class) is a set of devices connected to each other through any type of communication lines that allows the exchange of data between them.
Network topologies
Onions and layers
Wired communication
This introduction is a quick reminder of the contents seen in the electronics basics page.
There are quite a few wired protocols in which microcontrollers can talk to one another. Before digging into them, it is important to understand the differences between their characteristics.
Serial vs. Parallel
Parallel interfaces transfer multiple bits at the same time. They usually require buses of data - transmitting across eight, sixteen, or more wires. This means that waves of data can be sent, with high speeds, but with a lot of wires.
Image source: Sparkfun
Many printers use parallel communication before the advent of serial communication!
Serial interfaces stream their data with a reference signal, one single bit at a time. These interfaces can operate on as little as one wire, usually never more than four:
Image source: Sparkfun
Synchronous vs. Asynchronous
"Asynchronous" (not synchronous) means that data is transferred without support from an external clock signal. This transmission method is perfect for minimizing the required wires and I/O pins, but it does mean we need to put some extra effort into reliably transferring and receiving data.
Image source: Sparkfun
"Synchronous" data interface always pairs its data line(s) with a clock signal, so all devices on a synchronous bus share a common clock. This makes for a more straightforward, often faster transfer, but it also requires at least one extra wire between communicating devices.
Image source: Sparkfun
Serial communication: Learn more
In this section, we will focus on serial communication, making distinction between synchronous and asynchronous.
Asynchronous communication
We use the asynchronous communication when data can be sent without timing constraints as well as oftenly less speed, with the benefit of using one less wire, one less port on each side. The most well known asynchronous communication protocol is the RX/TX or simply Serial protocol (because it's the most important).
RX/TX
By RX/TX we know the most common way of serial communication. It requires only two wires, appart from a common ground:
Data is sent asynchronously, so it means that both ends of the communication need to agree on some topics, being the speed the most important one (known as baud rate).
We also have to agree on how long the data strings are. Generally, they are grouped by bytes, with some extras, like parity bits or and synchronisation bits (start and stop). Usually, an asynchronous serial communication frame consists of a START bit (1 bit) followed by a data byte (8 bits) and then a STOP bit (1 bit), which forms a 10-bit frame as shown in the figure below. The frame can also consist of 2 STOP bits instead of a single bit, and there can also be a PARITY bit after the STOP bit.
If you want to learn much more, you can visit this tutorial
UART
UART stands for Universal Asynchronous Receiver/Transmitter and is the piece of hardware in charge of managing the data. Microcontrollers might have one, many or none UARTs:
Sometimes it's also present in a hybrid way, as UsART, which implements both, synchronous and asynchronous communication.
Chips without UART still can implementing by bit-banging (using pins to send the data as voltage levels very quickly). The SoftwareSerial is for example used in this case.
Libraries for Arduino
The most basic example of all time:
Example using both, serial and software serial, when we only have one hardware serial comm:
Libraries for Python
V-USB
V-USB is a library that allows to add USB connectivity to ATtiny microcontrollers (it was previously named tinyUSB).
USB 1.1
V-USB will create an USB 1.1 compliant low-speed device.
USB is comprised of 4 lines: Vcc, GND, D+ and D-. It is a differential pair circuit in which, roughly, the difference between D+ and D- is the actual signal we want to transmit.
The data lines require 3.3V, and for that reason we need to limit the voltage coming from many USB ports (computers, chargers, etc). Some ways to do this:
**Great tutorials available h
Find a quite nice tutorial for the hardware here
And the actual implementation of V-USB here
Synchronous communication
When timing and speed are are important, and it's worth having more wires, we will use synchronous communication. This means that we will have a clock line that stablishes the rate at which data is transferred. Most common inter-chip communication is implemented like this.
Very important
I2C and SPI seen here are seen at a descriptive level. When facing a new design, sensor usage, etc. try to find already existing libraries from people like Adafruit, Sparkfun, Arduino and others. Unless the set up is super simple, the implementation is not straight forward in many cases and it's simpler to follow a more copy/paste approach.
I2C
The Inter-integrated Circuit (I2C) Protocol is a protocol intended to allow multiple slave digital integrated circuits (chips) to communicate with one or more master chips. It is only meant for short distance communications within a single device. I2C is a convenient way of setting up communication because:
It allows for several masters to be in the same system and for only the masters to be able to drive the data line high. This means that no slave will be able to lock the line in case other slave or master is talking:
Image Source: NXP semiconductors
So, I2C bus consists of two signals (apart from VCC and GND): SCL and SDA. SCL is the clock signal, and SDA is the data signal. Each device is recognized by an unique address (whether it is a microcontroller, LCD driver, memory or keyboard interface) and can operate as either a transmitter or receiver, depending on the function of the device. In addition to transmitters and receivers, devices can also be considered as masters or slaves when performing data transfers. A master is the device which initiates a data transfer on the bus and generates the clock signals to permit that transfer. At that time, any device addressed is considered a slave.
Check this AAN by NXP semiconductors to learn much more about I2C.
Remember the pull-ups!
The data lines need to be driven high when they are not used, and for that they need pull-up resistors. Values for the pull up resistors could be around 5kΩ.
The actual protocol works with messages broken up into two types of frame: an address frame, where the master indicates the slave to which the message is being sent, and one or more data frames, which are 8-bit data messages passed from master to slave or vice versa. Data is placed on the SDA line after SCL goes low, and is sampled after the SCL line goes high.
Image Source: Sparkfun
Grove connector from Seeed
Grove, by Seeed, uses this connector as a way to interface with several protocols. This is how it looks for the I2C one:
Libraries for Arduino
Examples explained
The following examples are copied from here and here.
Example 1 Master as receiver: requesting information
Receiver:
Sender:
Example 2 Master as sender: sending information
Sender:
Receiver:
Example (for an analog pressure sensor that sends data via I2C):
Libraries for Python
Example 1, master as receiver
Example 2, master as sender
WiringPi
If you are using a Raspberry Pi, you can use WiringPi (C++), instead of sm.BUS (Python).
sm.BUS in python is not greatly documented with examples, but here you can find some reference
SPI
Serial Peripheral Interface (SPI) is a synchronous serial protocol, used for short-distance communication, primarily in embedded systems.
Image Credit: SparkFun
It uses a master-slave architecture with a single master. The master device originates the frame for reading and writing. Multiple slave-devices are supported through selection with individual slave select (SS) lines.
All these pins are explained in the SPI tutorial above. To summarize:
In SPI, only one side generates the clock signal (usually called CLK or SCK for Serial ClocK). The side that generates the clock is called the “master”, and the other side is called the “slave”. There is always only one master (which is almost always your microcontroller), but there can be multiple slaves.
When data is sent from the master to a slave, it’s sent on a data line called MOSI, for “Master Out / Slave In”. If the slave needs to send a response back to the master, the master will continue to generate a prearranged number of clock cycles, and the slave will put the data onto a third data line called MISO, for “Master In / Slave Out”.
To select the Slave, we use the SS line, by dropping it, telling the particular slave to go active
Image Credit: SparkFun
We can summarize all this in the following image, but note we will be using a different Serial Communication on the PC side:
Image Credit: ATMEL
SPI is used by many programmers to flash the microcontroller's code onto the flash memory, mainly because it's fast, really fast. In many cases is the only protocol available, and in some other cases it's much faster than I2C.
Read the datasheet
For example, for the ATtiny, the Section 19.5 explains all the necessary instructions for the Serial Programming. Below, the needed connections are summarized:
A master can communicate with multiple slaves (however only one at a time). It does this by asserting SS for one slave and de-asserting it for all the others. The slave which has SS asserted (usually this means LOW) configures its MISO pin as an output so that slave, and that slave alone, can respond to the master. The other slaves ignore any incoming clock pulses if SS is not asserted. Thus you need one additional signal for each slave.
Libraries for arduino
Example, arduino as master, sending:
Looking to implement SPI?
Check the first response on this thread
OTA communication
RANGE VS POWER

Range on geography
HC08-Communication
Bluetooth communication
Both classic Bluetooth and low-energy Bluetooth apply the Adaptive Frequency Hopping (AFH) feature that detects interference from. For example, a WLAN device 802.11 b, g, n that transmits nearby, if such interference is detected, the channel is automatically placed in the blacklist. In order to handle the temporary interference, an implemented scheme retries the channels of the blacklist and if the interference has ceased the channel can be used. AFH prevents Bluetooth from interfering with other nearby wireless technologies.
The hardware that makes up the Bluetooth device is made up of two parts:
The LC or Link Controller is responsible for the processing of the baseband and the handling of the ARQ and FEC protocols of the physical layer; In addition, it handles both asynchronous and synchronous transfer functions, audio coding and data encryption.
Low-energy Bluetooth, also referred to as Bluetooth LE, Bluetooth ULP (Ultra Low Power) and Bluetooth Smart, is a new digital radio (wireless) interoperable technology for small devices developed by Bluetooth.
Master-Slaves
BlueTooth devices can act as Masters or as Slaves. The difference is that a BlueTooth Slave can only connect to a master and nobody else, instead a BlueTooth master, can connect to several Slaves or allow them to connect and receive and request information from all of them, arbitrating information transfers (up to a maximum of 7 Slaves).
-Wiring
AT COMMANDS FOR CONFIGURATION
Some commands need to be send with a "?" string at the end of the command to make it work.
For The Master Module (The other one that will be controlling the link.)
Connect to the FTDI to the computer and the bluetooth to the ftdi, select the port connection on the arduino IDE
You may type AT+CMODE=1 (master mode), and press enter. This will connect to all bluetooth modules within range, but it will only connect to one master module.
Now, type AT+ADDR, and press enter. You should get an address like "587A62500108", or something similar. Write this down, you will need it later.This is the mac address of the master module.
For The Slave Module (The other one that will be listening to the link.)
Connect to the FTDI to the computer and the bluetooth to the ftdi, select the port connection on the arduino IDE
You may type AT+CMODE=1 (master mode), and press enter. This will connect to all bluetooth modules within range, but it will only connect to one master module.
You may type AT+CMODE=0 ( slave mode), and press enter. This will connect to all bluetooth modules within range, but it will only connect to one master module.
Now, type AT+BIND="MAC ADDRESS OF THE MASTER" obviously with your respective address to the slave. Note the commas instead of colons given by the slave module.(in case your mac address has comas)
What should happen?
The modules should auto link when plugged in if not check for setting up the same setting in both devices and check the MacAddress
Example-1
Example-2
Example 3 - Python
NRF24-Communication
Caution working voltaje of : 3 ~ 3.6V Max
The NRF24L01 integrates an RF transceiver (transmitter + receiver) at a frequency between 2.4GHz to 2.5GHz, a free band for free use. The transmission speed is configurable between 250 Kbps, 1Mbps, and 2 Mbps and allows simultaneous connection with up to 6 devices.
The NRF24L01 also incorporates the necessary logic to make communication robust, such as correcting errors and forwarding data if necessary, freeing the processor of this task. The control of the module is done through the SPI bus, so it is easy to control it from a processor such as Arduino.
The band of frequency is of 2400 to 2525 MHz, being able to choose between 125 channels spaced at the rate of 1MHz. It is recommended to use the frequencies from 2501 to 2525 MHz to avoid interference with Wi-Fi networks.
But before starting with the example, you have to know that the NRF24L01 module is a transceiver and not a receiver transmitter.
A receiving transmitting equipment can send radio messages and receive them simultaneously because both circuits, although very similar, are isolated from each other and can be operated independently.
The first thing you have to do is download the latest version of the RF24 library and import it into your Arduino IDE, for this in the menu bar go to Sketch> Import Library> Add Library
The following example shows the sending of a text string from an Arduino sender to an Arduino receiver, which upon receiving the text shows it by serial port.
Sender Code
Receiver
More tutorials
HC12-Communication
The HC-12 is a half-duplex wireless serial communication module with 100 channels in the 433.4-473.0 MHz range that is capable of transmitting up to 1 km.
The HC-12 is a half-duplex 20 dBm (100 mW) transmitter paired with a receiver that has -117 dBm (2×10-15 W) sensitivity at 5000 bps.
Paired with an external antenna, these transceivers are capable of communicating up to and possibly slightly beyond 1 km in the open and are more than adequate for providing coverage throughout a typical house.
Setup & Configuration AT Serial Commands
Wiring

Pro´s
Con´s
More and more
Example Code Send-Receive
Antennas
Antenna based on the frecuency
Video of wavelenght penetration comparison
Monopole
Monopole antenna is the simplest form of antenna, which is basically just a piece of un-shielded wire. It’s very common in radio receivers because they are cheap and easy to repair. However they are not as effective as Dipole antennas.

Calculation of wire length for antenna
If the antenna is a quarter wave monopole antenna, then its length should be a quarter of the signal wavelength.
The more precise wire length is, the better signal you should get ideally. If you are using Coaxial Cable, it doesn’t matter how long the cable is with shielding, all that matter is the exposed wire (the part that is without the shielding). Alternatively if you are using a wire like copper wire, just cut it to the calculated length and you have a monopole antenna :)
Dipole antenna
Dipole antennas has a simple design. It’s basically just a monopole antenna with a ground sleeve at under the active element. The ground sleeve can supposedly boost the performance considerably

Half Wave dipole antenna
A half-wave dipole antenna consists of two quarter-wavelength conductors placed end to end for a total length of approximately L = λ/2

Patch antenna
Patch antennas are also directional, and can be found in linear and circular polarization. They generally have less directionality than Helical, and smaller foot-print.

WiFi
Before moving into the specifics of the code, it is important to know who is who.
From the ESP8266WiFi library docs: devices that connect to Wi-Fi network are called stations (STA). Connection to Wi-Fi is provided by an access point (AP), that acts as a hub for one or more stations. The access point on the other end is connected to a wired network. An access point is usually integrated with a router to provide access from Wi-Fi network to the internet. Each access point is recognized by a SSID (Service Set IDentifier), that essentially is the name of network you select when connecting a device (station) to the Wi-Fi.
In the case of the ESP8266, or ESP32, they can work as:
Libraries
Examples
Need security?
You can use TLS/SSL extensions to protect your data from being sniffed!
WIFIBROADCAST
Wifibroadcast is a project aimed at the live transmission of HD video (and other) data using wifi radios. One prominent use case is to transmit camera images.
In contrast to a normal wifi connection wifibroadcast tries to mimic the advantageous properties of an analog link (like graceful signal degradation, unidirectional data flow, no association between devices).
Wifibroadcast puts the wifi cards into monitor mode. This mode allows to send and receive arbitrary packets without association. Additionally, it is also possible to receive erroneous frames (where the checksum does not match). This way a true unidirectional connection is established which mimics the advantageous properties of an analog link.
Let's copy something
Remember that in the ESP32 Feather dosumentation you can find a lot of information about your board. And here you can find info about using MQTT on your ESP32 feather.
Lets create a network with low/high tech components:
MQTT broker address = 172.16.10.224
So when we type a message on our Arduino Serial monitor, the esp will receive that on the Serial port and send that message via MQTT to the broker. The broker will forward any received data to the subscribed devices, that means our second ESP will receive the data and (if our code works!) send it to the second computer to be reade on the Arduino serial monitor…
Seems complex? imagine the complexity of the journey of the wattsapp message you just sent to youur classmate!
To send a msg directly from the arduino Serial monitor just add this to your loop function.
c