ä»åã¯ã¡ãã£ãšæ å ±éãå€ããŠæžæ»ããŠããŸããã
䜿ããã€ã³ã³ããŒãã¯RaspberryPiPicoã§ã
䜿ãçµ±åéçºç°å¢ã¯ArduinoIDEã
ããããICã¯EEPROMã§ãã
éä¿¡æ¹åŒã¯I2Cæ¹åŒãæ¡çšããŸããã
以åRaspberryPiPicoãå¶åŸ¡ããã®ã«ã
ArduinoIDEã䜿çšãããšãI2Céä¿¡ãã§ããªãã
ãªããŠèšäºãæžããŸããããçŸåšã¯éä¿¡ã§ããããã«ãªããŸããã
ãã®æã®èšäºâââ
I2Céä¿¡ãã§ããããã«ãªã£ãã®ã§ã
EEPROMããŸãã§ããã ããããšããããã§ãã£ãŠã¿ãŸããããã£ã¡ãæéããã£ã…(ç¬ãèš)
Youtubeãã£ã³ãã«ã«ããŸããŸãªåç»ãäžããŠããŸãã
âââãã¡ãããYoutubeãã£ã³ãã«ã«ã¢ã¯ã»ã¹!! âââ
ä»å䜿ããã®ã玹ä»ã
ä»å䜿çšããã®ã¯ä»¥äžã®ãªã¹ãã®ãã®ã§ãã
ã©ãºãã€ãã³ã§ä»åã¯å¶åŸ¡ããã®ã§ãã©ãºãã€ãã³ã¯å¿ é ã§ãã
EEPROMã§ãããä»åã¯24LC256ãšããååŒã䜿çšããŸããã
ååŒã«ãã£ãŠã¯è¥å¹²åãæ±ãæ¹æ³ãç°ãªãã®ã§ããã
ããã®éãã«ã€ããŠã¯ããŒã¿ã·ãŒãã§ç¢ºèªããŠãã ããã
ããŒã¿ã·ãŒãã¯ãã¡ãâââ
http://akizukidenshi.com/download/24LC256.pdfããããEEPROMãšã¯ïŒ
EEPROMãããããäœãªã®ãã«ã€ããŠã§ããã
ç°¡åã«èšããšãé»æ°ãéãç¶ããªããŠãå€ãä¿æãç¶ããããICã§ãã
ããããäžæ®çºæ§ã¡ã¢ãªãªããŠåŒã°ãããã®ã§ããã
çšéãšããŠã¯ãSDã«ãŒããªãããã€ã¡ãŒãžããŠããããã°ãããšæããŸãã
SDã«ãŒãã¯ãã©ãã·ã¥ã¡ã¢ãªãªããŠååã§åçã¯ç°ãªããŸããã
çšéãšããŠã¯åããããªãã®ã§ãã
ãããããªãšããã«æžããŠãããŸããã
SDã«ãŒããšæ¯ã¹ãŠãæ°ãã€ãã®ããŒã¿ã®ããåãã§ããã°ã
æžã蟌ã¿åäœãEEPROMã®ã»ããå°ãããå°åããå©ããªããŠå©ç¹ãããããã§ãã
ãªã®ã§åºæ¿ã«èŒããã®ã¯SDã«ãŒãã®ãããªå°åãã®å©ãã«ãããã©ãã·ã¥ã¡ã¢ãªãããã
容éã¯å°ãããŠãå°åãã®å©ãEEPROMã䜿çšãããšããããšãªãã§ããã
ã¡ãªã¿ã«ä»å䜿çšããEEPROMã¯256Kbä¿æã§ãããã®ã§ããã
SDã«ãŒãã ãšæè¿ã¯ãã128GBãªããŠæ°çåã§ãŽããŽãããŠããã®ã§
容éã§åè² ãããšç¢ºå®ã«è² ããŸã…
EEPROMãšã©ãºãã€ãã³ãé ç·ããã
ããã§ã¯EEPROMãé ç·ããŠãããŸãããã
ãŸãã¯ä»å䜿çšããEEPROMã®å端åã«ã€ããŠã¿ãŠãããŸãããã
ããã€ã泚æç¹ããããŸããããŸãã¯é ç·å³ããèŠãããŸãã
泚æç¹ã¯ä»¥äž2ã€ã§ãã
SDAãšSCLã«ã¯ãã«ã¢ããæµæ2kΩãå ¥ããã
ãããå¿ãããšæ°žé ã«éä¿¡ã§ããŸããã
æµæå€ã®2kΩã§ããããã®å€ã¯ããŒã¿ã·ãŒãã«èšèŒãããŠããŸãã
24LC256ã®å Žåã¯2kΩã§ãããä»ã®ã¢ãã«ã ãšç°ãªãå Žåãããã®ã§ã
å¿ ãããŒã¿ã·ãŒãã確èªããŠãã«ã¢ããæµæãå ¥ããŠãããŸãããã
ã¡ãªã¿ã«…ããŒã¿ã·ãŒãäžã«ã¯ãSDAã ããã«ã¢ããæµæå ¥ãããšæžããŠãã£ãã¯ããªã®ã§ããã
SCLã«ãåãæµæãå ¥ããªããšåäœããªãã£ãã§ã…
WPãã³ã¯æžã蟌ã¿ã®å¶éãå¯èœã
EEPROMã®7çªãã³ã§ããããã¡ãã¯WPãã³ãšååãã€ããŠããŸãã
ãã®WPãã³ã¯ã5Vé»å§ããããããšã«ãããEEPROMãžã®æžã蟌ã¿ãå¶éã§ããŸãã
ä»åã¯èªã¿æžãã©ã¡ããè¡ãããã®ã§ãGNDã«èœãšããŠããŸãã
ããEEPROMã«æžã蟌ãã ããŒã¿ãèªã¿èŸŒãã ãã§ã誀ã£ãŠæ¶ããããªãå Žåã¯ã
ããã«5VããããŠãããã°æžã蟌ã¿ãããªãã§ãã
I2Cã®ã¢ãã¬ã¹ã¯é ç·ã«ãã£ãŠæ±ºãŸãã(å¢èšããã¡ããå¯èœ)
MCP23017ã®èšäºã§ã玹ä»ããŸãããã
I2Cã®æ¥ç¶æ©åšã¯ãã¢ãã¬ã¹ãèªç±ã«æ±ºããŠã䜿ããšãã«æå®ããæ¹åŒãäžè¬çã§ãã
ãã®EEPROMãã¢ãã¬ã¹ã8ãã¿ãŒã³æ±ºããããšãã§ããŸãã
ããã§ã¯ã©ããã£ãŠæ±ºããŠãããã§ããã
EEPROMã®1çª~3çªãã³ãã©ãã«ã€ãªããã«ãã£ãŠæ±ºãŸããŸãã
ä»åã®é ç·ã ãšã1çª~3çªãã³ãŸã§ãã¹ãŠãGNDã«æ¥ç¶ããŠããŸãã
ãã®å Žåã¯ãã¢ãã¬ã¹ã¯ã0b000ãšãªããŸãã
ãã1çªãã³ã5Vã«æ¥ç¶ããå Žåã¯ãã¢ãã¬ã¹ã¯0b001ãšãªããŸãã
ãã ããã¢ãã¬ã¹æå®ããå Žåã¯ããã®é ç·ã§æ±ºããã¢ãã¬ã¹ã«å ããŠã
ååŸã«ããŒã¿ãã¯ãããŸãã
ãããå«ããŠI2Cã®ã¢ãã¬ã¹ã«ãªããŸãã®ã§æ³šæã§ãã
å ·äœçã«ã¯ããŒã¿ã·ãŒãããã
A2ãšA1ãšA0ããããã3çªã2çªã1çªãã³ã«å¯Ÿå¿ããŠããŸãã
ããäžåºŠEEPROMã®ãã³é 眮ãæ²èŒããŠãããŸããã
ããã§ã¯ä»åã¯1çª~3çªãŸã§GNDã«æ¥ç¶âA0~A2ãŸã§0ãå ¥ãã
ãšããããšãªã®ã§ãã¢ãã¬ã¹ãšããŠã¯ã
0b10100000=0x50
ãšããããšã«ãªããŸãã
â»R/Wã®æåã§ãããæžã蟌ã¿ãŸã§è¡ãå Žåã¯0ã«ããå¿ èŠããããŸãã
ã¡ãªã¿ã«…
EEPROMã¯ãã¬ããããŒãã«çŽæ¥ãããã¿ã€ããšã
è¡šé¢å®è£ çšã®ãã®ããããŸãã
è¡šé¢å®è£ çšã®EEPROMã§ãããããªæãã§å€æåºæ¿ã䜿çšããã°
ãã¬ããããŒãã«ã€ãªããããšã¯å¯èœã§ãã
ã¯ãã ä»ããå®éã«ããŠããåç»ã貌ã£ãŠãããŸãã
ArduinoIDEã§ã©ãºãã€ãã³ã«I2Céä¿¡ã®ç¢ºèªãããã
é ç·ãçµãã£ããšããã§ã
å®éã«ArduinoIDEã§ã©ãºãã€ãã³ã䜿ã£ãŠæ¥ç¶ç¢ºèªãããŸãããã
以åI2Cã®æ¥ç¶ç¢ºèªæ¹æ³ã«ã€ããŠèª¬æããèšäºãæžããŸãããã
ãã¡ãã§äœ¿çšããã¹ã±ãããåå©çšããŸãã
#include <Wire.h>
void setup()
{
Wire.setSDA(8);//()ã®äžèº«ã¯GPçªå·ãé
ç·ã«ãã£ãŠç°ãªããŸãã
Wire.setSCL(9);//()ã®äžèº«ã¯GPçªå·ãé
ç·ã«ãã£ãŠç°ãªããŸãã
Wire.begin(); // Wire communication begin
Serial.begin(9600); // The baudrate of Serial monitor is set in 9600
while (!Serial); // Waiting for Serial Monitor
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address; //variable for error and I2C address
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for (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);
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 the next I2C scan
}
ã©ãºãã€ãã³ã§I2Cã«ææŠããèšäºã¯ãã¡ãâââ
ããŠãäžèšã¹ã±ãããæžã蟌ãã§ã©ããªã£ãã§ããããïŒ
ãã®ããã«0x50ãšã¢ãã¬ã¹ã衚瀺ãããŠããã°OKã§ãã
ããèŠã€ãããªãå Žåã¯é ç·ãæªããã§ãã
ããäžåºŠé ç·ã確èªããŠã¿ãŠäžããã
å®éã«EEPROMã«æžã蟌ãã§èªã¿èŸŒãã
ããã§ã¯æçµä»äžãã§ãã
ããããEEPROMãžã®æžã蟌ã¿âèªã¿èŸŒã¿ãè¡ããŸãã
ArduinoIDEã§æžã蟌ãã¹ã±ããããã¡ãã«äžããŠãããŸãã
#include <Wire.h>
#define eeprom 0x50 //EEPROMã®Address(é
ç·ã«ãã£ãŠå¯å€)
void setup(void)
{
Wire.setSDA(8); // RaspberryPiPicoã®SDAãã³ãæå®(ä»åã¯GP8)
Wire.setSCL(9); // RaspberryPiPicoã®SDAãã³ãæå®(ä»åã¯GP9)
Serial.begin(9600);
Wire.begin();
writeEEPROM(eeprom, 32001, 99); // ããã§EEPROMã«æžã蟌ãã32001çªå°ã«99ãæžã蟌ãã
}
void loop(){
delay(1000);
Serial.print(readEEPROM(eeprom, 32001)); // 32001çªå°ã1Secæ¯ã«èªãã§ã·ãªã¢ã«ãŠã£ã³ããŠã«è¡šç€ºããã
}
void writeEEPROM(int deviceaddress,int eeaddress, int data )
{
Wire.beginTransmission(deviceaddress); // I2Cã®ã¢ãã¬ã¹ãæå®ããŠéä¿¡éå§ã
Wire.write((int)(eeaddress >> 8)); // MSB(äžäœ8bitã®ã¿å
ã«ã¢ãã¬ã¹æå®ããã)
Wire.write((int)(eeaddress & 0xFF)); // LSB(äžäœ8bitãã¢ãã¬ã¹æå®ãã)
Wire.write(data); // æžã蟌ã¿ããããŒã¿ãæžãã
Wire.endTransmission(); // I2Cã®éä¿¡çµäºã
delay(5); // äžå¿waitãå
¥ããŠããã
}
byte readEEPROM(int deviceaddress,int eeaddress )
{
int rdata;
// ããããã¯åŠç¿çšã®print
Serial.print("(int)(eeaddress>>8)");
Serial.print((int)(eeaddress>>8));
Serial.print("::::");
Serial.print("(int)(eeaddress & 0xFF)");
Serial.print((int)(eeaddress & 0xFF));
Serial.print("::::");
// âãããŸã§åŠç¿çšã®print
Wire.beginTransmission(deviceaddress); // I2Cã®ã¢ãã¬ã¹ãæå®ããŠéä¿¡éå§ã
Wire.write((int)(eeaddress >> 8)); // MSB(äžäœ8bitã®ã¿å
ã«ã¢ãã¬ã¹æå®ããã)
Wire.write((int)(eeaddress & 0xFF)); // LSB(äžäœ8bitãã¢ãã¬ã¹æå®ãã)
Wire.endTransmission(); // I2Cã®éä¿¡çµäºã
Wire.requestFrom(deviceaddress,1);
// I2Cãæ¥ç¶å¯èœã§ããããšã確èªããããã§ãèªã¿èŸŒãã ããŒã¿ãreturnããŒã¿ã«æ ŒçŽããã
if (Wire.available())
{
rdata = Wire.read();
}
return rdata;
}
ã³ã¡ã³ãæã¯é©å®å ¥ããŠããŸããã
äžè¡ããããããªãã…ãšããããšãèããããã®ã§ã
åŒã£ããããããªãšããã«ã€ããŠã¯äžå¯§ã«èª¬æããŠãããŸãã
ãœãŒã¹ã³ãŒãã®è§£èª¬ã
#include <Wire.h>
#define eeprom 0x50 //EEPROMã®Address(é
ç·ã«ãã£ãŠå¯å€)
void setup(void)
{
Wire.setSDA(8); // RaspberryPiPicoã®SDAãã³ãæå®(ä»åã¯GP8)
Wire.setSCL(9); // RaspberryPiPicoã®SDAãã³ãæå®(ä»åã¯GP9)
Serial.begin(9600);
Wire.begin();
ãããŸã§ã¯å€§äžå€«ã§ãããã
Arduinoãšã¯ç°ãªãã®ããsetSDAãšsetSCLãè¿œå ã§å¿ èŠãªããšã§ããã
ä»ã¯EEPROMã®ã¢ãã¬ã¹ãé ç·ã§æ±ºãŸã£ãŠããã®ã§åé¡ãªããšæããŸãã
writeEEPROM(eeprom, 32001, 99); // ããã§EEPROMã«æžã蟌ãã32001çªå°ã«99ãæžã蟌ãã
ãã®äžæã§ãããé¢æ°åããŠããé¢ä¿ã§è§£èª¬ã¯åŸåãã«ããŸãã
EEPROMã«æžã蟌ãé¢æ°ã®è§£èª¬
void writeEEPROM(int deviceaddress,int eeaddress, int data )
{
Wire.beginTransmission(deviceaddress); // I2Cã®ã¢ãã¬ã¹ãæå®ããŠéä¿¡éå§ã
Wire.write((int)(eeaddress >> 8)); // MSB(äžäœ8bitã®ã¿å
ã«ã¢ãã¬ã¹æå®ããã)
Wire.write((int)(eeaddress & 0xFF)); // LSB(äžäœ8bitãã¢ãã¬ã¹æå®ãã)
Wire.write(data); // æžã蟌ã¿ããããŒã¿ãæžãã
Wire.endTransmission(); // I2Cã®éä¿¡çµäºã
delay(5); // äžå¿waitãå
¥ããŠããã
}
ããŠãæžã蟌ãæ¹æ³ã§ããã
å¿ èŠãªãã®ã¯ã
ãã®3ã€ãå¿ èŠã«ãªããŸãã
I2Cã¢ãã¬ã¹ã¯ä»å0x50ãªã®ã§ã²ã£ããããªããšæããŸããã
ãããããeeaddressã®ãšããã§ã¡ãã£ãšåŒã£ããã人ãããã®ã§ã¯ãªãããšæãã®ã§ã
ãããâã®èªã¿èŸŒã¿ã®é¢æ°ã§è§£èª¬ããŸããåãããšãããŠããã®ã§ã
EEPROMããèªã¿èŸŒãé¢æ°ã®è§£èª¬
byte readEEPROM(int deviceaddress,int eeaddress )
{
int rdata;
// ããããã¯åŠç¿çšã®print
Serial.print("(int)(eeaddress>>8)");
Serial.print((int)(eeaddress>>8));
Serial.print("::::");
Serial.print("(int)(eeaddress & 0xFF)");
Serial.print((int)(eeaddress & 0xFF));
Serial.print("::::");
// âãããŸã§åŠç¿çšã®print
Wire.beginTransmission(deviceaddress); // I2Cã®ã¢ãã¬ã¹ãæå®ããŠéä¿¡éå§ã
Wire.write((int)(eeaddress >> 8)); // MSB(äžäœ8bitã®ã¿å
ã«ã¢ãã¬ã¹æå®ããã)
Wire.write((int)(eeaddress & 0xFF)); // LSB(äžäœ8bitãã¢ãã¬ã¹æå®ãã)
Wire.endTransmission(); // I2Cã®éä¿¡çµäºã
Wire.requestFrom(deviceaddress,1);
// I2Cãæ¥ç¶å¯èœã§ããããšã確èªããããã§ãèªã¿èŸŒãã ããŒã¿ãreturnããŒã¿ã«æ ŒçŽããã
if (Wire.available())
{
rdata = Wire.read();
}
return rdata;
}
æžã蟌ããšããšåæ§ãå¿ èŠãªãã®ã¯å šãåãã§ãã
ããã§ã¯ãã®2è¡ã«ã€ããŠè§£èª¬ããŸããââ
Wire.write((int)(eeaddress >> 8)); // MSB(äžäœ8bitã®ã¿å
ã«ã¢ãã¬ã¹æå®ããã)
Wire.write((int)(eeaddress & 0xFF)); // LSB(äžäœ8bitãã¢ãã¬ã¹æå®ãã)
ãŸããã>>ããã®èšå·ã§ããããããã·ãããšåŒã°ããåŠçã§ãã
ä»åã®äœ¿ãæ¹ã ãšã8ãããâæ¹åãžã·ãããããããšãã䜿ãæ¹ã§ãã
ããŠããããäœãæå³ãããã§ããã
ãã®EEPROMã«ã¯ãäžäœã¢ãã¬ã¹ãšäžäœã¢ãã¬ã¹ãšãããã®ãååšããŠããŸãã
ã€ãŸããäŸãã°8æ¡ä»¥å ã®ã¢ãã¬ã¹ãæå®ããå Žåã
äžäœã¢ãã¬ã¹ã¯ããªãã0ã8å䞊ã¶ã¯ããªã®ã§ç¹ã«åé¡ã«ãªããŸãããã
ãã ãã8æ¡ãè¶ ããã¢ãã¬ã¹ãæå®ããå Žåã¯ãäžäœã¢ãã¬ã¹ã«å€ãå ¥ããå¿ èŠããããŸãã
å ·äœçã«ã¯ã0b11111111ãè¶ ããå Žåã§ããã
0b11111111=0xFF=0d255ãšãªããŸãã
ããã§ã¯ãäžäœã¢ãã¬ã¹ãæå®ããªããŠã¯ãããªãã®ã§ã©ããããïŒ
ããã¯äž8æ¡ãæ¶ããŠããŸãã°ãããã§ãã
äŸãã°ã0b100000000=0x100=0d256ãæå®ãããå Žåã¯ã
äžãã8æ¡ãæ¶ããŠã0b1ãšãªããŸãã
ãã®0b1ãäžäœã¢ãã¬ã¹ã«å ¥ãã¢ãã¬ã¹ãšãªããŸãã
ä»ã«ãã0d32000ãšãã倧ããªã¢ãã¬ã¹ãå®éã«å ¥ããŠããã®ãä»åã®ã¹ã±ããã§ãã
// ããããã¯åŠç¿çšã®print
Serial.print("(int)(eeaddress>>8)");
Serial.print((int)(eeaddress>>8));
Serial.print("::::");
Serial.print("(int)(eeaddress & 0xFF)");
Serial.print((int)(eeaddress & 0xFF));
Serial.print("::::");
// âãããŸã§åŠç¿çšã®print
åŠç¿çšãšããŠãã·ãªã¢ã«ãŠã£ã³ããŠã«åãã©ã¡ãŒã¿ãåºåããããã«ããŠããŸãã
ãã®çµæãšããŠã¯ã
(int)(eeaddress>>8)125::::(int)(eeaddress & 0xFF)0::::
ãããªããŸããã¢ãã¬ã¹ã¯0d32000ã§ãã
äžäœã¢ãã¬ã¹ã¯125ã§ãããã125*256=32,000ãšããããšã§ãã£ããäžèŽããŠããŸããã
次ã«ã&ãã§ãããããã¯è«çç©ãšåŒã°ãããã®ã§ãã
ãã®è«çç©ãéãããšã§ãã©ãã®ãããã1ã«ãªã£ãŠããããããããŸãã
å ·äœçãªäŸãšããŠã¯ã0b100&0b111ãšãªã£ãŠããå Žåã¯ã
0b100ãšãªããŸããã€ãŸã0x4ã§ããã
ä»åãã®è«çç©ã&ãã䜿ãå¿ èŠãããã®ããšãããšã
ããã¯äžäœã¢ãã¬ã¹ãååŸãããšãã«ãäžäœã¢ãã¬ã¹ãç¡èŠãããããã§ããã
äžäœã¢ãã¬ã¹äžäœã¢ãã¬ã¹åãããŠ16æ¡ã§æ§æãããŠããããã§ããã
äžäœã¢ãã¬ã¹ãšããŠå¿ èŠãªã®ã¯å³ããæ°ããŠ8æ¡ãŸã§ã
ã§ãããã0xFFãšè«çç©ãåãããšã«ãã£ãŠFFããäžäœã®ã¢ãã¬ã¹ã«ã€ããŠã¯ã
äžåèŠãªãããã«ããŠãããã§ãã
EEPROMã䜿ããšãã®æ³šæç¹ãŸãšãã
ãããŸã§ã話ããå 容ã®äžã§æ³šæããªããšãããªãç¹ããŸãšããŸããã
现ãã泚æç¹ã«ã€ããŠã¯ããäžåºŠèªã¿çŽããŠç¢ºèªããŠã¿ãŠãã ãããã
ä»åã®ãŸãšãã
ä»åã¯EEPROMã«ã€ããŠã®èšäºã§ããã
I2Cãã§ããããšã¯ããã£ãŠããŸãããã
ä»åEEPROMã®èªã¿æžãã¯åããŠã ã£ãã®ã§æéããããŸãã…
èªã¿æžãèªäœã¯ã§ããŸããã®ã§ä»åã®ç®æšã¯å®äºã§ããã
EEPROMèªäœãæžã蟌ã¿åæ°ã«éçããããããã®ã§ã
éã³ãããŠå£ããªãããã«æ°ãã€ããªããšãããŸãããããšã¯ãã100äžåãšãã¯ãããããã…
ã³ã¡ã³ã