Advance Innovation Centre
  • AIC Knowledge @ EEC for All
  • 😎Logical Thinking
    • Karel Robot
    • Code to Flowchart
    • Play with Docker
    • CNX Software
  • MCU & Interfacing with Infineon PSOC™
    • Basic MCU Interfacing
      • Introduction to CY8CKIT-062S2-43012 Pioneer Kit
      • Development Environment Preparation
      • PSoC™ 6S2 Peripherals Interfacing (GPIO)
        • Hello World and LED Blinking
        • GPIO Principles
        • PSoC™ 6S2 GPIO-HAL LED Blink Lab
        • PSoC™ 6S2 GPIO-PDL LED Blink Lab
        • Button "Bounce" Principles
          • Push/Pull Button to Turn ON/OFF LED via HAL
          • Push/Pull Button to Turn ON/OFF LED via PDL
          • GPIO Button Interrupt via HAL
          • GPIO Button Interrupt via PDL
        • GPIO variables & functions
      • PSoC™ 6S2 Peripherals Interfacing (ADC, PWM)
        • PSoC™ 6S2 SAR ADC
          • ADC Principles
          • PSoC™ 6S2 with ADC Labs
            • Reading potentiometer sensor value via an ADC HAL
            • Reading potentiometer sensor value via an ADC PDL
        • PSoC™ 6S2 PWM & TCPWM
          • PWM Principles
          • PSoC™ 6S2 for PMW Function Labs
            • LED Brightness using PWM via HAL
            • LED Brightness using PWM via PDL
    • Sensor Interfacing and HMI
      • OLED Display
        • OLED Display Principles
        • Calling BDH’s OLED functions
        • Display ADC via Potentiometer on OLED
      • BDH Shell
        • Shell Principles
        • LED Blinking and CAPSENSE via BDH Shell
        • Adding "History" command
        • Adding "Reboot" command
        • CAPSENSE Button and Slider
          • CAPSENSE Button and Slider with Capsense Tuner
          • CAPSENSE Button and Slider using FreeRTOS
    • Serial Communication & Visualization
      • UART, I2C, SPI Communication via Infineon PSoC™6
      • BMX160 Sensor Communication via Infineon PSoC™6
        • Reading ADC via HAL with Potentiometer and Displaying GUI on Serial Studio
        • Reading XENSIV-DPS-3XX Pressure Sensor and Displaying GUI on Serial Studio
        • Motion Sensors GUI Integration via Serial Studio
    • IoT Connectivity & Data Analytics via Node-Red
      • Node-Red Installation
      • Setting MQTTS to MQTT Broker
      • Sending PSoC6’s sensor to MQTT (node-red)
    • Edge AI on PSoC™
      • Machine Learning on PSoC™6 via Edge-Impulse
    • Infineon PSoC™ Troubleshooting
  • IoT Development with Infineon PSOC™ & BDH Platform
    • PSoC™ IoT Development Kit
      • Introduction to CY8CKIT-062S2-43012 Pioneer Kit
      • Development Environment Preparation
        • Hello World and LED Blinking
    • IoT Connectivity
      • Node-Red Installation
      • Controlling PSoC™ LED using MQTT
      • Setting MQTTS to MQTT Broker
      • Sending PSoC6’s sensor to MQTT (node-red)
    • BDH IoT Connectivity
    • WireLinX™ IoT PLC
    • BDH X-Brain Data Analytics
      • PSoC6 Data Collection to CSV log file
    • Data Visualization
      • สร้าง Dashboard ด้วย Looker Studio
  • 🖥️Operation Systems
    • Prerequisites
      • Guideline from Ubuntu
        • Ubuntu and VSCode on WSL2
      • ติดตั้ง WSL 2
      • Run Ubuntu on VirtualBox7
    • Zero to Linux Hero
      • Computer OS Architecture
      • Anatomy of Linux System
        • UNIX/Linux History
        • UNIX/Linux Evolution
        • GNU Project
        • Linux OS Architecture
        • Command Line Interface (CLI)
          • Basic Commands
          • 😎Level up your Linux Shell
          • File & Dir. Commands
          • Searching Commands
          • 😎ChatGPT-based Terminal
          • SysAdmin Commands
          • Network Commands
          • Hacker Commands
        • Busybox
        • Shell Script
          • Awk Script
          • Bash Shell Script
            • Bash Snippets
            • Bash Useful Examples
      • Anatomy of Linux Kernel
        • Linux Kernel Principles
        • Linux Environment for Developer
      • Anatomy of Embedded Linux
        • Embedded Linux
        • Host & Target
        • Cross Toolchains
        • Bootloader
        • Building Embedded Linux
    • Linux OS Dev. Engineer
      • Process Management
        • Process Basic
        • Process State
        • Basic Process Mgmt. Commands
        • Advance Process Mgmt. Commands
        • Process API Programming
      • IPC
        • IPC Anatomy
        • Signal Programming
        • Pipe Programming
        • FIFO Programming
        • Msg. Queue Programming
          • System V
        • Share Memory Programming
          • System V
        • Socket Programming
      • POSIX Threads
        • Multi-tasking Basic
        • POSIX Thread Anatomy
        • Threading Programming
      • Applied IPC
        • Remote Commander
        • Multi-Remote Commanders
      • Process Synchronization
        • Mutex Programming
        • Semaphore Programming
      • Applied IPC with Semaphore
  • ⌚Embedded Systems Development
    • Introduction to ESD
      • Why's ESD?
      • What it use for?
      • How it works?
    • Enbedded System Development via PSoC6
      • Basic MCU Interfacing
        • Introduction to CY8CKIT-062S2-43012 Pioneer Kit
        • Development Environment Preparation
        • PSoC™ 6S2 Peripherals Interfacing (GPIO)
          • Hello World and LED Blinking
          • GPIO Principles
          • PSoC™ 6S2 GPIO-HAL LED Blink Lab
          • PSoC™ 6S2 GPIO-PDL LED Blink Lab
          • Button "Bounce" Principles
            • Push/Pull Button to Turn ON/OFF LED via HAL
            • Push/Pull Button to Turn ON/OFF LED via PDL
            • GPIO Button Interrupt via HAL
            • GPIO Button Interrupt via PDL
          • GPIO variables & functions
        • PSoC™ 6S2 Peripherals Interfacing (ADC, PWM)
          • PSoC™ 6S2 SAR ADC
            • ADC Principles
            • PSoC™ 6S2 with ADC Labs
              • Reading potentiometer sensor value via an ADC HAL
              • Reading potentiometer sensor value via an ADC PDL
          • PSoC™ 6S2 PWM & TCPWM
            • PWM Principles
            • PSoC™ 6S2 for PMW Function Labs
              • LED Brightness using PWM via HAL
              • LED Brightness using PWM via PDL
      • Sensor Interfacing and HMI
        • OLED Display
          • OLED Display Principles
          • Calling BDH’s OLED functions
          • Display ADC via Potentiometer on OLED
        • BDH Shell
          • Shell Principles
          • LED Blinking and CAPSENSE via BDH Shell
          • Adding "History" command
          • Adding "Reboot" command
          • CAPSENSE Button and Slider
            • CAPSENSE Button and Slider with Capsense Tuner
            • CAPSENSE Button and Slider using FreeRTOS
      • Serial Communication & Visualization
        • UART, I2C, SPI Communication via Infineon PSoC™6
        • BMX160 Sensor Communication via Infineon PSoC™6
          • Reading ADC via HAL with Potentiometer and Displaying GUI on Serial Studio
          • Reading XENSIV-DPS-3XX Pressure Sensor and Displaying GUI on Serial Studio
          • Motion Sensors GUI Integration via Serial Studio
    • Edge Computing and IoT Connectivity
    • Cloud-Based Data Analytics and Digital Twin
    • Edge Vision AI
    • Resources
      • Basic Hardware and Firmware
        • Environment Preparation
          • การติดตั้งโปรแกรม Arduino IDE
            • ตัวอย่างการเริ่มต้นใช้งาน Arduino IDE
          • การติดตั้งโปรแกรมสำหรับใช้งานเครื่องมือวัด NI MyDAQ
            • ตัวอย่างการตั้งค่าใช้ Digital Multimeter -NI ELVISmx
            • ตัวอย่างการตั้งค่าใช้ Oscilloscope-NI ELVISmx
          • ติดตั้งโปรแกรม KingstVIS
        • Basic measurement
          • Basic Digital and Analog I/O
            • LAB: Basic Digital Input/Output
            • LAB: Basic Analog Input/Output
          • Waveform
            • LAB: Oscilloscope
            • LAB: Oscilloscope and Function Generator
            • LAB: Pulse Width Modulation (PWM)
              • Homework
        • Interfacing and Communication
          • LAB: UART, RS485, RS232 Protocol
          • LAB: I2C Protocol
            • HOMEWORK
          • LAB: SPI Protocol
      • IoT Connectivity
        • Example: IoT with MQTT on Node-red
        • Data logger
        • LAB: Data Visualization
  • 🛠️C/C++ for Embedded Programming
    • Development Environment Preparation
      • ติดตั้ง WSL 2
      • ติดตั้ง Ubuntu environment
      • ติดตั้งโปรแกรม Visual Studio Code
      • การเชื่อมต่อ Virtual studio code เข้ากับ WSL
      • ติดตั้ง docker on WSL
    • Principle C/C++ Programming
      • Get started with C++
      • Makefile
        • Makefile Examples
      • Compiling and running
        • How to create a program that you can enter inputs.
          • Lab 1 Exercise
      • Arguments
        • Command line arguments in C and C++
      • signed and unsigned data types
      • Variable and Operator
      • If and If else
      • Loop, Infinite loop, and flag
        • Loop and Flag exercise
      • Array
        • Get to know with arrays
        • Implement example
      • Vector
    • Object Oriented Programming (OOP) in C++
      • Class and Object
      • Encapsulation and Abstraction
      • Polymorphism and Inheritance
    • C/C++ Preprocessing
      • Macro
        • Quiz Macro
      • File Inclusion
      • Conditional Compilation
      • Pragma directive
        • Quiz Pragma
    • String in C++
      • Concatenation
      • Split
    • Type conversions for C/C++
      • Conversion using Cast operator
    • Error handling
    • Data logger
      • การสร้างไฟล์และเขียนไฟล์
      • การอ่านไฟล์
      • การเก็บข้อมูลกับTime stamp
    • High performance programing
      • Multi-task and Multi-thread
        • Multi-threading example
      • Mutex
      • Queue
      • OpenCV
    • C/C++ Techniques
      • Makefile in action
      • Object Oriented Programming (OOP) in C++
        • Class and Object
        • Encapsulation and Abstraction
        • Polymorphism and Inheritance
      • C/C++ Preprocessing
        • Macro
          • Quiz Macro
        • File Inclusion
        • Conditional Compilation
        • Pragma directive
          • Quiz Pragma
      • Binary, Octal and Hexadecimal Numbers
      • Array and properties of an array
        • Get to know with arrays
        • Implement example
      • What's next?
  • 🤖Artificial Intelligence (AI)
    • VAMStack Design House, BUU
    • Data Analytics
      • Data cleansing
      • Data analytics
      • Data analytic exercise
    • Machine Learning
      • Neural Network Layers
      • Machine learning type
      • Dataset
      • Using Edge Impulse for AI Model
    • Basic Image Processing
      • Computer Vision using Python Language
        • Installation
        • Computer Vision Basics
          • Pixel and Color
          • Draw image
          • Basic Image processing
          • Morphology Transformations
          • Gaussian blur
          • Simple Thresholding
          • Contour
          • Canny edge detection
        • Case Study
          • Coin counting
          • Color detection & tracking
        • VAM_CV SDK
  • ⚙️FPGA Design and Development
    • Verilog HDL via Vivado IDE
      • LAB1: Setting Environment and Create Project
        • Create Vivado Project
      • LAB2: Hardware Description Language Work Flow
        • Simulation code
      • LAB3: Design HDL Project
        • Top Level Design
        • Top-level Simulation
      • LAB4: Asynchronous VS Synchronous Circuit
        • Simulation Synchronous counter
    • C/C++ Programming on Ultra96v2 FPGA Board
      • Application C/C++ on Ultra96v2 Part 1
        • Design Overview
        • Step 1 - Burn the image to SD card
        • Step 2 - Bring up Ultra96v2
        • Step 3 - Installing the Vitis-AI runtime packages
      • Application C/C++ on Ultra96v2 Part 2
        • STEP 1 : Setting auto boot Wifi
        • STEP 2 : How to working on Embedded
        • STEP 3 : How to run the test code
  • 🤖Robotics
    • Dobot Magician
      • Instruction of Dobot
      • Software Download
      • Basically of Program
        • Teaching and Playback
        • Write and Draw
        • LaserEngraving
        • 3D Printer
    • Robotino
      • Software Download
        • Robotino View
        • Robotino SIM
      • Charging
      • Connecting
      • Follow Line example
        • Basic block in Follow Line
    • RaspBlock
      • Get Started with Raspblock
  • 🚩Special Topics
    • Node-Red
      • Set up Raspberry Pi
      • Install node red in Raspberry Pi
      • Get started with Node Red
        • Open node-red
        • Turn off node red
        • Install Dashboard on Node-red
        • Use node red to show message
        • Using Ultrasonic sensor with node-red
    • IoT Cloud
      • Overview
        • How do they work?
          • Basic Knowlege
      • Installations
        • Install Docker
        • Install Mosquitto Broker
        • Install InfluxDB
        • Install Telegraf
        • Install Grafana
      • Get Sensor Value and Send to MQTT
        • Connect ESP3266 to sensor
        • Connect ESP3266 to MQTT
      • Integration
    • Senses IoT
      • SENSES IoT Platform
      • LAB8: MCU send data to IoT platform
    • CrowPi Dev Kit
      • Raspberry Pi with CrowPi
      • Remote to Raspberry Pi
      • Cross-Compile
        • Lab 1: Programming and cross complier
      • Hardware and Interfaces Usage CLI
        • LAB: Usage GPIO via CLI
        • LAB: Scan I2C bus via CLI
      • Python library for Crow Pi
      • wiringPi library (C) for CrowPi
        • Lab2: Crowpi and sensors
    • LVGL Development
      • LVGL - Light and Versatile Embedded Graphics Library
        • Setting program for LVGL Simulator
        • Get started with LVGL simulator
        • Example Library of LVGL
        • Create your own screen
          • Exercise
        • Style
          • Exercise
        • Event
    • Docker OS
      • Docker OS Part 1
        • Part 1 : Installation
        • Part 2 : Basic Docker OS and Linux CLI
      • Docker OS Part 2
        • Part 1 : Docker communication
        • Part 2 : Docker compose
      • Application Gstreamer on devcontainer
        • STEP 1 : Setting gstreamer environment
        • STEP 2 : Create the Gstreamer element on template
        • STEP 3 : Testing and application on your gst element
  • 🤟Recommended by AIC
    • Skill Roadmap
      • Embedded Engineer
      • Developer
    • Hardware Programming
    • Embedded Programming
    • General-propose Programming
    • Algorithmica
    • Thai Expert Knowledge
    • RT-Thread University Program
      • Infineon PSoC6
      • Kernel
        • Kernel Basics
        • Thread Management
        • Clock Management
        • Inter-thread synchronization
        • Inter-thread communication
        • Memory Management
        • Interrupt Management
        • Kernel porting
        • Atomic Operations
        • RT-Thread SMP
        • Kernel API Changelog
      • Tools
      • Devices & Drivers
        • SENSOR Devices
        • Touch Equipment
        • CRYPTO Devices
        • AUDIO Devices
        • Pulse Encoder Devices
      • Components
        • C Library (libc)
        • ISO/ANSI C Standard
        • POSIX Standard
          • FILE (File IO)
          • Pthread
          • Timer
          • IPC Semaphore
          • IPC Message Queues
          • Dynamic Modules
        • Network Components
          • FinSH Console
          • FAL: Flash Abstraction Layer
          • Virtual File System
          • tmpfs: temporary file system
          • ulog log
          • utest testing framework
          • Power Management
          • RT-Link
        • Software Packages
          • Internet of Things
            • MQTT-umqtt
            • Telnet
          • Tools
            • SystemView
            • SEGGER_RTT
          • LVGL Manual
            • Touch Screen Driver
      • Demo
        • Infineon Gateway
        • Handwriting Recognition (MNIST)
        • Object Detection (Darknet)
        • ROS using RT-Thread
        • Control the car using RT-Thread
        • LiDAR via RT-Thread
        • Detection via RT-Thread and ROS
        • Sensor Driver Development Guide
