Problém s uploadom na arduino uno

Odpovědět
JanKubica
Příspěvky: 1
Registrován: 11 bře 2018, 10:00
Reputation: 0

Problém s uploadom na arduino uno

Příspěvek od JanKubica » 11 bře 2018, 10:16

Ahojte mám rozrobený projekt na ovládanie relé pomocou encodera, doteraz všetko fungovalo ok.
Keď som chcel zapojiť dve relé a ovládať dvoma samostanými encodermy nastal problém pri uplode, v programe mi síce napíše že nahrávanie dokončerné ale program samotný sa na arduino neaploadoval(display sa predtým vždy vypol) samotné arduino funguje, na overenie som tam skúsil nahrať jednoduchý "HELLO WORLD" a program prebehol v poriadku.
V prílohe posielam program keď niekto nájde chybu dajte púrosím vedieť.

Ešte jedna vec, keď som zapojil iba jedne encoder fungovalo na piny 3-4 fungovalo to ale akonáhle som ten encoder dal na ďalšie dva piny už to nefungovalo a ani upload neprebehol...

PROGRAM:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

// LCD SDA pin - A4
// LCD SCL pin - A5
const int PinA1 = 3; // ENCODER1 S2-D3
const int PinB1 = 4; // ENCODER1 S1-D4

const int PinA2 = 6; // ENCODER2 S2-11
const int PinB2 = 7; // ENCODER2 S1-12

int lastCount1 = 0; // LAST ROTTARY VALUE
int lastCount2 = 0;

// Updated by the ISR (Interrupt Service Routine)
volatile int virtualPositionD = 0;
volatile int virtualPositionP = 0;

// VARIABLES FOR THERMISTOR and SET UP VALUE FOR HEATER
int ThermistorPin1 = 0; // ANALOG PIN A0 FOR THERMISTOR 1
int ThermistorPin2 = 1; // ANALOG PIN A1 FOR THERMISTOR 2
int Vo;
float R1 = 10000; // KNOWN RESISTOR (10kOHM)
float logR2, R2, T1, Tc1, T2, Tc2;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
int low=25; // SETTING OF LOW TEMPERATURE
int medium=28; // SETTING OF MEDIUM TEMPERATURE
int high=32; // SETTING OF HIGH TEMPERATURE

int timer2=1000; // DELAY IN TEMPERATURE SECTION

// ------------------------------------------------------------------
// INTERRUPT INTERRUPT INTERRUPT INTERRUPT INTERRUPT
// ------------------------------------------------------------------

void isr1 ()
{
static unsigned long lastInterruptTime1 = 0;
unsigned long interruptTime1 = millis();
// If interrupts come faster than 5ms, assume it's a bounce and ignore
if (interruptTime1 - lastInterruptTime1 > 5)
{
if (digitalRead(PinB1) == LOW)
{
virtualPositionD=virtualPositionD-1 ; // Could be -5 or -10
}
else
{
virtualPositionD=virtualPositionD+1 ; // Could be +5 or +10
}
// Restrict value from 0 to +3
virtualPositionD = min(3, max(0, virtualPositionD));
// Keep track of when we were here last (no more than every 5ms)
lastInterruptTime1 = interruptTime1;
}
}
void isr2 ()
{
static unsigned long lastInterruptTime2 = 0;
unsigned long interruptTime2 = millis();
if (interruptTime2 - lastInterruptTime2 > 5)
{
if (digitalRead(PinB2) == LOW)
{
virtualPositionP=virtualPositionP-1;
}
else
{
virtualPositionP=virtualPositionP+1;
}
// Restrict value from 0 to +3
virtualPositionP=min(3, max(0, virtualPositionP));
// Keep track of when we were here last (no more than every 5ms)
lastInterruptTime2 = interruptTime2;
}
}

