Petoi Doc Center
🇹🇭 Thai
🇹🇭 Thai
  • ยินดีต้อนรับสู่ Petoi Doc Center
  • Infrared Remote
    • รีโมทคอนโทรล
  • Mobile App
    • คาลิเบเตอร์และคอนโทรลเลอร์
  • Desktop APP
    • การแนะนำเบื้องต้น
    • ตัวอัปโหลดเฟิร์มแวร์
    • การคาลิเบรทข้อต่อ
    • สกิลคอมโพสเซอร์
  • Arduino IDE
    • อัปโหลด Sketch สำหรับ NyBoard
    • อัปโหลด Sketch สำหรับ BiBoard
    • การคาลิเบรทด้วย Arduino IDE
    • ซีเรียลมอนิเตอร์
  • API
    • 🖇️ซีเรียลโปรโตคอล
    • 🐍คู่มือผู้ใช้ Python SerialMaster
    • 🐛MicroPython คอนโทรลเลอร์
      • การเรียกใช้ MicroPython บน ESP8266
      • ติดตั้ง WebREPL
      • การใช้โปรโตคอล ESP-NOW
    • 🍓การสื่อสารผ่านพอร์ตซีเรียลของ Raspberry Pi
    • 🤖ROS
  • Nyboard
    • NyBoard V1_0
    • NyBoard V1_1
  • BIBOARD
    • คู่มือเริ่มต้นใช้งาน BiBoard ฉบับรวบลัด
    • Demo Applications
      • 1.GPIO port
      • 2.Serial port
      • 3.Analog-digital converter
      • 4.Digital-Analog Converter
      • 5.EEPROM (Electrically Erasable Programmable read only memory)
      • 6.Gyro IMU(MPU6050)
      • 7.Infrared remote control
      • 8.PWM(Pulse Width Modulation)
      • 9.Servo(under construction)
      • 10.Classic Bluetooth serial port SPP
      • 11.Bluetooth low energy (BLE) serial port pass-through
      • 12.File system SPIFFS
      • 13.Add hardware partition configuration option in Arduino IDE
      • 14.Play MP3
      • 15.The usage of Wi-Fi OTA(Over-The-Air)
  • Communication Modules
    • Introduction
    • USB Uploader (CH340C or CH343G)
    • Dual Mode Bluetooth
    • WiFi ESP8266
      • ESP8266 + Python Scripts Implement wireless crowd control
  • Extensible Modules
    • Introduction
    • MU Camera
    • Ultrasonic Sensor
    • Light Sensor
    • Touch Sensor
    • Gesture Sensor
    • PIR Motion Sensor
  • Applications
    • Skill Creation
    • OpenCat Imitation Tutorial
    • Programmable Puppet Character
  • History
    • Upload Sketch For NyBoard (software 1.0)
  • Technical Support
    • 🛠️Supporting Application and Software
    • 🙋‍♂️FAQ(Frequently Asked Questions)
  • Useful Links 🕸
    • 🔭Official Site of Petoi
    • 💿GitHub of OpenCat
    • 🎪PetoiCamp (Forum)
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. BIBOARD
  2. Demo Applications

5.EEPROM (Electrically Erasable Programmable read only memory)

การใช้งาน EEPROM นั้นเหมือนกับ Arduino UNO มีสองการทำงาน: อ่านและเขียน

Read:

  • I2C address of EEPROM

  • The internal address of EEPROM (the address for storing data)

  • Read data

Write:

  • I2C address of EEPROM

  • The internal address of EEPROM (the address for storing data)

  • Write data

ในการสาธิต BiBoard ที่อยู่ของ EEPROM บนบัส I2C คือ 0x54 และความจุคือ 8192Bytes (64Kbit) เราเขียนค่าทั้งหมด 16 ค่าตามลำดับตั้งแต่ 0 ถึง 15 ใน EEPROM จากแอดเดรสแรก จากนั้นจึงอ่านเพื่อเปรียบเทียบ ในทางทฤษฎี ข้อมูลที่เขียนใน EEPROM และข้อมูลที่อ่านจากที่อยู่ที่เกี่ยวข้องควรเหมือนกัน

ในการทดสอบโรงงานของ NyBoard เราใช้วิธีนี้เช่นกัน แต่จะซับซ้อนกว่า เราจะใช้รายการคงที่เพื่อเติม EEPROM และอ่านเพื่อเปรียบเทียบ

#include <Wire.h>

#define EEPROM_ADDRESS 0x54
#define EEPROM_CAPACITY 8192       // 64Kbit
#define EEPROM_TESTBYTES 16

// write 1 byte EEPROM by address
void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data ) 
{
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.write(data);
  Wire.endTransmission();
 
  delay(5);
}

// read 1 byte EEPROM by address
byte readEEPROM(int deviceaddress, unsigned int eeaddress ) 
{
  byte rdata = 0xFF;
 
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.endTransmission();
 
  Wire.requestFrom(deviceaddress,1);
 
  if (Wire.available()) 
    rdata = Wire.read();
  return rdata;
}

void testI2CEEPROM(){

    byte tmpData = 0;

    Serial.println("EEPROM Testing...");
    
    // write EEPROM from 0 to EEPROM_TESTBYTES
    for(int i = 0; i < EEPROM_TESTBYTES; i++){
        writeEEPROM(EEPROM_ADDRESS, i, i % 256);
        delay(1);
    }

    Serial.println();
    
    // read from 0 to EEPROM_TESTBYTES
    for(int i = 0; i < EEPROM_TESTBYTES; i++){
        tmpData =  (int)readEEPROM(EEPROM_ADDRESS, i);
        Serial.print(tmpData);
        Serial.print("\t");
    }
}


void setup(){

    Serial.begin(115200);
    Wire.begin();
    
    testI2CEEPROM();
}

void loop(){
  
}

หมายเหตุ: การดำเนินการ EEPROM โดยเฉพาะการดำเนินการเขียน โดยทั่วไปจะไม่ใส่ลงในลูป () แม้ว่า EEPROM จะทนทานต่อการลบ (100,000 ครั้ง) หากมีการเขียนบล็อคบางบล็อกในลูปบ่อยๆ จะทำให้ EEPROM ทำงานผิดปกติ

Previous4.Digital-Analog ConverterNext6.Gyro IMU(MPU6050)

Last updated 2 years ago

Was this helpful?