Powered by GitBook
On this page
  • จุดประสงค์
  • LAB1: Basic I2C Communication
  • อุปกรณ์ทดลอง
  • โปรแกรม
  • ตั้งค่าโปรแกรม KingstVIS
  • PIN Connect
  • Code
  • บันทึกผลการทดลอง
  • LAB2: M5Stack อ่านค่า DHT12 Sensor
  • อุปกรณ์ทดลอง
  • โปรแกรม
  • ตั้งค่าโปรแกรม KingstVIS
  • PIN Connect
  • Code
  • บันทึกผลการทดลอง
  • LAB3: MCU to MCU communication
  • อุปกรณ์ทดลอง
  • ตั้งค่าโปรแกรม KingstVIS
  • PIN Connect
  • Code: M5Stack is a master reader
  • Code: Arduino UNO is a slave
  • บันทึกผลการทดลอง

Was this helpful?

  1. ⌚Embedded Systems Development
  2. Resources
  3. Basic Hardware and Firmware
  4. Interfacing and Communication

LAB: I2C Protocol

PreviousLAB: UART, RS485, RS232 ProtocolNextHOMEWORK

Last updated 2 years ago

Was this helpful?

Assoc. Prof. Wiroon Sriborrirux, Founder of Advance Innovation Center (AIC) and Bangsaen Design House (BDH), Electrical Engineering Department, Faculty of Engineering, Burapha University

