Sistimi ea ho Fumana Boitsebiso ba Lehae (tsoelapele)

Qala sebakeng sena sa marang-rang link tsa.
Khetho e bonolo ka ho fetisisa ea ho khutlisa tlhahisoleseling mabapi le ho bulela starter e bile khetho ka PC817 optocoupler. Setšoantšo sa potolohoSistimi ea ho Fumana Boitsebiso ba Lehae (tsoelapele)Liboto li na le lipotoloho tse tharo tse tšoanang, ntho e 'ngoe le e' ngoe e kenngoa ka mabokoseng a polasetiki a ABS, boholo ba 100x100 mm. Setšoantšo sa li-optocouplersSistimi ea ho Fumana Boitsebiso ba Lehae (tsoelapele) Ha e hokahane le lisebelisoa tsa ho qala tse nang le li-valve tsa semiconductor, hona joale ho lutla ha tsona ho lekane ho bula PC817 mme counter e tla qala ka bohata. Ho qhelela ka thoko boemo bo joalo e 'ngoe hape e eketsoa ka letoto ho potoloho ea optocoupler LED le pontšo ea ts'ebetso ea LED. Ho etsa sena, jumper J1 ea buloa 'me LED1 e eketsehileng ea LED e rekisoa ka hare.
Karolo ea ho amohela e entsoe ka leqepheng la 1Sistimi ea ho Fumana Boitsebiso ba Lehae (tsoelapele)leqepheng la 2Sistimi ea ho Fumana Boitsebiso ba Lehae (tsoelapele)boto ea nts'etsopele e amanang le ARDUINO MEGA 2560. Bakeng sa sena, sehokelo sa mela e 'meli se sebelisoa qetellong. Sesepa se nang le qeto ea 240x400, se nang le sekirini sa ho ts'oaroa se hanyetsang le sensor ea mocheso, se sebelisoa e le sesebelisoa sa ho bonts'a tlhahisoleseling. HX8352B.Sistimi ea ho Fumana Boitsebiso ba Lehae (tsoelapele) Ho feta moo, sehokelo sa ICSP setlapeng sa skrine se tlosoa 'me slot ea SD e nyenyane ha e sebelisoe. 'Nete ke hore "letsoalloa" SD socket e ke ke ea sebelisoa ka lebaka la khohlano beseng ea SPI. Bakeng sa karete ea flash, ho ile ha sebelisoa sebali sa karete se arohaneng, se neng se kenyelletsa 3,3V stabilizer le buffer chip e nang le lintlha tse tharo tse tsoang 74LVS125A. Mona ke moo rake e neng e nkemetse teng. Buffer ea linaha tse tharo, empa E01-ML01DP5 kapa 'mali oa karete e sebelitse. Litlhalosong tsa laeborari, SdFat e bone temoso mabapi le ho se lumellane le lisebelisoa tse ling. Mofetoleli oa boemo ho TXS0108E o ile oa tlosoa 'me oa nkeloa sebaka ke li-jumpers, hobane E01-ML01DP5 e mamella matšoao a 5V - ha ea ka ea thusa. Ho sebelisa oscilloscope, tahlehelo ea matšoao e ile ea fumanoa moleng oa MISO ha 'mali oa karete a hokahane. Ha ho hlahlojoa ka hloko, ho ile ha fumanoa hore litlhaloso tsa matšoao a nolofalletsang a litsela tsa OE 4 tsa 74LVS125A li ne li rekisoa feela ho terata e tloaelehileng 'me ho ne ho ke ke ha e-ba le puo ea naha leha e le efe ea boraro. The buffer chip e ne e sebelisoa e le converter ea boemo ba primitive ho tloha 5V ho ea 3.3V e sebelisa 3,3 KΩ resistors e hokahantsoeng ka letoto le mela ea matšoao. Ntle le mohala oa MISO. Phetoho ea eona e ka tlase e ka 'na ea hohela lipontšo sebakeng sa fatše. Kamora ho fumana hore lets'oao la ho nolofalletsa mohala oa MISO e ne e le pin 13, e ile ea ntšoa pina lesolderedSistimi ea ho Fumana Boitsebiso ba Lehae (tsoelapele)pakeng tsa sesebelisoa sa 9LVS74A CS khetha phini ea ho kenya (125) le sehanyetsi sa ho felisa. Joale, haeba ho se na monyetla oa ho fumana karete ea memori, buffer ea MISO e koetsoe ebile ha e sitise ts'ebetso ea sesebelisoa se seng.Setšoantšo sa boto ea ntlafatsoSistimi ea ho Fumana Boitsebiso ba Lehae (tsoelapele)Moamoheli o sebetsaSistimi ea ho Fumana Boitsebiso ba Lehae (tsoelapele)DS3231 e sebelisa bese ea software ea I2C (TWI) ho hokahanya oache.
Lenaneo la Arduino IDE// BOHLOKOA: Adafruit_TFTLCD LAEBRARI E LOKELA HO BA KA HO KHETHA
// E HLOMELLITSENG BAKENG SA TFT THEBE KAPA BOTO YA BREAKOUT.
// SHEBA DIKAKATSO TSE HLOKAHALANG HO Adafruit_TFTLCD.h BAKENG SA SETUP.
// ka Sehlopha sa Open-Smart le Sehlopha sa Catalex
//[imeile e sirelelitsoe]
//Lebenkele: dx.com
// open-smart.aliexpress.com/store/1199788
// Mosebetsi oa Demo: Bontša litšoantšo, litlhaku
//Arduino IDE: 1.6.5
// Boto: Arduino UNO R3, Arduino Mega2560, Arduino Leonardo

