Bonjour,
j'ai besoin d'une aide pour l'affichage sur le moniteur série de mon Arduino des informations reçu de la carte émettrice dans le protocole I2C
je reçois bien les informations avec sur RX de l'Arduino récepteur mais sur le moniteur série l'information est découpée en ce sens qu'elle s'affiche de manière verticale au lieu d'horizontale et j'aimerai une aide pour résoudre ce problème.
ci joint les codes
carte TX
#include "RTClib.h" #include <LiquidCrystal.h> #include <Wire.h> #include <SoftwareSerial.h> #define TEMPTYPE 0 // Use 0 for Celsius, SoftwareSerial mySerial(10, 11); int affiche=1; int start = 9; int en1=8; float t=0; float h=0; float p=0; String tRX; String hRX; String pRX; uint32_t delayMs; unsigned long Temps=millis(); unsigned long Temps1=millis(); const int rs = 2, EN = 3, D4 = 4, D5 = 5, D6 = 6, D7 = 7; LiquidCrystal lcd(rs, EN, D4, D5, D6, D7); DS1307 rtc; String RX; void setup() { Serial.begin(9600); Serial.println("ENTER Commands:"); mySerial.begin(9600); lcd.begin(16, 2); // utilisation d'un écran 16 colonnes et 2 lignes #ifdef AVR Wire.begin(); #else Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due #endif rtc.begin(); if (! rtc.isrunning()) { Serial.println("RTC is NOT running!"); // following line sets the RTC to the date & time this sketch was compiled rtc.adjust(DateTime(__DATE__, __TIME__)); } lcd.setCursor(0, 0); // top left lcd.print("bonjour"); delay(2000); lcd.print(" "); pinMode(start, INPUT); mySerial.write("AT+CONA0x882583F131BB \n"); Temps = millis(); } void loop() { if (mySerial.available()) { RX=(mySerial.readStringUntil(58)); Serial.println(RX); lcd.setCursor(0, 0); if(RX=="1"){ tRX=mySerial.readStringUntil(58); t= tRX.toFloat(); Serial.println(t); char tempBuffer[5]; dtostrf(t, 5, 2, tempBuffer); Wire.beginTransmission(4); // Envoyer vers device #4 Serial.println(tempBuffer); Wire.write(tempBuffer); Wire.endTransmission(); // Arreter la transmissionndelay(1000); // Attendre 1s } if(RX=="2"){ hRX=mySerial.readStringUntil(58); h= hRX.toFloat(); Serial.println(h); char tempBuffer[5]; dtostrf(h, 5, 2, tempBuffer); Wire.beginTransmission(4); // Envoyer vers device #4 Serial.println(tempBuffer); Wire.write(tempBuffer); Wire.endTransmission(); // Arreter la transmissionndelay(1000); // Attendre 1s } if(RX=="3"){ pRX=mySerial.readStringUntil(58); p= pRX.toFloat(); Serial.println(p); char tempBuffer[5]; dtostrf(p, 5, 2, tempBuffer); Wire.beginTransmission(4); // Envoyer vers device #4 Serial.println(tempBuffer); Wire.write(tempBuffer); Wire.endTransmission(); // Arreter la transmissionndelay(1000); // Attendre 1s } } if (Serial.available()) { mySerial.write(Serial.read()); } if (millis()-Temps1>1000){ lcd.setCursor(0, 1); DateTime now = rtc.now(); lcd.print(now.year(), DEC); lcd.print('/'); Wire.print('/'); Wire.beginTransmission(4); // Envoyer vers device #4 Serial.print(now.year(), DEC); Serial.print('/'); Wire.print(now.year(), DEC); Wire.endTransmission(); // Arreter la transmissionndelay(1000); // Attendre 1s lcd.print(now.month(), DEC); Wire.beginTransmission(4); // Envoyer vers device #4 Serial.print(now.month(), DEC); Serial.print('/'); Wire.print(now.month(), DEC); Wire.print('/'); Wire.endTransmission(); // Arreter la transmissionndelay(1000); // Attendre 1s lcd.print('/'); lcd.print(now.day(), DEC); Wire.beginTransmission(4); // Envoyer vers device #4 Serial.print(now.day(), DEC); Serial.print(' '); Wire.print(now.day(), DEC); Wire.print(' '); Wire.print(' '); Wire.print(' '); Wire.endTransmission(); // Arreter la transmissionndelay(1000); // Attendre 1s lcd.print(' '); lcd.print(' '); lcd.print(now.hour(), DEC); Wire.beginTransmission(4); // Envoyer vers device #4 Serial.print(now.hour(), DEC); Serial.print(' '); Serial.print(':'); Wire.print(':'); Wire.endTransmission(); // Arreter la transmissionndelay(1000); // Attendre 1s lcd.print(':'); lcd.println(now.minute(), DEC); Wire.beginTransmission(4); // Envoyer vers device #4 Wire.println(now.minute(), DEC); Wire.print(' '); Serial.println(now.minute(), DEC); Wire.endTransmission(); // Arreter la transmissionndelay(1000); // Attendre 1s Temps1=millis(); } if (millis()-Temps>5000){ if(affiche==1){ lcd.setCursor(0,0); lcd.print(" "); lcd.setCursor(0,0); lcd.print("Temp "); lcd.println(t); } if(affiche==2){ lcd.setCursor(0, 0); // top left lcd.print(" "); lcd.setCursor(0,0); lcd.print("Humidite "); lcd.print(h); } if(affiche==3){ lcd.setCursor(0, 0); // top left lcd.print(" "); lcd.setCursor(0, 0); // top left lcd.print("Pression "); lcd.print(p); } Temps=millis(); affiche++; if(affiche>3){ affiche=1; } } }
#include <Wire.h> #include "RTClib.h" #define START_CONVERT 0xEE #define STOP_CONVERT 0x22 #include <SoftwareSerial.h> String readString1=""; String readString2; String readString3; String readString4; String readString5; String readString6; String readString7; String readString8; String tRX; String hRX; String pRX; String RX; void setup() { Wire.begin(4); // join i2c bus with address #8 Wire.onReceive(receiveEvent); // register event Serial.begin(9600); Wire.write(START_CONVERT); } void manageEvent() { if (Wire.available() > 1) { // Enregistre le fait qu'au moins une valeur a été reçue sur le bus I2C, ce qui désactive // totalement l'effet du bouton. //receivedI2CSignal = true; int readString = Wire.read(); readString = readString < 0 ? 0 : readString; readString = readString > 255 ? 255 : readString; Serial.print("Valeur lue sur le bus I2C : '"); Serial.print(readString); Serial.println("'."); } } void loop(){ } //function that executes whenever data is received from master //this function is registered as an event, see setup() void receiveEvent(int howMany) { while ( Wire.available()) { // loop through all but the last char c = Wire.read(); // receive byte as a character Serial.print(c); // print the character } int x = Wire.read(); // receive byte as an integer Serial.println(); // print the integer if(readString1 == "1:") { Serial.println("test3:"); tRX=readString1; } if(readString2 == "2:") { tRX=readString2; } if(readString3 == "3:"){ tRX=readString3; Serial.println("test3:"); } if(readString4 == "4:") { tRX=readString4; } if(readString5 == "5:") { tRX=readString5; } if(readString6 == "6:"){ tRX=readString6; } if(readString7 == "7:") { tRX=readString7; } if(readString8 == "8:") { tRX=readString8; } int h = Wire.read(); // receive byte as an integer Serial.println(readString1); // print the integer readString1=""; }