To come in
Sewerage and drainpipes portal
  • Famous types of mustache in men: all about manhood
  • "Mix, but do not stir"
  • Do you need to be an erudite to become successful
  • 100 best snipers in history
  • Daily Fat Rate Animal Products
  • Symbols of Satanism (12 photos)
  • Serial SPI interface. Using resistors when pinning and pulling resistors on the MCU input or output pins Which mcu pin will have such a signal

    Serial SPI interface. Using resistors when pinning and pulling resistors on the MCU input or output pins Which mcu pin will have such a signal

    Another interesting and even useful project on NodeMCU is a creeping line with WiFi control... Surely, all of us every day see such devices on the streets of the city. For example, the creeping line is widely used in transport to display the route number, the next stop, and intrusive advertising of all sorts of things. A typical creeping line is an LED matrix with a sweep control circuit and a microcontroller on board. The text crawling over this matrix can be stored locally, or updated dynamically via WiFi or GSM. Of course, having such a powerful platform as NodeMCU (or any other ESP8266), you can make a running line at home. It is rational to install it somewhere in a public place, for example, at a school. Through such an information board, it will be convenient to report internal school news, the temperature outside the window, or even the names of excellent students! In our laboratory, we installed a ticker in a window on the first floor. With the help of this IoT device, we congratulated all passers-by a Happy New Year and Merry Christmas 🙂

    1. Connecting LED Matrix to NodeMCU

    We will work with ready-made matrix modules controlled by the MAX7219 microcircuit. We have already written in detail about the work of such modules in one of the lessons for the Arduino platform -. In short, each such module has 10 pins. Five on one side and the same on the other. This is done so that the modules can be connected one after the other in a chain. At the entrance we have:
    • two pins for power supply: ground GND and + 5V;
    • three contacts for the SPI bus: CS, DIN, CLK;
    Let's say we want to make a creeping line of four such modules. We take the first module and connect it to the NodeMCU according to the scheme:
    8x8 LED Array with MAX7219 VCC GND DIN CS CLK
    NodeMCU + 5V GND D7 D8 D5
    Then, we connect the other three to the first module:
    Stand appearance:
    Instead of four separate modules, it makes sense to use a ready-made assembly, for example, this:

    2. Program for controlling MAX7219 on NodeMCU

    Let's try to run a creeping line on matrices, while we cannot remotely connect to NodeMCU. That is, the creeping line will rotate some kind of static text. Basically, this is code from. The only thing that has changed is the size of the chain. Here we are using not six matrices, but only four. #include #include #include Max72xxPanel matrix \u003d Max72xxPanel (D8, 4, 1); unsigned long ticker_next; String tape \u003d "Hello from RobotClass!"; int spacer \u003d 1; int width \u003d 5 + spacer; void setup (void) (matrix.setIntensity (7);) void handleTicker () (for (int i \u003d 0; i< width * tape.length() + matrix.width() - 1 - spacer; i++) { matrix.fillScreen(LOW); int letter = i / width; int x = (matrix.width() - 1) - i % width; int y = (matrix.height() - 8) / 2; while (x + width - spacer >\u003d 0 && letter\u003e \u003d 0) (if (letter< tape.length()) { matrix.drawChar(x, y, tape, HIGH, LOW, 1); } letter--; x -= width; } matrix.write(); delay(50); } } void loop(void){ handleTicker(); } Подаем питание и на матрице начинает двигаться бегущая строка с текстом «Hello from RobotClass!»

    3. Web server on NodeMCU to control the LED array

    Now let's add a web server to the program, which will display one single HTML page with a field for entering the text of the scrolling line and with a button. #include #include #include #include #include #include const char * ssid \u003d "ESP"; // start WiFi point ESP ESP8266WebServer server (80); // start the server on port 80 Max72xxPanel matrix \u003d Max72xxPanel (D8, 4, 1); unsigned long ticker_next; String tape \u003d "RobotClass"; int spacer \u003d 1; int width \u003d 5 + spacer; // HTML page index.html const char page \u003d " " "Ticker control" "" "
    " "" "" "
    " "

    " ""; // the function is called when the client presses the button void handleSubmit () (tape \u003d server.arg (" text "); server.send (200," text / html ", page);) void handleRoot () (if ( server.hasArg ("text")) (handleSubmit ();) else (server.send (200, "text / html", page);)) void setup (void) (delay (1000); WiFi.softAP (ssid ); server.on ("/", handleRoot); server.begin (); matrix.setIntensity (7);) void handleTicker () (for (int i \u003d 0; i< width * tape.length() + matrix.width() - 1 - spacer; i++) { matrix.fillScreen(LOW); int letter = i / width; int x = (matrix.width() - 1) - i % width; int y = (matrix.height() - 8) / 2; // центровка по вертикали while (x + width - spacer >\u003d 0 && letter\u003e \u003d 0) (if (letter< tape.length()) { matrix.drawChar(x, y, tape, HIGH, LOW, 1); server.handleClient(); } letter--; x -= width; } matrix.write(); delay(50); } } void loop(void){ server.handleClient(); handleTicker(); } Загружаем программу на Node MCU и подаем питание. По-умолчанию, бегущая строка будет крутить текст «RobotClass». Чтобы его изменить, необходимо подключиться к WiFi точке «ESP» и зайти через браузер по адресу: http://127.0.0.1/ В ответ появится страница с полем для ввода текста бегущей строки и кнопкой «Set text». Вводим в поле новый текст, жмем кнопку и смотрим на бегущую строку! Your browser does not support the video tag.

    4. Creeping line in Russian

    In its current form, our device does not support Russian. If you try to enter text in Russian, instead of letters, utf8 codes will appear on the matrix. To fix this, we need an additional utf2rus function. In addition, we will add the password for the WiFi hotspot to the program. #include #include #include #include #include #include const char * ssid \u003d "ESP"; const char * pwd \u003d "makemyday"; // password for WiFi point ESP8266WebServer server (80); Max72xxPanel matrix \u003d Max72xxPanel (D8, 4, 1); unsigned long ticker_next; String tape \u003d "RobotClass.ru"; int spacer \u003d 1; int width \u003d 5 + spacer; const char page \u003d " " "" "" "Ticker control" "" "
    " "" "" "
    " "

    " ""; String utf8rus (String source) (int i, k; String target; unsigned char n; char m \u003d (" 0 "," \\ 0 "); k \u003d source.length (); i \u003d 0; while (i< k) { n = source[i]; i++; if (n >\u003d 0xC0) (switch (n) (case 0xD0: (n \u003d source [i]; i ++; if (n \u003d\u003d 0x81) (n \u003d 0xA8; break;) if (n\u003e \u003d 0x90 && n<= 0xBF) n = n + 0x2F; break; } case 0xD1: { n = source[i]; i++; if (n == 0x91) { n = 0xB7; break; } if (n >\u003d 0x80 && n<= 0x8F) n = n + 0x6F; break; } } } // switch m = n; target = target + String(m); } return target; } void handleSubmit(){ tape = utf8rus(server.arg("text")); server.send(200, "text/html", page); } void handleRoot() { if (server.hasArg("text")) { handleSubmit(); } else { server..softAP(ssid, pwd); server.on("/", handleRoot); server.begin(); matrix.setIntensity(7); } void handleTicker(){ for (int i = 0 ; i < width * tape.length() + matrix.width() - 1 - spacer; i++) { matrix.fillScreen(LOW); int letter = i / width; int x = (matrix.width() - 1) - i % width; int y = (matrix.height() - 8) / 2; while (x + width - spacer >\u003d 0 && letter\u003e \u003d 0) (if (letter< tape.length()) { matrix.drawChar(x, y, tape, HIGH, LOW, 1); server.handleClient(); } letter--; x -= width; } matrix.write(); delay(50); } } void loop(void){ server.handleClient(); handleTicker(); } Готово! Теперь устройство готово к непрерывной эксплуатации. Осталось сделать крепление для матрицы и поставить бегущую строку на видное место. Чертежи подходящего крепления можно найти тут:

    The Power-On Reset (POR) circuitry ensures that the microcontroller starts up only when Vcc reaches a safe level. As shown in Fig. 24, a built-in timer clocked by a built-in watchdog generator keeps the MCU from starting up for some time after reaching the power-on limit Vpot, independent of the slew rate Vcc (see Fig. 26).

    Table 6 shows the settings of the SUT1 and SUT0 bits used to set the length of the start-up delay period. The user is given the option to select the start time delay. Setting SUT 1/0 \u003d 00, which starts the MCU after 5 clock cycles, is used when using an external clock applied to the XTAL1 pin. This setting provides fast startup from power down or power save modes, provided a clock signal is present in these modes. See the Programming section for details.

    If the built-in start-up delay is sufficient, then RESET can be connected to Vcc directly or through an external pull-up resistor. By keeping the pin low while energizing, the power-on reset period can be extended. An example of such clocking is shown on. Figure: 27.

    Figure: 25. Initial launch of the MCU. RESET pin connected to Vcc, Vcc ramp up

    Figure: 26. Initial launch of MCU. RESET pin connected to Vcc, Vcc ramp up slowly

    According to previous notes, and after reading the specification, some probably had a question - what is this second mysterious MCU processor operating at 100 MHz? Why is it needed? How to use it?
    Meanwhile, the role of the MCU in some cases is extremely important. Those who have tried using Edison to work with various sensors may have already noticed that Intel Edison does not provide real-time response to their readings when working from Linux. And that's where the MCU comes in. It's time to tell a little about this embedded microcontroller, its architecture, applications and consider a practical example.

    Intel Edison software version 2.1 adds the ability to use an embedded microcontroller.

    Consider a system on a chip used in the Intel Edison Compute Module:

    The system-on-a-chip used in the Intel Edison Compute Module includes two processors:

    1. Dual-core Intel Atom processor running at 500 MHz. Designated as Host CPU.
    2. Microcontroller with Minute IA architecture, operating at 100 MHz. Designated as MCU.
    Let's consider the microcontroller in more detail. The Minute IA compute core is an energy efficient architecture based on 486 with added instructions for Pentium compatibility. In addition to the computational core, the microcontroller contains an input-output subsystem (GPIO, I2C, High Speed \u200b\u200bUART, DMA) and SRAM. The microcontroller has access to all GPIO ports in the Edison Compute Module. The total SRAM for code and data is 192 kb. The microcontroller runs the real-time operating system Viper OS from WindRiver.

    The microcontroller application runs on top of the Viper core and controls the peripherals connected to the MCU independently of the Intel Atom processor. For example, it can control GPIO ports, communicate with sensors via I2C or UART protocol, and communicate with an Intel Atom processor.

    Why do you need a microcontroller in Intel Edison?

    I would highlight two areas where an embedded microcontroller can be applied:
    1. Work with I / O ports and interfaces with real-time response.
    2. Energy efficiency.
    The Intel Atom processor and the standard Yocto Linux distribution do not allow real-time responsive applications out of the box. The application could be preempted by the task scheduler, resulting in unacceptable and unpredictable latency. The microcontroller runs a single application and real-time operating system, so it is possible to provide real-time response. This is required for many sensors, where the communication protocol depends on strict adherence to short time intervals. To connect them without a built-in microcontroller, you would have to use a separate microcontroller, on which to implement all the functionality for working with such sensors. An example of a solution for Intel Edison with an external microcontroller is the SparkFun Block for Intel Edison - Arduino expansion board.

    It is possible to improve energy efficiency using a microcontroller in those applications where the main processor can be in a sleep state, and the microcontroller can wait for a certain event (for example, exceeding threshold values \u200b\u200bfrom a sensor).
    The microcontroller wakes up the main processor if necessary. An example implementation is provided in Using the MCU SDK and API: Code examples.

    As an example of working with the Intel Edison microcontroller, consider connecting the HC-SR04 ultrasonic distance sensor. The measured distance will be displayed on the Grove LCD RGB Backlight character screen.



    The sensor has 4 outputs:
    • Vcc - 5V.
    • Trig - Trigger signal to the sensor. The microcontroller applies a 10 microsecond pulse to the sensor. The sensor initiates the measuring process.
    • Echo - Echo signal from sensor to microcontroller. The pulse duration is proportional to the measured distance.
    • Gnd - Earth.
    This is how the process of working with the sensor looks on the oscilloscope screen:

    • 1 channel - Trig
    • 2 channel - Echo
    The microcontroller applies a pulse to Trig... After that, the sensor responds with a pulse to Echo.
    The pulse width is proportional to the measured distance.
    The measured distance is calculated using the formula (taken from the sensor specification):
    distance (cm) \u003d Echo pulse duration (microseconds) / 58
    According to the specification, the sensor can measure distances from 2 to 400 cm.
    It will be problematic to measure the pulse duration with a predicted error without real-time.
    The measurement process can, for example, be supplanted by the scheduler and the measurement result will be incorrect.

    We connect HC-SR04 to Intel Edison microcontroller


    Components used:

    • Edison Compute Module
    • Edison Arduino Board
    • Grove basic shield
    • Grove LCD RGB Backlight Character Screen
    • Ultrasonic distance sensor HC-SR04
    • Bread board
    The first step is to connect the Edison Compute Module to the Edison Arduino board. Then we connect the Grove Basic Shield expansion board to the Edison Arduino Board. Grove LCD RGB Backlight connects to the I2C connector on the Grove Basic Shield.

    The HC-SR04 Ultrasonic Distance Sensor connects to the Grove Basic Shield as follows:

    • Vcc to + 5V.
    • Trig to pin # 3.
    • Echo to pin # 4.
    • Gnd to Gnd.
    Pins 3, 4 are randomly selected, you can use others instead.

    Intel Edison firmware update

    Microcontroller support is available in the Intel Edison® Board Firmware Software Release since version 2.1. If your firmware is older, you need to update it.

    You can find out the current firmware version with the command:
    # configure_edison --version
    This example was created on firmware version 146.

    The firmware update process is detailed in the Flashing Intel Edison article. Personally, I usually use the method described in the section Alternate flashing method.
    Read the instructions carefully before flashing.

    Connecting Intel Edison via Ethernet-over-USB

    To work with Edison from the MCU SDK, you need to create a network connection.
    To do this, for example, you need to connect a USB cable to the middle micro-USB port (the switch must be set towards the micro-USB ports)
    On Linux, the network is configured with the command:
    # ifconfig usb0 192.168.2.2
    Intel Edison IP: 192.168.2.15
    The connection process is described in more detail in the article Connecting to your Intel® Edison board using Ethernet over USB.

    MCU SDK

    A cross-platform development environment MCU SDK based on Eclipse has been released to create applications that will run on an embedded microcontroller. The installation process is detailed in the Installing the MCU SDK article.
    The MCU SDK allows you to create, compile, download and debug microcontroller applications.

    Interfacing with MCU

    Several interfaces are available to interact with the microcontroller from Linux:
    / dev / ttymcu0 - Channel for data exchange. You can work from Linux using standard file operations. From the program on the microcontroller, the exchange is performed using the host_send and host_receive functions.
    / dev / ttymcu1 - Channel through which the microcontroller sends debug messages using the debug_print function.
    / sys / devices / platform / intel_mcu / log_level - Allows you to set the level of debug messages (fatal, error, warning, info, debug).

    Linux program

    A small Python script that will receive data from an embedded microcontroller and display it on a character display. To work with the character display, we will use the Jhd1313m1 module from the UPM library.

    Show_distance.py script:

    import time import pyupm_i2clcd RET_ERROR \u003d -1 if __name__ \u003d\u003d "__main__": lcd \u003d pyupm_i2clcd.Jhd1313m1 (6, 0x3E, 0x62) with open ("/ dev / ttymcu0", "w + t") as f: while True: f.write ("get_distance \\ n") # Send command to MCU f.flush () line \u003d f.readline () # Read response from MCU, -1 \u003d ERROR value \u003d int (line.strip ("\\ n \\ r \\ t ")) lcd.clear () if value \u003d\u003d RET_ERROR: lcd.setColor (255, 0, 0) # RED lcd.write (" ERROR ") else: lcd.setColor (0, 255, 0) # GREEN lcd.write ("% d cm"% (value,)) time.sleep (1)

    Microcontroller program

    The program on the microcontroller should, upon receiving the get_distance command from the host, measure the distance and send the result to the host (distance in centimeters, or -1 in case of an error).
    Configuring ports on the Edison Arduino Board:
    ./init_DIG.sh -o 3 -d output ./init_DIG.sh -o 4 -d input
    Let me remind you that the microcontroller works with GPIO ports on the Edison Compute Module, which differ from the numbering on the Edison Arduino Board. The correspondence table is given, for example, at the end of the article Blinking an LED using the MCU.

    Microcontroller program in MCU SDK:

    #include "mcu_api.h" #include "mcu_errno.h" // Arduino Extension PIN \u003d 3 #define TRIG 12 // Arduino Extension PIN \u003d 4 #define ECHO 129 // From HC-SR04 datasheet #define MIN_DISTANCE 2 #define MAX_DISTANCE 400 #define MAX_WAIT 10000 #define RET_ERROR -1 int get_distance () (// Send Trig signal to HC-SR04 gpio_write (TRIG, 1); mcu_delay (10); gpio_write (TRIG, 0); // Read Echo signal from HC -SR04 int i; i \u003d 0; while ((gpio_read (ECHO) \u003d\u003d 0) && (i< MAX_WAIT)) { mcu_delay(1); i++; } unsigned long t0 = time_us(); if (gpio_read(ECHO) == 0 || i == MAX_WAIT) { return RET_ERROR; } i = 0; while ((gpio_read(ECHO) == 1) && (i < MAX_WAIT)) { mcu_delay(1); i++; } unsigned long t1 = time_us(); if (gpio_read(ECHO) == 1 || i == MAX_WAIT) { return RET_ERROR; } unsigned long distance = (t1 - t0) / 58; if (MIN_DISTANCE < distance && distance < MAX_DISTANCE) { return distance; } else { return RET_ERROR; } } #define MAX_BUF 255 unsigned char buf; void mcu_main() { // Setup Trig as OUTPUT gpio_setup(TRIG, 1); // Initially set Trig to LOW gpio_write(TRIG, 0); // Setup Echo as INPUT gpio_setup(ECHO, 0); while (1) { unsigned int len; len = host_receive(buf, MAX_BUF); if ((len >\u003d 12) && (strncmp (buf, "get_distance", 12) \u003d\u003d 0)) (unsigned int distance; distance \u003d get_distance (); len \u003d mcu_snprintf (buf, MAX_BUF, "% d \\ n", distance); host_send (buf, len);)))