Bonjour à tous,
Je débute en Processing et Arduino, et j'ai commencé un ensemble de programmes me permettant de démarrer ou d'éteindre des alimentations d'une carte de facon séquencée, avec remesure des tensions et courant de chaque alimentation.
Le pc envoit 1 caractere au Arduino, celui-ci répond par un caractere, puis par soit des flottants, soit des entiers.
Je bute en processing sur la maniere de piloter mon switch() avec le premier caractere recu, puis remplir un tableau pour afficher des valeurs.
Pouvez vous m'aidez svp ?
Arduino:
//definition des broches de mesures courant tension
#define WrapP5Volts A0
#define WrapP5Amps A1
#define WrapP15Volts A2
#define WrapP15Amps A2
#define WrapM15Volts A3
#define WrapM15Amps A3
#define WrapP25Volts A4
#define WrapP25Amps A4
#define WrapM25Volts A5
#define WrapM25Amps A5
//definition des broches de sorties
#define CmdP5Volts 13
#define CmdP15Volts 12
#define CmdM15Volts 11
#define CmdP25Volts 10
#define CmdM25Volts 9
#define CmdRESET 8
#define LEDBoardPowered 7
// sequencement des alimentations
int TimeRESETLOWms = 100;
int Time5Vto15Vstartupms = 20;
int Time15Vto25Vstartupms = 30;
int Time25Vto15Vshutdownms = 30;
int Time15Vto5Vshutdownms = 20;
#define SERIAL_COM_SPEED 115200
int char_received = 0; // incoming serial byte
float P5Volts; // 5V voltage received from the serial port
float P5Amps; // 5V current received from the serial port
float P15Volts; // +15V voltage received from the serial port
float P15Amps; // +15V current received from the serial port
float M15Volts; // -15V voltage received from the serial port
float M15Amps; // -15V current received from the serial port
float P25Volts; // +25V voltage received from the serial port
float P25Amps; // +25V current received from the serial port
float M25Volts; // -25V voltage received from the serial port
float M25Amps; // -25V current received from the serial port
void setup()
{
Serial.begin(SERIAL_COM_SPEED);
pinMode(CmdP5Volts, OUTPUT);
pinMode(CmdP15Volts, OUTPUT);
pinMode(CmdM15Volts, OUTPUT);
pinMode(CmdP25Volts, OUTPUT);
pinMode(CmdM25Volts, OUTPUT);
pinMode(CmdRESET, OUTPUT);
pinMode(LEDBoardPowered, OUTPUT);
digitalWrite(CmdP5Volts, LOW); //commutation alim +5V
digitalWrite(CmdP15Volts, LOW);//commutation alim +15V
digitalWrite(CmdM15Volts, LOW);//commutation alim -15V
digitalWrite(CmdP25Volts, LOW);//commutation alim +25V
digitalWrite(CmdM25Volts, LOW);//commutation alim -25V
digitalWrite(CmdRESET, LOW);//reset inactif
digitalWrite(LEDBoardPowered, LOW);//temoin carte sous tension
}
void loop()
{
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
switch (Serial.read()) {
case 'M': // Board On
digitalWrite(CmdP5Volts, HIGH); //commutation alim +5V
delay(Time5Vto15Vstartupms);
digitalWrite(CmdP15Volts, HIGH);//commutation alim +15V
digitalWrite(CmdM15Volts, HIGH);//commutation alim -15V
delay(Time15Vto25Vstartupms);
digitalWrite(CmdP25Volts, HIGH);//commutation alim +25V
digitalWrite(CmdM25Volts, HIGH);//commutation alim -25V
delay(TimeRESETLOWms);
digitalWrite(CmdRESET, LOW);//reset inactif si LOW
digitalWrite(LEDBoardPowered, HIGH);
break;
case 'A': // Board Off
digitalWrite(CmdP25Volts, LOW);//commutation alim +25V
digitalWrite(CmdM25Volts, LOW);//commutation alim -25V
delay(Time25Vto15Vshutdownms);
digitalWrite(CmdP15Volts, LOW);//commutation alim +15V
digitalWrite(CmdM15Volts, LOW);//commutation alim -15V
delay(Time15Vto5Vshutdownms);
digitalWrite(CmdP5Volts, LOW); //commutation alim +5V
digitalWrite(LEDBoardPowered, LOW);
break;
case 'R': // Board reset
digitalWrite(CmdRESET, HIGH);//reset actif si HIGH
delay(TimeRESETLOWms);
digitalWrite(CmdRESET, LOW);//reset inactif si LOW
break;
case 'S':
//following data will be settings
Serial.print("S");
// send to PC time Settings
Serial.print(TimeRESETLOWms, DEC);
Serial.print(",");
Serial.print(Time5Vto15Vstartupms, DEC);
Serial.print(",");
Serial.print(Time15Vto25Vstartupms, DEC);
Serial.print(",");
Serial.print(Time25Vto15Vshutdownms, DEC);
Serial.print(",");
Serial.println(Time15Vto5Vshutdownms, DEC);
break;
case 'W': // receive from PC new time Settings
//ne marche pas
//prevoir la mise en memoire Flash
TimeRESETLOWms = Serial.read();
Time5Vto15Vstartupms = Serial.read();
Time15Vto25Vstartupms = Serial.read();
Time25Vto15Vshutdownms = Serial.read();
Time15Vto5Vshutdownms = Serial.read();
break;
case 'N': // voltage and current measurements
//following data to be measurement
Serial.print("N");
//sending of measurements
Serial.print(P5Volts, DEC);
Serial.print(",");
Serial.print(P5Amps, DEC);
Serial.print(",");
Serial.print(P15Volts, DEC);
Serial.print(",");
Serial.print(P15Amps, DEC);
Serial.print(",");
Serial.print(M15Volts, DEC);
Serial.print(",");
Serial.print(M15Amps, DEC);
Serial.print(",");
Serial.print(P25Volts, DEC);
Serial.print(",");
Serial.print(P25Amps, DEC);
Serial.print(",");
Serial.print(M25Volts, DEC);
Serial.print(",");
//envoit fin trame par ajout d'un linefeed
Serial.println(M25Amps, DEC);
break;
}
}
//Mesure des tensions et courant
P5Volts = analogRead(WrapP5Volts)/45.0;
// wait 10 milliseconds for the adc to settle
// after the last reading:
delay(10);
P5Amps = analogRead(WrapP5Amps)/160.0;
delay(10);
P15Volts = analogRead(WrapP15Volts)/15.5;
delay(10);
P15Amps = analogRead(WrapP15Amps)/733.0;
delay(10);
M15Volts = analogRead(WrapM15Volts)/15.5;
delay(10);
M15Amps = analogRead(WrapM15Amps)/800.0;
delay(10);
P25Volts = analogRead(WrapP25Volts)/9.1;
delay(10);
P25Amps = analogRead(WrapP25Amps)/400.0;
delay(10);
M25Volts = analogRead(WrapM25Volts)/9.1;
delay(10);
M25Amps = analogRead(WrapM25Amps)/700.0;
delay(10);
}