Salve a tutti sono innanzitutto complimenti per il forum. Sono un nuovo utente alle prime armi con la programmazione Arduino. Vi spiego la mia problematica. Vorrei far comunicare due coppie di trasmettitori- ricevitori ad infrarosso (per realizzare in seguito un parcheggio automatizzato). Nello specifico il ricevitore è realizzato con un TSOP 34838 (sensibile ad una portante a 38 kHz). Finora sono riuscito a far funzionare una sola coppia di trasmettitori- ricevitori alla volta sfruttando una uscita pwm, la 11. Ho provato poi a modificare lo sketch in particolare i registri per utilizzare lo stesso sketch e utilizzare l'altra uscita pwm 3 (le porte 11 e 3 infatti sfruttano entrambi il timer0). Infatti risolto questo problematica vorrei far comunicare due coppie di trasmettitori-ricevitori ir contemporaneamente (collegate appunto alle porte 3 e 11) Dove sbaglio? E' possibile utilizzare per farlo le due porte 11 e 3 che fanno uso entrambi del timer0? Può essere questa la problematica? Lo sketch che ho adoperato (funzionante) per fare comunicare una singola coppia di Tx-Rx (porta 11) è il seguente:
#define RXTSOP 2 //Pin output TSOP
#define TXIR 11 //or pin 3 LED IR
#define LED13 7 //LED on pin 13
#include <Servo.h>
Servo myservo; // create servo object to control a servo
#define ServoM 12 //Connected to the servo motor.
#define BarLow 177 //Low position of the barrier.
#define BarUp 95 //Up position of the barrier.
//flag
boolean transmitting_IR; //transmission flag
// turn_off , turn_on, detect functions come as is from
// http://www.eng.utah.edu/~cs1410/Labs/lab09.html
void turn_off_IR ()
{
// Instead of just adjusting the output on pin 11, this code also
// turns off the timer controlling the PWM output on pin 11
TCCR2A = 0; // Disconnect PWM
TCCR2B = 0; // Stops the timer
OCR2A = 0; // No timer top
digitalWrite(TXIR, LOW); // Ensure output is off
transmitting_IR = false;
}
void turn_on_IR ()
{
// Set up Timer2 (which can be connected to pins 3 and 11)
// For full details, see:
// arduino.cc/en/Tutorial/SecretsOfArduinoPWM
// The syntax here has me baffled, but the patterns of usage
// are clear if you look at the ATMega328 diagrams.
// _BV appears to stand for 'bit value'
// Different bits need to be set to control each timer
// Refer to diagrams for clarity
TCCR2A = _BV(WGM21) | _BV(COM2A0); // This mode toggles output once per timer cycle
TCCR2B = _BV(CS20); // Do not scale the clock down - use 16 MHz timer rate.
OCR2A = 210; // Divide sys. clock by 210, 1/2 cycle = 76 khz, 1 cycle = 38 khz
// Output pin 11 should now be emitting a 38 khz signal.
transmitting_IR = true;
}
void detectIR()
{
if(digitalRead(RXTSOP)){
Serial.println(digitalRead(RXTSOP));
digitalWrite(LED13 ,HIGH);
myservo.write(BarUp);
delay(5000);
myservo.write(BarLow);
}else{
Serial.println(digitalRead(RXTSOP));
digitalWrite(LED13 ,LOW);
}
}
void setup(){
Serial.begin (9600);
myservo.attach(ServoM); // attaches the servo.
myservo.write(BarLow); //Barrier in the low position
pinMode(TXIR, OUTPUT);
pinMode(RXTSOP, INPUT);
turn_on_IR();
delay(100);
}
void loop(){
detectIR(); // search for IR
delay(50);
}
Tra parentesi ho modificato il seguente sketch per adoperare la porta 3 nel seguente modo:
Ho sostituito COM0A0 con COM0B0 e OCR0A con OCR0B. Ma niente
Spero mi possiate aiutare. Grazie in anticipo