จุดประสงค์

  1. เพื่อศึกษาการอ่านค่าข้อมูล sensor ที่ส่งข้อมูลผ่านสาย I2C

  2. เพื่อศึกษาการส่งข้อมูลระหว่าง Microcontroller ไปยัง Microcontroller โดยทั้งสองใช้การสื่อสารกันผ่าน I2C interface

LAB1: Basic I2C Communication

การทดลองนี้เป็นการเขียนโปรแกรมลงบอร์ด M5Stack ให้ค้นหา Address I2C ของ sensor ที่เชื่อมต่อกับบอร์ด M5Stack

อุปกรณ์ทดลอง

Components
Quantity

1

1

โปรแกรม

  1. Arduino IDE

  2. โปรแกรม KingstVIS

ตั้งค่าโปรแกรม KingstVIS

  • เชื่อมต่อ logic Analyzer กับ คอมพิวเตอร์

  • เปิดโปรแกรม Kingst VIS

  • ไปที่ Analyzers >> คลิ๊ก icon add(+) >> เลือก I2C

  • ไปที่ Analyzers >> คลิ๊ก icon setting >> Edit ตั้งค่าตามรูปด้านล่าง >> OK

  • ไปที่ Analyzers อีกครั้ง >> คลิ๊ก icon setting >> Display Format >> Dec เพื่อให้ decoder เป็นข้อมูลชุดตัว แบบเลขฐาน 10 (DEC)

  • ไปที่ Channel 0 เลือกกด Indicates "rising edge trigger"

