Bonjour, j’ai un programme pour récupérer les données de la sonde pH d’un de mes camarades et les renvoyer mais a la réception la valeur n’est pas la bonne sur le moniteur série.
Voici mon code partie émetteur
#include <VirtualWire.h> // inclusion de la librairie VirtualWire
#define SensorPin 0 //pH meter Analog output to Arduino Analog Input 0
unsigned long int avgValue; //Store the average value of the sensor feedback
float phValue ;
int buf[10],temp;
void setup() // Fonction setup()
{
Serial.begin(9600); // Initialisation du port série pour avoir un retour sur le serial monitor
Serial.println("Emetteur"); // Petit message de bienvenue
pinMode (A0, INPUT);
vw_setup(2000); // initialisation de la librairie VirtualWire à 2000 bauds (note: je n'utilise pas la broche PTT)
Serial.print("");
pinMode(13,OUTPUT);
Serial.begin(9600);
Serial.println("Ready"); //Test the serial monitor
}
void loop() // Fonction loop()
{
phValue=analogRead(A0);
Serial.print(phValue);
Serial.print(" "); // On signale le début de l'envoi
vw_send((uint8_t *)&phValue, sizeof phValue ); // On envoie le message
vw_wait_tx(); // On attend la fin de l'envoi
Serial.println(""); // On signal la fin de l'envoi
delay(1000); // Et on attend 1s pour pas flooder
for(int i=0;i<10;i++) //Get 10 sample value from the sensor for smooth the value
{
buf[i]=analogRead(SensorPin);
delay(10);
}
for(int i=0;i<9;i++) //sort the analog from small to large
{
for(int j=i+1;j<10;j++)
{
if(buf[i]>buf[j])
{
temp=buf[i];
buf[i]=buf[j];
buf[j]=temp;
}
}
}
avgValue=0;
for(int i=2;i<8;i++) //take the average value of 6 center sample
avgValue+=buf[i];
float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
phValue=3.5*phValue; //convert the millivolt into pH value
Serial.print(" pH:");
Serial.print(phValue,2);
Serial.println(" ");
digitalWrite(13, HIGH);
delay(800);
digitalWrite(13, LOW);
}
et la partie recepteur
#include <VirtualWire.h> // inclusion de la librairie VirtualWire
void setup() // Fonction setup()
{
Serial.begin(9600); // Initialisation du port série pour avoir un retour sur le serial monitor
Serial.println("Recepteur"); // Petit message de bienvenue
vw_setup(2000); // initialisation de la librairie VirtualWire à 2000 bauds (note: je n'utilise pas la broche PTT)
vw_rx_start(); // Activation de la partie réception de la librairie VirtualWire
}
float phValue;
void loop() // Fonction loop()
{
if (vw_wait_rx_max(200)) // Si un message est reçu dans les 200ms qui viennent
{
uint8_t lg=sizeof phValue;
if (vw_get_message((uint8_t *)&phValue, &lg)) // On copie le message, qu'il soit corrompu ou non
{
Serial.print("RX : ");
Serial.println(phValue);
}
}
}