Tabbas, ga tsarin labarin yadda ake amfani da na'urar daukar hotan takardu ta I2C tare da Arduino.
I2C ko Inter-Integrated Circuit yarjejeniya wata muhimmiyar yarjejeniya ce ta sadarwa da ƙananan masu kula da Arduino ke amfani da su don sadarwa tare da na'urori daban-daban, na'urorin nuni, da sauran masu sarrafawa. Fahimtar da amfani da ka'idar I2C na iya haɓaka iyawar ayyukan ku na Arduino sosai.
Bukatar gano ko tabbatar da adireshin I2C na na'ura (kamar firikwensin ko nuni) da aka haɗa zuwa Arduino na iya tashi wani lokaci. A wannan yanayin, na'urar daukar hotan takardu ta I2C ta zo da amfani. Yana iya gano adiresoshin duk na'urorin I2C da aka haɗa - muhimmin mataki na farko na amfani da sadarwar I2C yadda ya kamata.
Amfani da I2C Scanner
Mafi mashahurin na'urar daukar hoto I2C da ake da ita Tod E. Kurt, mai sha'awar arduino ne ya rubuta. Yana ba da amsa mai sauri da sauƙi akan na'urorin I2C da aka haɗa zuwa arduino.
#include
rashin aikin saiti ()
{
Wire.begin ();
Serial. Shiga (9600);
Serial.println ("nI2C Scanner");
}
mara amfani madauki ()
{
kuskuren byte, adireshin;
int nNa'urori;
Serial.println ("Scanning...");
nNa'urori = 0;
don (adireshi = 1; adireshi <127; adireshi ++ ) {// Fara da adireshin na'ura don ganin ko akwai amsa Wire.beginTransmission(adireshi); kuskure = Wire.endTransmission (); idan (kuskure == 0) {Serial.print ("Na'urar I2C da aka samu a adireshin 0x"); idan (adireshi <16) Serial.print (""); Serial.print (adireshi, HEX); Serial.println ("!"); nNa'urori++; } } idan (nNa'urori == 0) Serial.println ("Ba a sami na'urorin I2C ba"); sauran Serial.println (" aikata"); jinkirta (2000); } [/code]
Bayanin Code
Lambar tana farawa ta haɗa da ɗakin karatu na Wire wanda aka gina a cikin ɗakin karatu na Arduino wanda aka tsara don sadarwar I2C. Yana ba da ayyuka waɗanda ke taimakawa karantawa da rubuta bayanai a cikin bas ɗin I2C.
A cikin aikin saitin, Wire.begin() yana ƙaddamar da bas ɗin I2C kuma ana fara sadarwar Serial akan ƙimar baud na 9600.
A cikin aikin madauki, lambar tana duba kowane adireshi akan bas ɗin I2C, ƙoƙarin kafa sadarwa ta amfani da Wire.beginTransmission() da kuma kammala sadarwa tare da Wire.endTransmission().
Idan an sami na'ura a wani adireshi, lambar na'urar daukar hotan takardu ta I2C tana buga wannan adireshin a cikin serial Monitor. Idan ba a samo na'urori ba, na'urar daukar hotan takardu tana buga saƙon da ya dace. Tsarin dubawa yana maimaita kowane daƙiƙa biyu.
I2C a cikin ɗakunan karatu na Arduino
Laburaren Wire yana da mahimmanci don sadarwar I2C a cikin Arduino. Wannan ɗakin karatu yana ƙaddamar da hadaddun ayyuka da ke cikin I2C, yana mai sauƙaƙa ga masu farawa da ƙwararrun coders don amfani da wannan ka'idar sadarwa. An gina ɗakin karatu na Wire akan manyan ayyuka guda biyu: Wire.begin() da ake amfani dashi don ƙaddamar da bas ɗin I2C da Wire.beginTransmission(addr) wanda ke fara watsawa zuwa na'urar a adireshin 'addr'.
Koyo game da ɗakunan karatu na Arduino kamar Waya na iya haɓaka ayyukan na'urar ku ta I2C sosai. Wannan gaskiya ne musamman yayin da ake ƙara samun abokantaka na mai amfani, ana haɓaka ɗakunan karatu masu buɗewa, waɗanda ke ƙara sauƙaƙe amfani da hadaddun mu'amalar mu'amala kamar I2C.
Kowane aikin Arduino yana bunƙasa akan ingantaccen amfani da ɗakunan karatu. Ga na'urorin I2C, fahimtar ɗakin karatu na Wire yana da mahimmanci. Ina fatan wannan bayyani da cikakken kallon lambar bincikar I2C ta haɓaka ƙwarewar ku a cikin ƙa'idar I2C da Arduino.