PIN Connect

การต่อวงจร: บอร์ด M5Stack ต่อกับ เซนเซอร์ DHT12 และ BMP280

M5Stack
Sensor BMP280
Sensor DHT12

I2C (21D)

SDA

SDA

I2C (22C)

SCL

SCL

GND

GND

GND

ตัวอย่างวงจร

Code

M5Stack scan I2C address

// Code I2C scanner
#include <Wire.h>

void setup() {
  Wire.begin();

  Serial.begin(115200);
  while (!Serial); // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}

void loop() {
  int nDevices = 0;

  Serial.println("Scanning...");

  for (byte address = 1; address < 127; ++address) {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    byte error = Wire.endTransmission();

    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.print(address, HEX);
      Serial.println("  !");

      ++nDevices;
    } else if (error == 4) {
      Serial.print("Unknown error at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.println(address, HEX);
    }
  }
  if (nDevices == 0) {
    Serial.println("No I2C devices found\n");
  } else {
    Serial.println("done\n");
  }
  delay(5000); // Wait 5 seconds for next scan
}
  • การเขียนโปรแกรม scan หา Address ของเซนเซอร์นั้นใช้เพื่อทดสอบว่าเซนเซอร์ที่เชื่อมต่อนั้นอยู่ในเครือข่าย I2C ของบอร์ด Microcontroller แล้ว

  • เราสามารถหาค่า address ของเซนเซอร์ได้จาก datasheet ของเซนเซอร์ หรือ จาก code การทดลองนี้ ถ้าต้องการหาค่า I2C address ของ เซนเซอร์ตัวใดให้เชื่อมต่อเพียงเซนเซอร์ที่ต้องการหาและถอดวงจรเซนเซอร์ที่ไม่ต้องการออก

บันทึกผลการทดลอง

  1. หา I2C Address ของทั้งสอง sensor และ I2C Address ของ M5Stack แล้วเติมลงในตารางด้านล่าง

Devices
I2C Address

AIR PRESSURE Sensor (BMP280)

.....

Temp, Humidity Sensor (DHT12)

.....

M5Stack

.....

2. บันทึกภาพวงจรการทดลองและภาพผลที่แสดงบน Serial monitor ผลการ Scan หาค่า I2C Address ของเซนเซอร์

3. อธิบายว่าเพราะอะไรเราต้องรู้ค่า I2C Address ของอุปกรณ์ เมื่อเราต้องการใช้งานโปรโตคอล I2C

LAB2: M5Stack อ่านค่า DHT12 Sensor

ทดลองให้ M5Stack อ่านค่า DHT12 Sensor การทดลองนี้เป็นการเขียนโปรแกรมลงบอร์ด M5Stack ให้อ่านค่า DHT12 sensor และใช้ logic analyzer แสดงค่า sensor เมื่อ M5Stack ส่งคำสั่งอ่านค่า DHT12 sensor

อุปกรณ์ทดลอง

Components
Quantity

1

1

โปรแกรม

  1. Arduino IDE

  2. โปรแกรม KingstVIS

ตั้งค่าโปรแกรม KingstVIS

"ใช้แบบเดิม"

PIN Connect

การต่อวงจร: บอร์ด M5Stack ต่อกับเซนเซอร์ DHT12 และ Logic analyzer

M5Stack
Sensor DHT12
Logic Analyzer

I2C (21D)

SDA

Channel 0

I2C (22C)

SCL

Channel 1

GND

GND

GND

ติดตั้งไลบรารี่ DHT12 สำหรับเขียนโปรแกรม Arduino IDE อ่านค่า DHT12 sensor

  • เปิดโปรแกรม Arduino IDE

  • ไปที่ Sketch >> Include Library >>Manage Libraries...

  • พิมพ์ ค้นหา DHT12 >> เลือก DHT12 sensor library >> Install

  • หลังจากติดตั้งเรียบร้อยให้ปิดโปรแกรมแล้วเปิดใหม่

สร้างไฟล์แล้วเขียนโปรแกรมตาม code ด้านล่าง แล้ว upload code ลง M5Stack

Code

M5Stack read data DHT12 Sensor

//#include <M5Stack.h>
#include "DHT12.h"
#include <Wire.h> //The DHT12 uses I2C comunication.

DHT12 dht12; //Preset scale CELSIUS and ID 0x5c.

void setup() {
//    M5.begin();
  Serial.begin(115200);
  Wire.begin();
//    M5.Lcd.setCursor(80, 0, 4);
//    M5.Lcd.print("TEMPERATURE");
 
}

void loop() {
 
    float tmp = dht12.readTemperature();
    float hum = dht12.readHumidity();
//    M5.Lcd.setCursor(30, 100, 4); //display via moniter
//    M5.Lcd.printf("Temp: %2.1f  Humi: %2.0f%%", tmp, hum); //display via moniter
    Serial.printf("Temp: %2.1f  Humi: %2.0f%% \n", tmp, hum); //display via serial monitor
    delay(100);
}

บันทึกผลการทดลอง

  1. บันทึกผลการทดลองที่ Logic analyzer แสดง เทียบกับ Serial monitor และอธิบายว่าข้อมูลที่ได้เป็นอย่างไร

LAB3: MCU to MCU communication

การทดลองนี้เป็นการเขียนโปรแกรมลงบอร์ด M5Stack ให้ทำหน้าที่เป็น Master อ่านข้อความจาก Arduino UNO ที่ทำหน้าที่เป็น Slave ผ่าน I2C bus

อุปกรณ์ทดลอง

Components
Quantity

1

1

Arduino UNO

1

ตั้งค่าโปรแกรม KingstVIS

  • เชื่อมต่อ logic Analyzer กับ คอมพิวเตอร์

  • เปิดโปรแกรม Kingst VIS

  • ไปที่ Analyzers >> คลิ๊ก icon add(+) >> เลือก I2C

  • ไปที่ Analyzers >> คลิ๊ก icon setting >> Edit ตั้งค่าตามรูปด้านล่าง >> OK

  • ไปที่ Analyzers อีกครั้ง >> คลิ๊ก icon setting >> Display Format >> ASCII เพื่อให้ decoded เป็นข้อมูลชุด แบบตัวอักษร (ASCII)

  • ไปที่ Channel 0 เลือกกด Indicates "rising edge trigger"

PIN Connect

การต่อวงจร: บอร์ด M5Stack ต่อกับบอร์ด Arduino UNO และ Logic Analyzer

M5Stack
Arduino UNO
Logic Analyzer

SDA (pin 21D)

SDA (pin A4)

Channel 0

SCL (pin 22C)

SCL ( pin A5)

Channel 1

GND

GND

GND

ตัวอย่างวงจร

Code: M5Stack is a master reader

// Wire Master Reader

#include <Wire.h>
int i =0;
void setup() {
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(115200);  // start serial for output
}

void loop() {
  if(i==0){
  Wire.requestFrom(8, 6);    // request 6 bytes from slave device #8

  while (Wire.available()) { // slave may send less than requested
    char c = Wire.read(); // receive a byte as character
    Serial.print(c);   
  
    // print the character
 }
 i++;
  }

  delay(500);
}

Code: Arduino UNO is a slave

// Wire Slave Sender

#include <Wire.h>

void setup() {
  Wire.begin(8);        // join i2c bus with address #8
  Wire.onRequest(requestEvent); // register event
}

void loop() {
  delay(100);
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
  Wire.write("hello "); // respond with message of 6 bytes
  // as expected by master
   
}

บันทึกผลการทดลอง

  1. บันทึกผล Serial monitor แสดงข้อความที่บอร์ด M5Stack (Master) ได้รับ และข้อความบนโปรแกรม KingstVIS ของ logic analyzer

  2. อธิบายผลการทดลองที่ logic analyzer แสดงเทียบกับ serial monitor ของ M5Stack ที่ทำหน้าที่เป็น master

M5Stack Demo Board
Logic Analyzer (รุ่น LA1016 or LA2016)
M5Stack Demo Board
Logic Analyzer (รุ่น LA1016 or LA2016)
M5Stack Demo Board
Logic Analyzer (รุ่น LA1016 or LA2016)
อุปกรณ์การทดลอง
เลือกประเภท protocol ที่ต้องการวิเคราะห์
ตั้งค่า channel สำหรับวิเคราะห์ การส่งข้อมูลของ I2C โปรโตคอล
ตั้งค่า Display Format
ตั้งค่า Trigger Indicates "rising edge trigger"
การเชื่อมต่อวงจรเซนเซอร์ DHT12 และ BH280 กับบอร์ด M5Stack
อุปกรณ์การทดลอง
การเชื่อมต่อ DHT12 Sensor และ Logic analyzer กับบอร์ด M5Stack
อุปกรณ์การทดลอง
เลือกประเภท protocol ที่ต้องการวิเคราะห์
ตั้งค่า channel สำหรับวิเคราะห์ การส่งข้อมูลของ I2C โปรโตคอล
ตั้งค่า Display Format
ตั้งค่า Trigger Indicates "rising edge trigger"
การต่อวงจร I2C Pin ของบอร์ด Arduino UNO และ Logic Analyzer กับบอร์ด M5Stack