Теперь необходимо загрузить скетч в ардуино с помощью софта скачанного с официального сайта - arduino.cc (программное обеспечение бесплатно)
Или вы можете скопировать текст скетча:
// Тестировалось на Arduino IDE 1.8.7, Windows 7
#include "Wire.h"
String InString_;
String WriteByte_ = "WriteByte";
String WriteInt16_ = "WriteInt16";
String ReadByte_ = "ReadByte";
String ReadInt16_="ReadInt16";
String ReadString_="ReadString";
String INIT="";
String Function="";
byte InByte_;
byte OutByte_;
int OutInt_=0,OutIntCom_=0;
int InInt16_=0;
byte Length_=6;
char ch_;
void setup()
{
Serial.begin(9600); // COM Port
Wire.begin(); // I2C
do // connect to program
{
Serial.println("ARDUINO"); // write to COM Port
delay(500);
INIT=ReadStringCom(); // read answer
}
while(INIT != "INIT"); // connect to program
}
/////////////////////////////////////
void loop()
{
delay(500);
if(Serial.available()>0) //data from COM Port available
{
Function = ReadStringCom(); //read string (command) from COM Port
//delay(500);
if(Function=="WriteByte") // send command (byte) (0х00)
{
Function="";
delay(1000);
if(Serial.available()>0)
{
InByte_=(byte)(Serial.parseInt()); // read byte from COM Port
SendByte(InByte_); // Send byte to SM Bus
}
}
else if(Function==ReadByte_) // read (byte) (0х00)
{
Function="";
OutByte_= ReadDataByte(); // read byte from SM Bus
Serial.println(OutByte_); // Send byte to COM Port
}
else if(Function==ReadInt16_) // read (int16) (0х0000)
{
Function="";
OutIntCom_= ReadDataInt16(); // read int16 from SM Bus
Serial.println(OutIntCom_); // Send int16 to COM Port
}
else if(Function==ReadString_) // read string( Length = (0-255))
{
Function="";
byte b=5;
//delay(500);
//b=(byte)(Serial.parseInt()); // get Length from COM Port
Length_=b;
Function=ReadDataString(Length_); // read string from SM Bus
delay(500);
Serial.print(Function); // write string to COM Port
}
else if(WriteInt16_==Function) // send (int16) (0х00)
{
Function="";
if(Serial.available()>0)
InInt16_=Serial.read(); // read int16 from COM Port
SendInt16(InInt16_); // send (int16) to SM Bus
}
}// end if(Serial.available()>0)
}// end loop
///////////Functions\\\\\\\\\\\
void SendByte (byte Command_) //function send byte to SM Bus
{
Wire.beginTransmission(0x0B);
delay(100);
Wire.write(byte(Command_));
delay(100);
Wire.endTransmission();
}
void SendInt16 (int Command_) //function send int16 to SM Bus
{
Wire.beginTransmission(0x0B);
Wire.write(int(Command_));
Wire.endTransmission();
}
byte ReadDataByte() //function read byte from SM Bus
{
byte b;
Wire.beginTransmission(0x0B);
Wire.requestFrom(0x0B, 1);
b = Wire.read();
Wire.endTransmission();
return b;
}
int ReadDataInt16() //function read int16 from SM Bus
{
OutInt_=0;
int tmp=0;
Wire.beginTransmission(0x0B);
Wire.requestFrom(0x0B, 2);
tmp=Wire.read();
delay(100);
OutInt_+=Wire.read();
OutInt_=OutInt_<<8;
OutInt_+=tmp;
Wire.endTransmission();
return OutInt_;
}
String ReadDataString(int Length) //function read string from SM Bus
{
String str="";
Length=5;
delay(50);
Wire.beginTransmission(0x0B);
Wire.requestFrom(0x0B, Length);
while(Length-->0)
{
str+=(char)Wire.read();
}
Wire.endTransmission();
return str;
}
void WriteStringCom(String OutStringCom_) //function write string to COM Port
{
Serial.println(OutStringCom_);
}
void WriteByteCom(byte OutByteCom_) //function write byte to COM Port
{
Serial.println(OutByteCom_);
}
void WriteInt16Com(int Out_) //function write int16 to COM Port
{
Serial.println(Out_);
}
String ReadStringCom() //function read string from COM Port
{
if(Serial.available()>0)
{
InString_="";
while(Serial.available()>0)
InString_+=(char)Serial.read();
return InString_;
}
}