void setup()
{
// Rotary pulses are INPUTs
pinMode(PinA1, INPUT);
pinMode(PinB1, INPUT);

pinMode(PinA2, INPUT);
pinMode(PinB2, INPUT);

// Attach the routine to service the interrupts
attachInterrupt(digitalPinToInterrupt(PinA1), isr1, LOW);
attachInterrupt(digitalPinToInterrupt(PinA2), isr2, LOW);

lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(" WELCOME ");
lcd.print(" JAN ");
delay(1000);
lcd.clear();

pinMode(2, OUTPUT); // RELE DRIVER
pinMode(5, OUTPUT); // RELE PASSENGER
Serial.begin(9600);
}

void loop()
{
Serial.print("virtualPositionD: ");
Serial.println(virtualPositionD);
Serial.print("virtualPositionP: ");
Serial.println(virtualPositionP);
Serial.println("");
Serial.println(Tc1);
Serial.println(" ");


// MAIN PROGRAM FOR CONTROL RELEY START
if (virtualPositionD==0)
{
lcd.setCursor(0,0);
lcd.print("D: OFF");
digitalWrite(2,LOW);
}
else if (virtualPositionD==1)
{
lcd.setCursor(0,0);
lcd.print("D: LOW");
if (Tc1<low and virtualPositionD==1)
{
digitalWrite(2,HIGH);
}
else if (Tc1>low and virtualPositionD==1)
{
digitalWrite(2,LOW);
}
}
else if (virtualPositionD==2)
{
lcd.setCursor(0,0);
lcd.print("D: MED");
if (Tc1<medium and virtualPositionD==2)
{
digitalWrite(2,HIGH);
}
else if (Tc1>medium and virtualPositionD==2)
{
digitalWrite(2,LOW);
}
}
else if (virtualPositionD==3)
{
lcd.setCursor(0,0);
lcd.print("D: HIG");
if (Tc1<high and virtualPositionD==3)
{
digitalWrite(2,HIGH);
}
else if (Tc1>high and virtualPositionD==3)
{
digitalWrite(2,LOW);
}
}
// MAIN PROGRAM FOR CONTROL RELEY START
if (virtualPositionP==0)
{
lcd.setCursor(0,1);
lcd.print("P: OFF");
digitalWrite(5,LOW);
}
else if (virtualPositionP==1)
{
lcd.setCursor(0,1);
lcd.print("P: LOW");
if (Tc2<low and virtualPositionP==1)
{
digitalWrite(5,HIGH);
}
else if (Tc2>low and virtualPositionP==1)
{
digitalWrite(5,LOW);
}
}
else if (virtualPositionP==2)
{
lcd.setCursor(0,1);
lcd.print("P: MED");
if (Tc2<medium and virtualPositionP==2)
{
digitalWrite(5,HIGH);
}
else if (Tc2>medium and virtualPositionP==2)
{
digitalWrite(5,LOW);
}
}
else if (virtualPositionP==3)
{
lcd.setCursor(0,1);
lcd.print("P: HIG");
if (Tc2<high and virtualPositionP==3)
{
digitalWrite(5,HIGH);
}
else if (Tc2>high and virtualPositionP==3)
{
digitalWrite(5,LOW);
}
}

// THERMISTOR1 START
Vo = analogRead(ThermistorPin1);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
T1 = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
Tc1 = T1 - 273.15;
lcd.setCursor(7,0);
lcd.print(Tc1);
lcd.print(" C ");
delay(timer2);
// THERMISTOR1 END

// THERMISTOR2 START
Vo = analogRead(ThermistorPin2);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
T2 = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
Tc2 = T2 - 273.15;
lcd.setCursor(7,1);
lcd.print(Tc2);
lcd.print(" C ");
delay(timer2);
// THERMISTOR2 END

// If the current rotary switch position has changed then update everything
if (virtualPositionD != lastCount1)
{
lastCount1 = virtualPositionD ; // Keep track of this new value
}
if (virtualPositionP != lastCount2)
{
lastCount2 = virtualPositionP ; // Keep track of this new value
}
}
Přílohy
NOVY_ENCODER_a_THERMISTOR_plus_LCD_choseSEAT_update_code.ino
PROGRAM
(8.02 KiB) Staženo 148 x

Odpovědět

Kdo je online

Uživatelé prohlížející si toto fórum: Žádní registrovaní uživatelé a 18 hostů