// Boto: OPEN-SMART UNO R3 5V / 3.3V, Arduino UNO R3, Arduino Mega2560
//3.2INCH TFT:
// www.aliexpress.com/store/product/3-2-TFT-LCD-Display-module-Touch-Screen-Shield-board-onboard-temperature-sensor-w-Touch-Pen/1199788_32755473754.html?spm=2114.12010615.0.0.bXDdc3
//OPEN-SMART UNO R3 5V / 3.3V:
// www.aliexpress.com/store/product/OPEN-SMART-5V-3-3V-Compatible-UNO-R3-CH340G-ATMEGA328P-Development-Board-with-USB-Cable-for/1199788_32758607490.html?spm=2114.12010615.0.0.ckMTaN

# kenyeletsa // Laeborari ea litšoantšo tsa mantlha
//#kenyelletsa // Laeborari e kgethehileng ya Hardware
# kenyeletsa
MCUFRIEND_kbv tft;
# kenyeletsa "SdFat.h" // Sebelisa laeborari ea SdFat
SdFat SD;
SdFile faele;
File myFile;
# hlalosa SD_CS_PIN SS

# kenyeletsa // Hokela laeborari ho sebetsa le bese ea SPI
# kenyeletsa // Hokela faele ea litlhophiso ho tsoa laebraring ea RF24
# kenyeletsa // Hokela laeborari ho sebetsa le nRF24L24+
RF24 radio(47, 49);

# kenyeletsa

DS3231 rtc(27, 25);
Nako t;

uint16_t r = 6000;
uint32_t k = 0;

data e telele e sa tekenehang;
float leb_1;
float leb_2;
float leb_3;
float leb_4;

uint8_t pipe;
int rc = 0;

uint8_t time_sec_prev;
uint8_t time_day_prev;

//************************************************ ****************/ /
// Haeba u sebelisa OPEN-SMART TFT breakout board //
// E u khothalletsa hore u kenye 5V-3.3V level converting circuit.
// Ehlile u ka sebelisa mofuta oa OPEN-SMART UNO Black ka 5V/3.3V switch ea matla,
// o hloka feela ho fetohela ho 3.3V.
// Lithako tsa taolo bakeng sa LCD li ka abeloa ho leha e le efe ea digital kapa
// lithakhisa tsa analoge...empa re tla sebelisa lithakhisa tsa analoge kaha sena se re lumella ho etsa joalo
//——————————————-|
// TFT Breakout - Arduino UNO / Mega2560 / OPEN-SMART UNO Black
// GND - GND
// 3V3 - 3.3V
//CS - A3
// RS - A2
// WR - A1
// RD - A0
// RST - RESET
// LED - GND
// DB0 - 8
// DB1 - 9
// DB2 - 10
// DB3 - 11
// DB4 - 4
// DB5 - 13
// DB6 - 6
// DB7 - 7

// Fana ka mabitso a ka baloang ke batho ho boleng bo tloaelehileng ba mebala ea 16-bit:
#define BLACK 0x0000
#define BLUE 0x001F
#hlalosa RED 0xF800
#define GREEN 0x07E0
#hlalosa CYAN 0x07FF
#hlalosa MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define GRAY 0x8C51
#hlalosa GRAYD 0x39E7

// Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// Haeba u sebelisa thebe, melao eohle ea taolo le data e tsitsitsoe, le
// Phatlalatso e bonolo e ka sebelisoa ka boikhethelo:
// Adafruit_TFTLCD tft;
uint16_t g_identifier;

Khoele ea dataString;
// String numfileMonth = "1.txt";
char perv [] = {"2.txt"};
// String * numfileMonth = "1.txt" (sizeof (numfileMonth));
///////////////////////////////////////// ///////////////

setup void (void) {

rtc. qala ();

// Ho beha nako, qolla mela e hlokahalang
// rtc.setDOW(6); // Letsatsi la beke
// rtc.setTime(22, 04, 0); // Nako, ka sebopeho sa lihora tse 24.
// rtc.setDate(4, 5, 2019); // Letsatsi, Mphalane 29, 2018

Serial.begin (2000000);
//////// Ho qala skrineng
tft.begin(0x65);
tft.reset();
tft.setRotation(0);
tft.cp437(nnete);
/////////////////Sephetho sa mabitso, lisebelisoa tsa thepa, lebitso la mokhatlo
tft.fillScreen(E TŠOANA);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.setCursor(8, 0);
tft.println("BATSOALI & BUILD");
tft.setCursor(30, 20);
tft.print (utf8rus("Moetsi V.V"));
tft.setCursor(40, 40);
tft.print (utf8rus("Turner I.I." ));
tieho (2000);

radio.qala(); // Qala mosebetsi nRF24L01+
radio.setChannel(120); // Hlalosa mocha oa ho amohela data (ho tloha ho 0 ho isa ho 127)
radio.setDataRate(RF24_250KBPS); // Hlalosa sekhahla sa phetisetso ea data (RF24_250KBPS, RF24_1MBPS, RF24_2MBPS), RF24_1MBPS - 1Mbit/s
radio.setPALevel(RF24_PA_MAX); // Hlalosa matla a transmitter (RF24_PA_MIN=-18dBm, RF24_PA_LOW=-12dBm, RF24_PA_HIGH=-6dBm, RF24_PA_MAX=0dBm)
radio.openReadingPipe(1, 0xAABBCCDD11LL); // Bula phala e le 'ngoe e nang le sesupo sa 1 transmitter 1xAABBCCDD0, ho amohela data
// Bula pipe 2 e nang le transmitter ID 2xAABBCCDD0 ho amohela data
radio.startListening(); // Bulela moamoheli, qala ho mamela lipeipi tse bulehileng
// radio.stopListening();
////////Sephetho sa tlhahisoleseding ya tshebeletso
tft.fillScreen(E TŠOANA);
tft.setCursor(8, 0);
tft.setTextSize(1);
//////// Qala ho qala karete ea SD
Serial.println("Karete ea SD ea pele");
tft.println("Karete ea SD ea pele");
tft.setCursor(8, 10);
////////Ho qala karete
haeba (!SD. qala(SD_CS_PIN)) {
Serial.println("pele e hlolehile!");
tft.fillRect(8, 10, 85, 7, RED);
tft.setTextColor(BLACK);
tft.println("Qalong e hlolehile!");
khutla;
}
tft.setTextColor(WHITE);
Serial.println("ho qala ho entsoe");
tft.println("Ho qalisoa ho entsoe");
tieho (2000);
//////// Nako le letsatsi la ho bala le ho abela mefuta e fapaneng
t = rtc.getTime ();
time_sec_prev = t.sec;
time_day_prev = t.date;
//////// Hlahisa letsatsi ka likhoka e le hore u se ke ua emela hore letsatsi le fetohe bakeng sa pontšo
tft.setCursor(180, 0); // ho beha boemo ba sesupa
tft.fillRect(178, 0, 65, 7, GRAY); // ho hleka sebaka sa tlhahiso ya nako
tft.setTextSize(1);
tft.print(rtc.getDateStr());
////////Outlwa lebitso la dintho tse laolang
tft.setTextSize(2);
tft.setCursor(60, 25);
tft.println (utf8rus("Winches I");
//////// Ho theha faele ea log le ho hlahisa sephetho sa boiteko ba ho bopa
tft.setTextSize(1);
tft.setCursor(130, 10); // haeba faele ea log 2.txt e bōptjoa, joale ho ngolla faele ho tla tsoela pele
haeba (SD.exists(perv)) {
//tft.setCursor(0, 90);
tft.println(perv);
Serial.println(perv);
} hape {
myFile = SD.open(perv, FILE_WRITE); // haeba faele 2.txt e le sieo, e tla etsoa
myFile.koala();
tft.println(perv);
Serial.println(perv);
}
}

sekheo se se nang letho (ha se na letho) {
//////// Ho hlahloba boteng ba kopo ea ho hlahisa logi ho sebali sa boema-kepe ba COM
haeba (Serial.available() > 0) {
haeba (1 == Serial.bala());
//////// 'Me haeba "1" e amoheloa, joale tlhahiso
File myFile = SD.open(perv);
// haeba faele e fumaneha, e ngolle:
haeba (myFile) {
ha (myFile.available()) {
Serial.ngola(myFile.read());
}
myFile.koala();
}
hosele {
Serial.println("ho bula phoso .txt");
}
}
////////Nako ya ho bala
t = rtc.getTime ();
tft.setTextColor(WHITE);
//////// Haeba nako e fetohile, joale bonts'a lipalo tse ncha tsa oache
haeba (time_sec_prev != t.sec) {
tft.setCursor(120, 0); // ho beha boemo ba sesupa
tft.fillRect(118, 0, 50, 7, GRAY); // ho hleka sebaka sa tlhahiso ya nako
tft.setTextSize(1);
tft.print(rtc.getTimeStr()); // lipalo tsa oache ea tlhahiso
time_sec_prev = t.sec;
}
//////// Haeba letsatsi le fetohile, hlahisa letsatsi le lecha
haeba (time_day_prev != t.date) {
tft.setCursor(180, 0); // ho beha boemo ba sesupa
tft.fillRect(178, 0, 65, 7, GRAY); // sebaka se hlakileng sa letsatsi
tft.setTextSize(1);
tft.print(rtc.getDateStr()); // bonts'a lipalo tsa letsatsi
time_day_prev = t.date;
}
//////// Haeba kamohelo ea seea-le-moea e fumaneha, joale
haeba (radio.available(&pipe)) {
////////ho hlahloba hore na buffer e amohelang e tletse,
radio.bala(&data, sizeof(data));
//////// haeba aterese e hlokahalang ea transmitter e fumaneha, joale
haeba (pipe == 1) {
////////e emetse tatellano e tsamaisanang ya zero ho tsebahatsa
//ho qala ho thibela data
haeba (data == 0000) {
rc = 0;
} hape {
rc++;
}
//////// Ho rekota litekanyetso tsa li-counter le ho li bala ka 10th le 100th ea hora
haeba (rc == 1) {
leb_1 = data / 3600.0;
}

haeba (rc == 2) {
leb_2 = data / 3600.0;
}

haeba (rc == 3) {
leb_3 = data / 3600.0;
}

haeba (rc == 4) {
leb_4 = data / 3600.0;
}
}
}
r++;
k++; // k'haontane feela
//////// Ntlafatso ya data ka nako e itseng
haeba (r>= 6500) {
tft.setTextSize(2);
tft.fillRect(0, 41, 180, 64, GRAYD);
Serial.println("Lebedki I");
tft.setCursor(0, 41);
tft.println(leb_1);
Serial.println(leb_1);
tft.println(leb_2);
Serial.println(leb_2);
tft.println(leb_3);
Serial.println(leb_3);
tft.println(leb_4);
Serial.println(leb_4);
Serial.println(k);
r = 0;
}
//////// Ngola data ho log ho SD metsotso e meng le e meng e 10.
haeba ((t.min % 10 == 0) && (t.sec == 0)) {
tft.setTextSize(1);
tft.setCursor(200, 10);
tft.setTextColor(BLACK);
//////// Ho theha khoele ka sebopeho sa .csv
String dataString = Khoele (rtc.getDateStr()) + ", "+(rtc.getTimeStr()) + ", " + (leb_1) + ", " + (leb_2)
+ ", " + (leb_3) + ", " + (leb_4) + ", ";
//////// Ngola faeleng 'me u hlahise liphetho tsa mokhoa oa ho ngola
myFile = SD.open(perv, FILE_WRITE); // haeba ho se na faele e bitsoang "2.txt", e tla etsoa.
haeba (myFile) {
myFile.println(dataString);
myFile.koala();
tft.fillRect(198, 8, 42, 10, THOBELA);
tft.println("SD OK");
Serial.println("SD OK");
tieho(900); // lieha, ho seng joalo e tlaleha ho baloa ha 13 ho fihlela motsotsoana o fetile
} hape {
tft.fillRect(198, 8, 42, 10, RED);
tft.println("SD ERR");
Serial.println("SD ERR");
}
}
}Lenaneo la ho fetolela litlhaku/* Hlakola lifonti tsa Serussia ho tloha UTF-8 ho ea ho Windows-1251 */

String utf8rus(Mohloli oa likhoele)
{
ke,k;
Sepheo sa likhoele;
saennweng char n;
char m[2] = {'0', '' };

k = mohloli.bolelele(); ke = 0;

ha (ke <k) {
n = mohloli[i]; ke++;

haeba (n >= 0xC0) {
switjha (n) {
mohlala 0xD0: {
n = mohloli[i]; ke++;
haeba (n == 0x81) {n = 0xA8; khefu; }
haeba (n >= 0x90 && n <= 0xBF) n = n + 0x30;//0x2F
qhetsola;
}
mohlala 0xD1: {
n = mohloli[i]; ke++;
haeba (n == 0x91) {n = 0xB8; khefu; }
haeba (n >= 0x80 && n <= 0x8F) n = n + 0x70;//0x6F
qhetsola;
}
}
}
m[0] = n; target = target + Khoele(m);
}
sepheo sa ho khutlisa;
}Lenaneo la transcoding la litlhaku bakeng sa tlhahiso ea Cyrillic ka ho sebelisa laeborari ea Adafruit_GFX le behiloe foldareng e tšoanang le lenaneo le ka sehloohong. Hape o hloka ho khutlisa faele ea glcdfont.c ho Adafruit_GFX ka fonte e fapaneng. ke laebrari e nang le sebaka se hlokahalang. Lintlha tse ling mabapi le Russification li ka fumanoa habonolo Marang-rang.
Ho akaretsa, ke tla re tsamaiso e phetse ho latela litebello, ho se ho le bonolo ho shebella nako ea ts'ebetso ea lisebelisoa. Le hoja ntho e 'ngoe le e' ngoe e bokane holim'a liboto tsa bohobe, ha ho na litletlebo tsa hang-hang mabapi le mosebetsi. Lintho tsa pele li 'nile tsa sebetsa ka nako e fetang likhoeli tse tšeletseng' me li pholohile mariha. Moralo oa morao-rao E 'nile ea sebetsa bakeng sa likarolo tse 9 tse laoloang ho tloha ka la 5 Hlakubele' me nako ea ts'ebetso e ntse e ngolisoa ka molao ho e sebelisa.

Source: www.habr.com

Eketsa ka tlhaloso